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

Allow tokens to be awarded to MFA-required objects

Summary:
Depends on D19901. Ref T13222. See PHI873. Currently, the MFA code and the (older, not-really-transactional) token code don't play nicely.

In particular, if the Editor throws we tend to get half an effect applied.

For now, just make this work. Some day it could become more modern so that the transaction actually applies the write.

Test Plan: Awarded and rescinded tokens from an MFA-required object.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13222

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

+61 -15
+3 -1
src/applications/tokens/controller/PhabricatorTokenGiveController.php
··· 47 47 } 48 48 49 49 $done_uri = $handle->getURI(); 50 - if ($request->isDialogFormPost()) { 50 + if ($request->isFormOrHisecPost()) { 51 51 $content_source = PhabricatorContentSource::newFromRequest($request); 52 52 53 53 $editor = id(new PhabricatorTokenGivenEditor()) 54 54 ->setActor($viewer) 55 + ->setRequest($request) 56 + ->setCancelURI($handle->getURI()) 55 57 ->setContentSource($content_source); 56 58 if ($is_give) { 57 59 $token_phid = $request->getStr('tokenPHID');
+58 -14
src/applications/tokens/editor/PhabricatorTokenGivenEditor.php
··· 4 4 extends PhabricatorEditor { 5 5 6 6 private $contentSource; 7 + private $request; 8 + private $cancelURI; 7 9 8 10 public function setContentSource(PhabricatorContentSource $content_source) { 9 11 $this->contentSource = $content_source; ··· 14 16 return $this->contentSource; 15 17 } 16 18 19 + public function setRequest(AphrontRequest $request) { 20 + $this->request = $request; 21 + return $this; 22 + } 23 + 24 + public function getRequest() { 25 + return $this->request; 26 + } 27 + 28 + public function setCancelURI($cancel_uri) { 29 + $this->cancelURI = $cancel_uri; 30 + return $this; 31 + } 32 + 33 + public function getCancelURI() { 34 + return $this->cancelURI; 35 + } 36 + 17 37 public function addToken($object_phid, $token_phid) { 18 38 $token = $this->validateToken($token_phid); 19 39 $object = $this->validateObject($object_phid); ··· 41 61 id(new PhabricatorTokenCount())->getTableName(), 42 62 $object->getPHID()); 43 63 44 - $token_given->saveTransaction(); 64 + $current_token_phid = null; 65 + if ($current_token) { 66 + $current_token_phid = $current_token->getTokenPHID(); 67 + } 45 68 46 - $current_token_phid = null; 47 - if ($current_token) { 48 - $current_token_phid = $current_token->getTokenPHID(); 49 - } 69 + try { 70 + $this->publishTransaction( 71 + $object, 72 + $current_token_phid, 73 + $token->getPHID()); 74 + } catch (Exception $ex) { 75 + $token_given->killTransaction(); 76 + throw $ex; 77 + } 50 78 51 - $this->publishTransaction( 52 - $object, 53 - $current_token_phid, 54 - $token->getPHID()); 79 + $token_given->saveTransaction(); 55 80 56 81 $subscribed_phids = $object->getUsersToNotifyOfTokenGiven(); 57 82 if ($subscribed_phids) { ··· 86 111 return; 87 112 } 88 113 89 - $this->executeDeleteToken($object, $token_given); 90 - $this->publishTransaction( 91 - $object, 92 - $token_given->getTokenPHID(), 93 - null); 114 + $token_given->openTransaction(); 115 + $this->executeDeleteToken($object, $token_given); 116 + 117 + try { 118 + $this->publishTransaction( 119 + $object, 120 + $token_given->getTokenPHID(), 121 + null); 122 + } catch (Exception $ex) { 123 + $token_given->killTransaction(); 124 + throw $ex; 125 + } 126 + 127 + $token_given->saveTransaction(); 94 128 } 95 129 96 130 private function executeDeleteToken( ··· 165 199 ->setContentSource($this->getContentSource()) 166 200 ->setContinueOnNoEffect(true) 167 201 ->setContinueOnMissingFields(true); 202 + 203 + $request = $this->getRequest(); 204 + if ($request) { 205 + $editor->setRequest($request); 206 + } 207 + 208 + $cancel_uri = $this->getCancelURI(); 209 + if ($cancel_uri) { 210 + $editor->setCancelURI($cancel_uri); 211 + } 168 212 169 213 $editor->applyTransactions($object, $xactions); 170 214 }