mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-30 00:18:21 +01:00
Paradigms, paradigms, paradigms
Summary: Fixes T4693. Test Plan: {F146407} Reviewers: chad, btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4693 Differential Revision: https://secure.phabricator.com/D8829
This commit is contained in:
parent
0cfc5aa0aa
commit
5cbdda413c
9 changed files with 171 additions and 27 deletions
|
@ -22,8 +22,11 @@ final class ConduitAPI_token_give_Method extends ConduitAPI_token_Method {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(ConduitAPIRequest $request) {
|
public function execute(ConduitAPIRequest $request) {
|
||||||
|
$content_source = PhabricatorContentSource::newFromConduitRequest($request);
|
||||||
|
|
||||||
$editor = id(new PhabricatorTokenGivenEditor())
|
$editor = id(new PhabricatorTokenGivenEditor())
|
||||||
->setActor($request->getUser());
|
->setActor($request->getUser())
|
||||||
|
->setContentSource($content_source);
|
||||||
|
|
||||||
if ($request->getValue('tokenPHID')) {
|
if ($request->getValue('tokenPHID')) {
|
||||||
$editor->addToken(
|
$editor->addToken(
|
||||||
|
|
|
@ -36,15 +36,16 @@ final class PhabricatorTokenGiveController extends PhabricatorTokenController {
|
||||||
|
|
||||||
$done_uri = $handle->getURI();
|
$done_uri = $handle->getURI();
|
||||||
if ($request->isDialogFormPost()) {
|
if ($request->isDialogFormPost()) {
|
||||||
|
$content_source = PhabricatorContentSource::newFromRequest($request);
|
||||||
|
|
||||||
|
$editor = id(new PhabricatorTokenGivenEditor())
|
||||||
|
->setActor($user)
|
||||||
|
->setContentSource($content_source);
|
||||||
if ($is_give) {
|
if ($is_give) {
|
||||||
$token_phid = $request->getStr('tokenPHID');
|
$token_phid = $request->getStr('tokenPHID');
|
||||||
$editor = id(new PhabricatorTokenGivenEditor())
|
$editor->addToken($handle->getPHID(), $token_phid);
|
||||||
->setActor($user)
|
|
||||||
->addToken($handle->getPHID(), $token_phid);
|
|
||||||
} else {
|
} else {
|
||||||
$editor = id(new PhabricatorTokenGivenEditor())
|
$editor->deleteToken($handle->getPHID());
|
||||||
->setActor($user)
|
|
||||||
->deleteToken($handle->getPHID());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return id(new AphrontReloadResponse())->setURI($done_uri);
|
return id(new AphrontReloadResponse())->setURI($done_uri);
|
||||||
|
|
|
@ -3,9 +3,21 @@
|
||||||
final class PhabricatorTokenGivenEditor
|
final class PhabricatorTokenGivenEditor
|
||||||
extends PhabricatorEditor {
|
extends PhabricatorEditor {
|
||||||
|
|
||||||
|
private $contentSource;
|
||||||
|
|
||||||
|
public function setContentSource(PhabricatorContentSource $content_source) {
|
||||||
|
$this->contentSource = $content_source;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContentSource() {
|
||||||
|
return $this->contentSource;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
$current_token = $this->loadCurrentToken($object);
|
||||||
|
|
||||||
$actor = $this->requireActor();
|
$actor = $this->requireActor();
|
||||||
|
|
||||||
|
@ -16,7 +28,9 @@ final class PhabricatorTokenGivenEditor
|
||||||
|
|
||||||
$token_given->openTransaction();
|
$token_given->openTransaction();
|
||||||
|
|
||||||
$this->executeDeleteToken($object);
|
if ($current_token) {
|
||||||
|
$this->executeDeleteToken($object, $current_token);
|
||||||
|
}
|
||||||
|
|
||||||
$token_given->save();
|
$token_given->save();
|
||||||
|
|
||||||
|
@ -29,6 +43,16 @@ final class PhabricatorTokenGivenEditor
|
||||||
|
|
||||||
$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;
|
||||||
|
@ -57,22 +81,23 @@ final class PhabricatorTokenGivenEditor
|
||||||
|
|
||||||
public function deleteToken($object_phid) {
|
public function deleteToken($object_phid) {
|
||||||
$object = $this->validateObject($object_phid);
|
$object = $this->validateObject($object_phid);
|
||||||
return $this->executeDeleteToken($object);
|
$token_given = $this->loadCurrentToken($object);
|
||||||
}
|
|
||||||
|
|
||||||
private function executeDeleteToken($object) {
|
|
||||||
$actor = $this->requireActor();
|
|
||||||
|
|
||||||
$token_given = id(new PhabricatorTokenGiven())->loadOneWhere(
|
|
||||||
'authorPHID = %s AND objectPHID = %s',
|
|
||||||
$actor->getPHID(),
|
|
||||||
$object->getPHID());
|
|
||||||
if (!$token_given) {
|
if (!$token_given) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$token_given->openTransaction();
|
$this->executeDeleteToken($object, $token_given);
|
||||||
|
$this->publishTransaction(
|
||||||
|
$object,
|
||||||
|
$token_given->getTokenPHID(),
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function executeDeleteToken(
|
||||||
|
PhabricatorTokenReceiverInterface $object,
|
||||||
|
PhabricatorTokenGiven $token_given) {
|
||||||
|
|
||||||
|
$token_given->openTransaction();
|
||||||
$token_given->delete();
|
$token_given->delete();
|
||||||
|
|
||||||
queryfx(
|
queryfx(
|
||||||
|
@ -81,21 +106,20 @@ final class PhabricatorTokenGivenEditor
|
||||||
ON DUPLICATE KEY UPDATE tokenCount = tokenCount - 1',
|
ON DUPLICATE KEY UPDATE tokenCount = tokenCount - 1',
|
||||||
id(new PhabricatorTokenCount())->getTableName(),
|
id(new PhabricatorTokenCount())->getTableName(),
|
||||||
$object->getPHID());
|
$object->getPHID());
|
||||||
|
|
||||||
$token_given->saveTransaction();
|
$token_given->saveTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function validateToken($token_phid) {
|
private function validateToken($token_phid) {
|
||||||
$tokens = id(new PhabricatorTokenQuery())
|
$token = id(new PhabricatorTokenQuery())
|
||||||
->setViewer($this->requireActor())
|
->setViewer($this->requireActor())
|
||||||
->withPHIDs(array($token_phid))
|
->withPHIDs(array($token_phid))
|
||||||
->execute();
|
->executeOne();
|
||||||
|
|
||||||
if (empty($tokens)) {
|
if (!$token) {
|
||||||
throw new Exception("No such token!");
|
throw new Exception(pht('No such token "%s"!', $token_phid));
|
||||||
}
|
}
|
||||||
|
|
||||||
return head($tokens);
|
return $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function validateObject($object_phid) {
|
private function validateObject($object_phid) {
|
||||||
|
@ -105,10 +129,46 @@ final class PhabricatorTokenGivenEditor
|
||||||
->executeOne();
|
->executeOne();
|
||||||
|
|
||||||
if (!$object) {
|
if (!$object) {
|
||||||
throw new Exception("No such object!");
|
throw new Exception(pht('No such object "%s"!', $object_phid));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function loadCurrentToken(PhabricatorTokenReceiverInterface $object) {
|
||||||
|
return id(new PhabricatorTokenGiven())->loadOneWhere(
|
||||||
|
'authorPHID = %s AND objectPHID = %s',
|
||||||
|
$this->requireActor()->getPHID(),
|
||||||
|
$object->getPHID());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function publishTransaction(
|
||||||
|
PhabricatorTokenReceiverInterface $object,
|
||||||
|
$old_token_phid,
|
||||||
|
$new_token_phid) {
|
||||||
|
|
||||||
|
if (!($object instanceof PhabricatorApplicationTransactionInterface)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$actor = $this->requireActor();
|
||||||
|
|
||||||
|
$xactions = array();
|
||||||
|
$xactions[] = id($object->getApplicationTransactionTemplate())
|
||||||
|
->setTransactionType(PhabricatorTransactions::TYPE_TOKEN)
|
||||||
|
->setOldValue($old_token_phid)
|
||||||
|
->setNewValue($new_token_phid);
|
||||||
|
|
||||||
|
$editor = $object->getApplicationTransactionEditor()
|
||||||
|
->setActor($actor)
|
||||||
|
->setContentSource($this->getContentSource())
|
||||||
|
->setContinueOnNoEffect(true)
|
||||||
|
->setContinueOnMissingFields(true);
|
||||||
|
|
||||||
|
$editor->applyTransactions(
|
||||||
|
$object->getApplicationTransactionObject(),
|
||||||
|
$xactions);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ final class PhabricatorTransactions {
|
||||||
const TYPE_EDGE = 'core:edge';
|
const TYPE_EDGE = 'core:edge';
|
||||||
const TYPE_CUSTOMFIELD = 'core:customfield';
|
const TYPE_CUSTOMFIELD = 'core:customfield';
|
||||||
const TYPE_BUILDABLE = 'harbormaster:buildable';
|
const TYPE_BUILDABLE = 'harbormaster:buildable';
|
||||||
|
const TYPE_TOKEN = 'token:give';
|
||||||
|
|
||||||
const COLOR_RED = 'red';
|
const COLOR_RED = 'red';
|
||||||
const COLOR_ORANGE = 'orange';
|
const COLOR_ORANGE = 'orange';
|
||||||
|
|
|
@ -159,6 +159,10 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
$types[] = PhabricatorTransactions::TYPE_BUILDABLE;
|
$types[] = PhabricatorTransactions::TYPE_BUILDABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->object instanceof PhabricatorTokenReceiverInterface) {
|
||||||
|
$types[] = PhabricatorTransactions::TYPE_TOKEN;
|
||||||
|
}
|
||||||
|
|
||||||
return $types;
|
return $types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,6 +231,7 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
case PhabricatorTransactions::TYPE_EDIT_POLICY:
|
case PhabricatorTransactions::TYPE_EDIT_POLICY:
|
||||||
case PhabricatorTransactions::TYPE_JOIN_POLICY:
|
case PhabricatorTransactions::TYPE_JOIN_POLICY:
|
||||||
case PhabricatorTransactions::TYPE_BUILDABLE:
|
case PhabricatorTransactions::TYPE_BUILDABLE:
|
||||||
|
case PhabricatorTransactions::TYPE_TOKEN:
|
||||||
return $xaction->getNewValue();
|
return $xaction->getNewValue();
|
||||||
case PhabricatorTransactions::TYPE_EDGE:
|
case PhabricatorTransactions::TYPE_EDGE:
|
||||||
return $this->getEdgeTransactionNewValue($xaction);
|
return $this->getEdgeTransactionNewValue($xaction);
|
||||||
|
@ -317,6 +322,7 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case PhabricatorTransactions::TYPE_BUILDABLE:
|
case PhabricatorTransactions::TYPE_BUILDABLE:
|
||||||
|
case PhabricatorTransactions::TYPE_TOKEN:
|
||||||
return;
|
return;
|
||||||
case PhabricatorTransactions::TYPE_VIEW_POLICY:
|
case PhabricatorTransactions::TYPE_VIEW_POLICY:
|
||||||
$object->setViewPolicy($xaction->getNewValue());
|
$object->setViewPolicy($xaction->getNewValue());
|
||||||
|
@ -337,6 +343,7 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
PhabricatorApplicationTransaction $xaction) {
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case PhabricatorTransactions::TYPE_BUILDABLE:
|
case PhabricatorTransactions::TYPE_BUILDABLE:
|
||||||
|
case PhabricatorTransactions::TYPE_TOKEN:
|
||||||
return;
|
return;
|
||||||
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
|
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
|
||||||
$subeditor = id(new PhabricatorSubscriptionsEditor())
|
$subeditor = id(new PhabricatorSubscriptionsEditor())
|
||||||
|
|
|
@ -36,3 +36,23 @@ interface PhabricatorApplicationTransactionInterface {
|
||||||
public function getApplicationTransactionTemplate();
|
public function getApplicationTransactionTemplate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TEMPLATE IMPLEMENTATION /////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
||||||
|
/*
|
||||||
|
|
||||||
|
public function getApplicationTransactionEditor() {
|
||||||
|
return new <<<???>>>Editor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApplicationTransactionObject() {
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApplicationTransactionTemplate() {
|
||||||
|
return new <<<???>>>Transaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
|
@ -53,7 +53,7 @@ abstract class PhabricatorApplicationTransaction
|
||||||
public function shouldGenerateOldValue() {
|
public function shouldGenerateOldValue() {
|
||||||
switch ($this->getTransactionType()) {
|
switch ($this->getTransactionType()) {
|
||||||
case PhabricatorTransactions::TYPE_BUILDABLE:
|
case PhabricatorTransactions::TYPE_BUILDABLE:
|
||||||
return false;
|
case PhabricatorTransactions::TYPE_TOKEN:
|
||||||
case PhabricatorTransactions::TYPE_CUSTOMFIELD:
|
case PhabricatorTransactions::TYPE_CUSTOMFIELD:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -236,6 +236,8 @@ abstract class PhabricatorApplicationTransaction
|
||||||
$phids[] = array($new);
|
$phids[] = array($new);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case PhabricatorTransactions::TYPE_TOKEN:
|
||||||
|
break;
|
||||||
case PhabricatorTransactions::TYPE_BUILDABLE:
|
case PhabricatorTransactions::TYPE_BUILDABLE:
|
||||||
$phid = $this->getMetadataValue('harbormaster:buildablePHID');
|
$phid = $this->getMetadataValue('harbormaster:buildablePHID');
|
||||||
if ($phid) {
|
if ($phid) {
|
||||||
|
@ -335,11 +337,33 @@ abstract class PhabricatorApplicationTransaction
|
||||||
return 'link';
|
return 'link';
|
||||||
case PhabricatorTransactions::TYPE_BUILDABLE:
|
case PhabricatorTransactions::TYPE_BUILDABLE:
|
||||||
return 'wrench';
|
return 'wrench';
|
||||||
|
case PhabricatorTransactions::TYPE_TOKEN:
|
||||||
|
if ($this->getNewValue()) {
|
||||||
|
return 'like';
|
||||||
|
} else {
|
||||||
|
return 'dislike';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'edit';
|
return 'edit';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getToken() {
|
||||||
|
switch ($this->getTransactionType()) {
|
||||||
|
case PhabricatorTransactions::TYPE_TOKEN:
|
||||||
|
$old = $this->getOldValue();
|
||||||
|
$new = $this->getNewValue();
|
||||||
|
if ($new) {
|
||||||
|
$icon = substr($new, 10);
|
||||||
|
} else {
|
||||||
|
$icon = substr($old, 10);
|
||||||
|
}
|
||||||
|
return array($icon, !$this->getNewValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
public function getColor() {
|
public function getColor() {
|
||||||
switch ($this->getTransactionType()) {
|
switch ($this->getTransactionType()) {
|
||||||
case PhabricatorTransactions::TYPE_BUILDABLE:
|
case PhabricatorTransactions::TYPE_BUILDABLE:
|
||||||
|
@ -400,6 +424,8 @@ abstract class PhabricatorApplicationTransaction
|
||||||
|
|
||||||
public function shouldHideForMail(array $xactions) {
|
public function shouldHideForMail(array $xactions) {
|
||||||
switch ($this->getTransactionType()) {
|
switch ($this->getTransactionType()) {
|
||||||
|
case PhabricatorTransactions::TYPE_TOKEN:
|
||||||
|
return true;
|
||||||
case PhabricatorTransactions::TYPE_BUILDABLE:
|
case PhabricatorTransactions::TYPE_BUILDABLE:
|
||||||
switch ($this->getNewValue()) {
|
switch ($this->getNewValue()) {
|
||||||
case HarbormasterBuildable::STATUS_PASSED:
|
case HarbormasterBuildable::STATUS_PASSED:
|
||||||
|
@ -414,6 +440,11 @@ abstract class PhabricatorApplicationTransaction
|
||||||
}
|
}
|
||||||
|
|
||||||
public function shouldHideForFeed() {
|
public function shouldHideForFeed() {
|
||||||
|
switch ($this->getTransactionType()) {
|
||||||
|
case PhabricatorTransactions::TYPE_TOKEN:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->shouldHide();
|
return $this->shouldHide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,6 +599,21 @@ abstract class PhabricatorApplicationTransaction
|
||||||
$this->renderHandleLink($author_phid));
|
$this->renderHandleLink($author_phid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case PhabricatorTransactions::TYPE_TOKEN:
|
||||||
|
if ($old && $new) {
|
||||||
|
return pht(
|
||||||
|
'%s updated a token.',
|
||||||
|
$this->renderHandleLink($author_phid));
|
||||||
|
} else if ($old) {
|
||||||
|
return pht(
|
||||||
|
'%s rescinded a token.',
|
||||||
|
$this->renderHandleLink($author_phid));
|
||||||
|
} else {
|
||||||
|
return pht(
|
||||||
|
'%s awarded a token.',
|
||||||
|
$this->renderHandleLink($author_phid));
|
||||||
|
}
|
||||||
|
|
||||||
case PhabricatorTransactions::TYPE_BUILDABLE:
|
case PhabricatorTransactions::TYPE_BUILDABLE:
|
||||||
switch ($this->getNewValue()) {
|
switch ($this->getNewValue()) {
|
||||||
case HarbormasterBuildable::STATUS_PASSED:
|
case HarbormasterBuildable::STATUS_PASSED:
|
||||||
|
|
|
@ -317,6 +317,11 @@ class PhabricatorApplicationTransactionView extends AphrontView {
|
||||||
->setIcon($xaction->getIcon())
|
->setIcon($xaction->getIcon())
|
||||||
->setColor($xaction->getColor());
|
->setColor($xaction->getColor());
|
||||||
|
|
||||||
|
list($token, $token_removed) = $xaction->getToken();
|
||||||
|
if ($token) {
|
||||||
|
$event->setToken($token, $token_removed);
|
||||||
|
}
|
||||||
|
|
||||||
if (!$this->shouldSuppressTitle($xaction, $group)) {
|
if (!$this->shouldSuppressTitle($xaction, $group)) {
|
||||||
$title = $xaction->getTitle();
|
$title = $xaction->getTitle();
|
||||||
if ($xaction->hasChangeDetails()) {
|
if ($xaction->hasChangeDetails()) {
|
||||||
|
|
|
@ -127,6 +127,7 @@
|
||||||
|
|
||||||
.phui-timeline-view .phui-icon-view.phui-timeline-token {
|
.phui-timeline-view .phui-icon-view.phui-timeline-token {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
|
margin-right: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.phui-timeline-token.strikethrough {
|
.phui-timeline-token.strikethrough {
|
||||||
|
|
Loading…
Add table
Reference in a new issue