[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/legalpad/storage/ -> LegalpadDocumentSignature.php (source)

   1  <?php
   2  
   3  final class LegalpadDocumentSignature
   4    extends LegalpadDAO
   5    implements PhabricatorPolicyInterface {
   6  
   7    const VERIFIED = 0;
   8    const UNVERIFIED = 1;
   9  
  10    protected $documentPHID;
  11    protected $documentVersion;
  12    protected $signatureType;
  13    protected $signerPHID;
  14    protected $signerName;
  15    protected $signerEmail;
  16    protected $signatureData = array();
  17    protected $verified;
  18    protected $isExemption = 0;
  19    protected $exemptionPHID;
  20    protected $secretKey;
  21  
  22    private $document = self::ATTACHABLE;
  23  
  24    public function getConfiguration() {
  25      return array(
  26        self::CONFIG_SERIALIZATION => array(
  27          'signatureData' => self::SERIALIZATION_JSON,
  28        ),
  29        self::CONFIG_COLUMN_SCHEMA => array(
  30          'documentVersion' => 'uint32',
  31          'signatureType' => 'text4',
  32          'signerPHID' => 'phid?',
  33          'signerName' => 'text255',
  34          'signerEmail' => 'text255',
  35          'secretKey' => 'bytes20',
  36          'verified' => 'bool?',
  37          'isExemption' => 'bool',
  38          'exemptionPHID' => 'phid?',
  39        ),
  40        self::CONFIG_KEY_SCHEMA => array(
  41          'key_signer' => array(
  42            'columns' => array('signerPHID', 'dateModified'),
  43          ),
  44          'secretKey' => array(
  45            'columns' => array('secretKey'),
  46          ),
  47          'key_document' => array(
  48            'columns' => array('documentPHID', 'signerPHID', 'documentVersion'),
  49          ),
  50        ),
  51      ) + parent::getConfiguration();
  52    }
  53  
  54    public function save() {
  55      if (!$this->getSecretKey()) {
  56        $this->setSecretKey(Filesystem::readRandomCharacters(20));
  57      }
  58      return parent::save();
  59    }
  60  
  61    public function isVerified() {
  62      return ($this->getVerified() != self::UNVERIFIED);
  63    }
  64  
  65    public function getDocument() {
  66      return $this->assertAttached($this->document);
  67    }
  68  
  69    public function attachDocument(LegalpadDocument $document) {
  70      $this->document = $document;
  71      return $this;
  72    }
  73  
  74  
  75  /* -(  PhabricatorPolicyInterface  )----------------------------------------- */
  76  
  77  
  78    public function getCapabilities() {
  79      return array(
  80        PhabricatorPolicyCapability::CAN_VIEW,
  81      );
  82    }
  83  
  84    public function getPolicy($capability) {
  85      switch ($capability) {
  86        case PhabricatorPolicyCapability::CAN_VIEW:
  87          return $this->getDocument()->getPolicy(
  88            PhabricatorPolicyCapability::CAN_EDIT);
  89      }
  90    }
  91  
  92    public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
  93      return ($viewer->getPHID() == $this->getSignerPHID());
  94    }
  95  
  96    public function describeAutomaticCapability($capability) {
  97      return null;
  98    }
  99  
 100  }


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