mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 16:52:41 +01:00
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
This commit is contained in:
parent
efb01bf34f
commit
6a6db0ac8e
2 changed files with 62 additions and 16 deletions
|
@ -47,11 +47,13 @@ final class PhabricatorTokenGiveController extends PhabricatorTokenController {
|
||||||
}
|
}
|
||||||
|
|
||||||
$done_uri = $handle->getURI();
|
$done_uri = $handle->getURI();
|
||||||
if ($request->isDialogFormPost()) {
|
if ($request->isFormOrHisecPost()) {
|
||||||
$content_source = PhabricatorContentSource::newFromRequest($request);
|
$content_source = PhabricatorContentSource::newFromRequest($request);
|
||||||
|
|
||||||
$editor = id(new PhabricatorTokenGivenEditor())
|
$editor = id(new PhabricatorTokenGivenEditor())
|
||||||
->setActor($viewer)
|
->setActor($viewer)
|
||||||
|
->setRequest($request)
|
||||||
|
->setCancelURI($handle->getURI())
|
||||||
->setContentSource($content_source);
|
->setContentSource($content_source);
|
||||||
if ($is_give) {
|
if ($is_give) {
|
||||||
$token_phid = $request->getStr('tokenPHID');
|
$token_phid = $request->getStr('tokenPHID');
|
||||||
|
|
|
@ -4,6 +4,8 @@ final class PhabricatorTokenGivenEditor
|
||||||
extends PhabricatorEditor {
|
extends PhabricatorEditor {
|
||||||
|
|
||||||
private $contentSource;
|
private $contentSource;
|
||||||
|
private $request;
|
||||||
|
private $cancelURI;
|
||||||
|
|
||||||
public function setContentSource(PhabricatorContentSource $content_source) {
|
public function setContentSource(PhabricatorContentSource $content_source) {
|
||||||
$this->contentSource = $content_source;
|
$this->contentSource = $content_source;
|
||||||
|
@ -14,6 +16,24 @@ final class PhabricatorTokenGivenEditor
|
||||||
return $this->contentSource;
|
return $this->contentSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setRequest(AphrontRequest $request) {
|
||||||
|
$this->request = $request;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRequest() {
|
||||||
|
return $this->request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCancelURI($cancel_uri) {
|
||||||
|
$this->cancelURI = $cancel_uri;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCancelURI() {
|
||||||
|
return $this->cancelURI;
|
||||||
|
}
|
||||||
|
|
||||||
public function addToken($object_phid, $token_phid) {
|
public function addToken($object_phid, $token_phid) {
|
||||||
$token = $this->validateToken($token_phid);
|
$token = $this->validateToken($token_phid);
|
||||||
$object = $this->validateObject($object_phid);
|
$object = $this->validateObject($object_phid);
|
||||||
|
@ -41,18 +61,23 @@ final class PhabricatorTokenGivenEditor
|
||||||
id(new PhabricatorTokenCount())->getTableName(),
|
id(new PhabricatorTokenCount())->getTableName(),
|
||||||
$object->getPHID());
|
$object->getPHID());
|
||||||
|
|
||||||
|
$current_token_phid = null;
|
||||||
|
if ($current_token) {
|
||||||
|
$current_token_phid = $current_token->getTokenPHID();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->publishTransaction(
|
||||||
|
$object,
|
||||||
|
$current_token_phid,
|
||||||
|
$token->getPHID());
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
$token_given->killTransaction();
|
||||||
|
throw $ex;
|
||||||
|
}
|
||||||
|
|
||||||
$token_given->saveTransaction();
|
$token_given->saveTransaction();
|
||||||
|
|
||||||
$current_token_phid = null;
|
|
||||||
if ($current_token) {
|
|
||||||
$current_token_phid = $current_token->getTokenPHID();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->publishTransaction(
|
|
||||||
$object,
|
|
||||||
$current_token_phid,
|
|
||||||
$token->getPHID());
|
|
||||||
|
|
||||||
$subscribed_phids = $object->getUsersToNotifyOfTokenGiven();
|
$subscribed_phids = $object->getUsersToNotifyOfTokenGiven();
|
||||||
if ($subscribed_phids) {
|
if ($subscribed_phids) {
|
||||||
$related_phids = $subscribed_phids;
|
$related_phids = $subscribed_phids;
|
||||||
|
@ -86,11 +111,20 @@ final class PhabricatorTokenGivenEditor
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->executeDeleteToken($object, $token_given);
|
$token_given->openTransaction();
|
||||||
$this->publishTransaction(
|
$this->executeDeleteToken($object, $token_given);
|
||||||
$object,
|
|
||||||
$token_given->getTokenPHID(),
|
try {
|
||||||
null);
|
$this->publishTransaction(
|
||||||
|
$object,
|
||||||
|
$token_given->getTokenPHID(),
|
||||||
|
null);
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
$token_given->killTransaction();
|
||||||
|
throw $ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
$token_given->saveTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function executeDeleteToken(
|
private function executeDeleteToken(
|
||||||
|
@ -166,6 +200,16 @@ final class PhabricatorTokenGivenEditor
|
||||||
->setContinueOnNoEffect(true)
|
->setContinueOnNoEffect(true)
|
||||||
->setContinueOnMissingFields(true);
|
->setContinueOnMissingFields(true);
|
||||||
|
|
||||||
|
$request = $this->getRequest();
|
||||||
|
if ($request) {
|
||||||
|
$editor->setRequest($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
$cancel_uri = $this->getCancelURI();
|
||||||
|
if ($cancel_uri) {
|
||||||
|
$editor->setCancelURI($cancel_uri);
|
||||||
|
}
|
||||||
|
|
||||||
$editor->applyTransactions($object, $xactions);
|
$editor->applyTransactions($object, $xactions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue