@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 "resign" and "close" Audit actions

Summary: Ref T4896. Hook these up with new stuff.

Test Plan:
- Closed an audit.
- Resigned from an audit.

Reviewers: joshuaspence, btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4896

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

+115 -35
+4 -33
src/applications/audit/editor/PhabricatorAuditCommentEditor.php
··· 69 69 } 70 70 71 71 if ($action == PhabricatorAuditActionConstants::CLOSE) { 72 - if (!PhabricatorEnv::getEnvConfig('audit.can-author-close-audit')) { 73 - throw new Exception('Cannot Close Audit without enabling'. 74 - 'audit.can-author-close-audit'); 75 - } 76 - // "Close" means wipe out all the concerns. 77 - $concerned_status = PhabricatorAuditStatusConstants::CONCERNED; 78 - foreach ($requests as $request) { 79 - if ($request->getAuditStatus() == $concerned_status) { 80 - $request->setAuditStatus(PhabricatorAuditStatusConstants::CLOSED); 81 - $request->save(); 82 - } 83 - } 72 + 73 + // This is now applied by the transaction Editor. 74 + 84 75 } else if ($action == PhabricatorAuditActionConstants::RESIGN) { 85 - // "Resign" has unusual rules for writing user rows, only affects the 86 - // user row (never package/project rows), and always affects the user 87 - // row (other actions don't, if they were able to affect a package/project 88 - // row). 89 - $actor_request = null; 90 - foreach ($requests as $request) { 91 - if ($request->getAuditorPHID() == $actor->getPHID()) { 92 - $actor_request = $request; 93 - break; 94 - } 95 - } 96 - if (!$actor_request) { 97 - $actor_request = id(new PhabricatorRepositoryAuditRequest()) 98 - ->setCommitPHID($commit->getPHID()) 99 - ->setAuditorPHID($actor->getPHID()) 100 - ->setAuditReasons(array('Resigned')); 101 - } 102 76 103 - $actor_request 104 - ->setAuditStatus(PhabricatorAuditStatusConstants::RESIGNED) 105 - ->save(); 77 + // This is now applied by the transaction Editor. 106 78 107 - $requests[] = $actor_request; 108 79 } else { 109 80 $have_any_requests = false; 110 81 foreach ($requests as $request) {
+111 -2
src/applications/audit/editor/PhabricatorAuditEditor.php
··· 119 119 ->save(); 120 120 } 121 121 122 - $object->updateAuditStatus($requests); 123 122 $object->attachAudits($requests); 124 - $object->save(); 125 123 return; 126 124 } 127 125 128 126 return parent::applyCustomExternalTransaction($object, $xaction); 129 127 } 130 128 129 + protected function applyFinalEffects( 130 + PhabricatorLiskDAO $object, 131 + array $xactions) { 132 + 133 + $status_concerned = PhabricatorAuditStatusConstants::CONCERNED; 134 + $status_closed = PhabricatorAuditStatusConstants::CLOSED; 135 + $status_resigned = PhabricatorAuditStatusConstants::RESIGNED; 136 + 137 + $actor_phid = $this->requireActor()->getPHID(); 138 + 139 + foreach ($xactions as $xaction) { 140 + switch ($xaction->getTransactionType()) { 141 + case PhabricatorAuditActionConstants::ACTION: 142 + switch ($xaction->getNewValue()) { 143 + case PhabricatorAuditActionConstants::CLOSE: 144 + // "Close" means wipe out all the concerns. 145 + $requests = $object->getAudits(); 146 + foreach ($requests as $request) { 147 + if ($request->getAuditStatus() == $status_concerned) { 148 + $request 149 + ->setAuditStatus($status_closed) 150 + ->save(); 151 + } 152 + } 153 + break; 154 + case PhabricatorAuditActionConstants::RESIGN: 155 + $requests = $object->getAudits(); 156 + $requests = mpull($requests, null, 'getAuditorPHID'); 157 + $actor_request = idx($requests, $actor_phid); 158 + 159 + if ($actor_request) { 160 + $actor_request 161 + ->setAuditStatus($status_resigned) 162 + ->save(); 163 + } 164 + break; 165 + } 166 + break; 167 + } 168 + } 169 + 170 + $requests = $object->getAudits(); 171 + $object->updateAuditStatus($requests); 172 + $object->save(); 173 + 174 + return $xactions; 175 + } 176 + 131 177 protected function sortTransactions(array $xactions) { 132 178 $xactions = parent::sortTransactions($xactions); 133 179 ··· 145 191 146 192 return array_values(array_merge($head, $tail)); 147 193 } 194 + 195 + protected function validateTransaction( 196 + PhabricatorLiskDAO $object, 197 + $type, 198 + array $xactions) { 199 + 200 + $errors = parent::validateTransaction($object, $type, $xactions); 201 + 202 + foreach ($xactions as $xaction) { 203 + switch ($type) { 204 + case PhabricatorAuditActionConstants::ACTION: 205 + $error = $this->validateAuditAction( 206 + $object, 207 + $type, 208 + $xaction, 209 + $xaction->getNewValue()); 210 + if ($error) { 211 + $errors[] = new PhabricatorApplicationTransactionValidationError( 212 + $type, 213 + pht('Invalid'), 214 + $error, 215 + $xaction); 216 + } 217 + break; 218 + } 219 + } 220 + 221 + return $errors; 222 + } 223 + 224 + private function validateAuditAction( 225 + PhabricatorLiskDAO $object, 226 + $type, 227 + PhabricatorAuditTransaction $xaction, 228 + $action) { 229 + 230 + $can_author_close_key = 'audit.can-author-close-audit'; 231 + $can_author_close = PhabricatorEnv::getEnvConfig($can_author_close_key); 232 + 233 + $actor_is_author = ($object->getAuthorPHID()) && 234 + ($object->getAuthorPHID() == $this->requireActor()->getPHID()); 235 + 236 + switch ($action) { 237 + case PhabricatorAuditActionConstants::CLOSE: 238 + if (!$actor_is_author) { 239 + return pht( 240 + 'You can not close this audit because you are not the author '. 241 + 'of the commit.'); 242 + } 243 + 244 + if (!$can_author_close) { 245 + return pht( 246 + 'You can not close this audit because "%s" is disabled in '. 247 + 'the Phabricator configuration.', 248 + $can_author_close_key); 249 + } 250 + 251 + break; 252 + } 253 + 254 + return null; 255 + } 256 + 148 257 149 258 protected function supportsSearch() { 150 259 return true;