Skip to content
Browse files

If users are on the email to Phabricator, do not send them the Phabri…

…cator reply.

Summary: When we receive an email, figure out if any of the other tos and ccs are users. If they are, pass their phids through the stach as "exclude phids" and exclude them from getting the email.

Test Plan: used the various applications (audit, differential, maniphest) and noted emails were sent as expected.

Reviewers: epriestley, vrana

Reviewed By: vrana

CC: aran, Korvin, vrana

Maniphest Tasks: T1676

Differential Revision: https://secure.phabricator.com/D3645
  • Loading branch information...
1 parent b605878 commit d9c6e07f2c4e42aa20407c90119d667b1bc4611b @bobtrahan bobtrahan committed
Showing with 302 additions and 292 deletions.
  1. +14 −0 src/__phutil_library_map__.php
  2. +3 −1 src/applications/audit/PhabricatorAuditReplyHandler.php
  3. +1 −1 src/applications/audit/controller/PhabricatorAuditAddCommentController.php
  4. +33 −40 src/applications/audit/editor/PhabricatorAuditCommentEditor.php
  5. +1 −1 src/applications/conduit/method/differential/ConduitAPI_differential_close_Method.php
  6. +1 −1 src/applications/conduit/method/differential/ConduitAPI_differential_createcomment_Method.php
  7. +1 −1 src/applications/conduit/method/differential/ConduitAPI_differential_createrevision_Method.php
  8. +1 −1 src/applications/conduit/method/differential/ConduitAPI_differential_markcommitted_Method.php
  9. +2 −2 src/applications/conduit/method/differential/ConduitAPI_differential_updaterevision_Method.php
  10. +1 −0 src/applications/conduit/method/maniphest/ConduitAPI_maniphest_Method.php
  11. +1 −1 src/applications/conduit/method/phriction/ConduitAPI_phriction_edit_Method.php
  12. +3 −1 src/applications/differential/DifferentialReplyHandler.php
  13. +1 −1 src/applications/differential/controller/DifferentialCommentSaveController.php
  14. +2 −3 src/applications/differential/controller/DifferentialRevisionEditController.php
  15. +25 −26 src/applications/differential/editor/DifferentialCommentEditor.php
  16. +8 −14 src/applications/differential/editor/DifferentialRevisionEditor.php
  17. +1 −1 src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php
  18. +1 −1 src/applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php
  19. +13 −23 src/applications/differential/mail/DifferentialMail.php
  20. +1 −1 src/applications/diffusion/controller/DiffusionCommitEditController.php
  21. +3 −0 src/applications/maniphest/ManiphestReplyHandler.php
  22. +1 −0 src/applications/maniphest/controller/ManiphestBatchEditController.php
  23. +1 −0 src/applications/maniphest/controller/ManiphestSubpriorityController.php
  24. +1 −0 src/applications/maniphest/controller/ManiphestTaskEditController.php
  25. +1 −0 src/applications/maniphest/controller/ManiphestTransactionSaveController.php
  26. +13 −1 src/applications/maniphest/editor/ManiphestTransactionEditor.php
  27. +1 −0 src/applications/maniphest/event/ManiphestEdgeEventListener.php
  28. +10 −0 src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php
  29. +11 −1 src/applications/metamta/storage/PhabricatorMetaMTAMail.php
  30. +23 −0 src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php
  31. +6 −30 src/applications/people/PhabricatorUserEditor.php
  32. +2 −2 src/applications/phame/controller/blog/PhameBlogDeleteController.php
  33. +1 −1 src/applications/phame/controller/blog/PhameBlogEditController.php
  34. +2 −2 src/applications/phame/controller/post/PhamePostDeleteController.php
  35. +1 −1 src/applications/phame/controller/post/PhamePostEditController.php
  36. +1 −1 src/applications/phriction/controller/PhrictionDeleteController.php
  37. +1 −1 src/applications/phriction/controller/PhrictionEditController.php
  38. +6 −17 src/applications/phriction/editor/PhrictionDocumentEditor.php
  39. +1 −1 src/applications/ponder/controller/PonderAnswerSaveController.php
  40. +1 −1 src/applications/ponder/controller/PonderCommentSaveController.php
  41. +1 −1 src/applications/ponder/controller/PonderQuestionAskController.php
  42. +1 −1 src/applications/ponder/controller/PonderVoteSaveController.php
  43. +6 −14 src/applications/ponder/editor/PonderAnswerEditor.php
  44. +5 −15 src/applications/ponder/editor/PonderCommentEditor.php
  45. +4 −14 src/applications/ponder/editor/PonderQuestionEditor.php
  46. +6 −16 src/applications/ponder/editor/PonderVoteEditor.php
  47. +1 −1 src/applications/project/controller/PhabricatorProjectCreateController.php
  48. +1 −1 src/applications/project/controller/PhabricatorProjectMembersEditController.php
  49. +1 −1 src/applications/project/controller/PhabricatorProjectProfileEditController.php
  50. +12 −21 src/applications/project/editor/PhabricatorProjectEditor.php
  51. +1 −1 src/applications/project/editor/__tests__/PhabricatorProjectEditorTestCase.php
  52. +3 −1 ...ications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php
  53. +2 −1 src/applications/search/controller/PhabricatorSearchAttachController.php
  54. +1 −1 src/applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php
  55. +3 −12 src/applications/subscriptions/editor/PhabricatorSubscriptionsEditor.php
  56. +47 −0 src/infrastructure/PhabricatorEditor.php
  57. +3 −3 src/infrastructure/edges/__tests__/PhabricatorEdgeTestCase.php
  58. +3 −9 src/infrastructure/edges/editor/PhabricatorEdgeEditor.php
