3 final class LegalpadRequireSignatureHeraldAction
6 const DO_SIGNED
= 'do.signed';
7 const DO_REQUIRED
= 'do.required';
9 const ACTIONCONST
= 'legalpad.require';
11 public function getActionGroupKey() {
12 return HeraldSupportActionGroup
::ACTIONGROUPKEY
;
15 public function supportsObject($object) {
16 // TODO: This could probably be more general. Note that we call
17 // getAuthorPHID() on the object explicitly below, and this also needs to
19 return ($object instanceof DifferentialRevision
);
22 protected function applyRequire(array $phids) {
23 $adapter = $this->getAdapter();
25 $edgetype_legal = LegalpadObjectNeedsSignatureEdgeType
::EDGECONST
;
26 $current = $adapter->loadEdgePHIDs($edgetype_legal);
28 $allowed_types = array(
29 PhabricatorLegalpadDocumentPHIDType
::TYPECONST
,
32 $targets = $this->loadStandardTargets($phids, $allowed_types, $current);
37 $phids = array_fuse(array_keys($targets));
39 $object = $adapter->getObject();
40 $author_phid = $object->getAuthorPHID();
42 $signatures = id(new LegalpadDocumentSignatureQuery())
43 ->setViewer(PhabricatorUser
::getOmnipotentUser())
44 ->withDocumentPHIDs($phids)
45 ->withSignerPHIDs(array($author_phid))
47 $signatures = mpull($signatures, null, 'getDocumentPHID');
50 foreach ($phids as $phid) {
51 if (isset($signatures[$phid])) {
58 $this->logEffect(self
::DO_SIGNED
, $phids);
65 $xaction = $adapter->newTransaction()
66 ->setTransactionType(PhabricatorTransactions
::TYPE_EDGE
)
67 ->setMetadataValue('edge:type', $edgetype_legal)
73 $adapter->queueTransaction($xaction);
75 $this->logEffect(self
::DO_REQUIRED
, $phids);
78 protected function getActionEffectMap() {
80 self
::DO_SIGNED
=> array(
81 'icon' => 'fa-terminal',
83 'name' => pht('Already Signed'),
85 self
::DO_REQUIRED
=> array(
86 'icon' => 'fa-terminal',
88 'name' => pht('Required Signature'),
93 protected function renderActionEffectDescription($type, $data) {
97 '%s document(s) are already signed: %s.',
99 $this->renderHandleList($data));
100 case self
::DO_REQUIRED
:
102 'Required %s signature(s): %s.',
104 $this->renderHandleList($data));
108 public function getHeraldActionName() {
109 return pht('Require signatures');
112 public function supportsRuleType($rule_type) {
113 return ($rule_type != HeraldRuleTypeConfig
::RULE_TYPE_PERSONAL
);
116 public function applyEffect($object, HeraldEffect
$effect) {
117 return $this->applyRequire($effect->getTarget());
120 public function getHeraldActionStandardType() {
121 return self
::STANDARD_PHID_LIST
;
124 protected function getDatasource() {
125 return new LegalpadDocumentDatasource();
128 public function renderActionDescription($value) {
130 'Require document signatures: %s.',
131 $this->renderHandleList($value));
134 public function isActionAvailable() {
135 return id(new PhabricatorLegalpadApplication())->isInstalled();