Changeset View
Changeset View
Standalone View
Standalone View
src/applications/packages/storage/PackagesSignature.php
- This file was added.
| <?php | |||||
| /** | |||||
| * This is an auxilary DAO. It's only viewable in the context of a version. | |||||
| */ | |||||
| final class PackagesSignature extends PackagesDAO | |||||
| implements | |||||
| PhabricatorPolicyInterface, | |||||
| PhabricatorDestructibleInterface { | |||||
| protected $signerPHID; | |||||
| protected $versionPHID; | |||||
| // $details will list what exactly was signed. | |||||
| protected $details = array(); | |||||
| protected $publicKey; | |||||
| protected $description; | |||||
| // TODO add pubkey fingerprint, for search? | |||||
Lint: TODO Comment: This comment has a TODO. | |||||
Not Done Inline ActionsThe view policy for a signature should probably always be the version view policy? The edit policy should probably always be only the signer PHID? I don't think it makes sense to disavow other users' signatures, or at least can't come up with a reason to do this. The only case I can think of is that someone might be signing stuff as "CONFIRMED: THIS SOFTWARE SUCKS LOL" far in the future, but that seems like a whole lot of effort. epriestley: The view policy for a signature should probably always be the version view policy?
The edit… | |||||
Not Done Inline Actionsthat was my plan (Also for Version so inherit it from Package), but I couldn't figure out how to do it, so I left it for later. avivey: that was my plan (Also for Version so inherit it from Package), but I couldn't figure out how… | |||||
| private $version = self::ATTACHABLE; | |||||
| public static function initializeNewSignature(PhabricatorUser $actor) { | |||||
| $app = id(new PhabricatorApplicationQuery()) | |||||
| ->setViewer($actor) | |||||
| ->withClasses(array('PhabricatorPackagesApplication')) | |||||
| ->executeOne(); | |||||
| $view_policy = $app->getPolicy(PackagesDefaultViewCapability::CAPABILITY); | |||||
| return id(new PackagesSignature()) | |||||
| ->setSignerPHID($actor->getPHID()); | |||||
| } | |||||
| protected function getConfiguration() { | |||||
| return array( | |||||
| self::CONFIG_AUX_PHID => true, | |||||
| self::CONFIG_SERIALIZATION => array( | |||||
| 'details' => self::SERIALIZATION_JSON, | |||||
| ), | |||||
| self::CONFIG_COLUMN_SCHEMA => array( | |||||
| 'publicKey' => 'text', | |||||
| 'description' => 'text', | |||||
| ), | |||||
| self::CONFIG_KEY_SCHEMA => array( | |||||
| 'key_signer' => array( | |||||
| 'columns' => array('signerPHID'), | |||||
| ), | |||||
| 'key_version' => array( | |||||
| 'columns' => array('versionPHID'), | |||||
| ), | |||||
| ), | |||||
| ) + parent::getConfiguration(); | |||||
| } | |||||
| public function generatePHID() { | |||||
| return PhabricatorPHID::generateNewPHID( | |||||
| PackagesSignaturePHIDType::TYPECONST); | |||||
| } | |||||
| public function getVersion() { | |||||
| return $this->assertAttached($this->version); | |||||
| } | |||||
| public function attachVersion(PackagesVersion $version) { | |||||
| $this->version = $version; | |||||
| return $this; | |||||
| } | |||||
| /* -( PhabricatorPolicyInterface )----------------------------------------- */ | |||||
| public function getCapabilities() { | |||||
| return array( | |||||
| PhabricatorPolicyCapability::CAN_VIEW, | |||||
| PhabricatorPolicyCapability::CAN_EDIT, | |||||
| ); | |||||
| } | |||||
| public function getPolicy($capability) { | |||||
| return $this->getVersion()->getPolicy($capability); | |||||
| } | |||||
| public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { | |||||
| return $this->getVersion()->hasAutomaticCapability($capability, $viewer); | |||||
| } | |||||
| public function describeAutomaticCapability($capability) { | |||||
| return pht('A signature has the same policies as its package'); | |||||
| } | |||||
| /* -( PhabricatorDestructibleInterface )----------------------------------- */ | |||||
| public function destroyObjectPermanently( | |||||
| PhabricatorDestructionEngine $engine) { | |||||
| $this->openTransaction(); | |||||
| $this->delete(); | |||||
| $this->saveTransaction(); | |||||
| } | |||||
| } | |||||
This comment has a TODO.