[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/tokens/storage/ -> PhabricatorTokenGiven.php (source)

   1  <?php
   2  
   3  final class PhabricatorTokenGiven extends PhabricatorTokenDAO
   4    implements PhabricatorPolicyInterface {
   5  
   6    protected $authorPHID;
   7    protected $objectPHID;
   8    protected $tokenPHID;
   9  
  10    private $object = self::ATTACHABLE;
  11  
  12    public function getConfiguration() {
  13      return array(
  14        self::CONFIG_KEY_SCHEMA => array(
  15          'key_all' => array(
  16            'columns' => array('objectPHID', 'authorPHID'),
  17            'unique' => true,
  18          ),
  19          'key_author' => array(
  20            'columns' => array('authorPHID'),
  21          ),
  22          'key_token' => array(
  23            'columns' => array('tokenPHID'),
  24          ),
  25        ),
  26      ) + parent::getConfiguration();
  27    }
  28  
  29    public function attachObject(PhabricatorTokenReceiverInterface $object) {
  30      $this->object = $object;
  31      return $this;
  32    }
  33  
  34    public function getObject() {
  35      return $this->assertAttached($this->object);
  36    }
  37  
  38    public function getCapabilities() {
  39      return array(
  40        PhabricatorPolicyCapability::CAN_VIEW,
  41        PhabricatorPolicyCapability::CAN_EDIT,
  42      );
  43    }
  44  
  45    public function getPolicy($capability) {
  46      switch ($capability) {
  47        case PhabricatorPolicyCapability::CAN_VIEW:
  48          return $this->getObject()->getPolicy($capability);
  49        default:
  50          return PhabricatorPolicies::POLICY_NOONE;
  51      }
  52    }
  53  
  54    public function hasAutomaticCapability($capability, PhabricatorUser $user) {
  55      switch ($capability) {
  56        case PhabricatorPolicyCapability::CAN_VIEW:
  57          return $this->getObject()->hasAutomaticCapability(
  58            $capability,
  59            $user);
  60        default:
  61          if ($user->getPHID() == $this->authorPHID) {
  62            return true;
  63          }
  64          return false;
  65      }
  66    }
  67  
  68    public function describeAutomaticCapability($capability) {
  69      switch ($capability) {
  70        case PhabricatorPolicyCapability::CAN_VIEW:
  71          return pht(
  72            'A token inherits the policies of the object it is awarded to.');
  73        case PhabricatorPolicyCapability::CAN_EDIT:
  74          return pht(
  75            'The user who gave a token can always edit it.');
  76      }
  77      return null;
  78    }
  79  
  80  
  81  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1