16
16
* limitations under the License.
17
17
*/
18
18
19
- final class PhabricatorAuditCommentEditor {
19
+ final class PhabricatorAuditCommentEditor extends PhabricatorEditor {
20
20
21
21
private $ commit ;
22
- private $ user ;
23
22
24
23
private $ attachInlineComments ;
25
24
private $ auditors = array ();
@@ -30,11 +29,6 @@ public function __construct(PhabricatorRepositoryCommit $commit) {
30
29
return $ this ;
31
30
}
32
31
33
- public function setUser (PhabricatorUser $ user ) {
34
- $ this ->user = $ user ;
35
- return $ this ;
36
- }
37
-
38
32
public function addAuditors (array $ auditor_phids ) {
39
33
$ this ->auditors = array_merge ($ this ->auditors , $ auditor_phids );
40
34
return $ this ;
@@ -53,7 +47,7 @@ public function setAttachInlineComments($attach_inline_comments) {
53
47
public function addComment (PhabricatorAuditComment $ comment ) {
54
48
55
49
$ commit = $ this ->commit ;
56
- $ user = $ this ->user ;
50
+ $ actor = $ this ->getActor () ;
57
51
58
52
$ other_comments = id (new PhabricatorAuditComment ())->loadAllWhere (
59
53
'targetPHID = %s ' ,
@@ -64,12 +58,12 @@ public function addComment(PhabricatorAuditComment $comment) {
64
58
$ inline_comments = id (new PhabricatorAuditInlineComment ())->loadAllWhere (
65
59
'authorPHID = %s AND commitPHID = %s
66
60
AND auditCommentID IS NULL ' ,
67
- $ user ->getPHID (),
61
+ $ actor ->getPHID (),
68
62
$ commit ->getPHID ());
69
63
}
70
64
71
65
$ comment
72
- ->setActorPHID ($ user ->getPHID ())
66
+ ->setActorPHID ($ actor ->getPHID ())
73
67
->setTargetPHID ($ commit ->getPHID ())
74
68
->save ();
75
69
@@ -106,13 +100,13 @@ public function addComment(PhabricatorAuditComment $comment) {
106
100
$ ccs = array_merge ($ ccs , $ metacc );
107
101
}
108
102
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
110
104
// they have authority over to reflect the most recent status. The general
111
105
// idea here is that if audit has triggered for, e.g., several packages, but
112
106
// a user owns all of them, they can clear the audit requirement in one go
113
107
// without auditing the commit for each trigger.
114
108
115
- $ audit_phids = self ::loadAuditPHIDsForUser ($ this -> user );
109
+ $ audit_phids = self ::loadAuditPHIDsForUser ($ actor );
116
110
$ audit_phids = array_fill_keys ($ audit_phids , true );
117
111
118
112
$ requests = id (new PhabricatorRepositoryAuditRequest ())
@@ -128,7 +122,7 @@ public function addComment(PhabricatorAuditComment $comment) {
128
122
// and handle the no-effect cases (e.g., closing and already-closed audit).
129
123
130
124
131
- $ user_is_author = ($ user ->getPHID () == $ commit ->getAuthorPHID ());
125
+ $ actor_is_author = ($ actor ->getPHID () == $ commit ->getAuthorPHID ());
132
126
133
127
if ($ action == PhabricatorAuditActionConstants::CLOSE ) {
134
128
// "Close" means wipe out all the concerns.
@@ -144,33 +138,34 @@ public function addComment(PhabricatorAuditComment $comment) {
144
138
// user row (never package/project rows), and always affects the user
145
139
// row (other actions don't, if they were able to affect a package/project
146
140
// row).
147
- $ user_request = null ;
141
+ $ actor_request = null ;
148
142
foreach ($ requests as $ request ) {
149
- if ($ request ->getAuditorPHID () == $ user ->getPHID ()) {
150
- $ user_request = $ request ;
143
+ if ($ request ->getAuditorPHID () == $ actor ->getPHID ()) {
144
+ $ actor_request = $ request ;
151
145
break ;
152
146
}
153
147
}
154
- if (!$ user_request ) {
155
- $ user_request = id (new PhabricatorRepositoryAuditRequest ())
148
+ if (!$ actor_request ) {
149
+ $ actor_request = id (new PhabricatorRepositoryAuditRequest ())
156
150
->setCommitPHID ($ commit ->getPHID ())
157
- ->setAuditorPHID ($ user ->getPHID ())
151
+ ->setAuditorPHID ($ actor ->getPHID ())
158
152
->setAuditReasons (array ("Resigned " ));
159
153
}
160
154
161
- $ user_request
155
+ $ actor_request
162
156
->setAuditStatus (PhabricatorAuditStatusConstants::RESIGNED )
163
157
->save ();
164
158
165
- $ requests [] = $ user_request ;
159
+ $ requests [] = $ actor_request ;
166
160
} else {
167
161
$ have_any_requests = false ;
168
162
foreach ($ requests as $ request ) {
169
163
if (empty ($ audit_phids [$ request ->getAuditorPHID ()])) {
170
164
continue ;
171
165
}
172
166
173
- $ request_is_for_user = ($ request ->getAuditorPHID () == $ user ->getPHID ());
167
+ $ request_is_for_actor =
168
+ ($ request ->getAuditorPHID () == $ actor ->getPHID ());
174
169
175
170
$ have_any_requests = true ;
176
171
$ new_status = null ;
@@ -181,15 +176,15 @@ public function addComment(PhabricatorAuditComment $comment) {
181
176
// Commenting or adding cc's/auditors doesn't change status.
182
177
break ;
183
178
case PhabricatorAuditActionConstants::ACCEPT :
184
- if (!$ user_is_author || $ request_is_for_user ) {
179
+ if (!$ actor_is_author || $ request_is_for_actor ) {
185
180
// When modifying your own commits, you act only on behalf of
186
181
// yourself, not your packages/projects -- the idea being that
187
182
// you can't accept your own commits.
188
183
$ new_status = PhabricatorAuditStatusConstants::ACCEPTED ;
189
184
}
190
185
break ;
191
186
case PhabricatorAuditActionConstants::CONCERN :
192
- if (!$ user_is_author || $ request_is_for_user ) {
187
+ if (!$ actor_is_author || $ request_is_for_actor ) {
193
188
// See above.
194
189
$ new_status = PhabricatorAuditStatusConstants::CONCERNED ;
195
190
}
@@ -203,7 +198,7 @@ public function addComment(PhabricatorAuditComment $comment) {
203
198
}
204
199
}
205
200
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
207
202
// new one to represent their audit state.
208
203
if (!$ have_any_requests ) {
209
204
$ new_status = null ;
@@ -227,7 +222,7 @@ public function addComment(PhabricatorAuditComment $comment) {
227
222
228
223
$ request = id (new PhabricatorRepositoryAuditRequest ())
229
224
->setCommitPHID ($ commit ->getPHID ())
230
- ->setAuditorPHID ($ user ->getPHID ())
225
+ ->setAuditorPHID ($ actor ->getPHID ())
231
226
->setAuditStatus ($ new_status )
232
227
->setAuditReasons (array ("Voluntary Participant " ))
233
228
->save ();
@@ -270,7 +265,7 @@ public function addComment(PhabricatorAuditComment $comment) {
270
265
->setAuditorPHID ($ auditor_phid )
271
266
->setAuditStatus ($ audit_requested )
272
267
->setAuditReasons (
273
- array ('Added by ' . $ user ->getUsername ()))
268
+ array ('Added by ' . $ actor ->getUsername ()))
274
269
->save ();
275
270
}
276
271
}
@@ -283,7 +278,7 @@ public function addComment(PhabricatorAuditComment $comment) {
283
278
->setAuditorPHID ($ cc_phid )
284
279
->setAuditStatus ($ audit_cc )
285
280
->setAuditReasons (
286
- array ('Added by ' . $ user ->getUsername ()))
281
+ array ('Added by ' . $ actor ->getUsername ()))
287
282
->save ();
288
283
}
289
284
}
@@ -322,13 +317,10 @@ public static function loadAuditPHIDsForUser(PhabricatorUser $user) {
322
317
}
323
318
324
319
// 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 ();
332
324
foreach ($ projects as $ project ) {
333
325
$ phids [$ project ->getPHID ()] = true ;
334
326
}
@@ -341,18 +333,18 @@ private function publishFeedStory(
341
333
array $ more_phids ) {
342
334
343
335
$ commit = $ this ->commit ;
344
- $ user = $ this ->user ;
336
+ $ actor = $ this ->getActor () ;
345
337
346
338
$ related_phids = array_merge (
347
339
array (
348
- $ user ->getPHID (),
340
+ $ actor ->getPHID (),
349
341
$ commit ->getPHID (),
350
342
),
351
343
$ more_phids );
352
344
353
345
id (new PhabricatorFeedStoryPublisher ())
354
346
->setRelatedPHIDs ($ related_phids )
355
- ->setStoryAuthorPHID ($ user ->getPHID ())
347
+ ->setStoryAuthorPHID ($ actor ->getPHID ())
356
348
->setStoryTime (time ())
357
349
->setStoryType (PhabricatorFeedStoryTypeConstants::STORY_AUDIT )
358
350
->setStoryData (
@@ -445,6 +437,7 @@ private function sendMail(
445
437
->setThreadID ($ thread_id , $ is_new )
446
438
->addHeader ('Thread-Topic ' , $ thread_topic )
447
439
->setRelatedPHID ($ commit ->getPHID ())
440
+ ->setExcludeMailRecipientPHIDs ($ this ->getExcludeMailRecipientPHIDs ())
448
441
->setIsBulk (true )
449
442
->setBody ($ body );
450
443
@@ -484,8 +477,8 @@ private function renderMailBody(
484
477
assert_instances_of ($ inline_comments , 'PhabricatorInlineCommentInterface ' );
485
478
486
479
$ commit = $ this ->commit ;
487
- $ user = $ this ->user ;
488
- $ name = $ user ->getUsername ();
480
+ $ actor = $ this ->getActor () ;
481
+ $ name = $ actor ->getUsername ();
489
482
490
483
$ verb = PhabricatorAuditActionConstants::getActionPastTenseVerb (
491
484
$ comment ->getAction ());
0 commit comments