@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.

Use transactions to apply "add auditors" action in Audit

Summary:
Ref T4896. Move the write for "Add Auditors" inside the new Editor.

There are no longer any readers or writers for metadata, so remove the calls for it.

Test Plan: Added auditors from the web UI.

Reviewers: joshuaspence, btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4896

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

+49 -87
+8 -8
resources/celerity/map.php
··· 8 8 return array( 9 9 'names' => array( 10 10 'core.pkg.css' => '66ada2ec', 11 - 'core.pkg.js' => 'c3965034', 11 + 'core.pkg.js' => '8cd3cd8c', 12 12 'darkconsole.pkg.js' => 'df001cab', 13 13 'differential.pkg.css' => '4a93db37', 14 14 'differential.pkg.js' => '79503aa4', ··· 463 463 'rsrc/js/core/behavior-error-log.js' => 'a5d7cf86', 464 464 'rsrc/js/core/behavior-fancy-datepicker.js' => 'a5573bcd', 465 465 'rsrc/js/core/behavior-file-tree.js' => '88236f00', 466 - 'rsrc/js/core/behavior-form.js' => '3b1557b3', 466 + 'rsrc/js/core/behavior-form.js' => '5c54cbf3', 467 467 'rsrc/js/core/behavior-gesture.js' => '3ab51e2c', 468 468 'rsrc/js/core/behavior-global-drag-and-drop.js' => '3672899b', 469 469 'rsrc/js/core/behavior-high-security-warning.js' => '8fc1c918', ··· 551 551 'javelin-behavior-aphront-basic-tokenizer' => 'b3a4b884', 552 552 'javelin-behavior-aphront-crop' => 'fa0f4fc2', 553 553 'javelin-behavior-aphront-drag-and-drop-textarea' => '92eb531d', 554 - 'javelin-behavior-aphront-form-disable-on-submit' => '3b1557b3', 554 + 'javelin-behavior-aphront-form-disable-on-submit' => '5c54cbf3', 555 555 'javelin-behavior-aphront-more' => 'a80d0378', 556 556 'javelin-behavior-audio-source' => '59b251eb', 557 557 'javelin-behavior-audit-preview' => 'd835b03a', ··· 1069 1069 'javelin-dom', 1070 1070 'javelin-magical-init', 1071 1071 ), 1072 - '3b1557b3' => array( 1073 - 'javelin-behavior', 1074 - 'javelin-stratcom', 1075 - 'javelin-dom', 1076 - ), 1077 1072 '3b3e1664' => array( 1078 1073 'javelin-behavior', 1079 1074 'javelin-dom', ··· 1213 1208 '5bc2cb21' => array( 1214 1209 'javelin-behavior', 1215 1210 'javelin-stratcom', 1211 + ), 1212 + '5c54cbf3' => array( 1213 + 'javelin-behavior', 1214 + 'javelin-stratcom', 1215 + 'javelin-dom', 1216 1216 ), 1217 1217 '5fefb143' => array( 1218 1218 'javelin-behavior',
+2 -4
src/applications/audit/controller/PhabricatorAuditAddCommentController.php
··· 15 15 $commit = id(new DiffusionCommitQuery()) 16 16 ->setViewer($user) 17 17 ->withPHIDs(array($commit_phid)) 18 + ->needAuditRequests(true) 18 19 ->executeOne(); 19 20 if (!$commit) { 20 21 return new Aphront404Response(); ··· 31 32 $auditors = $request->getArr('auditors'); 32 33 $comments[] = id(new PhabricatorAuditComment()) 33 34 ->setAction(PhabricatorAuditActionConstants::ADD_AUDITORS) 34 - ->setMetadata( 35 - array( 36 - PhabricatorAuditComment::METADATA_ADDED_AUDITORS => $auditors, 37 - )); 35 + ->setNewValue(array_fuse($auditors)); 38 36 break; 39 37 case PhabricatorAuditActionConstants::ADD_CCS: 40 38 $comments[] = id(new PhabricatorAuditComment())
+1 -36
src/applications/audit/editor/PhabricatorAuditCommentEditor.php
··· 47 47 $audit_phids = self::loadAuditPHIDsForUser($actor); 48 48 $audit_phids = array_fill_keys($audit_phids, true); 49 49 50 - $requests = id(new PhabricatorRepositoryAuditRequest()) 51 - ->loadAllWhere( 52 - 'commitPHID = %s', 53 - $commit->getPHID()); 50 + $requests = $commit->getAudits(); 54 51 55 52 // TODO: We should validate the action, currently we allow anyone to, e.g., 56 53 // close an audit if they muck with form parameters. I'll followup with this ··· 179 176 ->save(); 180 177 $requests[] = $request; 181 178 } 182 - } 183 - } 184 - 185 - $auditors = array(); 186 - 187 - foreach ($comments as $comment) { 188 - $meta = $comment->getMetadata(); 189 - 190 - $auditor_phids = idx( 191 - $meta, 192 - PhabricatorAuditComment::METADATA_ADDED_AUDITORS, 193 - array()); 194 - foreach ($auditor_phids as $phid) { 195 - $auditors[] = $phid; 196 - } 197 - } 198 - 199 - $requests_by_auditor = mpull($requests, null, 'getAuditorPHID'); 200 - $requests_phids = array_keys($requests_by_auditor); 201 - 202 - $auditors = array_diff($auditors, $requests_phids); 203 - 204 - if ($auditors) { 205 - foreach ($auditors as $auditor_phid) { 206 - $audit_requested = PhabricatorAuditStatusConstants::AUDIT_REQUESTED; 207 - $requests[] = id (new PhabricatorRepositoryAuditRequest()) 208 - ->setCommitPHID($commit->getPHID()) 209 - ->setAuditorPHID($auditor_phid) 210 - ->setAuditStatus($audit_requested) 211 - ->setAuditReasons( 212 - array('Added by '.$actor->getUsername())) 213 - ->save(); 214 179 } 215 180 } 216 181
+36 -1
src/applications/audit/editor/PhabricatorAuditEditor.php
··· 86 86 case PhabricatorAuditActionConstants::INLINE: 87 87 return; 88 88 case PhabricatorAuditActionConstants::ADD_AUDITORS: 89 - // TODO: For now, these are applied externally. 89 + $new = $xaction->getNewValue(); 90 + if (!is_array($new)) { 91 + $new = array(); 92 + } 93 + 94 + $old = $xaction->getOldValue(); 95 + if (!is_array($old)) { 96 + $old = array(); 97 + } 98 + 99 + $add = array_diff_key($new, $old); 100 + 101 + $actor = $this->requireActor(); 102 + 103 + $requests = $object->getAudits(); 104 + $requests = mpull($requests, null, 'getAuditorPHID'); 105 + foreach ($add as $phid) { 106 + if (isset($requests[$phid])) { 107 + continue; 108 + } 109 + 110 + $audit_requested = PhabricatorAuditStatusConstants::AUDIT_REQUESTED; 111 + $requests[] = id (new PhabricatorRepositoryAuditRequest()) 112 + ->setCommitPHID($object->getPHID()) 113 + ->setAuditorPHID($phid) 114 + ->setAuditStatus($audit_requested) 115 + ->setAuditReasons( 116 + array( 117 + 'Added by '.$actor->getUsername(), 118 + )) 119 + ->save(); 120 + } 121 + 122 + $object->updateAuditStatus($requests); 123 + $object->attachAudits($requests); 124 + $object->save(); 90 125 return; 91 126 } 92 127
+1
src/applications/audit/mail/PhabricatorAuditMailReceiver.php
··· 17 17 return id(new DiffusionCommitQuery()) 18 18 ->setViewer($viewer) 19 19 ->withIDs(array($id)) 20 + ->needAuditRequests(true) 20 21 ->executeOne(); 21 22 } 22 23
-38
src/applications/audit/storage/PhabricatorAuditComment.php
··· 3 3 final class PhabricatorAuditComment 4 4 implements PhabricatorMarkupInterface { 5 5 6 - const METADATA_ADDED_AUDITORS = 'added-auditors'; 7 - 8 6 const MARKUP_FIELD_BODY = 'markup:body'; 9 7 10 8 private $proxyComment; ··· 143 141 default: 144 142 return $this->proxy->getNewValue(); 145 143 } 146 - } 147 - 148 - public function setMetadata(array $metadata) { 149 - if (!$this->proxy->getTransactionType()) { 150 - throw new Exception(pht('Call setAction() before getMetadata()!')); 151 - } 152 - 153 - $type = $this->proxy->getTransactionType(); 154 - switch ($type) { 155 - case PhabricatorAuditActionConstants::ADD_AUDITORS: 156 - $raw_phids = idx($metadata, self::METADATA_ADDED_AUDITORS, array()); 157 - break; 158 - default: 159 - throw new Exception(pht('No metadata expected!')); 160 - } 161 - 162 - $this->proxy->setNewValue(array_fuse($raw_phids)); 163 - 164 - return $this; 165 - } 166 - 167 - public function getMetadata() { 168 - if (!$this->proxy->getTransactionType()) { 169 - throw new Exception(pht('Call setAction() before getMetadata()!')); 170 - } 171 - 172 - $type = $this->proxy->getTransactionType(); 173 - $new_value = $this->proxy->getNewValue(); 174 - switch ($type) { 175 - case PhabricatorAuditActionConstants::ADD_AUDITORS: 176 - return array( 177 - self::METADATA_ADDED_AUDITORS => array_keys($new_value), 178 - ); 179 - } 180 - 181 - return array(); 182 144 } 183 145 184 146 public function save() {
+1
src/applications/diffusion/conduit/DiffusionCreateCommentConduitAPIMethod.php
··· 43 43 $commit = id(new DiffusionCommitQuery()) 44 44 ->setViewer($request->getUser()) 45 45 ->withPHIDs(array($commit_phid)) 46 + ->needAuditRequests(true) 46 47 ->executeOne(); 47 48 if (!$commit) { 48 49 throw new ConduitException('ERR_BAD_COMMIT');