mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 03:50:54 +01:00
Added a Note Credential Type for Passphrase
Summary: Closes T8481. Test Plan: Verify that in Passphrase > Create an option to create a Note credential exists and credentials of type Note are createable. Reviewers: epriestley, #blessed_reviewers, eadler, lpriestley Reviewed By: eadler Subscribers: joshuaspence, epriestley, Korvin Maniphest Tasks: T8481 Differential Revision: https://secure.phabricator.com/D13261
This commit is contained in:
parent
5240ae8bd1
commit
9537f983f6
6 changed files with 62 additions and 9 deletions
|
@ -1271,6 +1271,7 @@ phutil_register_library_map(array(
|
|||
'PassphraseCredentialTypeTestCase' => 'applications/passphrase/credentialtype/__tests__/PassphraseCredentialTypeTestCase.php',
|
||||
'PassphraseCredentialViewController' => 'applications/passphrase/controller/PassphraseCredentialViewController.php',
|
||||
'PassphraseDAO' => 'applications/passphrase/storage/PassphraseDAO.php',
|
||||
'PassphraseNoteCredentialType' => 'applications/passphrase/credentialtype/PassphraseNoteCredentialType.php',
|
||||
'PassphrasePasswordCredentialType' => 'applications/passphrase/credentialtype/PassphrasePasswordCredentialType.php',
|
||||
'PassphrasePasswordKey' => 'applications/passphrase/keys/PassphrasePasswordKey.php',
|
||||
'PassphraseQueryConduitAPIMethod' => 'applications/passphrase/conduit/PassphraseQueryConduitAPIMethod.php',
|
||||
|
@ -4766,6 +4767,7 @@ phutil_register_library_map(array(
|
|||
'PassphraseCredentialTypeTestCase' => 'PhabricatorTestCase',
|
||||
'PassphraseCredentialViewController' => 'PassphraseController',
|
||||
'PassphraseDAO' => 'PhabricatorLiskDAO',
|
||||
'PassphraseNoteCredentialType' => 'PassphraseCredentialType',
|
||||
'PassphrasePasswordCredentialType' => 'PassphraseCredentialType',
|
||||
'PassphrasePasswordKey' => 'PassphraseAbstractKey',
|
||||
'PassphraseQueryConduitAPIMethod' => 'PassphraseConduitAPIMethod',
|
||||
|
|
|
@ -47,7 +47,7 @@ final class PassphraseCredentialEditController extends PassphraseController {
|
|||
$is_new = true;
|
||||
|
||||
// Prefill username if provided.
|
||||
$credential->setUsername($request->getStr('username'));
|
||||
$credential->setUsername((string)$request->getStr('username'));
|
||||
|
||||
if (!$request->getStr('isInitialized')) {
|
||||
$type->didInitializeNewCredential($viewer, $credential);
|
||||
|
@ -151,10 +151,11 @@ final class PassphraseCredentialEditController extends PassphraseController {
|
|||
$credential->openTransaction();
|
||||
|
||||
if (!$credential->getIsLocked()) {
|
||||
if ($type->shouldRequireUsername()) {
|
||||
$xactions[] = id(new PassphraseCredentialTransaction())
|
||||
->setTransactionType($type_username)
|
||||
->setNewValue($v_username);
|
||||
|
||||
}
|
||||
// If some value other than a sequence of bullets was provided for
|
||||
// the credential, update it. In particular, note that we are
|
||||
// explicitly allowing empty secrets: one use case is HTTP auth where
|
||||
|
@ -263,6 +264,7 @@ final class PassphraseCredentialEditController extends PassphraseController {
|
|||
pht('This credential is permanently locked and can not be edited.'));
|
||||
}
|
||||
|
||||
if ($type->shouldRequireUsername()) {
|
||||
$form
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
|
@ -270,7 +272,9 @@ final class PassphraseCredentialEditController extends PassphraseController {
|
|||
->setLabel(pht('Login/Username'))
|
||||
->setValue($v_username)
|
||||
->setDisabled($credential_is_locked)
|
||||
->setError($e_username))
|
||||
->setError($e_username));
|
||||
}
|
||||
$form
|
||||
->appendChild(
|
||||
$secret_control
|
||||
->setName('secret')
|
||||
|
|
|
@ -182,9 +182,11 @@ final class PassphraseCredentialViewController extends PassphraseController {
|
|||
pht('Editable By'),
|
||||
$descriptions[PhabricatorPolicyCapability::CAN_EDIT]);
|
||||
|
||||
if ($type->shouldRequireUsername()) {
|
||||
$properties->addProperty(
|
||||
pht('Username'),
|
||||
$credential->getUsername());
|
||||
}
|
||||
|
||||
$used_by_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
||||
$credential->getPHID(),
|
||||
|
|
|
@ -131,4 +131,8 @@ abstract class PassphraseCredentialType extends Phobject {
|
|||
return $secret;
|
||||
}
|
||||
|
||||
public function shouldRequireUsername() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
final class PassphraseNoteCredentialType
|
||||
extends PassphraseCredentialType {
|
||||
|
||||
const CREDENTIAL_TYPE = 'note';
|
||||
const PROVIDES_TYPE = 'provides/note';
|
||||
|
||||
public function getCredentialType() {
|
||||
return self::CREDENTIAL_TYPE;
|
||||
}
|
||||
|
||||
public function getProvidesType() {
|
||||
return self::PROVIDES_TYPE;
|
||||
}
|
||||
|
||||
public function getCredentialTypeName() {
|
||||
return pht('Note');
|
||||
}
|
||||
|
||||
public function getCredentialTypeDescription() {
|
||||
return pht('Store a plaintext note.');
|
||||
}
|
||||
|
||||
public function getSecretLabel() {
|
||||
return pht('Note');
|
||||
}
|
||||
|
||||
public function newSecretControl() {
|
||||
return id(new AphrontFormTextAreaControl());
|
||||
}
|
||||
|
||||
public function shouldRequireUsername() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -174,6 +174,10 @@ final class PassphraseCredentialTransactionEditor
|
|||
}
|
||||
break;
|
||||
case PassphraseCredentialTransaction::TYPE_USERNAME:
|
||||
$credential_type = $object->getCredentialTypeImplementation();
|
||||
if (!$credential_type->shouldRequireUsername()) {
|
||||
break;
|
||||
}
|
||||
$missing = $this->validateIsEmptyTextField(
|
||||
$object->getUsername(),
|
||||
$xactions);
|
||||
|
|
Loading…
Reference in a new issue