@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Write separate comments for every action in Audit

Summary:
Ref T4896. Depends on D10023. Prepares the code for the final migration.

The transaction table stores one row per distinct effect (e.g., add CCs) rather than one row per user action (e.g., "add CCs + comment"). We can double-read that table as long as the code doesn't expect transactions/comments to have multiple different effects, and doesn't try to write any such rows.

Everywhere that we were writing a big "X + Y" comment, write two separate "X" and "Y" comments instead. Like D10023, this disrupts the UI a little (you get more boxes), but that will be resolved once the rendering code swaps over. Otherwise, this retains the existing behavior.

Test Plan:
- Used `diffusion.createcomment` to add comments, raise concern, and accept.
- Previewed commenting, adding auditors/ccs, accepting, raising concern.
- Actually performed commenting, adding auditors/ccs, accepting, raising concern.
- Added a user with mentions.
- Added an explicit CC and a mention user.

Reviewers: btrahan, joshuaspence

Reviewed By: joshuaspence

Subscribers: epriestley

Maniphest Tasks: T4896

Differential Revision: https://secure.phabricator.com/D10052

+154 -112
+29 -15
src/applications/audit/controller/PhabricatorAuditAddCommentController.php
··· 15 15 $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( 16 16 'phid = %s', 17 17 $commit_phid); 18 - 19 18 if (!$commit) { 20 19 return new Aphront404Response(); 21 20 } 22 21 23 22 $phids = array($commit_phid); 24 23 25 - $action = $request->getStr('action'); 26 - 27 - $comment = id(new PhabricatorAuditComment()) 28 - ->setAction($action) 29 - ->setContent($request->getStr('content')); 24 + $comments = array(); 30 25 31 26 // make sure we only add auditors or ccs if the action matches 27 + $action = $request->getStr('action'); 32 28 switch ($action) { 33 - case 'add_auditors': 29 + case PhabricatorAuditActionConstants::ADD_AUDITORS: 34 30 $auditors = $request->getArr('auditors'); 35 - $ccs = array(); 31 + $comments[] = id(new PhabricatorAuditComment()) 32 + ->setAction(PhabricatorAuditActionConstants::ADD_AUDITORS) 33 + ->setMetadata( 34 + array( 35 + PhabricatorAuditComment::METADATA_ADDED_AUDITORS => $auditors, 36 + )); 36 37 break; 37 - case 'add_ccs': 38 - $auditors = array(); 38 + case PhabricatorAuditActionConstants::ADD_CCS: 39 39 $ccs = $request->getArr('ccs'); 40 + $comments[] = id(new PhabricatorAuditComment()) 41 + ->setAction(PhabricatorAuditActionConstants::ADD_CCS) 42 + ->setMetadata( 43 + array( 44 + PhabricatorAuditComment::METADATA_ADDED_CCS => $ccs, 45 + )); 46 + break; 47 + case PhabricatorAuditActionConstants::COMMENT: 48 + // We'll deal with this below. 40 49 break; 41 50 default: 42 - $auditors = array(); 43 - $ccs = array(); 51 + $comments[] = id(new PhabricatorAuditComment()) 52 + ->setAction($action); 44 53 break; 45 54 } 46 55 56 + $content = $request->getStr('content'); 57 + if (strlen($content)) { 58 + $comments[] = id(new PhabricatorAuditComment()) 59 + ->setAction(PhabricatorAuditActionConstants::COMMENT) 60 + ->setContent($content); 61 + } 62 + 47 63 id(new PhabricatorAuditCommentEditor($commit)) 48 64 ->setActor($user) 49 65 ->setAttachInlineComments(true) 50 - ->addAuditors($auditors) 51 - ->addCCs($ccs) 52 - ->addComment($comment); 66 + ->addComments($comments); 53 67 54 68 $handles = $this->loadViewerHandles($phids); 55 69 $uri = $handles[$commit_phid]->getURI();
+54 -30
src/applications/audit/controller/PhabricatorAuditPreviewController.php
··· 20 20 21 21 $action = $request->getStr('action'); 22 22 23 - $comment = id(new PhabricatorAuditComment()) 24 - ->setActorPHID($user->getPHID()) 25 - ->setTargetPHID($commit->getPHID()) 26 - ->setAction($action) 27 - ->setContent($request->getStr('content')); 28 - 29 23 $phids = array( 30 24 $user->getPHID(), 31 25 $commit->getPHID(), 32 26 ); 33 27 34 - $auditors = $request->getStrList('auditors'); 35 - if ($action == PhabricatorAuditActionConstants::ADD_AUDITORS && $auditors) { 36 - $comment->setMetadata(array( 37 - PhabricatorAuditComment::METADATA_ADDED_AUDITORS => $auditors)); 38 - $phids = array_merge($phids, $auditors); 28 + $comments = array(); 29 + 30 + if ($action != PhabricatorAuditActionConstants::COMMENT) { 31 + $action_comment = id(new PhabricatorAuditComment()) 32 + ->setActorPHID($user->getPHID()) 33 + ->setTargetPHID($commit->getPHID()) 34 + ->setAction($action); 35 + 36 + $auditors = $request->getStrList('auditors'); 37 + if ($action == PhabricatorAuditActionConstants::ADD_AUDITORS && 38 + $auditors) { 39 + 40 + $action_comment->setMetadata(array( 41 + PhabricatorAuditComment::METADATA_ADDED_AUDITORS => $auditors)); 42 + $phids = array_merge($phids, $auditors); 43 + } 44 + 45 + $ccs = $request->getStrList('ccs'); 46 + if ($action == PhabricatorAuditActionConstants::ADD_CCS && $ccs) { 47 + $action_comment->setMetadata(array( 48 + PhabricatorAuditComment::METADATA_ADDED_CCS => $ccs)); 49 + $phids = array_merge($phids, $ccs); 50 + } 51 + 52 + $comments[] = $action_comment; 39 53 } 40 54 41 - $ccs = $request->getStrList('ccs'); 42 - if ($action == PhabricatorAuditActionConstants::ADD_CCS && $ccs) { 43 - $comment->setMetadata(array( 44 - PhabricatorAuditComment::METADATA_ADDED_CCS => $ccs)); 45 - $phids = array_merge($phids, $ccs); 55 + $content = $request->getStr('content'); 56 + if (strlen($content)) { 57 + $comments[] = id(new PhabricatorAuditComment()) 58 + ->setActorPHID($user->getPHID()) 59 + ->setTargetPHID($commit->getPHID()) 60 + ->setAction(PhabricatorAuditActionConstants::COMMENT) 61 + ->setContent($content); 46 62 } 47 63 48 64 $engine = new PhabricatorMarkupEngine(); 49 65 $engine->setViewer($user); 50 - $engine->addObject( 51 - $comment, 52 - PhabricatorAuditComment::MARKUP_FIELD_BODY); 66 + foreach ($comments as $comment) { 67 + $engine->addObject( 68 + $comment, 69 + PhabricatorAuditComment::MARKUP_FIELD_BODY); 70 + } 53 71 $engine->process(); 54 72 55 - $view = id(new DiffusionCommentView()) 56 - ->setMarkupEngine($engine) 57 - ->setUser($user) 58 - ->setComment($comment) 59 - ->setIsPreview(true); 73 + $views = array(); 74 + foreach ($comments as $comment) { 75 + $view = id(new DiffusionCommentView()) 76 + ->setMarkupEngine($engine) 77 + ->setUser($user) 78 + ->setComment($comment) 79 + ->setIsPreview(true); 60 80 61 - $phids = array_merge($phids, $view->getRequiredHandlePHIDs()); 81 + $phids = array_merge($phids, $view->getRequiredHandlePHIDs()); 82 + $views[] = $view; 83 + } 62 84 63 85 $handles = $this->loadViewerHandles($phids); 64 - $view->setHandles($handles); 86 + 87 + foreach ($views as $view) { 88 + $view->setHandles($handles); 89 + } 65 90 66 91 id(new PhabricatorDraft()) 67 - ->setAuthorPHID($comment->getActorPHID()) 92 + ->setAuthorPHID($user->getPHID()) 68 93 ->setDraftKey('diffusion-audit-'.$this->id) 69 - ->setDraft($comment->getContent()) 94 + ->setDraft($content) 70 95 ->replaceOrDelete(); 71 96 72 - return id(new AphrontAjaxResponse()) 73 - ->setContent($view->render()); 97 + return id(new AphrontAjaxResponse())->setContent(hsprintf('%s', $views)); 74 98 } 75 99 76 100 }
+57 -62
src/applications/audit/editor/PhabricatorAuditCommentEditor.php
··· 3 3 final class PhabricatorAuditCommentEditor extends PhabricatorEditor { 4 4 5 5 private $commit; 6 - 7 6 private $attachInlineComments; 8 - private $auditors = array(); 9 - private $ccs = array(); 10 - 11 7 private $noEmail; 12 8 13 9 public function __construct(PhabricatorRepositoryCommit $commit) { ··· 15 11 return $this; 16 12 } 17 13 18 - public function addAuditors(array $auditor_phids) { 19 - $this->auditors = array_merge($this->auditors, $auditor_phids); 20 - return $this; 21 - } 22 - 23 - public function addCCs(array $cc_phids) { 24 - $this->ccs = array_merge($this->ccs, $cc_phids); 25 - return $this; 26 - } 27 - 28 14 public function setAttachInlineComments($attach_inline_comments) { 29 15 $this->attachInlineComments = $attach_inline_comments; 30 16 return $this; ··· 35 21 return $this; 36 22 } 37 23 38 - public function addComment(PhabricatorAuditComment $comment) { 24 + public function addComments(array $comments) { 25 + assert_instances_of($comments, 'PhabricatorAuditComment'); 39 26 40 27 $commit = $this->commit; 41 28 $actor = $this->getActor(); ··· 51 38 $commit->getPHID()); 52 39 } 53 40 54 - $comment 55 - ->setActorPHID($actor->getPHID()) 56 - ->setTargetPHID($commit->getPHID()) 57 - ->save(); 41 + $content_blocks = array(); 42 + foreach ($comments as $comment) { 43 + $content_blocks[] = $comment->getContent(); 44 + } 58 45 59 - $content_blocks = array($comment->getContent()); 60 46 foreach ($inline_comments as $inline) { 61 47 $content_blocks[] = $inline->getContent(); 62 48 } 63 49 64 - $ccs = $this->ccs; 65 - $auditors = $this->auditors; 66 - 67 - $metadata = $comment->getMetadata(); 68 - $metacc = array(); 69 - 70 50 // Find any "@mentions" in the content blocks. 71 51 $mention_ccs = PhabricatorMarkupEngine::extractPHIDsFromMentions( 72 52 $this->getActor(), 73 53 $content_blocks); 74 54 if ($mention_ccs) { 75 - $metacc = idx( 76 - $metadata, 77 - PhabricatorAuditComment::METADATA_ADDED_CCS, 78 - array()); 79 - foreach ($mention_ccs as $cc_phid) { 80 - $metacc[] = $cc_phid; 81 - } 82 - } 83 - 84 - if ($metacc) { 85 - $ccs = array_merge($ccs, $metacc); 55 + $comments[] = id(new PhabricatorAuditComment()) 56 + ->setAction(PhabricatorAuditActionConstants::ADD_CCS) 57 + ->setMetadata( 58 + array( 59 + PhabricatorAuditComment::METADATA_ADDED_CCS => $mention_ccs, 60 + )); 86 61 } 87 62 88 63 // When an actor submits an audit comment, we update all the audit requests ··· 101 76 102 77 $action = $comment->getAction(); 103 78 104 - 105 79 // TODO: We should validate the action, currently we allow anyone to, e.g., 106 80 // close an audit if they muck with form parameters. I'll followup with this 107 81 // and handle the no-effect cases (e.g., closing and already-closed audit). 108 82 83 + $actor_is_author = ($actor->getPHID() == $commit->getAuthorPHID()); 109 84 110 - $actor_is_author = ($actor->getPHID() == $commit->getAuthorPHID()); 85 + // Pick a meaningful action, if we have one. 86 + $action = PhabricatorAuditActionConstants::COMMENT; 87 + foreach ($comments as $comment) { 88 + switch ($comment->getAction()) { 89 + case PhabricatorAuditActionConstants::CLOSE: 90 + case PhabricatorAuditActionConstants::RESIGN: 91 + case PhabricatorAuditActionConstants::ACCEPT: 92 + case PhabricatorAuditActionConstants::CONCERN: 93 + $action = $comment->getAction(); 94 + break; 95 + } 96 + } 111 97 112 98 if ($action == PhabricatorAuditActionConstants::CLOSE) { 113 99 if (!PhabricatorEnv::getEnvConfig('audit.can-author-close-audit')) { 114 - throw new Exception('Cannot Close Audit without enabling'. 100 + throw new Exception('Cannot Close Audit without enabling'. 115 101 'audit.can-author-close-audit'); 116 102 } 117 103 // "Close" means wipe out all the concerns. ··· 219 205 } 220 206 } 221 207 222 - $requests_by_auditor = mpull($requests, null, 'getAuditorPHID'); 223 - $requests_phids = array_keys($requests_by_auditor); 208 + $auditors = array(); 209 + $ccs = array(); 210 + foreach ($comments as $comment) { 211 + $meta = $comment->getMetadata(); 224 212 225 - $ccs = array_diff($ccs, $requests_phids); 226 - $auditors = array_diff($auditors, $requests_phids); 213 + $auditor_phids = idx( 214 + $meta, 215 + PhabricatorAuditComment::METADATA_ADDED_AUDITORS, 216 + array()); 217 + foreach ($auditor_phids as $phid) { 218 + $auditors[] = $phid; 219 + } 227 220 228 - if ($action == PhabricatorAuditActionConstants::ADD_CCS) { 229 - if ($ccs) { 230 - $metadata[PhabricatorAuditComment::METADATA_ADDED_CCS] = $ccs; 231 - $comment->setMetaData($metadata); 232 - } else { 233 - $comment->setAction(PhabricatorAuditActionConstants::COMMENT); 221 + $cc_phids = idx( 222 + $meta, 223 + PhabricatorAuditComment::METADATA_ADDED_CCS, 224 + array()); 225 + foreach ($cc_phids as $phid) { 226 + $ccs[] = $phid; 234 227 } 235 228 } 236 229 237 - if ($action == PhabricatorAuditActionConstants::ADD_AUDITORS) { 238 - if ($auditors) { 239 - $metadata[PhabricatorAuditComment::METADATA_ADDED_AUDITORS] 240 - = $auditors; 241 - $comment->setMetaData($metadata); 242 - } else { 243 - $comment->setAction(PhabricatorAuditActionConstants::COMMENT); 244 - } 245 - } 230 + $requests_by_auditor = mpull($requests, null, 'getAuditorPHID'); 231 + $requests_phids = array_keys($requests_by_auditor); 246 232 247 - $comment->save(); 233 + $ccs = array_diff($ccs, $requests_phids); 234 + $auditors = array_diff($auditors, $requests_phids); 248 235 249 236 if ($auditors) { 250 237 foreach ($auditors as $auditor_phid) { ··· 275 262 $commit->updateAuditStatus($requests); 276 263 $commit->save(); 277 264 278 - $comments = array($comment); 265 + foreach ($comments as $comment) { 266 + $comment 267 + ->setActorPHID($actor->getPHID()) 268 + ->setTargetPHID($commit->getPHID()) 269 + ->save(); 270 + } 271 + 279 272 foreach ($inline_comments as $inline) { 280 273 $xaction = id(new PhabricatorAuditComment()) 281 274 ->setAction(PhabricatorAuditActionConstants::INLINE) ··· 307 300 $feed_dont_publish_phids = array_keys($feed_dont_publish_phids); 308 301 309 302 $feed_phids = array_diff($requests_phids, $feed_dont_publish_phids); 310 - $this->publishFeedStory($comment, $feed_phids); 303 + foreach ($comments as $comment) { 304 + $this->publishFeedStory($comment, $feed_phids); 305 + } 311 306 312 307 id(new PhabricatorSearchIndexer()) 313 308 ->queueDocumentForIndexing($commit->getPHID());
+1 -1
src/applications/audit/mail/PhabricatorAuditReplyHandler.php
··· 45 45 $editor->setActor($actor); 46 46 $editor->setExcludeMailRecipientPHIDs( 47 47 $this->getExcludeMailRecipientPHIDs()); 48 - $editor->addComment($comment); 48 + $editor->addComments(array($comment)); 49 49 } 50 50 51 51 }
+13 -4
src/applications/diffusion/conduit/DiffusionCreateCommentConduitAPIMethod.php
··· 69 69 throw new ConduitException('ERR_BAD_ACTION'); 70 70 } 71 71 72 - $comment = id(new PhabricatorAuditComment()) 73 - ->setAction($action) 74 - ->setContent($message); 72 + $comments = array(); 73 + 74 + if ($action != PhabricatorAuditActionConstants::COMMENT) { 75 + $comments[] = id(new PhabricatorAuditComment()) 76 + ->setAction($action); 77 + } 78 + 79 + if (strlen($message)) { 80 + $comments[] = id(new PhabricatorAuditComment()) 81 + ->setAction(PhabricatorAuditActionConstants::COMMENT) 82 + ->setContent($message); 83 + } 75 84 76 85 id(new PhabricatorAuditCommentEditor($commit)) 77 86 ->setActor($request->getUser()) 78 87 ->setNoEmail($request->getValue('silent')) 79 - ->addComment($comment); 88 + ->addComments($comments); 80 89 81 90 return true; 82 91 // get the full uri of the comment?