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

Apply "accept" and "resign" actions with transactions

Summary: Ref T4896. Applies these actions using new transaction stuff.

Test Plan:
- Accepted and raised concern with my own commit, verifying the special project/package behavior.
- Accepted and raised concern with another author's commit, verifying the authority-over-packages/projects behavior.
- Accepted a commit I was not affiliated wiht, verifying the "join as an auditor" behavior.

Reviewers: joshuaspence, btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4896

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

+58 -118
-117
src/applications/audit/editor/PhabricatorAuditCommentEditor.php
··· 38 38 $commit->getPHID()); 39 39 } 40 40 41 - // When an actor submits an audit comment, we update all the audit requests 42 - // they have authority over to reflect the most recent status. The general 43 - // idea here is that if audit has triggered for, e.g., several packages, but 44 - // a user owns all of them, they can clear the audit requirement in one go 45 - // without auditing the commit for each trigger. 46 - 47 - $audit_phids = self::loadAuditPHIDsForUser($actor); 48 - $audit_phids = array_fill_keys($audit_phids, true); 49 - 50 - $requests = $commit->getAudits(); 51 - 52 - // TODO: We should validate the action, currently we allow anyone to, e.g., 53 - // close an audit if they muck with form parameters. I'll followup with this 54 - // and handle the no-effect cases (e.g., closing and already-closed audit). 55 - 56 - $actor_is_author = ($actor->getPHID() == $commit->getAuthorPHID()); 57 - 58 - // Pick a meaningful action, if we have one. 59 - $action = PhabricatorAuditActionConstants::COMMENT; 60 - foreach ($comments as $comment) { 61 - switch ($comment->getAction()) { 62 - case PhabricatorAuditActionConstants::CLOSE: 63 - case PhabricatorAuditActionConstants::RESIGN: 64 - case PhabricatorAuditActionConstants::ACCEPT: 65 - case PhabricatorAuditActionConstants::CONCERN: 66 - $action = $comment->getAction(); 67 - break; 68 - } 69 - } 70 - 71 - if ($action == PhabricatorAuditActionConstants::CLOSE) { 72 - 73 - // This is now applied by the transaction Editor. 74 - 75 - } else if ($action == PhabricatorAuditActionConstants::RESIGN) { 76 - 77 - // This is now applied by the transaction Editor. 78 - 79 - } else { 80 - $have_any_requests = false; 81 - foreach ($requests as $request) { 82 - if (empty($audit_phids[$request->getAuditorPHID()])) { 83 - continue; 84 - } 85 - 86 - $request_is_for_actor = 87 - ($request->getAuditorPHID() == $actor->getPHID()); 88 - 89 - $have_any_requests = true; 90 - $new_status = null; 91 - switch ($action) { 92 - case PhabricatorAuditActionConstants::COMMENT: 93 - case PhabricatorAuditActionConstants::ADD_CCS: 94 - case PhabricatorAuditActionConstants::ADD_AUDITORS: 95 - // Commenting or adding cc's/auditors doesn't change status. 96 - break; 97 - case PhabricatorAuditActionConstants::ACCEPT: 98 - if (!$actor_is_author || $request_is_for_actor) { 99 - // When modifying your own commits, you act only on behalf of 100 - // yourself, not your packages/projects -- the idea being that 101 - // you can't accept your own commits. 102 - $new_status = PhabricatorAuditStatusConstants::ACCEPTED; 103 - } 104 - break; 105 - case PhabricatorAuditActionConstants::CONCERN: 106 - if (!$actor_is_author || $request_is_for_actor) { 107 - // See above. 108 - $new_status = PhabricatorAuditStatusConstants::CONCERNED; 109 - } 110 - break; 111 - default: 112 - throw new Exception("Unknown action '{$action}'!"); 113 - } 114 - if ($new_status !== null) { 115 - $request->setAuditStatus($new_status); 116 - $request->save(); 117 - } 118 - } 119 - 120 - // If the actor has no current authority over any audit trigger, make a 121 - // new one to represent their audit state. 122 - if (!$have_any_requests) { 123 - $new_status = null; 124 - switch ($action) { 125 - case PhabricatorAuditActionConstants::COMMENT: 126 - case PhabricatorAuditActionConstants::ADD_AUDITORS: 127 - case PhabricatorAuditActionConstants::ADD_CCS: 128 - break; 129 - case PhabricatorAuditActionConstants::ACCEPT: 130 - $new_status = PhabricatorAuditStatusConstants::ACCEPTED; 131 - break; 132 - case PhabricatorAuditActionConstants::CONCERN: 133 - $new_status = PhabricatorAuditStatusConstants::CONCERNED; 134 - break; 135 - case PhabricatorAuditActionConstants::CLOSE: 136 - // Impossible to reach this block with 'close'. 137 - default: 138 - throw new Exception("Unknown or invalid action '{$action}'!"); 139 - } 140 - 141 - if ($new_status !== null) { 142 - $request = id(new PhabricatorRepositoryAuditRequest()) 143 - ->setCommitPHID($commit->getPHID()) 144 - ->setAuditorPHID($actor->getPHID()) 145 - ->setAuditStatus($new_status) 146 - ->setAuditReasons(array('Voluntary Participant')) 147 - ->save(); 148 - $requests[] = $request; 149 - } 150 - } 151 - } 152 - 153 - $commit->updateAuditStatus($requests); 154 - $commit->save(); 155 - 156 - $commit->attachAudits($requests); 157 - 158 41 // Convert old comments into real transactions and apply them with a 159 42 // normal editor. 160 43
+58 -1
src/applications/audit/editor/PhabricatorAuditEditor.php
··· 133 133 $status_concerned = PhabricatorAuditStatusConstants::CONCERNED; 134 134 $status_closed = PhabricatorAuditStatusConstants::CLOSED; 135 135 $status_resigned = PhabricatorAuditStatusConstants::RESIGNED; 136 + $status_accepted = PhabricatorAuditStatusConstants::ACCEPTED; 137 + $status_concerned = PhabricatorAuditStatusConstants::CONCERNED; 136 138 137 139 $actor_phid = $this->requireActor()->getPHID(); 140 + $actor_is_author = ($object->getAuthorPHID()) && 141 + ($actor_phid == $object->getAuthorPHID()); 138 142 139 143 foreach ($xactions as $xaction) { 140 144 switch ($xaction->getTransactionType()) { 141 145 case PhabricatorAuditActionConstants::ACTION: 142 - switch ($xaction->getNewValue()) { 146 + $new = $xaction->getNewValue(); 147 + switch ($new) { 143 148 case PhabricatorAuditActionConstants::CLOSE: 144 149 // "Close" means wipe out all the concerns. 145 150 $requests = $object->getAudits(); ··· 162 167 ->save(); 163 168 } 164 169 break; 170 + case PhabricatorAuditActionConstants::ACCEPT: 171 + case PhabricatorAuditActionConstants::CONCERN: 172 + if ($new == PhabricatorAuditActionConstants::ACCEPT) { 173 + $new_status = $status_accepted; 174 + } else { 175 + $new_status = $status_concerned; 176 + } 177 + 178 + $requests = $object->getAudits(); 179 + $requests = mpull($requests, null, 'getAuditorPHID'); 180 + 181 + // Figure out which requests the actor has authority over: these 182 + // are user requests where they are the auditor, and packages 183 + // and projects they are a member of. 184 + 185 + if ($actor_is_author) { 186 + // When modifying your own commits, you act only on behalf of 187 + // yourself, not your packages/projects -- the idea being that 188 + // you can't accept your own commits. 189 + $authority_phids = array($actor_phid); 190 + } else { 191 + $authority_phids = 192 + PhabricatorAuditCommentEditor::loadAuditPHIDsForUser( 193 + $this->requireActor()); 194 + } 195 + 196 + $authority = array_select_keys( 197 + $requests, 198 + $authority_phids); 199 + 200 + if (!$authority) { 201 + // If the actor has no authority over any existing requests, 202 + // create a new request for them. 203 + 204 + $actor_request = id(new PhabricatorRepositoryAuditRequest()) 205 + ->setCommitPHID($object->getPHID()) 206 + ->setAuditorPHID($actor_phid) 207 + ->setAuditStatus($new_status) 208 + ->save(); 209 + 210 + $requests[$actor_phid] = $actor_request; 211 + $object->attachAudits($requests); 212 + } else { 213 + // Otherwise, update the audit status of the existing requests. 214 + foreach ($authority as $request) { 215 + $request 216 + ->setAuditStatus($new_status) 217 + ->save(); 218 + } 219 + } 220 + break; 221 + 165 222 } 166 223 break; 167 224 }