Path: blob/master/src/applications/passphrase/storage/PassphraseCredential.php
12256 views
<?php12final class PassphraseCredential extends PassphraseDAO3implements4PhabricatorApplicationTransactionInterface,5PhabricatorPolicyInterface,6PhabricatorFlaggableInterface,7PhabricatorSubscribableInterface,8PhabricatorDestructibleInterface,9PhabricatorSpacesInterface,10PhabricatorFulltextInterface,11PhabricatorFerretInterface {1213protected $name;14protected $credentialType;15protected $providesType;16protected $viewPolicy;17protected $editPolicy;18protected $description;19protected $username;20protected $secretID;21protected $isDestroyed;22protected $isLocked = 0;23protected $allowConduit = 0;24protected $authorPHID;25protected $spacePHID;2627private $secret = self::ATTACHABLE;28private $implementation = self::ATTACHABLE;2930public static function initializeNewCredential(PhabricatorUser $actor) {31$app = id(new PhabricatorApplicationQuery())32->setViewer($actor)33->withClasses(array('PhabricatorPassphraseApplication'))34->executeOne();3536$view_policy = $app->getPolicy(PassphraseDefaultViewCapability::CAPABILITY);37$edit_policy = $app->getPolicy(PassphraseDefaultEditCapability::CAPABILITY);3839return id(new PassphraseCredential())40->setName('')41->setUsername('')42->setDescription('')43->setIsDestroyed(0)44->setAuthorPHID($actor->getPHID())45->setViewPolicy($view_policy)46->setEditPolicy($edit_policy)47->setSpacePHID($actor->getDefaultSpacePHID());48}4950public function getMonogram() {51return 'K'.$this->getID();52}5354public function getURI() {55return '/'.$this->getMonogram();56}5758protected function getConfiguration() {59return array(60self::CONFIG_AUX_PHID => true,61self::CONFIG_COLUMN_SCHEMA => array(62'name' => 'text255',63'credentialType' => 'text64',64'providesType' => 'text64',65'description' => 'text',66'username' => 'text255',67'secretID' => 'id?',68'isDestroyed' => 'bool',69'isLocked' => 'bool',70'allowConduit' => 'bool',71),72self::CONFIG_KEY_SCHEMA => array(73'key_secret' => array(74'columns' => array('secretID'),75'unique' => true,76),77'key_type' => array(78'columns' => array('credentialType'),79),80'key_provides' => array(81'columns' => array('providesType'),82),83),84) + parent::getConfiguration();85}8687public function generatePHID() {88return PhabricatorPHID::generateNewPHID(89PassphraseCredentialPHIDType::TYPECONST);90}9192public function attachSecret(PhutilOpaqueEnvelope $secret = null) {93$this->secret = $secret;94return $this;95}9697public function getSecret() {98return $this->assertAttached($this->secret);99}100101public function getCredentialTypeImplementation() {102$type = $this->getCredentialType();103return PassphraseCredentialType::getTypeByConstant($type);104}105106public function attachImplementation(PassphraseCredentialType $impl) {107$this->implementation = $impl;108return $this;109}110111public function getImplementation() {112return $this->assertAttached($this->implementation);113}114115116/* -( PhabricatorApplicationTransactionInterface )------------------------- */117118119public function getApplicationTransactionEditor() {120return new PassphraseCredentialTransactionEditor();121}122123public function getApplicationTransactionTemplate() {124return new PassphraseCredentialTransaction();125}126127128/* -( PhabricatorPolicyInterface )----------------------------------------- */129130131public function getCapabilities() {132return array(133PhabricatorPolicyCapability::CAN_VIEW,134PhabricatorPolicyCapability::CAN_EDIT,135);136}137138public function getPolicy($capability) {139switch ($capability) {140case PhabricatorPolicyCapability::CAN_VIEW:141return $this->getViewPolicy();142case PhabricatorPolicyCapability::CAN_EDIT:143return $this->getEditPolicy();144}145}146147public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {148return false;149}150151152/* -( PhabricatorSubscribableInterface )----------------------------------- */153154155public function isAutomaticallySubscribed($phid) {156return false;157}158159160/* -( PhabricatorDestructibleInterface )----------------------------------- */161162public function destroyObjectPermanently(163PhabricatorDestructionEngine $engine) {164165$this->openTransaction();166$secrets = id(new PassphraseSecret())->loadAllWhere(167'id = %d',168$this->getSecretID());169foreach ($secrets as $secret) {170$secret->delete();171}172$this->delete();173$this->saveTransaction();174}175176177/* -( PhabricatorSpacesInterface )----------------------------------------- */178179180public function getSpacePHID() {181return $this->spacePHID;182}183184185/* -( PhabricatorFulltextInterface )--------------------------------------- */186187188public function newFulltextEngine() {189return new PassphraseCredentialFulltextEngine();190}191192193/* -( PhabricatorFerretInterface )----------------------------------------- */194195196public function newFerretEngine() {197return new PassphraseCredentialFerretEngine();198}199200201}202203204