Skip to content

Commit d9c6e07

Browse files
committed
If users are on the email to Phabricator, do not send them the Phabricator 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
1 parent b605878 commit d9c6e07

File tree

58 files changed

+302
-292
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+302
-292
lines changed

src/__phutil_library_map__.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@
668668
'PhabricatorEdgeGraph' => 'infrastructure/edges/util/PhabricatorEdgeGraph.php',
669669
'PhabricatorEdgeQuery' => 'infrastructure/edges/query/PhabricatorEdgeQuery.php',
670670
'PhabricatorEdgeTestCase' => 'infrastructure/edges/__tests__/PhabricatorEdgeTestCase.php',
671+
'PhabricatorEditor' => 'infrastructure/PhabricatorEditor.php',
671672
'PhabricatorEmailLoginController' => 'applications/auth/controller/PhabricatorEmailLoginController.php',
672673
'PhabricatorEmailTokenController' => 'applications/auth/controller/PhabricatorEmailTokenController.php',
673674
'PhabricatorEmailVerificationController' => 'applications/people/controller/PhabricatorEmailVerificationController.php',
@@ -1450,6 +1451,7 @@
14501451
'DifferentialChangesetParserTestCase' => 'ArcanistPhutilTestCase',
14511452
'DifferentialChangesetViewController' => 'DifferentialController',
14521453
'DifferentialComment' => 'DifferentialDAO',
1454+
'DifferentialCommentEditor' => 'PhabricatorEditor',
14531455
'DifferentialCommentMail' => 'DifferentialMail',
14541456
'DifferentialCommentPreviewController' => 'DifferentialController',
14551457
'DifferentialCommentSaveController' => 'DifferentialController',
@@ -1507,6 +1509,7 @@
15071509
'DifferentialRevisionCommentView' => 'AphrontView',
15081510
'DifferentialRevisionDetailView' => 'AphrontView',
15091511
'DifferentialRevisionEditController' => 'DifferentialController',
1512+
'DifferentialRevisionEditor' => 'PhabricatorEditor',
15101513
'DifferentialRevisionIDFieldParserTestCase' => 'PhabricatorTestCase',
15111514
'DifferentialRevisionIDFieldSpecification' => 'DifferentialFieldSpecification',
15121515
'DifferentialRevisionListController' => 'DifferentialController',
@@ -1714,6 +1717,7 @@
17141717
1 => 'PhabricatorMarkupInterface',
17151718
),
17161719
'ManiphestTransactionDetailView' => 'ManiphestView',
1720+
'ManiphestTransactionEditor' => 'PhabricatorEditor',
17171721
'ManiphestTransactionListView' => 'ManiphestView',
17181722
'ManiphestTransactionPreviewController' => 'ManiphestController',
17191723
'ManiphestTransactionSaveController' => 'ManiphestController',
@@ -1765,6 +1769,7 @@
17651769
'PhabricatorApplicationsListController' => 'PhabricatorController',
17661770
'PhabricatorAuditAddCommentController' => 'PhabricatorAuditController',
17671771
'PhabricatorAuditComment' => 'PhabricatorAuditDAO',
1772+
'PhabricatorAuditCommentEditor' => 'PhabricatorEditor',
17681773
'PhabricatorAuditCommitListView' => 'AphrontView',
17691774
'PhabricatorAuditController' => 'PhabricatorController',
17701775
'PhabricatorAuditDAO' => 'PhabricatorLiskDAO',
@@ -1839,6 +1844,7 @@
18391844
'PhabricatorDraftDAO' => 'PhabricatorLiskDAO',
18401845
'PhabricatorEdgeConfig' => 'PhabricatorEdgeConstants',
18411846
'PhabricatorEdgeCycleException' => 'Exception',
1847+
'PhabricatorEdgeEditor' => 'PhabricatorEditor',
18421848
'PhabricatorEdgeGraph' => 'AbstractDirectedGraph',
18431849
'PhabricatorEdgeQuery' => 'PhabricatorQuery',
18441850
'PhabricatorEdgeTestCase' => 'PhabricatorTestCase',
@@ -2083,6 +2089,7 @@
20832089
'PhabricatorProjectController' => 'PhabricatorController',
20842090
'PhabricatorProjectCreateController' => 'PhabricatorProjectController',
20852091
'PhabricatorProjectDAO' => 'PhabricatorLiskDAO',
2092+
'PhabricatorProjectEditor' => 'PhabricatorEditor',
20862093
'PhabricatorProjectEditorTestCase' => 'PhabricatorTestCase',
20872094
'PhabricatorProjectListController' => 'PhabricatorProjectController',
20882095
'PhabricatorProjectMembersEditController' => 'PhabricatorProjectController',
@@ -2202,6 +2209,7 @@
22022209
'PhabricatorStorageManagementWorkflow' => 'PhutilArgumentWorkflow',
22032210
'PhabricatorSubscribersQuery' => 'PhabricatorQuery',
22042211
'PhabricatorSubscriptionsEditController' => 'PhabricatorController',
2212+
'PhabricatorSubscriptionsEditor' => 'PhabricatorEditor',
22052213
'PhabricatorSubscriptionsUIEventListener' => 'PhutilEventListener',
22062214
'PhabricatorSymbolNameLinter' => 'ArcanistXHPASTLintNamingHook',
22072215
'PhabricatorTaskmasterDaemon' => 'PhabricatorDaemon',
@@ -2229,6 +2237,7 @@
22292237
1 => 'PhutilPerson',
22302238
),
22312239
'PhabricatorUserDAO' => 'PhabricatorLiskDAO',
2240+
'PhabricatorUserEditor' => 'PhabricatorEditor',
22322241
'PhabricatorUserEmail' => 'PhabricatorUserDAO',
22332242
'PhabricatorUserLDAPInfo' => 'PhabricatorUserDAO',
22342243
'PhabricatorUserLog' => 'PhabricatorUserDAO',
@@ -2304,6 +2313,7 @@
23042313
'PhrictionDiffController' => 'PhrictionController',
23052314
'PhrictionDocument' => 'PhrictionDAO',
23062315
'PhrictionDocumentController' => 'PhrictionController',
2316+
'PhrictionDocumentEditor' => 'PhabricatorEditor',
23072317
'PhrictionDocumentPreviewController' => 'PhrictionController',
23082318
'PhrictionDocumentStatus' => 'PhrictionConstants',
23092319
'PhrictionDocumentTestCase' => 'PhabricatorTestCase',
@@ -2318,6 +2328,7 @@
23182328
1 => 'PhabricatorMarkupInterface',
23192329
2 => 'PonderVotableInterface',
23202330
),
2331+
'PonderAnswerEditor' => 'PhabricatorEditor',
23212332
'PonderAnswerListView' => 'AphrontView',
23222333
'PonderAnswerPreviewController' => 'PonderController',
23232334
'PonderAnswerQuery' => 'PhabricatorOffsetPagedQuery',
@@ -2329,6 +2340,7 @@
23292340
0 => 'PonderDAO',
23302341
1 => 'PhabricatorMarkupInterface',
23312342
),
2343+
'PonderCommentEditor' => 'PhabricatorEditor',
23322344
'PonderCommentListView' => 'AphrontView',
23332345
'PonderCommentMail' => 'PonderMail',
23342346
'PonderCommentQuery' => 'PhabricatorQuery',
@@ -2347,6 +2359,7 @@
23472359
),
23482360
'PonderQuestionAskController' => 'PonderController',
23492361
'PonderQuestionDetailView' => 'AphrontView',
2362+
'PonderQuestionEditor' => 'PhabricatorEditor',
23502363
'PonderQuestionPreviewController' => 'PonderController',
23512364
'PonderQuestionQuery' => 'PhabricatorOffsetPagedQuery',
23522365
'PonderQuestionSummaryView' => 'AphrontView',
@@ -2355,6 +2368,7 @@
23552368
'PonderRuleQuestion' => 'PhabricatorRemarkupRuleObjectName',
23562369
'PonderUserProfileView' => 'AphrontView',
23572370
'PonderVotableView' => 'AphrontView',
2371+
'PonderVoteEditor' => 'PhabricatorEditor',
23582372
'PonderVoteSaveController' => 'PonderController',
23592373
'QueryFormattingTestCase' => 'PhabricatorTestCase',
23602374
),

src/applications/audit/PhabricatorAuditReplyHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) {
6161
->setContent($mail->getCleanTextBody());
6262

6363
$editor = new PhabricatorAuditCommentEditor($commit);
64-
$editor->setUser($actor);
64+
$editor->setActor($actor);
65+
$editor->setExcludeMailRecipientPHIDs(
66+
$this->getExcludeMailRecipientPHIDs());
6567
$editor->addComment($comment);
6668
}
6769

src/applications/audit/controller/PhabricatorAuditAddCommentController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function processRequest() {
6161
}
6262

6363
id(new PhabricatorAuditCommentEditor($commit))
64-
->setUser($user)
64+
->setActor($user)
6565
->setAttachInlineComments(true)
6666
->addAuditors($auditors)
6767
->addCCs($ccs)

src/applications/audit/editor/PhabricatorAuditCommentEditor.php

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
* limitations under the License.
1717
*/
1818

19-
final class PhabricatorAuditCommentEditor {
19+
final class PhabricatorAuditCommentEditor extends PhabricatorEditor {
2020

2121
private $commit;
22-
private $user;
2322

2423
private $attachInlineComments;
2524
private $auditors = array();
@@ -30,11 +29,6 @@ public function __construct(PhabricatorRepositoryCommit $commit) {
3029
return $this;
3130
}
3231

33-
public function setUser(PhabricatorUser $user) {
34-
$this->user = $user;
35-
return $this;
36-
}
37-
3832
public function addAuditors(array $auditor_phids) {
3933
$this->auditors = array_merge($this->auditors, $auditor_phids);
4034
return $this;
@@ -53,7 +47,7 @@ public function setAttachInlineComments($attach_inline_comments) {
5347
public function addComment(PhabricatorAuditComment $comment) {
5448

5549
$commit = $this->commit;
56-
$user = $this->user;
50+
$actor = $this->getActor();
5751

5852
$other_comments = id(new PhabricatorAuditComment())->loadAllWhere(
5953
'targetPHID = %s',
@@ -64,12 +58,12 @@ public function addComment(PhabricatorAuditComment $comment) {
6458
$inline_comments = id(new PhabricatorAuditInlineComment())->loadAllWhere(
6559
'authorPHID = %s AND commitPHID = %s
6660
AND auditCommentID IS NULL',
67-
$user->getPHID(),
61+
$actor->getPHID(),
6862
$commit->getPHID());
6963
}
7064

7165
$comment
72-
->setActorPHID($user->getPHID())
66+
->setActorPHID($actor->getPHID())
7367
->setTargetPHID($commit->getPHID())
7468
->save();
7569

@@ -106,13 +100,13 @@ public function addComment(PhabricatorAuditComment $comment) {
106100
$ccs = array_merge($ccs, $metacc);
107101
}
108102

109-
// When a user submits an audit comment, we update all the audit requests
103+
// When an actor submits an audit comment, we update all the audit requests
110104
// they have authority over to reflect the most recent status. The general
111105
// idea here is that if audit has triggered for, e.g., several packages, but
112106
// a user owns all of them, they can clear the audit requirement in one go
113107
// without auditing the commit for each trigger.
114108

115-
$audit_phids = self::loadAuditPHIDsForUser($this->user);
109+
$audit_phids = self::loadAuditPHIDsForUser($actor);
116110
$audit_phids = array_fill_keys($audit_phids, true);
117111

118112
$requests = id(new PhabricatorRepositoryAuditRequest())
@@ -128,7 +122,7 @@ public function addComment(PhabricatorAuditComment $comment) {
128122
// and handle the no-effect cases (e.g., closing and already-closed audit).
129123

130124

131-
$user_is_author = ($user->getPHID() == $commit->getAuthorPHID());
125+
$actor_is_author = ($actor->getPHID() == $commit->getAuthorPHID());
132126

133127
if ($action == PhabricatorAuditActionConstants::CLOSE) {
134128
// "Close" means wipe out all the concerns.
@@ -144,33 +138,34 @@ public function addComment(PhabricatorAuditComment $comment) {
144138
// user row (never package/project rows), and always affects the user
145139
// row (other actions don't, if they were able to affect a package/project
146140
// row).
147-
$user_request = null;
141+
$actor_request = null;
148142
foreach ($requests as $request) {
149-
if ($request->getAuditorPHID() == $user->getPHID()) {
150-
$user_request = $request;
143+
if ($request->getAuditorPHID() == $actor->getPHID()) {
144+
$actor_request = $request;
151145
break;
152146
}
153147
}
154-
if (!$user_request) {
155-
$user_request = id(new PhabricatorRepositoryAuditRequest())
148+
if (!$actor_request) {
149+
$actor_request = id(new PhabricatorRepositoryAuditRequest())
156150
->setCommitPHID($commit->getPHID())
157-
->setAuditorPHID($user->getPHID())
151+
->setAuditorPHID($actor->getPHID())
158152
->setAuditReasons(array("Resigned"));
159153
}
160154

161-
$user_request
155+
$actor_request
162156
->setAuditStatus(PhabricatorAuditStatusConstants::RESIGNED)
163157
->save();
164158

165-
$requests[] = $user_request;
159+
$requests[] = $actor_request;
166160
} else {
167161
$have_any_requests = false;
168162
foreach ($requests as $request) {
169163
if (empty($audit_phids[$request->getAuditorPHID()])) {
170164
continue;
171165
}
172166

173-
$request_is_for_user = ($request->getAuditorPHID() == $user->getPHID());
167+
$request_is_for_actor =
168+
($request->getAuditorPHID() == $actor->getPHID());
174169

175170
$have_any_requests = true;
176171
$new_status = null;
@@ -181,15 +176,15 @@ public function addComment(PhabricatorAuditComment $comment) {
181176
// Commenting or adding cc's/auditors doesn't change status.
182177
break;
183178
case PhabricatorAuditActionConstants::ACCEPT:
184-
if (!$user_is_author || $request_is_for_user) {
179+
if (!$actor_is_author || $request_is_for_actor) {
185180
// When modifying your own commits, you act only on behalf of
186181
// yourself, not your packages/projects -- the idea being that
187182
// you can't accept your own commits.
188183
$new_status = PhabricatorAuditStatusConstants::ACCEPTED;
189184
}
190185
break;
191186
case PhabricatorAuditActionConstants::CONCERN:
192-
if (!$user_is_author || $request_is_for_user) {
187+
if (!$actor_is_author || $request_is_for_actor) {
193188
// See above.
194189
$new_status = PhabricatorAuditStatusConstants::CONCERNED;
195190
}
@@ -203,7 +198,7 @@ public function addComment(PhabricatorAuditComment $comment) {
203198
}
204199
}
205200

206-
// If the user has no current authority over any audit trigger, make a
201+
// If the actor has no current authority over any audit trigger, make a
207202
// new one to represent their audit state.
208203
if (!$have_any_requests) {
209204
$new_status = null;
@@ -227,7 +222,7 @@ public function addComment(PhabricatorAuditComment $comment) {
227222

228223
$request = id(new PhabricatorRepositoryAuditRequest())
229224
->setCommitPHID($commit->getPHID())
230-
->setAuditorPHID($user->getPHID())
225+
->setAuditorPHID($actor->getPHID())
231226
->setAuditStatus($new_status)
232227
->setAuditReasons(array("Voluntary Participant"))
233228
->save();
@@ -270,7 +265,7 @@ public function addComment(PhabricatorAuditComment $comment) {
270265
->setAuditorPHID($auditor_phid)
271266
->setAuditStatus($audit_requested)
272267
->setAuditReasons(
273-
array('Added by ' . $user->getUsername()))
268+
array('Added by ' . $actor->getUsername()))
274269
->save();
275270
}
276271
}
@@ -283,7 +278,7 @@ public function addComment(PhabricatorAuditComment $comment) {
283278
->setAuditorPHID($cc_phid)
284279
->setAuditStatus($audit_cc)
285280
->setAuditReasons(
286-
array('Added by ' . $user->getUsername()))
281+
array('Added by ' . $actor->getUsername()))
287282
->save();
288283
}
289284
}
@@ -322,13 +317,10 @@ public static function loadAuditPHIDsForUser(PhabricatorUser $user) {
322317
}
323318

324319
// The user can audit on behalf of all projects they are a member of.
325-
$query = new PhabricatorProjectQuery();
326-
327-
// TODO: As above.
328-
$query->setViewer($user);
329-
330-
$query->withMemberPHIDs(array($user->getPHID()));
331-
$projects = $query->execute();
320+
$projects = id(new PhabricatorProjectQuery())
321+
->setViewer($user)
322+
->withMemberPHIDs(array($user->getPHID()))
323+
->execute();
332324
foreach ($projects as $project) {
333325
$phids[$project->getPHID()] = true;
334326
}
@@ -341,18 +333,18 @@ private function publishFeedStory(
341333
array $more_phids) {
342334

343335
$commit = $this->commit;
344-
$user = $this->user;
336+
$actor = $this->getActor();
345337

346338
$related_phids = array_merge(
347339
array(
348-
$user->getPHID(),
340+
$actor->getPHID(),
349341
$commit->getPHID(),
350342
),
351343
$more_phids);
352344

353345
id(new PhabricatorFeedStoryPublisher())
354346
->setRelatedPHIDs($related_phids)
355-
->setStoryAuthorPHID($user->getPHID())
347+
->setStoryAuthorPHID($actor->getPHID())
356348
->setStoryTime(time())
357349
->setStoryType(PhabricatorFeedStoryTypeConstants::STORY_AUDIT)
358350
->setStoryData(
@@ -445,6 +437,7 @@ private function sendMail(
445437
->setThreadID($thread_id, $is_new)
446438
->addHeader('Thread-Topic', $thread_topic)
447439
->setRelatedPHID($commit->getPHID())
440+
->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs())
448441
->setIsBulk(true)
449442
->setBody($body);
450443

@@ -484,8 +477,8 @@ private function renderMailBody(
484477
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
485478

486479
$commit = $this->commit;
487-
$user = $this->user;
488-
$name = $user->getUsername();
480+
$actor = $this->getActor();
481+
$name = $actor->getUsername();
489482

490483
$verb = PhabricatorAuditActionConstants::getActionPastTenseVerb(
491484
$comment->getAction());

src/applications/conduit/method/differential/ConduitAPI_differential_close_Method.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ protected function execute(ConduitAPIRequest $request) {
6363

6464
$editor = new DifferentialCommentEditor(
6565
$revision,
66-
$request->getUser()->getPHID(),
6766
DifferentialAction::ACTION_CLOSE);
67+
$editor->setActor($request->getUser());
6868
$editor->save();
6969

7070
$revision->setStatus(ArcanistDifferentialRevisionStatus::CLOSED);

src/applications/conduit/method/differential/ConduitAPI_differential_createcomment_Method.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ protected function execute(ConduitAPIRequest $request) {
6363

6464
$editor = new DifferentialCommentEditor(
6565
$revision,
66-
$request->getUser()->getPHID(),
6766
$action);
67+
$editor->setActor($request->getUser());
6868
$editor->setContentSource($content_source);
6969
$editor->setMessage($request->getValue('message'));
7070
$editor->setNoEmail($request->getValue('silent'));

src/applications/conduit/method/differential/ConduitAPI_differential_createrevision_Method.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function execute(ConduitAPIRequest $request) {
5454
$revision = DifferentialRevisionEditor::newRevisionFromConduitWithDiff(
5555
$fields,
5656
$diff,
57-
$request->getUser()->getPHID());
57+
$request->getUser());
5858

5959
return array(
6060
'revisionid' => $revision->getID(),

0 commit comments

Comments
 (0)