2013-02-15 16:47:14 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorTokenGiven extends PhabricatorTokenDAO
|
|
|
|
implements PhabricatorPolicyInterface {
|
|
|
|
|
|
|
|
protected $authorPHID;
|
|
|
|
protected $objectPHID;
|
|
|
|
protected $tokenPHID;
|
|
|
|
|
2013-09-03 15:02:14 +02:00
|
|
|
private $object = self::ATTACHABLE;
|
2013-02-15 16:47:14 +01:00
|
|
|
|
2014-09-19 14:45:24 +02:00
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_KEY_SCHEMA => array(
|
|
|
|
'key_all' => array(
|
|
|
|
'columns' => array('objectPHID', 'authorPHID'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
2013-02-15 16:47:14 +01:00
|
|
|
public function attachObject(PhabricatorTokenReceiverInterface $object) {
|
|
|
|
$this->object = $object;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getObject() {
|
2013-09-03 15:02:14 +02:00
|
|
|
return $this->assertAttached($this->object);
|
2013-02-15 16:47:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-27 17:43:41 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-15 16:47:14 +01:00
|
|
|
}
|