[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/oauthserver/storage/ -> PhabricatorOAuthServerClient.php (source)

   1  <?php
   2  
   3  final class PhabricatorOAuthServerClient
   4    extends PhabricatorOAuthServerDAO
   5    implements PhabricatorPolicyInterface {
   6  
   7    protected $secret;
   8    protected $name;
   9    protected $redirectURI;
  10    protected $creatorPHID;
  11  
  12    public function getEditURI() {
  13      return '/oauthserver/client/edit/'.$this->getPHID().'/';
  14    }
  15  
  16    public function getViewURI() {
  17      return '/oauthserver/client/view/'.$this->getPHID().'/';
  18    }
  19  
  20    public function getDeleteURI() {
  21      return '/oauthserver/client/delete/'.$this->getPHID().'/';
  22    }
  23  
  24    public static function initializeNewClient(PhabricatorUser $actor) {
  25      return id(new PhabricatorOAuthServerClient())
  26        ->setCreatorPHID($actor->getPHID())
  27        ->setSecret(Filesystem::readRandomCharacters(32));
  28    }
  29  
  30    public function getConfiguration() {
  31      return array(
  32        self::CONFIG_AUX_PHID => true,
  33        self::CONFIG_COLUMN_SCHEMA => array(
  34          'name' => 'text255',
  35          'secret' => 'text32',
  36          'redirectURI' => 'text255',
  37        ),
  38        self::CONFIG_KEY_SCHEMA => array(
  39          'key_phid' => null,
  40          'phid' => array(
  41            'columns' => array('phid'),
  42            'unique' => true,
  43          ),
  44          'creatorPHID' => array(
  45            'columns' => array('creatorPHID'),
  46          ),
  47        ),
  48      ) + parent::getConfiguration();
  49    }
  50  
  51    public function generatePHID() {
  52      return PhabricatorPHID::generateNewPHID(
  53        PhabricatorOAuthServerClientPHIDType::TYPECONST);
  54    }
  55  
  56  
  57  /* -(  PhabricatorPolicyInterface  )----------------------------------------- */
  58  
  59  
  60    public function getCapabilities() {
  61      return array(
  62        PhabricatorPolicyCapability::CAN_VIEW,
  63        PhabricatorPolicyCapability::CAN_EDIT,
  64      );
  65    }
  66  
  67    public function getPolicy($capability) {
  68      switch ($capability) {
  69        case PhabricatorPolicyCapability::CAN_VIEW:
  70          return PhabricatorPolicies::POLICY_USER;
  71        case PhabricatorPolicyCapability::CAN_EDIT:
  72          return PhabricatorPolicies::POLICY_NOONE;
  73      }
  74    }
  75  
  76    public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
  77      switch ($capability) {
  78        case PhabricatorPolicyCapability::CAN_EDIT:
  79          return ($viewer->getPHID() == $this->getCreatorPHID());
  80      }
  81      return false;
  82    }
  83  
  84    public function describeAutomaticCapability($capability) {
  85      switch ($capability) {
  86        case PhabricatorPolicyCapability::CAN_EDIT:
  87          return pht("Only an application's creator can edit it.");
  88      }
  89      return null;
  90    }
  91  
  92  }


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