Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/xaction/DiffusionCommitActionTransaction.php
12241 views
1
<?php
2
3
abstract class DiffusionCommitActionTransaction
4
extends DiffusionCommitTransactionType {
5
6
final public function getCommitActionKey() {
7
return $this->getPhobjectClassConstant('ACTIONKEY', 32);
8
}
9
10
public function isActionAvailable($object, PhabricatorUser $viewer) {
11
try {
12
$this->validateAction($object, $viewer);
13
return true;
14
} catch (Exception $ex) {
15
return false;
16
}
17
}
18
19
abstract protected function validateAction($object, PhabricatorUser $viewer);
20
abstract protected function getCommitActionLabel();
21
22
public function getCommandKeyword() {
23
return null;
24
}
25
26
public function getCommandAliases() {
27
return array();
28
}
29
30
public function getCommandSummary() {
31
return null;
32
}
33
34
protected function getCommitActionOrder() {
35
return 1000;
36
}
37
38
public function getCommitActionOrderVector() {
39
return id(new PhutilSortVector())
40
->addInt($this->getCommitActionOrder());
41
}
42
43
protected function getCommitActionGroupKey() {
44
return DiffusionCommitEditEngine::ACTIONGROUP_COMMIT;
45
}
46
47
protected function getCommitActionDescription() {
48
return null;
49
}
50
51
public static function loadAllActions() {
52
return id(new PhutilClassMapQuery())
53
->setAncestorClass(__CLASS__)
54
->setUniqueMethod('getCommitActionKey')
55
->execute();
56
}
57
58
protected function isViewerCommitAuthor(
59
PhabricatorRepositoryCommit $commit,
60
PhabricatorUser $viewer) {
61
62
if (!$viewer->getPHID()) {
63
return false;
64
}
65
66
return ($viewer->getPHID() === $commit->getEffectiveAuthorPHID());
67
}
68
69
public function newEditField(
70
PhabricatorRepositoryCommit $commit,
71
PhabricatorUser $viewer) {
72
73
// Actions in the "audit" group, like "Accept Commit", do not require
74
// that the actor be able to edit the commit.
75
$group_audit = DiffusionCommitEditEngine::ACTIONGROUP_AUDIT;
76
$is_audit = ($this->getCommitActionGroupKey() == $group_audit);
77
78
$field = id(new PhabricatorApplyEditField())
79
->setKey($this->getCommitActionKey())
80
->setTransactionType($this->getTransactionTypeConstant())
81
->setCanApplyWithoutEditCapability($is_audit)
82
->setValue(true);
83
84
if ($this->isActionAvailable($commit, $viewer)) {
85
$label = $this->getCommitActionLabel();
86
if ($label !== null) {
87
$field->setCommentActionLabel($label);
88
89
$description = $this->getCommitActionDescription();
90
$field->setActionDescription($description);
91
92
$group_key = $this->getCommitActionGroupKey();
93
$field->setCommentActionGroupKey($group_key);
94
95
$field->setActionConflictKey('commit.action');
96
}
97
}
98
99
return $field;
100
}
101
102
public function validateTransactions($object, array $xactions) {
103
$errors = array();
104
$actor = $this->getActor();
105
106
$action_exception = null;
107
try {
108
$this->validateAction($object, $actor);
109
} catch (Exception $ex) {
110
$action_exception = $ex;
111
}
112
113
foreach ($xactions as $xaction) {
114
if ($action_exception) {
115
$errors[] = $this->newInvalidError(
116
$action_exception->getMessage(),
117
$xaction);
118
}
119
}
120
121
return $errors;
122
}
123
124
}
125
126