@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 203 lines 5.3 kB view raw
1<?php 2 3final class PassphraseCredential extends PassphraseDAO 4 implements 5 PhabricatorApplicationTransactionInterface, 6 PhabricatorPolicyInterface, 7 PhabricatorFlaggableInterface, 8 PhabricatorMentionableInterface, 9 PhabricatorSubscribableInterface, 10 PhabricatorDestructibleInterface, 11 PhabricatorSpacesInterface, 12 PhabricatorFulltextInterface, 13 PhabricatorFerretInterface { 14 15 protected $name; 16 protected $credentialType; 17 protected $providesType; 18 protected $viewPolicy; 19 protected $editPolicy; 20 protected $description; 21 protected $username; 22 protected $secretID; 23 protected $isDestroyed; 24 protected $isLocked = 0; 25 protected $allowConduit = 0; 26 protected $authorPHID; 27 protected $spacePHID; 28 29 private $secret = self::ATTACHABLE; 30 private $implementation = self::ATTACHABLE; 31 32 public static function initializeNewCredential(PhabricatorUser $actor) { 33 $app = id(new PhabricatorApplicationQuery()) 34 ->setViewer($actor) 35 ->withClasses(array(PhabricatorPassphraseApplication::class)) 36 ->executeOne(); 37 38 $view_policy = $app->getPolicy(PassphraseDefaultViewCapability::CAPABILITY); 39 $edit_policy = $app->getPolicy(PassphraseDefaultEditCapability::CAPABILITY); 40 41 return id(new PassphraseCredential()) 42 ->setName('') 43 ->setUsername('') 44 ->setDescription('') 45 ->setIsDestroyed(0) 46 ->setAuthorPHID($actor->getPHID()) 47 ->setViewPolicy($view_policy) 48 ->setEditPolicy($edit_policy) 49 ->setSpacePHID($actor->getDefaultSpacePHID()); 50 } 51 52 public function getMonogram() { 53 return 'K'.$this->getID(); 54 } 55 56 public function getURI() { 57 return '/'.$this->getMonogram(); 58 } 59 60 protected function getConfiguration() { 61 return array( 62 self::CONFIG_AUX_PHID => true, 63 self::CONFIG_COLUMN_SCHEMA => array( 64 'name' => 'text255', 65 'credentialType' => 'text64', 66 'providesType' => 'text64', 67 'description' => 'text', 68 'username' => 'text255', 69 'secretID' => 'id?', 70 'isDestroyed' => 'bool', 71 'isLocked' => 'bool', 72 'allowConduit' => 'bool', 73 ), 74 self::CONFIG_KEY_SCHEMA => array( 75 'key_secret' => array( 76 'columns' => array('secretID'), 77 'unique' => true, 78 ), 79 'key_type' => array( 80 'columns' => array('credentialType'), 81 ), 82 'key_provides' => array( 83 'columns' => array('providesType'), 84 ), 85 ), 86 ) + parent::getConfiguration(); 87 } 88 89 public function generatePHID() { 90 return PhabricatorPHID::generateNewPHID( 91 PassphraseCredentialPHIDType::TYPECONST); 92 } 93 94 public function attachSecret(?PhutilOpaqueEnvelope $secret = null) { 95 $this->secret = $secret; 96 return $this; 97 } 98 99 public function getSecret() { 100 return $this->assertAttached($this->secret); 101 } 102 103 public function getCredentialTypeImplementation() { 104 $type = $this->getCredentialType(); 105 return PassphraseCredentialType::getTypeByConstant($type); 106 } 107 108 public function attachImplementation(PassphraseCredentialType $impl) { 109 $this->implementation = $impl; 110 return $this; 111 } 112 113 public function getImplementation() { 114 return $this->assertAttached($this->implementation); 115 } 116 117 118/* -( PhabricatorApplicationTransactionInterface )------------------------- */ 119 120 121 public function getApplicationTransactionEditor() { 122 return new PassphraseCredentialTransactionEditor(); 123 } 124 125 public function getApplicationTransactionTemplate() { 126 return new PassphraseCredentialTransaction(); 127 } 128 129 130/* -( PhabricatorPolicyInterface )----------------------------------------- */ 131 132 133 public function getCapabilities() { 134 return array( 135 PhabricatorPolicyCapability::CAN_VIEW, 136 PhabricatorPolicyCapability::CAN_EDIT, 137 ); 138 } 139 140 public function getPolicy($capability) { 141 switch ($capability) { 142 case PhabricatorPolicyCapability::CAN_VIEW: 143 return $this->getViewPolicy(); 144 case PhabricatorPolicyCapability::CAN_EDIT: 145 return $this->getEditPolicy(); 146 } 147 } 148 149 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 150 return false; 151 } 152 153 154/* -( PhabricatorSubscribableInterface )----------------------------------- */ 155 156 157 public function isAutomaticallySubscribed($phid) { 158 return false; 159 } 160 161 162/* -( PhabricatorDestructibleInterface )----------------------------------- */ 163 164 public function destroyObjectPermanently( 165 PhabricatorDestructionEngine $engine) { 166 167 $this->openTransaction(); 168 $secrets = id(new PassphraseSecret())->loadAllWhere( 169 'id = %d', 170 $this->getSecretID()); 171 foreach ($secrets as $secret) { 172 $secret->delete(); 173 } 174 $this->delete(); 175 $this->saveTransaction(); 176 } 177 178 179/* -( PhabricatorSpacesInterface )----------------------------------------- */ 180 181 182 public function getSpacePHID() { 183 return $this->spacePHID; 184 } 185 186 187/* -( PhabricatorFulltextInterface )--------------------------------------- */ 188 189 190 public function newFulltextEngine() { 191 return new PassphraseCredentialFulltextEngine(); 192 } 193 194 195/* -( PhabricatorFerretInterface )----------------------------------------- */ 196 197 198 public function newFerretEngine() { 199 return new PassphraseCredentialFerretEngine(); 200 } 201 202 203}