Skip to content

Commit 42b1c73

Browse files
davidreussepriestley
authored and
epriestley
committed
Allow CC's/Auditors added to audits
Test Plan: Added CC's/Auditors, clicked the form elements, and saw correct behaviour. Verified that metadata was present in the detail table. Reviewers: epriestley Reviewed By: epriestley CC: aran, epriestley, 20after4, Koolvin Maniphest Tasks: T904 Differential Revision: https://secure.phabricator.com/D2002
1 parent 8069694 commit 42b1c73

15 files changed

+252
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ALTER TABLE phabricator_audit.audit_comment
2+
ADD metadata LONGTEXT COLLATE utf8_bin NOT NULL;
3+
4+
UPDATE phabricator_audit.audit_comment
5+
SET metadata = '{}' WHERE metadata = '';

src/applications/audit/constants/action/PhabricatorAuditActionConstants.php

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ final class PhabricatorAuditActionConstants {
2323
const COMMENT = 'comment';
2424
const RESIGN = 'resign';
2525
const CLOSE = 'close';
26+
const ADD_CCS = 'add_ccs';
27+
const ADD_AUDITORS = 'add_auditors';
2628

2729
public static function getActionNameMap() {
2830
static $map = array(
@@ -31,6 +33,8 @@ public static function getActionNameMap() {
3133
self::ACCEPT => 'Accept Commit',
3234
self::RESIGN => 'Resign from Audit',
3335
self::CLOSE => 'Close Audit',
36+
self::ADD_CCS => 'Add CCs',
37+
self::ADD_AUDITORS => 'Add Auditors',
3438
);
3539

3640
return $map;
@@ -48,6 +52,8 @@ public static function getActionPastTenseVerb($action) {
4852
self::ACCEPT => 'accepted',
4953
self::RESIGN => 'resigned from',
5054
self::CLOSE => 'closed',
55+
self::ADD_CCS => 'added CCs to',
56+
self::ADD_AUDITORS => 'added auditors to',
5157
);
5258
return idx($map, $action, 'updated');
5359
}

src/applications/audit/constants/status/PhabricatorAuditStatusConstants.php

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ final class PhabricatorAuditStatusConstants {
2626
const AUDIT_REQUESTED = 'requested';
2727
const RESIGNED = 'resigned';
2828
const CLOSED = 'closed';
29+
const CC = 'cc';
2930

3031
public static function getStatusNameMap() {
3132
static $map = array(
@@ -37,6 +38,7 @@ public static function getStatusNameMap() {
3738
self::AUDIT_REQUESTED => 'Audit Requested',
3839
self::RESIGNED => 'Resigned',
3940
self::CLOSED => 'Closed',
41+
self::CC => "Was CC'd",
4042
);
4143

4244
return $map;

src/applications/audit/controller/addcomment/PhabricatorAuditAddCommentController.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,24 @@ public function processRequest() {
3636
return new Aphront404Response();
3737
}
3838

39+
$phids = array($commit_phid);
40+
41+
$action = $request->getStr('action');
42+
3943
$comment = id(new PhabricatorAuditComment())
40-
->setAction($request->getStr('action'))
44+
->setAction($action)
4145
->setContent($request->getStr('content'));
4246

47+
$auditors = $request->getArr('auditors');
48+
$ccs = $request->getArr('ccs');
4349

4450
id(new PhabricatorAuditCommentEditor($commit))
4551
->setUser($user)
4652
->setAttachInlineComments(true)
53+
->addAuditors($auditors)
54+
->addCCs($ccs)
4755
->addComment($comment);
4856

49-
$phids = array($commit_phid);
5057
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
5158
$uri = $handles[$commit_phid]->getURI();
5259

src/applications/audit/controller/preview/PhabricatorAuditPreviewController.php

+24-2
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,40 @@ public function processRequest() {
3434
return new Aphront404Response();
3535
}
3636

37+
$action = $request->getStr('action');
38+
3739
$comment = id(new PhabricatorAuditComment())
3840
->setActorPHID($user->getPHID())
3941
->setTargetPHID($commit->getPHID())
40-
->setAction($request->getStr('action'))
42+
->setAction($action)
4143
->setContent($request->getStr('content'));
4244

45+
$phids = array(
46+
$user->getPHID(),
47+
$commit->getPHID(),
48+
);
49+
50+
$auditors = $request->getStrList('auditors');
51+
if ($action == PhabricatorAuditActionConstants::ADD_AUDITORS && $auditors) {
52+
$comment->setMetadata(array(
53+
PhabricatorAuditComment::METADATA_ADDED_AUDITORS => $auditors));
54+
$phids = array_merge($phids, $auditors);
55+
}
56+
57+
$ccs = $request->getStrList('ccs');
58+
if ($action == PhabricatorAuditActionConstants::ADD_CCS && $ccs) {
59+
$comment->setMetadata(array(
60+
PhabricatorAuditComment::METADATA_ADDED_CCS => $ccs));
61+
$phids = array_merge($phids, $ccs);
62+
}
63+
4364
$view = id(new DiffusionCommentView())
4465
->setUser($user)
4566
->setComment($comment)
4667
->setIsPreview(true);
4768

48-
$phids = $view->getRequiredHandlePHIDs();
69+
$phids = array_merge($phids, $view->getRequiredHandlePHIDs());
70+
4971
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
5072
$view->setHandles($handles);
5173

src/applications/audit/controller/preview/__init__.php

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
phutil_require_module('phabricator', 'aphront/response/404');
1010
phutil_require_module('phabricator', 'aphront/response/ajax');
11+
phutil_require_module('phabricator', 'applications/audit/constants/action');
1112
phutil_require_module('phabricator', 'applications/audit/controller/base');
1213
phutil_require_module('phabricator', 'applications/audit/storage/auditcomment');
1314
phutil_require_module('phabricator', 'applications/diffusion/view/comment');

src/applications/audit/editor/comment/PhabricatorAuditCommentEditor.php

+109-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ final class PhabricatorAuditCommentEditor {
2222
private $user;
2323

2424
private $attachInlineComments;
25+
private $auditors = array();
26+
private $ccs = array();
2527

2628
public function __construct(PhabricatorRepositoryCommit $commit) {
2729
$this->commit = $commit;
@@ -33,6 +35,16 @@ public function setUser(PhabricatorUser $user) {
3335
return $this;
3436
}
3537

38+
public function addAuditors(array $auditor_phids) {
39+
$this->auditors = array_merge($this->auditors, $auditor_phids);
40+
return $this;
41+
}
42+
43+
public function addCCs(array $cc_phids) {
44+
$this->ccs = array_merge($this->ccs, $cc_phids);
45+
return $this;
46+
}
47+
3648
public function setAttachInlineComments($attach_inline_comments) {
3749
$this->attachInlineComments = $attach_inline_comments;
3850
return $this;
@@ -61,13 +73,39 @@ public function addComment(PhabricatorAuditComment $comment) {
6173
->setTargetPHID($commit->getPHID())
6274
->save();
6375

76+
$content_blocks = array($comment->getContent());
77+
6478
if ($inline_comments) {
6579
foreach ($inline_comments as $inline) {
6680
$inline->setAuditCommentID($comment->getID());
6781
$inline->save();
82+
$content_blocks[] = $inline->getContent();
83+
}
84+
}
85+
86+
$ccs = $this->ccs;
87+
$auditors = $this->auditors;
88+
89+
$metadata = $comment->getMetadata();
90+
$metacc = array();
91+
92+
// Find any "@mentions" in the content blocks.
93+
$mention_ccs = PhabricatorMarkupEngine::extractPHIDsFromMentions(
94+
$content_blocks);
95+
if ($mention_ccs) {
96+
$metacc = idx(
97+
$metadata,
98+
PhabricatorAuditComment::METADATA_ADDED_CCS,
99+
array());
100+
foreach ($mention_ccs as $cc_phid) {
101+
$metacc[] = $cc_phid;
68102
}
69103
}
70104

105+
if ($metacc) {
106+
$ccs = array_merge($ccs, $metacc);
107+
}
108+
71109
// When a user submits an audit comment, we update all the audit requests
72110
// they have authority over to reflect the most recent status. The general
73111
// idea here is that if audit has triggered for, e.g., several packages, but
@@ -114,7 +152,9 @@ public function addComment(PhabricatorAuditComment $comment) {
114152
$new_status = null;
115153
switch ($action) {
116154
case PhabricatorAuditActionConstants::COMMENT:
117-
// Comments don't change audit statuses.
155+
case PhabricatorAuditActionConstants::ADD_CCS:
156+
case PhabricatorAuditActionConstants::ADD_AUDITORS:
157+
// Commenting or adding cc's/auditors doesn't change status.
118158
break;
119159
case PhabricatorAuditActionConstants::ACCEPT:
120160
if (!$user_is_author || $request_is_for_user) {
@@ -152,6 +192,8 @@ public function addComment(PhabricatorAuditComment $comment) {
152192
$new_status = null;
153193
switch ($action) {
154194
case PhabricatorAuditActionConstants::COMMENT:
195+
case PhabricatorAuditActionConstants::ADD_CCS:
196+
case PhabricatorAuditActionConstants::ADD_AUDITORS:
155197
$new_status = PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED;
156198
break;
157199
case PhabricatorAuditActionConstants::ACCEPT:
@@ -181,12 +223,65 @@ public function addComment(PhabricatorAuditComment $comment) {
181223
}
182224
}
183225

226+
$requests_by_auditor = mpull($requests, null, 'getAuditorPHID');
227+
$requests_phids = array_keys($requests_by_auditor);
228+
229+
$ccs = array_diff($ccs, $requests_phids);
230+
$auditors = array_diff($auditors, $requests_phids);
231+
232+
if ($action == PhabricatorAuditActionConstants::ADD_CCS) {
233+
if ($ccs) {
234+
$metadata[PhabricatorAuditComment::METADATA_ADDED_CCS] = $ccs;
235+
$comment->setMetaData($metadata);
236+
} else {
237+
$comment->setAction(PhabricatorAuditActionConstants::COMMENT);
238+
}
239+
}
240+
241+
if ($action == PhabricatorAuditActionConstants::ADD_AUDITORS) {
242+
if ($auditors) {
243+
$metadata[PhabricatorAuditComment::METADATA_ADDED_AUDITORS]
244+
= $auditors;
245+
$comment->setMetaData($metadata);
246+
} else {
247+
$comment->setAction(PhabricatorAuditActionConstants::COMMENT);
248+
}
249+
}
250+
251+
$comment->save();
252+
253+
if ($auditors) {
254+
foreach ($auditors as $auditor_phid) {
255+
$audit_requested = PhabricatorAuditStatusConstants::AUDIT_REQUESTED;
256+
$requests[] = id (new PhabricatorRepositoryAuditRequest())
257+
->setCommitPHID($commit->getPHID())
258+
->setAuditorPHID($auditor_phid)
259+
->setAuditStatus($audit_requested)
260+
->setAuditReasons(
261+
array('Added by ' . $user->getUsername()))
262+
->save();
263+
}
264+
}
265+
266+
if ($ccs) {
267+
foreach ($ccs as $cc_phid) {
268+
$audit_cc = PhabricatorAuditStatusConstants::CC;
269+
$requests[] = id (new PhabricatorRepositoryAuditRequest())
270+
->setCommitPHID($commit->getPHID())
271+
->setAuditorPHID($cc_phid)
272+
->setAuditStatus($audit_cc)
273+
->setAuditReasons(
274+
array('Added by ' . $user->getUsername()))
275+
->save();
276+
}
277+
}
278+
184279
$commit->updateAuditStatus($requests);
185280
$commit->save();
186281

187282
$this->publishFeedStory($comment, array_keys($audit_phids));
188283
PhabricatorSearchCommitIndexer::indexCommit($commit);
189-
$this->sendMail($comment, $other_comments, $inline_comments);
284+
$this->sendMail($comment, $other_comments, $inline_comments, $requests);
190285
}
191286

192287

@@ -256,7 +351,9 @@ private function publishFeedStory(
256351
private function sendMail(
257352
PhabricatorAuditComment $comment,
258353
array $other_comments,
259-
array $inline_comments) {
354+
array $inline_comments,
355+
array $requests) {
356+
260357
assert_instances_of($other_comments, 'PhabricatorAuditComment');
261358
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
262359

@@ -277,6 +374,8 @@ private function sendMail(
277374
PhabricatorAuditActionConstants::ACCEPT => 'Accepted',
278375
PhabricatorAuditActionConstants::RESIGN => 'Resigned',
279376
PhabricatorAuditActionConstants::CLOSE => 'Closed',
377+
PhabricatorAuditActionConstants::ADD_CCS => 'Added CCs',
378+
PhabricatorAuditActionConstants::ADD_AUDITORS => 'Added Auditors',
280379
);
281380
$verb = idx($map, $comment->getAction(), 'Commented On');
282381

@@ -297,6 +396,7 @@ private function sendMail(
297396
$inline_comments);
298397

299398
$email_to = array();
399+
$email_cc = array();
300400

301401
$author_phid = $data->getCommitDetail('authorPHID');
302402
if ($author_phid) {
@@ -308,6 +408,12 @@ private function sendMail(
308408
$email_cc[] = $other_comment->getActorPHID();
309409
}
310410

411+
foreach ($requests as $request) {
412+
if ($request->getAuditStatus() == PhabricatorAuditStatusConstants::CC) {
413+
$email_cc[] = $request->getAuditorPHID();
414+
}
415+
}
416+
311417
$phids = array_merge($email_to, $email_cc);
312418
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
313419

src/applications/audit/editor/comment/__init__.php

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
phutil_require_module('phabricator', 'applications/diffusion/query/path');
1414
phutil_require_module('phabricator', 'applications/feed/constants/story');
1515
phutil_require_module('phabricator', 'applications/feed/publisher');
16+
phutil_require_module('phabricator', 'applications/markup/engine');
1617
phutil_require_module('phabricator', 'applications/metamta/storage/mail');
1718
phutil_require_module('phabricator', 'applications/owners/storage/owner');
1819
phutil_require_module('phabricator', 'applications/owners/storage/package');

src/applications/audit/storage/auditcomment/PhabricatorAuditComment.php

+7
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,21 @@
1818

1919
final class PhabricatorAuditComment extends PhabricatorAuditDAO {
2020

21+
const METADATA_ADDED_AUDITORS = 'added-auditors';
22+
const METADATA_ADDED_CCS = 'added-ccs';
23+
2124
protected $phid;
2225
protected $actorPHID;
2326
protected $targetPHID;
2427
protected $action;
2528
protected $content;
29+
protected $metadata = array();
2630

2731
public function getConfiguration() {
2832
return array(
33+
self::CONFIG_SERIALIZATION => array(
34+
'metadata' => self::SERIALIZATION_JSON,
35+
),
2936
self::CONFIG_AUX_PHID => true,
3037
) + parent::getConfiguration();
3138
}

0 commit comments

Comments
 (0)