diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 02a011ec72..5ef56bd01a 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1645,6 +1645,7 @@ phutil_register_library_map(array( 'PassphraseSSHPrivateKeyTextCredentialType' => 'applications/passphrase/credentialtype/PassphraseSSHPrivateKeyTextCredentialType.php', 'PassphraseSchemaSpec' => 'applications/passphrase/storage/PassphraseSchemaSpec.php', 'PassphraseSecret' => 'applications/passphrase/storage/PassphraseSecret.php', + 'PassphraseTokenCredentialType' => 'applications/passphrase/credentialtype/PassphraseTokenCredentialType.php', 'PasteConduitAPIMethod' => 'applications/paste/conduit/PasteConduitAPIMethod.php', 'PasteCreateConduitAPIMethod' => 'applications/paste/conduit/PasteCreateConduitAPIMethod.php', 'PasteCreateMailReceiver' => 'applications/paste/mail/PasteCreateMailReceiver.php', @@ -5949,6 +5950,7 @@ phutil_register_library_map(array( 'PassphraseSSHPrivateKeyTextCredentialType' => 'PassphraseSSHPrivateKeyCredentialType', 'PassphraseSchemaSpec' => 'PhabricatorConfigSchemaSpec', 'PassphraseSecret' => 'PassphraseDAO', + 'PassphraseTokenCredentialType' => 'PassphraseCredentialType', 'PasteConduitAPIMethod' => 'ConduitAPIMethod', 'PasteCreateConduitAPIMethod' => 'PasteConduitAPIMethod', 'PasteCreateMailReceiver' => 'PhabricatorMailReceiver', diff --git a/src/applications/passphrase/controller/PassphraseCredentialViewController.php b/src/applications/passphrase/controller/PassphraseCredentialViewController.php index 46bb13a688..db31964773 100644 --- a/src/applications/passphrase/controller/PassphraseCredentialViewController.php +++ b/src/applications/passphrase/controller/PassphraseCredentialViewController.php @@ -14,20 +14,16 @@ final class PassphraseCredentialViewController extends PassphraseController { return new Aphront404Response(); } - $type = PassphraseCredentialType::getTypeByConstant( - $credential->getCredentialType()); - if (!$type) { - throw new Exception(pht('Credential has invalid type "%s"!', $type)); - } + $type = $credential->getImplementation(); $timeline = $this->buildTransactionTimeline( $credential, new PassphraseCredentialTransactionQuery()); $timeline->setShouldTerminate(true); - $title = pht('%s %s', 'K'.$credential->getID(), $credential->getName()); + $title = pht('%s %s', $credential->getMonogram(), $credential->getName()); $crumbs = $this->buildApplicationCrumbs(); - $crumbs->addTextCrumb('K'.$credential->getID()); + $crumbs->addTextCrumb($credential->getMonogram()); $crumbs->setBorder(true); $header = $this->buildHeaderView($credential); diff --git a/src/applications/passphrase/credentialtype/PassphraseTokenCredentialType.php b/src/applications/passphrase/credentialtype/PassphraseTokenCredentialType.php new file mode 100644 index 0000000000..d057d61eba --- /dev/null +++ b/src/applications/passphrase/credentialtype/PassphraseTokenCredentialType.php @@ -0,0 +1,37 @@ +getCredentialTypeImplementation(); + $credential_type = $object->getImplementation(); if (!$credential_type->shouldRequireUsername()) { break; } diff --git a/src/applications/passphrase/keys/PassphraseAbstractKey.php b/src/applications/passphrase/keys/PassphraseAbstractKey.php index da56de15af..e3d902236d 100644 --- a/src/applications/passphrase/keys/PassphraseAbstractKey.php +++ b/src/applications/passphrase/keys/PassphraseAbstractKey.php @@ -32,13 +32,13 @@ abstract class PassphraseAbstractKey extends Phobject { PassphraseCredential $credential, $provides_type) { - $type = $credential->getCredentialTypeImplementation(); + $type = $credential->getImplementation(); if (!$type) { throw new Exception( pht( 'Credential "%s" is of unknown type "%s"!', - 'K'.$credential->getID(), + $credential->getMonogram(), $credential->getCredentialType())); } @@ -46,7 +46,7 @@ abstract class PassphraseAbstractKey extends Phobject { throw new Exception( pht( 'Credential "%s" must provide "%s", but provides "%s"!', - 'K'.$credential->getID(), + $credential->getMonogram(), $provides_type, $type->getProvidesType())); } diff --git a/src/applications/passphrase/query/PassphraseCredentialQuery.php b/src/applications/passphrase/query/PassphraseCredentialQuery.php index 9411fa8a77..3a78ac0d13 100644 --- a/src/applications/passphrase/query/PassphraseCredentialQuery.php +++ b/src/applications/passphrase/query/PassphraseCredentialQuery.php @@ -89,6 +89,17 @@ final class PassphraseCredentialQuery } } + foreach ($page as $key => $credential) { + $type = PassphraseCredentialType::getTypeByConstant( + $credential->getCredentialType()); + if (!$type) { + unset($page[$key]); + continue; + } + + $credential->attachImplementation(clone $type); + } + return $page; } diff --git a/src/applications/passphrase/storage/PassphraseCredential.php b/src/applications/passphrase/storage/PassphraseCredential.php index 8384f5bd52..88bc4595bd 100644 --- a/src/applications/passphrase/storage/PassphraseCredential.php +++ b/src/applications/passphrase/storage/PassphraseCredential.php @@ -25,6 +25,7 @@ final class PassphraseCredential extends PassphraseDAO protected $spacePHID; private $secret = self::ATTACHABLE; + private $implementation = self::ATTACHABLE; public static function initializeNewCredential(PhabricatorUser $actor) { $app = id(new PhabricatorApplicationQuery()) @@ -98,6 +99,15 @@ final class PassphraseCredential extends PassphraseDAO return PassphraseCredentialType::getTypeByConstant($type); } + public function attachImplementation(PassphraseCredentialType $impl) { + $this->implementation = $impl; + return $this; + } + + public function getImplementation() { + return $this->assertAttached($this->implementation); + } + /* -( PhabricatorApplicationTransactionInterface )------------------------- */