View
14 src/__phutil_library_map__.php
@@ -668,6 +668,7 @@
'PhabricatorEdgeGraph' => 'infrastructure/edges/util/PhabricatorEdgeGraph.php',
'PhabricatorEdgeQuery' => 'infrastructure/edges/query/PhabricatorEdgeQuery.php',
'PhabricatorEdgeTestCase' => 'infrastructure/edges/__tests__/PhabricatorEdgeTestCase.php',
+ 'PhabricatorEditor' => 'infrastructure/PhabricatorEditor.php',
'PhabricatorEmailLoginController' => 'applications/auth/controller/PhabricatorEmailLoginController.php',
'PhabricatorEmailTokenController' => 'applications/auth/controller/PhabricatorEmailTokenController.php',
'PhabricatorEmailVerificationController' => 'applications/people/controller/PhabricatorEmailVerificationController.php',
@@ -1450,6 +1451,7 @@
'DifferentialChangesetParserTestCase' => 'ArcanistPhutilTestCase',
'DifferentialChangesetViewController' => 'DifferentialController',
'DifferentialComment' => 'DifferentialDAO',
+ 'DifferentialCommentEditor' => 'PhabricatorEditor',
'DifferentialCommentMail' => 'DifferentialMail',
'DifferentialCommentPreviewController' => 'DifferentialController',
'DifferentialCommentSaveController' => 'DifferentialController',
@@ -1507,6 +1509,7 @@
'DifferentialRevisionCommentView' => 'AphrontView',
'DifferentialRevisionDetailView' => 'AphrontView',
'DifferentialRevisionEditController' => 'DifferentialController',
+ 'DifferentialRevisionEditor' => 'PhabricatorEditor',
'DifferentialRevisionIDFieldParserTestCase' => 'PhabricatorTestCase',
'DifferentialRevisionIDFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialRevisionListController' => 'DifferentialController',
@@ -1714,6 +1717,7 @@
1 => 'PhabricatorMarkupInterface',
),
'ManiphestTransactionDetailView' => 'ManiphestView',
+ 'ManiphestTransactionEditor' => 'PhabricatorEditor',
'ManiphestTransactionListView' => 'ManiphestView',
'ManiphestTransactionPreviewController' => 'ManiphestController',
'ManiphestTransactionSaveController' => 'ManiphestController',
@@ -1765,6 +1769,7 @@
'PhabricatorApplicationsListController' => 'PhabricatorController',
'PhabricatorAuditAddCommentController' => 'PhabricatorAuditController',
'PhabricatorAuditComment' => 'PhabricatorAuditDAO',
+ 'PhabricatorAuditCommentEditor' => 'PhabricatorEditor',
'PhabricatorAuditCommitListView' => 'AphrontView',
'PhabricatorAuditController' => 'PhabricatorController',
'PhabricatorAuditDAO' => 'PhabricatorLiskDAO',
@@ -1839,6 +1844,7 @@
'PhabricatorDraftDAO' => 'PhabricatorLiskDAO',
'PhabricatorEdgeConfig' => 'PhabricatorEdgeConstants',
'PhabricatorEdgeCycleException' => 'Exception',
+ 'PhabricatorEdgeEditor' => 'PhabricatorEditor',
'PhabricatorEdgeGraph' => 'AbstractDirectedGraph',
'PhabricatorEdgeQuery' => 'PhabricatorQuery',
'PhabricatorEdgeTestCase' => 'PhabricatorTestCase',
@@ -2083,6 +2089,7 @@
'PhabricatorProjectController' => 'PhabricatorController',
'PhabricatorProjectCreateController' => 'PhabricatorProjectController',
'PhabricatorProjectDAO' => 'PhabricatorLiskDAO',
+ 'PhabricatorProjectEditor' => 'PhabricatorEditor',
'PhabricatorProjectEditorTestCase' => 'PhabricatorTestCase',
'PhabricatorProjectListController' => 'PhabricatorProjectController',
'PhabricatorProjectMembersEditController' => 'PhabricatorProjectController',
@@ -2202,6 +2209,7 @@
'PhabricatorStorageManagementWorkflow' => 'PhutilArgumentWorkflow',
'PhabricatorSubscribersQuery' => 'PhabricatorQuery',
'PhabricatorSubscriptionsEditController' => 'PhabricatorController',
+ 'PhabricatorSubscriptionsEditor' => 'PhabricatorEditor',
'PhabricatorSubscriptionsUIEventListener' => 'PhutilEventListener',
'PhabricatorSymbolNameLinter' => 'ArcanistXHPASTLintNamingHook',
'PhabricatorTaskmasterDaemon' => 'PhabricatorDaemon',
@@ -2229,6 +2237,7 @@
1 => 'PhutilPerson',
),
'PhabricatorUserDAO' => 'PhabricatorLiskDAO',
+ 'PhabricatorUserEditor' => 'PhabricatorEditor',
'PhabricatorUserEmail' => 'PhabricatorUserDAO',
'PhabricatorUserLDAPInfo' => 'PhabricatorUserDAO',
'PhabricatorUserLog' => 'PhabricatorUserDAO',
@@ -2304,6 +2313,7 @@
'PhrictionDiffController' => 'PhrictionController',
'PhrictionDocument' => 'PhrictionDAO',
'PhrictionDocumentController' => 'PhrictionController',
+ 'PhrictionDocumentEditor' => 'PhabricatorEditor',
'PhrictionDocumentPreviewController' => 'PhrictionController',
'PhrictionDocumentStatus' => 'PhrictionConstants',
'PhrictionDocumentTestCase' => 'PhabricatorTestCase',
@@ -2318,6 +2328,7 @@
1 => 'PhabricatorMarkupInterface',
2 => 'PonderVotableInterface',
),
+ 'PonderAnswerEditor' => 'PhabricatorEditor',
'PonderAnswerListView' => 'AphrontView',
'PonderAnswerPreviewController' => 'PonderController',
'PonderAnswerQuery' => 'PhabricatorOffsetPagedQuery',
@@ -2329,6 +2340,7 @@
0 => 'PonderDAO',
1 => 'PhabricatorMarkupInterface',
),
+ 'PonderCommentEditor' => 'PhabricatorEditor',
'PonderCommentListView' => 'AphrontView',
'PonderCommentMail' => 'PonderMail',
'PonderCommentQuery' => 'PhabricatorQuery',
@@ -2347,6 +2359,7 @@
),
'PonderQuestionAskController' => 'PonderController',
'PonderQuestionDetailView' => 'AphrontView',
+ 'PonderQuestionEditor' => 'PhabricatorEditor',
'PonderQuestionPreviewController' => 'PonderController',
'PonderQuestionQuery' => 'PhabricatorOffsetPagedQuery',
'PonderQuestionSummaryView' => 'AphrontView',
@@ -2355,6 +2368,7 @@
'PonderRuleQuestion' => 'PhabricatorRemarkupRuleObjectName',
'PonderUserProfileView' => 'AphrontView',
'PonderVotableView' => 'AphrontView',
+ 'PonderVoteEditor' => 'PhabricatorEditor',
'PonderVoteSaveController' => 'PonderController',
'QueryFormattingTestCase' => 'PhabricatorTestCase',
),
View
4 src/applications/audit/PhabricatorAuditReplyHandler.php
@@ -61,7 +61,9 @@ protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) {
->setContent($mail->getCleanTextBody());
$editor = new PhabricatorAuditCommentEditor($commit);
- $editor->setUser($actor);
+ $editor->setActor($actor);
+ $editor->setExcludeMailRecipientPHIDs(
+ $this->getExcludeMailRecipientPHIDs());
$editor->addComment($comment);
}
View
2 src/applications/audit/controller/PhabricatorAuditAddCommentController.php
@@ -61,7 +61,7 @@ public function processRequest() {
}
id(new PhabricatorAuditCommentEditor($commit))
- ->setUser($user)
+ ->setActor($user)
->setAttachInlineComments(true)
->addAuditors($auditors)
->addCCs($ccs)
View
73 src/applications/audit/editor/PhabricatorAuditCommentEditor.php
@@ -16,10 +16,9 @@
* limitations under the License.
*/
-final class PhabricatorAuditCommentEditor {
+final class PhabricatorAuditCommentEditor extends PhabricatorEditor {
private $commit;
- private $user;
private $attachInlineComments;
private $auditors = array();
@@ -30,11 +29,6 @@ public function __construct(PhabricatorRepositoryCommit $commit) {
return $this;
}
- public function setUser(PhabricatorUser $user) {
- $this->user = $user;
- return $this;
- }
-
public function addAuditors(array $auditor_phids) {
$this->auditors = array_merge($this->auditors, $auditor_phids);
return $this;
@@ -53,7 +47,7 @@ public function setAttachInlineComments($attach_inline_comments) {
public function addComment(PhabricatorAuditComment $comment) {
$commit = $this->commit;
- $user = $this->user;
+ $actor = $this->getActor();
$other_comments = id(new PhabricatorAuditComment())->loadAllWhere(
'targetPHID = %s',
@@ -64,12 +58,12 @@ public function addComment(PhabricatorAuditComment $comment) {
$inline_comments = id(new PhabricatorAuditInlineComment())->loadAllWhere(
'authorPHID = %s AND commitPHID = %s
AND auditCommentID IS NULL',
- $user->getPHID(),
+ $actor->getPHID(),
$commit->getPHID());
}
$comment
- ->setActorPHID($user->getPHID())
+ ->setActorPHID($actor->getPHID())
->setTargetPHID($commit->getPHID())
->save();
@@ -106,13 +100,13 @@ public function addComment(PhabricatorAuditComment $comment) {
$ccs = array_merge($ccs, $metacc);
}
- // When a user submits an audit comment, we update all the audit requests
+ // When an actor submits an audit comment, we update all the audit requests
// they have authority over to reflect the most recent status. The general
// idea here is that if audit has triggered for, e.g., several packages, but
// a user owns all of them, they can clear the audit requirement in one go
// without auditing the commit for each trigger.
- $audit_phids = self::loadAuditPHIDsForUser($this->user);
+ $audit_phids = self::loadAuditPHIDsForUser($actor);
$audit_phids = array_fill_keys($audit_phids, true);
$requests = id(new PhabricatorRepositoryAuditRequest())
@@ -128,7 +122,7 @@ public function addComment(PhabricatorAuditComment $comment) {
// and handle the no-effect cases (e.g., closing and already-closed audit).
- $user_is_author = ($user->getPHID() == $commit->getAuthorPHID());
+ $actor_is_author = ($actor->getPHID() == $commit->getAuthorPHID());
if ($action == PhabricatorAuditActionConstants::CLOSE) {
// "Close" means wipe out all the concerns.
@@ -144,25 +138,25 @@ public function addComment(PhabricatorAuditComment $comment) {
// user row (never package/project rows), and always affects the user
// row (other actions don't, if they were able to affect a package/project
// row).
- $user_request = null;
+ $actor_request = null;
foreach ($requests as $request) {
- if ($request->getAuditorPHID() == $user->getPHID()) {
- $user_request = $request;
+ if ($request->getAuditorPHID() == $actor->getPHID()) {
+ $actor_request = $request;
break;
}
}
- if (!$user_request) {
- $user_request = id(new PhabricatorRepositoryAuditRequest())
+ if (!$actor_request) {
+ $actor_request = id(new PhabricatorRepositoryAuditRequest())
->setCommitPHID($commit->getPHID())
- ->setAuditorPHID($user->getPHID())
+ ->setAuditorPHID($actor->getPHID())
->setAuditReasons(array("Resigned"));
}
- $user_request
+ $actor_request
->setAuditStatus(PhabricatorAuditStatusConstants::RESIGNED)
->save();
- $requests[] = $user_request;
+ $requests[] = $actor_request;
} else {
$have_any_requests = false;
foreach ($requests as $request) {
@@ -170,7 +164,8 @@ public function addComment(PhabricatorAuditComment $comment) {
continue;
}
- $request_is_for_user = ($request->getAuditorPHID() == $user->getPHID());
+ $request_is_for_actor =
+ ($request->getAuditorPHID() == $actor->getPHID());
$have_any_requests = true;
$new_status = null;
@@ -181,7 +176,7 @@ public function addComment(PhabricatorAuditComment $comment) {
// Commenting or adding cc's/auditors doesn't change status.
break;
case PhabricatorAuditActionConstants::ACCEPT:
- if (!$user_is_author || $request_is_for_user) {
+ if (!$actor_is_author || $request_is_for_actor) {
// When modifying your own commits, you act only on behalf of
// yourself, not your packages/projects -- the idea being that
// you can't accept your own commits.
@@ -189,7 +184,7 @@ public function addComment(PhabricatorAuditComment $comment) {
}
break;
case PhabricatorAuditActionConstants::CONCERN:
- if (!$user_is_author || $request_is_for_user) {
+ if (!$actor_is_author || $request_is_for_actor) {
// See above.
$new_status = PhabricatorAuditStatusConstants::CONCERNED;
}
@@ -203,7 +198,7 @@ public function addComment(PhabricatorAuditComment $comment) {
}
}
- // If the user has no current authority over any audit trigger, make a
+ // If the actor has no current authority over any audit trigger, make a
// new one to represent their audit state.
if (!$have_any_requests) {
$new_status = null;
@@ -227,7 +222,7 @@ public function addComment(PhabricatorAuditComment $comment) {
$request = id(new PhabricatorRepositoryAuditRequest())
->setCommitPHID($commit->getPHID())
- ->setAuditorPHID($user->getPHID())
+ ->setAuditorPHID($actor->getPHID())
->setAuditStatus($new_status)
->setAuditReasons(array("Voluntary Participant"))
->save();
@@ -270,7 +265,7 @@ public function addComment(PhabricatorAuditComment $comment) {
->setAuditorPHID($auditor_phid)
->setAuditStatus($audit_requested)
->setAuditReasons(
- array('Added by ' . $user->getUsername()))
+ array('Added by ' . $actor->getUsername()))
->save();
}
}
@@ -283,7 +278,7 @@ public function addComment(PhabricatorAuditComment $comment) {
->setAuditorPHID($cc_phid)
->setAuditStatus($audit_cc)
->setAuditReasons(
- array('Added by ' . $user->getUsername()))
+ array('Added by ' . $actor->getUsername()))
->save();
}
}
@@ -322,13 +317,10 @@ public static function loadAuditPHIDsForUser(PhabricatorUser $user) {
}
// The user can audit on behalf of all projects they are a member of.
- $query = new PhabricatorProjectQuery();
-
- // TODO: As above.
- $query->setViewer($user);
-
- $query->withMemberPHIDs(array($user->getPHID()));
- $projects = $query->execute();
+ $projects = id(new PhabricatorProjectQuery())
+ ->setViewer($user)
+ ->withMemberPHIDs(array($user->getPHID()))
+ ->execute();
foreach ($projects as $project) {
$phids[$project->getPHID()] = true;
}
@@ -341,18 +333,18 @@ private function publishFeedStory(
array $more_phids) {
$commit = $this->commit;
- $user = $this->user;
+ $actor = $this->getActor();
$related_phids = array_merge(
array(
- $user->getPHID(),
+ $actor->getPHID(),
$commit->getPHID(),
),
$more_phids);
id(new PhabricatorFeedStoryPublisher())
->setRelatedPHIDs($related_phids)
- ->setStoryAuthorPHID($user->getPHID())
+ ->setStoryAuthorPHID($actor->getPHID())
->setStoryTime(time())
->setStoryType(PhabricatorFeedStoryTypeConstants::STORY_AUDIT)
->setStoryData(
@@ -445,6 +437,7 @@ private function sendMail(
->setThreadID($thread_id, $is_new)
->addHeader('Thread-Topic', $thread_topic)
->setRelatedPHID($commit->getPHID())
+ ->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs())
->setIsBulk(true)
->setBody($body);
@@ -484,8 +477,8 @@ private function renderMailBody(
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
$commit = $this->commit;
- $user = $this->user;
- $name = $user->getUsername();
+ $actor = $this->getActor();
+ $name = $actor->getUsername();
$verb = PhabricatorAuditActionConstants::getActionPastTenseVerb(
$comment->getAction());
View
2 src/applications/conduit/method/differential/ConduitAPI_differential_close_Method.php
@@ -63,8 +63,8 @@ protected function execute(ConduitAPIRequest $request) {
$editor = new DifferentialCommentEditor(
$revision,
- $request->getUser()->getPHID(),
DifferentialAction::ACTION_CLOSE);
+ $editor->setActor($request->getUser());
$editor->save();
$revision->setStatus(ArcanistDifferentialRevisionStatus::CLOSED);
View
2 ...applications/conduit/method/differential/ConduitAPI_differential_createcomment_Method.php
@@ -63,8 +63,8 @@ protected function execute(ConduitAPIRequest $request) {
$editor = new DifferentialCommentEditor(
$revision,
- $request->getUser()->getPHID(),
$action);
+ $editor->setActor($request->getUser());
$editor->setContentSource($content_source);
$editor->setMessage($request->getValue('message'));
$editor->setNoEmail($request->getValue('silent'));
View
2 ...pplications/conduit/method/differential/ConduitAPI_differential_createrevision_Method.php
@@ -54,7 +54,7 @@ protected function execute(ConduitAPIRequest $request) {
$revision = DifferentialRevisionEditor::newRevisionFromConduitWithDiff(
$fields,
$diff,
- $request->getUser()->getPHID());
+ $request->getUser());
return array(
'revisionid' => $revision->getID(),
View
2 ...applications/conduit/method/differential/ConduitAPI_differential_markcommitted_Method.php
@@ -67,8 +67,8 @@ protected function execute(ConduitAPIRequest $request) {
$editor = new DifferentialCommentEditor(
$revision,
- $request->getUser()->getPHID(),
DifferentialAction::ACTION_CLOSE);
+ $editor->setActor($request->getUser());
$editor->save();
}
View
4 ...pplications/conduit/method/differential/ConduitAPI_differential_updaterevision_Method.php
@@ -72,8 +72,8 @@ protected function execute(ConduitAPIRequest $request) {
array());
$editor = new DifferentialRevisionEditor(
- $revision,
- $revision->getAuthorPHID());
+ $revision);
+ $editor->setActor($request->getUser());
$editor->setContentSource($content_source);
$fields = $request->getValue('fields');
$editor->copyFieldsFromConduit($fields);
View
1 src/applications/conduit/method/maniphest/ConduitAPI_maniphest_Method.php
@@ -196,6 +196,7 @@ protected function applyRequest(
$transactions = $event->getValue('transactions');
$editor = new ManiphestTransactionEditor();
+ $editor->setActor($request->getUser());
$editor->applyTransactions($task, $transactions);
$event = new PhabricatorEvent(
View
2 src/applications/conduit/method/phriction/ConduitAPI_phriction_edit_Method.php
@@ -48,7 +48,7 @@ protected function execute(ConduitAPIRequest $request) {
$slug = $request->getValue('slug');
$editor = id(PhrictionDocumentEditor::newForSlug($slug))
- ->setUser($request->getUser())
+ ->setActor($request->getUser())
->setTitle($request->getValue('title'))
->setContent($request->getValue('content'))
->setDescription($request->getvalue('description'))
View
4 src/applications/differential/DifferentialReplyHandler.php
@@ -138,8 +138,10 @@ public function handleAction($body) {
try {
$editor = new DifferentialCommentEditor(
$this->getMailReceiver(),
- $actor->getPHID(),
$command);
+ $editor->setActor($actor);
+ $editor->setExcludeMailRecipientPHIDs(
+ $this->getExcludeMailRecipientPHIDs());
// NOTE: We have to be careful about this because Facebook's
// implementation jumps straight into handleAction() and will not have
View
2 src/applications/differential/controller/DifferentialCommentSaveController.php
@@ -37,7 +37,6 @@ public function processRequest() {
$editor = new DifferentialCommentEditor(
$revision,
- $request->getUser()->getPHID(),
$action);
$content_source = PhabricatorContentSource::newForSource(
@@ -48,6 +47,7 @@ public function processRequest() {
try {
$editor
+ ->setActor($request->getUser())
->setMessage($comment)
->setContentSource($content_source)
->setAttachInlineComments(true)
View
5 src/applications/differential/controller/DifferentialRevisionEditController.php
@@ -62,8 +62,6 @@ public function processRequest() {
if ($request->isFormPost() && !$request->getStr('viaDiffView')) {
- $user_phid = $request->getUser()->getPHID();
-
foreach ($aux_fields as $aux_field) {
$aux_field->setValueFromRequest($request);
try {
@@ -74,7 +72,8 @@ public function processRequest() {
}
if (!$errors) {
- $editor = new DifferentialRevisionEditor($revision, $user_phid);
+ $editor = new DifferentialRevisionEditor($revision);
+ $editor->setActor($request->getUser());
if ($diff) {
$editor->addDiff($diff, $request->getStr('comments'));
}
View
51 src/applications/differential/editor/DifferentialCommentEditor.php
@@ -16,10 +16,9 @@
* limitations under the License.
*/
-final class DifferentialCommentEditor {
+final class DifferentialCommentEditor extends PhabricatorEditor {
protected $revision;
- protected $actorPHID;
protected $action;
protected $attachInlineComments;
@@ -37,11 +36,9 @@
public function __construct(
DifferentialRevision $revision,
- $actor_phid,
$action) {
$this->revision = $revision;
- $this->actorPHID = $actor_phid;
$this->action = $action;
}
@@ -112,16 +109,16 @@ public function setNoEmail($no_email) {
}
public function save() {
- $revision = $this->revision;
- $action = $this->action;
- $actor_phid = $this->actorPHID;
- $actor = id(new PhabricatorUser())->loadOneWhere('PHID = %s', $actor_phid);
- $actor_is_author = ($actor_phid == $revision->getAuthorPHID());
- $allow_self_accept = PhabricatorEnv::getEnvConfig(
+ $actor = $this->requireActor();
+ $revision = $this->revision;
+ $action = $this->action;
+ $actor_phid = $actor->getPHID();
+ $actor_is_author = ($actor_phid == $revision->getAuthorPHID());
+ $allow_self_accept = PhabricatorEnv::getEnvConfig(
'differential.allow-self-accept', false);
$always_allow_close = PhabricatorEnv::getEnvConfig(
'differential.always-allow-close', false);
- $revision_status = $revision->getStatus();
+ $revision_status = $revision->getStatus();
$revision->loadRelationships();
$reviewer_phids = $revision->getReviewers();
@@ -135,7 +132,7 @@ public function save() {
if ($this->attachInlineComments) {
$inline_comments = id(new DifferentialInlineComment())->loadAllWhere(
'authorPHID = %s AND revisionID = %d AND commentID IS NULL',
- $this->actorPHID,
+ $actor_phid,
$revision->getID());
}
@@ -414,7 +411,7 @@ public function save() {
DifferentialRevisionEditor::addCC(
$revision,
$cc,
- $this->actorPHID);
+ $actor_phid);
}
$key = DifferentialComment::METADATA_ADDED_CCS;
@@ -490,12 +487,12 @@ public function save() {
if ($action != DifferentialAction::ACTION_RESIGN) {
DifferentialRevisionEditor::addCC(
$revision,
- $this->actorPHID,
- $this->actorPHID);
+ $actor_phid,
+ $actor_phid);
}
$comment = id(new DifferentialComment())
- ->setAuthorPHID($this->actorPHID)
+ ->setAuthorPHID($actor_phid)
->setRevisionID($revision->getID())
->setAction($action)
->setContent((string)$this->message)
@@ -541,7 +538,7 @@ public function save() {
DifferentialRevisionEditor::addCC(
$revision,
$cc_phid,
- $this->actorPHID);
+ $actor_phid);
$metacc[] = $cc_phid;
}
$metadata[DifferentialComment::METADATA_ADDED_CCS] = $metacc;
@@ -553,10 +550,10 @@ public function save() {
$revision->saveTransaction();
- $phids = array($this->actorPHID);
+ $phids = array($actor_phid);
$handles = id(new PhabricatorObjectHandleData($phids))
->loadHandles();
- $actor_handle = $handles[$this->actorPHID];
+ $actor_handle = $handles[$actor_phid];
$xherald_header = HeraldTranscript::loadXHeraldRulesHeader(
$revision->getPHID());
@@ -568,6 +565,7 @@ public function save() {
$comment,
$changesets,
$inline_comments))
+ ->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs())
->setToPHIDs(
array_merge(
$revision->getReviewers(),
@@ -586,7 +584,7 @@ public function save() {
'revision_author_phid' => $revision->getAuthorPHID(),
'action' => $comment->getAction(),
'feedback_content' => $comment->getContent(),
- 'actor_phid' => $this->actorPHID,
+ 'actor_phid' => $actor_phid,
);
id(new PhabricatorTimelineEvent('difx', $event_data))
->recordEvent();
@@ -596,11 +594,11 @@ public function save() {
->setStoryType(PhabricatorFeedStoryTypeConstants::STORY_DIFFERENTIAL)
->setStoryData($event_data)
->setStoryTime(time())
- ->setStoryAuthorPHID($this->actorPHID)
+ ->setStoryAuthorPHID($actor_phid)
->setRelatedPHIDs(
array(
$revision->getPHID(),
- $this->actorPHID,
+ $actor_phid,
$revision->getAuthorPHID(),
))
->setPrimaryObjectPHID($revision->getPHID())
@@ -642,10 +640,11 @@ private function filterAddedCCs(array $ccs) {
}
private function alterReviewers() {
- $revision = $this->revision;
- $added_reviewers = $this->getAddedReviewers();
+ $actor_phid = $this->getActor()->getPHID();
+ $revision = $this->revision;
+ $added_reviewers = $this->getAddedReviewers();
$removed_reviewers = $this->getRemovedReviewers();
- $reviewer_phids = $revision->getReviewers();
+ $reviewer_phids = $revision->getReviewers();
$reviewer_phids_map = array_fill_keys($reviewer_phids, true);
foreach ($added_reviewers as $k => $user_phid) {
@@ -672,7 +671,7 @@ private function alterReviewers() {
$reviewer_phids,
$removed_reviewers,
$added_reviewers,
- $this->actorPHID);
+ $actor_phid);
}
return array($added_reviewers, $removed_reviewers);
View
22 src/applications/differential/editor/DifferentialRevisionEditor.php
@@ -21,10 +21,9 @@
* reviewers, diffs, and CCs. Unlike simple edits, these changes trigger
* complicated email workflows.
*/
-final class DifferentialRevisionEditor {
+final class DifferentialRevisionEditor extends PhabricatorEditor {
protected $revision;
- protected $actorPHID;
protected $cc = null;
protected $reviewers = null;
@@ -35,24 +34,22 @@
private $auxiliaryFields = array();
private $contentSource;
- public function __construct(DifferentialRevision $revision, $actor_phid) {
+ public function __construct(DifferentialRevision $revision) {
$this->revision = $revision;
- $this->actorPHID = $actor_phid;
}
public static function newRevisionFromConduitWithDiff(
array $fields,
DifferentialDiff $diff,
- $user_phid) {
+ PhabricatorUser $actor) {
$revision = new DifferentialRevision();
$revision->setPHID($revision->generatePHID());
-
- $revision->setAuthorPHID($user_phid);
+ $revision->setAuthorPHID($actor->getPHID());
$revision->setStatus(ArcanistDifferentialRevisionStatus::NEEDS_REVIEW);
- $editor = new DifferentialRevisionEditor($revision, $user_phid);
-
+ $editor = new DifferentialRevisionEditor($revision);
+ $editor->setActor($actor);
$editor->copyFieldsFromConduit($fields);
$editor->addDiff($diff, null);
@@ -63,19 +60,16 @@ public static function newRevisionFromConduitWithDiff(
public function copyFieldsFromConduit(array $fields) {
+ $actor = $this->getActor();
$revision = $this->revision;
$revision->loadRelationships();
$aux_fields = DifferentialFieldSelector::newSelector()
->getFieldSpecifications();
- $user = id(new PhabricatorUser())->loadOneWhere(
- 'phid = %s',
- $this->actorPHID);
-
foreach ($aux_fields as $key => $aux_field) {
$aux_field->setRevision($revision);
- $aux_field->setUser($user);
+ $aux_field->setUser($actor);
if (!$aux_field->shouldAppearOnCommitMessage()) {
unset($aux_fields[$key]);
}
View
2 src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php
@@ -102,7 +102,7 @@ public function didParseCommit(
}
id(new PhabricatorEdgeEditor())
- ->setUser($user)
+ ->setActor($user)
->addEdge(
$task->getPHID(),
PhabricatorEdgeConfig::TYPE_TASK_HAS_COMMIT,
View
2 ...cations/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php
@@ -74,7 +74,7 @@ public function didWriteRevision(DifferentialRevisionEditor $editor) {
$rem_phids = array_diff($old_phids, $add_phids);
$edge_editor = id(new PhabricatorEdgeEditor())
- ->setUser($this->getUser());
+ ->setActor($this->getUser());
foreach ($add_phids as $phid) {
$edge_editor->addEdge($revision_phid, $edge_type, $phid);
View
36 src/applications/differential/mail/DifferentialMail.php
@@ -20,6 +20,7 @@
protected $to = array();
protected $cc = array();
+ protected $excludePHIDs = array();
protected $actorHandle;
@@ -91,6 +92,7 @@ public function send() {
$template
->setIsHTML($this->shouldMarkMailAsHTML())
->setParentMessageID($this->parentMessageID)
+ ->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs())
->addHeader('Thread-Topic', $this->getThreadTopic());
$template->setAttachments($attachments);
@@ -315,35 +317,23 @@ protected function formatText($text) {
return implode("\n", $text);
}
- public function setToPHIDs(array $to) {
- $this->to = $this->filterContactPHIDs($to);
+ public function setExcludeMailRecipientPHIDs(array $exclude) {
+ $this->excludePHIDs = $exclude;
return $this;
}
- public function setCCPHIDs(array $cc) {
- $this->cc = $this->filterContactPHIDs($cc);
- return $this;
+ public function getExcludeMailRecipientPHIDs() {
+ return $this->excludePHIDs;
}
- protected function filterContactPHIDs(array $phids) {
- return $phids;
-
- // TODO: actually do this?
+ public function setToPHIDs(array $to) {
+ $this->to = $to;
+ return $this;
+ }
- // Differential revisions use Subscriptions for CCs, so any arbitrary
- // PHID can end up CC'd to them. Only try to actually send email PHIDs
- // which have ToolsHandle types that are marked emailable. If we don't
- // filter here, sending the email will fail.
-/*
- $handles = array();
- prep(new ToolsHandleData($phids, $handles));
- foreach ($handles as $phid => $handle) {
- if (!$handle->isEmailable()) {
- unset($handles[$phid]);
- }
- }
- return array_keys($handles);
-*/
+ public function setCCPHIDs(array $cc) {
+ $this->cc = $cc;
+ return $this;
}
protected function getToPHIDs() {
View
2 src/applications/diffusion/controller/DiffusionCommitEditController.php
@@ -51,7 +51,7 @@ public function processRequest() {
$rem_proj_phids = array_diff($current_proj_phids,
$new_proj_phids);
$editor = id(new PhabricatorEdgeEditor());
- $editor->setUser($user);
+ $editor->setActor($user);
foreach ($rem_proj_phids as $phid) {
$editor->removeEdge($commit_phid, $edge_type, $phid);
}
View
3 src/applications/maniphest/ManiphestReplyHandler.php
@@ -167,7 +167,10 @@ protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) {
$editor = new ManiphestTransactionEditor();
+ $editor->setActor($user);
$editor->setParentMessageID($mail->getMessageID());
+ $editor->setExcludeMailRecipientPHIDs(
+ $this->getExcludeMailRecipientPHIDs());
$editor->applyTransactions($task, $xactions);
$event = new PhabricatorEvent(
View
1 src/applications/maniphest/controller/ManiphestBatchEditController.php
@@ -41,6 +41,7 @@ public function processRequest() {
$xactions = $this->buildTransactions($actions, $task);
if ($xactions) {
$editor = new ManiphestTransactionEditor();
+ $editor->setActor($user);
$editor->applyTransactions($task, $xactions);
}
}
View
1 src/applications/maniphest/controller/ManiphestSubpriorityController.php
@@ -59,6 +59,7 @@ public function processRequest() {
$xaction->setNewValue($after_pri);
$editor = new ManiphestTransactionEditor();
+ $editor->setActor($request->getUser());
$editor->applyTransactions($task, array($xaction));
}
View
1 src/applications/maniphest/controller/ManiphestTaskEditController.php
@@ -231,6 +231,7 @@ public function processRequest() {
$transactions = $event->getValue('transactions');
$editor = new ManiphestTransactionEditor();
+ $editor->setActor($user);
$editor->setAuxiliaryFields($aux_fields);
$editor->applyTransactions($task, $transactions);
View
1 src/applications/maniphest/controller/ManiphestTransactionSaveController.php
@@ -244,6 +244,7 @@ public function processRequest() {
$transactions = $event->getValue('transactions');
$editor = new ManiphestTransactionEditor();
+ $editor->setActor($user);
$editor->applyTransactions($task, $transactions);
$draft = id(new PhabricatorDraft())->loadOneWhere(
View
14 src/applications/maniphest/editor/ManiphestTransactionEditor.php
@@ -19,9 +19,10 @@
/**
* @group maniphest
*/
-final class ManiphestTransactionEditor {
+final class ManiphestTransactionEditor extends PhabricatorEditor {
private $parentMessageID;
+ private $excludePHIDs = array();
private $auxiliaryFields = array();
public function setAuxiliaryFields(array $fields) {
@@ -35,6 +36,15 @@ public function setParentMessageID($parent_message_id) {
return $this;
}
+ public function setExcludePHIDs(array $exclude) {
+ $this->excludePHIDs = $exclude;
+ return $this;
+ }
+
+ public function getExcludePHIDs() {
+ return $this->excludePHIDs;
+ }
+
public function applyTransactions(ManiphestTask $task, array $transactions) {
assert_instances_of($transactions, 'ManiphestTransaction');
@@ -221,6 +231,7 @@ protected function getSubjectPrefix() {
}
private function sendEmail($task, $transactions, $email_to, $email_cc) {
+ $exclude = $this->getExcludePHIDs();
$email_to = array_filter(array_unique($email_to));
$email_cc = array_filter(array_unique($email_cc));
@@ -276,6 +287,7 @@ private function sendEmail($task, $transactions, $email_to, $email_cc) {
->addHeader('Thread-Topic', "T{$task_id}: ".$task->getOriginalTitle())
->setThreadID($thread_id, $is_create)
->setRelatedPHID($task->getPHID())
+ ->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs())
->setIsBulk(true)
->setMailTags($mailtags)
->setBody($body->render());
View
1 src/applications/maniphest/event/ManiphestEdgeEventListener.php
@@ -73,6 +73,7 @@ private function handleDidEditEvent(PhutilEvent $event) {
$new_edges = $this->loadAllEdges($event);
$editor = new ManiphestTransactionEditor();
+ $editor->setActor($event->getUser());
foreach ($tasks as $phid => $task) {
$xactions = array();
View
10 src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php
@@ -20,6 +20,7 @@
private $mailReceiver;
private $actor;
+ private $excludePHIDs = array();
final public function setMailReceiver($mail_receiver) {
$this->validateMailReceiver($mail_receiver);
@@ -40,6 +41,15 @@
return $this->actor;
}
+ final public function setExcludeMailRecipientPHIDs(array $exclude) {
+ $this->excludePHIDs = $exclude;
+ return $this;
+ }
+
+ final public function getExcludeMailRecipientPHIDs() {
+ return $this->excludePHIDs;
+ }
+
abstract public function validateMailReceiver($mail_receiver);
abstract public function getPrivateReplyHandlerEmailAddress(
PhabricatorObjectHandle $handle);
View
12 src/applications/metamta/storage/PhabricatorMetaMTAMail.php
@@ -36,6 +36,8 @@
protected $nextRetry;
protected $relatedPHID;
+ private $excludePHIDs = array();
+
public function __construct() {
$this->status = self::STATUS_QUEUE;
@@ -119,6 +121,14 @@ public function addCCs(array $phids) {
return $this;
}
+ public function setExcludeMailRecipientPHIDs($exclude) {
+ $this->excludePHIDs = $exclude;
+ return $this;
+ }
+ private function getExcludeMailRecipientPHIDs() {
+ return $this->excludePHIDs;
+ }
+
public function getTranslation(array $objects) {
$default_translation = PhabricatorEnv::getEnvConfig('translation.provider');
$return = null;
@@ -349,7 +359,7 @@ public function sendNow(
$this->loadEmailAndNameDataFromPHIDs($phids);
- $exclude = array();
+ $exclude = array_fill_keys($this->getExcludeMailRecipientPHIDs(), true);
$params = $this->parameters;
$default = PhabricatorEnv::getEnvConfig('metamta.default-address');
View
23 src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php
@@ -62,6 +62,23 @@ public function getToAddresses() {
return $this->getRawEmailAddresses(idx($this->headers, 'to'));
}
+ private function loadExcludeMailRecipientPHIDs() {
+ $addresses = array_merge(
+ $this->getToAddresses(),
+ $this->getCCAddresses()
+ );
+
+ $users = id(new PhabricatorUserEmail())
+ ->loadAllWhere('address IN (%Ls)', $addresses);
+ $user_phids = mpull($users, 'getUserPHID');
+
+ $mailing_lists = id(new PhabricatorMetaMTAMailingList())
+ ->loadAllWhere('email in (%Ls)', $addresses);
+ $mailing_list_phids = mpull($mailing_lists, 'getPHID');
+
+ return array_merge($user_phids, $mailing_list_phids);
+ }
+
/**
* Parses "to" addresses, looking for a public create email address
* first and if not found parsing the "to" address for reply handler
@@ -182,9 +199,12 @@ public function processReceivedMail() {
$receiver->setPriority(ManiphestTaskPriority::PRIORITY_TRIAGE);
$editor = new ManiphestTransactionEditor();
+ $editor->setActor($user);
$handler = $editor->buildReplyHandler($receiver);
$handler->setActor($user);
+ $handler->setExcludeMailRecipientPHIDs(
+ $this->loadExcludeMailRecipientPHIDs());
$handler->processEmail($this);
$this->setRelatedPHID($receiver->getPHID());
@@ -248,6 +268,7 @@ public function processReceivedMail() {
if ($receiver instanceof ManiphestTask) {
$editor = new ManiphestTransactionEditor();
+ $editor->setActor($user);
$handler = $editor->buildReplyHandler($receiver);
} else if ($receiver instanceof DifferentialRevision) {
$handler = DifferentialMail::newReplyHandlerForRevision($receiver);
@@ -257,6 +278,8 @@ public function processReceivedMail() {
}
$handler->setActor($user);
+ $handler->setExcludeMailRecipientPHIDs(
+ $this->loadExcludeMailRecipientPHIDs());
$handler->processEmail($this);
$this->setMessage('OK');
View
36 src/applications/people/PhabricatorUserEditor.php
@@ -26,24 +26,11 @@
* @task email Adding, Removing and Changing Email
* @task internal Internals
*/
-final class PhabricatorUserEditor {
+final class PhabricatorUserEditor extends PhabricatorEditor {
- private $actor;
private $logs = array();
-/* -( Configuration )------------------------------------------------------ */
-
-
- /**
- * @task config
- */
- public function setActor(PhabricatorUser $actor) {
- $this->actor = $actor;
- return $this;
- }
-
-
/* -( Creating and Editing Users )----------------------------------------- */
@@ -88,7 +75,7 @@ public function createNewUser(
}
$log = PhabricatorUserLog::newLog(
- $this->actor,
+ $this->getActor(),
$user,
PhabricatorUserLog::ACTION_CREATE);
$log->setNewValue($email->getAddress());
@@ -147,7 +134,7 @@ public function changePassword(
$user->save();
$log = PhabricatorUserLog::newLog(
- $this->actor,
+ $this->getActor(),
$user,
PhabricatorUserLog::ACTION_CHANGE_PASSWORD);
$log->save();
@@ -186,7 +173,7 @@ public function changeUsername(PhabricatorUser $user, $username) {
}
$log = PhabricatorUserLog::newLog(
- $this->actor,
+ $actor,
$user,
PhabricatorUserLog::ACTION_CHANGE_USERNAME);
$log->setOldValue($old_username);
@@ -429,7 +416,7 @@ public function addEmail(
}
$log = PhabricatorUserLog::newLog(
- $this->actor,
+ $actor,
$user,
PhabricatorUserLog::ACTION_EMAIL_ADD);
$log->setNewValue($email->getAddress());
@@ -474,7 +461,7 @@ public function removeEmail(
$email->delete();
$log = PhabricatorUserLog::newLog(
- $this->actor,
+ $actor,
$user,
PhabricatorUserLog::ACTION_EMAIL_REMOVE);
$log->setOldValue($email->getAddress());
@@ -556,17 +543,6 @@ public function changePrimaryEmail(
/**
* @task internal
*/
- private function requireActor() {
- if (!$this->actor) {
- throw new Exception("User edit requires actor!");
- }
- return $this->actor;
- }
-
-
- /**
- * @task internal
- */
private function willAddEmail(PhabricatorUserEmail $email) {
// Hard check before write to prevent creation of disallowed email
View
4 src/applications/phame/controller/blog/PhameBlogDeleteController.php
@@ -88,8 +88,8 @@ public function processRequest() {
$blogger_phids = array_keys($blogger_edges);
$post_edges = $edges[$blog_phid][$post_edge_type];
$post_phids = array_keys($post_edges);
- $editor = id(new PhabricatorEdgeEditor());
- $editor->setUser($user);
+ $editor = id(new PhabricatorEdgeEditor())
+ ->setActor($user);
foreach ($blogger_phids as $phid) {
$editor->removeEdge($blog_phid, $blogger_edge_type, $phid);
}
View
2 src/applications/phame/controller/blog/PhameBlogEditController.php
@@ -163,7 +163,7 @@ public function processRequest() {
$rem_phids = array_diff($old_bloggers, $new_bloggers);
$editor = new PhabricatorEdgeEditor();
$edge_type = PhabricatorEdgeConfig::TYPE_BLOG_HAS_BLOGGER;
- $editor->setUser($user);
+ $editor->setActor($user);
foreach ($add_phids as $phid) {
$editor->addEdge($blog->getPHID(), $edge_type, $phid);
}
View
4 src/applications/phame/controller/post/PhamePostDeleteController.php
@@ -62,8 +62,8 @@ public function processRequest() {
$blog_edges = $edges[$post_phid][$edge_type];
$blog_phids = array_keys($blog_edges);
- $editor = id(new PhabricatorEdgeEditor());
- $editor->setUser($user);
+ $editor = id(new PhabricatorEdgeEditor())
+ ->setActor($user);
foreach ($blog_phids as $phid) {
$editor->removeEdge($post_phid, $edge_type, $phid);
}
View
2 src/applications/phame/controller/post/PhamePostEditController.php
@@ -198,7 +198,7 @@ public function processRequest() {
$editor = new PhabricatorEdgeEditor();
$edge_type = PhabricatorEdgeConfig::TYPE_POST_HAS_BLOG;
- $editor->setUser($user);
+ $editor->setActor($user);
foreach ($blogs_to_publish as $phid) {
$editor->addEdge($post->getPHID(), $edge_type, $phid);
}
View
2 src/applications/phriction/controller/PhrictionDeleteController.php
@@ -41,7 +41,7 @@ public function processRequest() {
if ($request->isFormPost()) {
$editor = id(PhrictionDocumentEditor::newForSlug($document->getSlug()))
- ->setUser($user)
+ ->setActor($user)
->delete();
return id(new AphrontRedirectResponse())->setURI($document_uri);
}
View
2 src/applications/phriction/controller/PhrictionEditController.php
@@ -134,7 +134,7 @@ public function processRequest() {
if (!count($errors)) {
$editor = id(PhrictionDocumentEditor::newForSlug($document->getSlug()))
- ->setUser($user)
+ ->setActor($user)
->setTitle($title)
->setContent($request->getStr('content'))
->setDescription($notes);
View
23 src/applications/phriction/editor/PhrictionDocumentEditor.php
@@ -21,13 +21,11 @@
*
* @group phriction
*/
-final class PhrictionDocumentEditor {
+final class PhrictionDocumentEditor extends PhabricatorEditor {
private $document;
private $content;
- private $user;
-
private $newTitle;
private $newContent;
private $description;
@@ -65,11 +63,6 @@ public static function newForSlug($slug) {
return $obj;
}
- public function setUser(PhabricatorUser $user) {
- $this->user = $user;
- return $this;
- }
-
public function setTitle($title) {
$this->newTitle = $title;
return $this;
@@ -90,9 +83,7 @@ public function getDocument() {
}
public function delete() {
- if (!$this->user) {
- throw new Exception("Call setUser() before deleting a document!");
- }
+ $actor = $this->requireActor();
// TODO: Should we do anything about deleting an already-deleted document?
// We currently allow it.
@@ -109,9 +100,7 @@ public function delete() {
}
public function save() {
- if (!$this->user) {
- throw new Exception("Call setUser() before updating a document!");
- }
+ $actor = $this->requireActor();
if ($this->newContent === '') {
// If this is an edit which deletes all the content, just treat it as
@@ -134,7 +123,7 @@ private function buildContentTemplate(
$new_content = new PhrictionContent();
$new_content->setSlug($document->getSlug());
- $new_content->setAuthorPHID($this->user->getPHID());
+ $new_content->setAuthorPHID($this->getActor()->getPHID());
$new_content->setChangeType(PhrictionChangeType::CHANGE_EDIT);
$new_content->setTitle(
@@ -214,7 +203,7 @@ private function updateDocument($document, $content, $new_content) {
$related_phids = array(
$document->getPHID(),
- $this->user->getPHID(),
+ $this->getActor()->getPHID(),
);
if ($project_phid) {
@@ -223,7 +212,7 @@ private function updateDocument($document, $content, $new_content) {
id(new PhabricatorFeedStoryPublisher())
->setRelatedPHIDs($related_phids)
- ->setStoryAuthorPHID($this->user->getPHID())
+ ->setStoryAuthorPHID($this->getActor()->getPHID())
->setStoryTime(time())
->setStoryType(PhabricatorFeedStoryTypeConstants::STORY_PHRICTION)
->setStoryData(
View
2 src/applications/ponder/controller/PonderAnswerSaveController.php
@@ -60,7 +60,7 @@ public function processRequest() {
->setContentSource($content_source);
id(new PonderAnswerEditor())
- ->setUser($user)
+ ->setActor($user)
->setQuestion($question)
->setAnswer($res)
->saveAnswer();
View
2 src/applications/ponder/controller/PonderCommentSaveController.php
@@ -61,7 +61,7 @@ public function processRequest() {
->setQuestion($question)
->setComment($res)
->setTargetPHID($target)
- ->setUser($user)
+ ->setActor($user)
->save();
return id(new AphrontRedirectResponse())
View
2 src/applications/ponder/controller/PonderQuestionAskController.php
@@ -53,7 +53,7 @@ public function processRequest() {
id(new PonderQuestionEditor())
->setQuestion($question)
- ->setUser($user)
+ ->setActor($user)
->save();
return id(new AphrontRedirectResponse())
View
2 src/applications/ponder/controller/PonderVoteSaveController.php
@@ -49,7 +49,7 @@ public function processRequest() {
$editor = id(new PonderVoteEditor())
->setVotable($target)
- ->setUser($user)
+ ->setActor($user)
->setVote($newvote)
->saveVote();
View
20 src/applications/ponder/editor/PonderAnswerEditor.php
@@ -16,10 +16,10 @@
* limitations under the License.
*/
-final class PonderAnswerEditor {
+final class PonderAnswerEditor extends PhabricatorEditor {
+
private $question;
private $answer;
- private $viewer;
private $shouldEmail = true;
public function setQuestion($question) {
@@ -32,15 +32,8 @@ public function setAnswer($answer) {
return $this;
}
- public function setUser(PhabricatorUser $user) {
- $this->viewer = $user;
- return $this;
- }
-
public function saveAnswer() {
- if (!$this->viewer) {
- throw new Exception("Must set user before saving question");
- }
+ $actor = $this->requireActor();
if (!$this->question) {
throw new Exception("Must set question before saving answer");
}
@@ -50,7 +43,6 @@ public function saveAnswer() {
$question = $this->question;
$answer = $this->answer;
- $viewer = $this->viewer;
$conn = $answer->establishConnection('w');
$trans = $conn->openTransaction();
$trans->beginReadLocking();
@@ -76,7 +68,7 @@ public function saveAnswer() {
// subscribe author and @mentions
$subeditor = id(new PhabricatorSubscriptionsEditor())
->setObject($question)
- ->setUser($viewer);
+ ->setActor($actor);
$subeditor->subscribeExplicit(array($answer->getAuthorPHID()));
@@ -98,7 +90,7 @@ public function saveAnswer() {
id(new PonderMentionMail(
$question,
$answer,
- $viewer))
+ $actor))
->setToPHIDs($at_mention_phids)
->send();
}
@@ -115,7 +107,7 @@ public function saveAnswer() {
id(new PonderAnsweredMail(
$question,
$answer,
- $viewer))
+ $actor))
->setToPHIDs($other_subs)
->send();
}
View
20 src/applications/ponder/editor/PonderCommentEditor.php
@@ -16,13 +16,11 @@
* limitations under the License.
*/
-
-final class PonderCommentEditor {
+final class PonderCommentEditor extends PhabricatorEditor {
private $question;
private $comment;
private $targetPHID;
- private $viewer;
private $shouldEmail = true;
public function setComment(PonderComment $comment) {
@@ -40,12 +38,8 @@ public function setTargetPHID($target) {
return $this;
}
- public function setUser(PhabricatorUser $user) {
- $this->viewer = $user;
- return $this;
- }
-
public function save() {
+ $actor = $this->requireActor();
if (!$this->comment) {
throw new Exception("Must set comment before saving it");
}
@@ -55,14 +49,10 @@ public function save() {
if (!$this->targetPHID) {
throw new Exception("Must set target before saving comment");
}
- if (!$this->viewer) {
- throw new Exception("Must set viewer before saving comment");
- }
$comment = $this->comment;
$question = $this->question;
$target = $this->targetPHID;
- $viewer = $this->viewer;
$comment->save();
$question->attachRelated();
@@ -71,7 +61,7 @@ public function save() {
// subscribe author and @mentions
$subeditor = id(new PhabricatorSubscriptionsEditor())
->setObject($question)
- ->setUser($viewer);
+ ->setActor($actor);
$subeditor->subscribeExplicit(array($comment->getAuthorPHID()));
@@ -92,7 +82,7 @@ public function save() {
id(new PonderMentionMail(
$question,
$comment,
- $viewer))
+ $actor))
->setToPHIDs($at_mention_phids)
->send();
}
@@ -124,7 +114,7 @@ public function save() {
id(new PonderCommentMail(
$question,
$comment,
- $viewer))
+ $actor))
->setToPHIDs($other_subs)
->send();
}
View
18 src/applications/ponder/editor/PonderQuestionEditor.php
@@ -16,11 +16,9 @@
* limitations under the License.
*/
-
-final class PonderQuestionEditor {
+final class PonderQuestionEditor extends PhabricatorEditor {
private $question;
- private $viewer;
private $shouldEmail = true;
public function setQuestion(PonderQuestion $question) {
@@ -28,25 +26,17 @@ public function setQuestion(PonderQuestion $question) {
return $this;
}
- public function setUser(PhabricatorUser $user) {
- $this->viewer = $user;
- return $this;
- }
-
public function setShouldEmail($se) {
$this->shouldEmail = $se;
return $this;
}
public function save() {
- if (!$this->viewer) {
- throw new Exception("Must set user before saving question");
- }
+ $actor = $this->requireActor();
if (!$this->question) {
throw new Exception("Must set question before saving it");
}
- $viewer = $this->viewer;
$question = $this->question;
$question->save();
@@ -57,7 +47,7 @@ public function save() {
// subscribe author and @mentions
$subeditor = id(new PhabricatorSubscriptionsEditor())
->setObject($question)
- ->setUser($viewer);
+ ->setActor($actor);
$subeditor->subscribeExplicit(array($question->getAuthorPHID()));
@@ -72,7 +62,7 @@ public function save() {
id(new PonderMentionMail(