forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorTokenGiven.php
64 lines (53 loc) · 1.6 KB
/
PhabricatorTokenGiven.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
final class PhabricatorTokenGiven extends PhabricatorTokenDAO
implements PhabricatorPolicyInterface {
protected $authorPHID;
protected $objectPHID;
protected $tokenPHID;
private $object = self::ATTACHABLE;
public function attachObject(PhabricatorTokenReceiverInterface $object) {
$this->object = $object;
return $this;
}
public function getObject() {
return $this->assertAttached($this->object);
}
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->getObject()->getPolicy($capability);
default:
return PhabricatorPolicies::POLICY_NOONE;
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $user) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->getObject()->hasAutomaticCapability(
$capability,
$user);
default:
if ($user->getPHID() == $this->authorPHID) {
return true;
}
return false;
}
}
public function describeAutomaticCapability($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return pht(
'A token inherits the policies of the object it is awarded to.');
case PhabricatorPolicyCapability::CAN_EDIT:
return pht(
'The user who gave a token can always edit it.');
}
return null;
}
}