mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-08 13:51:02 +01:00
82c891f586
Summary: Ref T10978. This prepares for swapping the comment UI to stacked actions. These are only accessible via the API. Test Plan: Used the API to accept, raise concern with, and reject commits. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10978 Differential Revision: https://secure.phabricator.com/D17182
118 lines
2.8 KiB
PHP
118 lines
2.8 KiB
PHP
<?php
|
|
|
|
abstract class DiffusionCommitActionTransaction
|
|
extends DiffusionCommitTransactionType {
|
|
|
|
final public function getCommitActionKey() {
|
|
return $this->getPhobjectClassConstant('ACTIONKEY', 32);
|
|
}
|
|
|
|
public function isActionAvailable($object, PhabricatorUser $viewer) {
|
|
try {
|
|
$this->validateAction($object, $viewer);
|
|
return true;
|
|
} catch (Exception $ex) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
abstract protected function validateAction($object, PhabricatorUser $viewer);
|
|
abstract protected function getCommitActionLabel();
|
|
|
|
public function getCommandKeyword() {
|
|
return null;
|
|
}
|
|
|
|
public function getCommandAliases() {
|
|
return array();
|
|
}
|
|
|
|
public function getCommandSummary() {
|
|
return null;
|
|
}
|
|
|
|
protected function getCommitActionOrder() {
|
|
return 1000;
|
|
}
|
|
|
|
public function getCommitActionOrderVector() {
|
|
return id(new PhutilSortVector())
|
|
->addInt($this->getCommitActionOrder());
|
|
}
|
|
|
|
protected function getCommitActionGroupKey() {
|
|
return DiffusionCommitEditEngine::ACTIONGROUP_COMMIT;
|
|
}
|
|
|
|
protected function getCommitActionDescription() {
|
|
return null;
|
|
}
|
|
|
|
public static function loadAllActions() {
|
|
return id(new PhutilClassMapQuery())
|
|
->setAncestorClass(__CLASS__)
|
|
->setUniqueMethod('getCommitActionKey')
|
|
->execute();
|
|
}
|
|
|
|
protected function isViewerCommitAuthor(
|
|
PhabricatorRepositoryCommit $commit,
|
|
PhabricatorUser $viewer) {
|
|
|
|
if (!$viewer->getPHID()) {
|
|
return false;
|
|
}
|
|
|
|
return ($viewer->getPHID() === $commit->getAuthorPHID());
|
|
}
|
|
|
|
public function newEditField(
|
|
PhabricatorRepositoryCommit $commit,
|
|
PhabricatorUser $viewer) {
|
|
|
|
$field = id(new PhabricatorApplyEditField())
|
|
->setKey($this->getCommitActionKey())
|
|
->setTransactionType($this->getTransactionTypeConstant())
|
|
->setValue(true);
|
|
|
|
if ($this->isActionAvailable($commit, $viewer)) {
|
|
$label = $this->getCommitActionLabel();
|
|
if ($label !== null) {
|
|
$field->setCommentActionLabel($label);
|
|
|
|
$description = $this->getCommitActionDescription();
|
|
$field->setActionDescription($description);
|
|
|
|
$group_key = $this->getCommitActionGroupKey();
|
|
$field->setCommentActionGroupKey($group_key);
|
|
|
|
$field->setActionConflictKey('commit.action');
|
|
}
|
|
}
|
|
|
|
return $field;
|
|
}
|
|
|
|
public function validateTransactions($object, array $xactions) {
|
|
$errors = array();
|
|
$actor = $this->getActor();
|
|
|
|
$action_exception = null;
|
|
try {
|
|
$this->validateAction($object, $actor);
|
|
} catch (Exception $ex) {
|
|
$action_exception = $ex;
|
|
}
|
|
|
|
foreach ($xactions as $xaction) {
|
|
if ($action_exception) {
|
|
$errors[] = $this->newInvalidError(
|
|
$action_exception->getMessage(),
|
|
$xaction);
|
|
}
|
|
}
|
|
|
|
return $errors;
|
|
}
|
|
|
|
}
|