Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/legalpad/policyrule/PhabricatorLegalpadSignaturePolicyRule.php
13498 views
1
<?php
2
3
final class PhabricatorLegalpadSignaturePolicyRule
4
extends PhabricatorPolicyRule {
5
6
private $signatures = array();
7
8
public function getRuleDescription() {
9
return pht('signers of legalpad documents');
10
}
11
12
public function willApplyRules(
13
PhabricatorUser $viewer,
14
array $values,
15
array $objects) {
16
17
$values = array_unique(array_filter(array_mergev($values)));
18
if (!$values) {
19
return;
20
}
21
22
// TODO: This accepts signature of any version of the document, even an
23
// older version.
24
25
$documents = id(new LegalpadDocumentQuery())
26
->setViewer(PhabricatorUser::getOmnipotentUser())
27
->withPHIDs($values)
28
->withSignerPHIDs(array($viewer->getPHID()))
29
->execute();
30
$this->signatures = mpull($documents, 'getPHID', 'getPHID');
31
}
32
33
public function applyRule(
34
PhabricatorUser $viewer,
35
$value,
36
PhabricatorPolicyInterface $object) {
37
38
foreach ($value as $document_phid) {
39
if (!isset($this->signatures[$document_phid])) {
40
return false;
41
}
42
}
43
44
return true;
45
}
46
47
public function getValueControlType() {
48
return self::CONTROL_TYPE_TOKENIZER;
49
}
50
51
public function getValueControlTemplate() {
52
return $this->getDatasourceTemplate(new LegalpadDocumentDatasource());
53
}
54
55
public function getRuleOrder() {
56
return 900;
57
}
58
59
public function getValueForStorage($value) {
60
PhutilTypeSpec::newFromString('list<string>')->check($value);
61
return array_values($value);
62
}
63
64
public function getValueForDisplay(PhabricatorUser $viewer, $value) {
65
$handles = id(new PhabricatorHandleQuery())
66
->setViewer($viewer)
67
->withPHIDs($value)
68
->execute();
69
return mpull($handles, 'getFullName', 'getPHID');
70
}
71
72
public function ruleHasEffect($value) {
73
return (bool)$value;
74
}
75
76
}
77
78