@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.

Add a "Token" Credential type

Summary: Ref T9456. This is just a convenience type for things like API tokens, to make it harder for users to make mistakes and keep SSH keys out of the dropdown for "choose your API token".

Test Plan: {F879820}

Reviewers: chad

Reviewed By: chad

Subscribers: joshuaspence

Maniphest Tasks: T9456

Differential Revision: https://secure.phabricator.com/D14284

+67 -11
+2
src/__phutil_library_map__.php
··· 1645 1645 'PassphraseSSHPrivateKeyTextCredentialType' => 'applications/passphrase/credentialtype/PassphraseSSHPrivateKeyTextCredentialType.php', 1646 1646 'PassphraseSchemaSpec' => 'applications/passphrase/storage/PassphraseSchemaSpec.php', 1647 1647 'PassphraseSecret' => 'applications/passphrase/storage/PassphraseSecret.php', 1648 + 'PassphraseTokenCredentialType' => 'applications/passphrase/credentialtype/PassphraseTokenCredentialType.php', 1648 1649 'PasteConduitAPIMethod' => 'applications/paste/conduit/PasteConduitAPIMethod.php', 1649 1650 'PasteCreateConduitAPIMethod' => 'applications/paste/conduit/PasteCreateConduitAPIMethod.php', 1650 1651 'PasteCreateMailReceiver' => 'applications/paste/mail/PasteCreateMailReceiver.php', ··· 5949 5950 'PassphraseSSHPrivateKeyTextCredentialType' => 'PassphraseSSHPrivateKeyCredentialType', 5950 5951 'PassphraseSchemaSpec' => 'PhabricatorConfigSchemaSpec', 5951 5952 'PassphraseSecret' => 'PassphraseDAO', 5953 + 'PassphraseTokenCredentialType' => 'PassphraseCredentialType', 5952 5954 'PasteConduitAPIMethod' => 'ConduitAPIMethod', 5953 5955 'PasteCreateConduitAPIMethod' => 'PasteConduitAPIMethod', 5954 5956 'PasteCreateMailReceiver' => 'PhabricatorMailReceiver',
+3 -7
src/applications/passphrase/controller/PassphraseCredentialViewController.php
··· 14 14 return new Aphront404Response(); 15 15 } 16 16 17 - $type = PassphraseCredentialType::getTypeByConstant( 18 - $credential->getCredentialType()); 19 - if (!$type) { 20 - throw new Exception(pht('Credential has invalid type "%s"!', $type)); 21 - } 17 + $type = $credential->getImplementation(); 22 18 23 19 $timeline = $this->buildTransactionTimeline( 24 20 $credential, 25 21 new PassphraseCredentialTransactionQuery()); 26 22 $timeline->setShouldTerminate(true); 27 23 28 - $title = pht('%s %s', 'K'.$credential->getID(), $credential->getName()); 24 + $title = pht('%s %s', $credential->getMonogram(), $credential->getName()); 29 25 $crumbs = $this->buildApplicationCrumbs(); 30 - $crumbs->addTextCrumb('K'.$credential->getID()); 26 + $crumbs->addTextCrumb($credential->getMonogram()); 31 27 $crumbs->setBorder(true); 32 28 33 29 $header = $this->buildHeaderView($credential);
+37
src/applications/passphrase/credentialtype/PassphraseTokenCredentialType.php
··· 1 + <?php 2 + 3 + final class PassphraseTokenCredentialType 4 + extends PassphraseCredentialType { 5 + 6 + const CREDENTIAL_TYPE = 'token'; 7 + const PROVIDES_TYPE = 'provides/token'; 8 + 9 + public function getCredentialType() { 10 + return self::CREDENTIAL_TYPE; 11 + } 12 + 13 + public function getProvidesType() { 14 + return self::PROVIDES_TYPE; 15 + } 16 + 17 + public function getCredentialTypeName() { 18 + return pht('Token'); 19 + } 20 + 21 + public function getCredentialTypeDescription() { 22 + return pht('Store an API token.'); 23 + } 24 + 25 + public function getSecretLabel() { 26 + return pht('Token'); 27 + } 28 + 29 + public function newSecretControl() { 30 + return id(new AphrontFormTextControl()); 31 + } 32 + 33 + public function shouldRequireUsername() { 34 + return false; 35 + } 36 + 37 + }
+1 -1
src/applications/passphrase/editor/PassphraseCredentialTransactionEditor.php
··· 174 174 } 175 175 break; 176 176 case PassphraseCredentialTransaction::TYPE_USERNAME: 177 - $credential_type = $object->getCredentialTypeImplementation(); 177 + $credential_type = $object->getImplementation(); 178 178 if (!$credential_type->shouldRequireUsername()) { 179 179 break; 180 180 }
+3 -3
src/applications/passphrase/keys/PassphraseAbstractKey.php
··· 32 32 PassphraseCredential $credential, 33 33 $provides_type) { 34 34 35 - $type = $credential->getCredentialTypeImplementation(); 35 + $type = $credential->getImplementation(); 36 36 37 37 if (!$type) { 38 38 throw new Exception( 39 39 pht( 40 40 'Credential "%s" is of unknown type "%s"!', 41 - 'K'.$credential->getID(), 41 + $credential->getMonogram(), 42 42 $credential->getCredentialType())); 43 43 } 44 44 ··· 46 46 throw new Exception( 47 47 pht( 48 48 'Credential "%s" must provide "%s", but provides "%s"!', 49 - 'K'.$credential->getID(), 49 + $credential->getMonogram(), 50 50 $provides_type, 51 51 $type->getProvidesType())); 52 52 }
+11
src/applications/passphrase/query/PassphraseCredentialQuery.php
··· 89 89 } 90 90 } 91 91 92 + foreach ($page as $key => $credential) { 93 + $type = PassphraseCredentialType::getTypeByConstant( 94 + $credential->getCredentialType()); 95 + if (!$type) { 96 + unset($page[$key]); 97 + continue; 98 + } 99 + 100 + $credential->attachImplementation(clone $type); 101 + } 102 + 92 103 return $page; 93 104 } 94 105
+10
src/applications/passphrase/storage/PassphraseCredential.php
··· 25 25 protected $spacePHID; 26 26 27 27 private $secret = self::ATTACHABLE; 28 + private $implementation = self::ATTACHABLE; 28 29 29 30 public static function initializeNewCredential(PhabricatorUser $actor) { 30 31 $app = id(new PhabricatorApplicationQuery()) ··· 96 97 public function getCredentialTypeImplementation() { 97 98 $type = $this->getCredentialType(); 98 99 return PassphraseCredentialType::getTypeByConstant($type); 100 + } 101 + 102 + public function attachImplementation(PassphraseCredentialType $impl) { 103 + $this->implementation = $impl; 104 + return $this; 105 + } 106 + 107 + public function getImplementation() { 108 + return $this->assertAttached($this->implementation); 99 109 } 100 110 101 111