1
0
Fork 0
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:
Paul Kassianik 2015-06-16 13:44:51 -07:00 committed by epriestley
parent 5240ae8bd1
commit 9537f983f6
6 changed files with 62 additions and 9 deletions

View file

@ -1271,6 +1271,7 @@ phutil_register_library_map(array(
'PassphraseCredentialTypeTestCase' => 'applications/passphrase/credentialtype/__tests__/PassphraseCredentialTypeTestCase.php', 'PassphraseCredentialTypeTestCase' => 'applications/passphrase/credentialtype/__tests__/PassphraseCredentialTypeTestCase.php',
'PassphraseCredentialViewController' => 'applications/passphrase/controller/PassphraseCredentialViewController.php', 'PassphraseCredentialViewController' => 'applications/passphrase/controller/PassphraseCredentialViewController.php',
'PassphraseDAO' => 'applications/passphrase/storage/PassphraseDAO.php', 'PassphraseDAO' => 'applications/passphrase/storage/PassphraseDAO.php',
'PassphraseNoteCredentialType' => 'applications/passphrase/credentialtype/PassphraseNoteCredentialType.php',
'PassphrasePasswordCredentialType' => 'applications/passphrase/credentialtype/PassphrasePasswordCredentialType.php', 'PassphrasePasswordCredentialType' => 'applications/passphrase/credentialtype/PassphrasePasswordCredentialType.php',
'PassphrasePasswordKey' => 'applications/passphrase/keys/PassphrasePasswordKey.php', 'PassphrasePasswordKey' => 'applications/passphrase/keys/PassphrasePasswordKey.php',
'PassphraseQueryConduitAPIMethod' => 'applications/passphrase/conduit/PassphraseQueryConduitAPIMethod.php', 'PassphraseQueryConduitAPIMethod' => 'applications/passphrase/conduit/PassphraseQueryConduitAPIMethod.php',
@ -4766,6 +4767,7 @@ phutil_register_library_map(array(
'PassphraseCredentialTypeTestCase' => 'PhabricatorTestCase', 'PassphraseCredentialTypeTestCase' => 'PhabricatorTestCase',
'PassphraseCredentialViewController' => 'PassphraseController', 'PassphraseCredentialViewController' => 'PassphraseController',
'PassphraseDAO' => 'PhabricatorLiskDAO', 'PassphraseDAO' => 'PhabricatorLiskDAO',
'PassphraseNoteCredentialType' => 'PassphraseCredentialType',
'PassphrasePasswordCredentialType' => 'PassphraseCredentialType', 'PassphrasePasswordCredentialType' => 'PassphraseCredentialType',
'PassphrasePasswordKey' => 'PassphraseAbstractKey', 'PassphrasePasswordKey' => 'PassphraseAbstractKey',
'PassphraseQueryConduitAPIMethod' => 'PassphraseConduitAPIMethod', 'PassphraseQueryConduitAPIMethod' => 'PassphraseConduitAPIMethod',

View file

@ -47,7 +47,7 @@ final class PassphraseCredentialEditController extends PassphraseController {
$is_new = true; $is_new = true;
// Prefill username if provided. // Prefill username if provided.
$credential->setUsername($request->getStr('username')); $credential->setUsername((string)$request->getStr('username'));
if (!$request->getStr('isInitialized')) { if (!$request->getStr('isInitialized')) {
$type->didInitializeNewCredential($viewer, $credential); $type->didInitializeNewCredential($viewer, $credential);
@ -151,10 +151,11 @@ final class PassphraseCredentialEditController extends PassphraseController {
$credential->openTransaction(); $credential->openTransaction();
if (!$credential->getIsLocked()) { if (!$credential->getIsLocked()) {
if ($type->shouldRequireUsername()) {
$xactions[] = id(new PassphraseCredentialTransaction()) $xactions[] = id(new PassphraseCredentialTransaction())
->setTransactionType($type_username) ->setTransactionType($type_username)
->setNewValue($v_username); ->setNewValue($v_username);
}
// If some value other than a sequence of bullets was provided for // If some value other than a sequence of bullets was provided for
// the credential, update it. In particular, note that we are // the credential, update it. In particular, note that we are
// explicitly allowing empty secrets: one use case is HTTP auth where // 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.')); pht('This credential is permanently locked and can not be edited.'));
} }
if ($type->shouldRequireUsername()) {
$form $form
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
@ -270,7 +272,9 @@ final class PassphraseCredentialEditController extends PassphraseController {
->setLabel(pht('Login/Username')) ->setLabel(pht('Login/Username'))
->setValue($v_username) ->setValue($v_username)
->setDisabled($credential_is_locked) ->setDisabled($credential_is_locked)
->setError($e_username)) ->setError($e_username));
}
$form
->appendChild( ->appendChild(
$secret_control $secret_control
->setName('secret') ->setName('secret')

View file

@ -182,9 +182,11 @@ final class PassphraseCredentialViewController extends PassphraseController {
pht('Editable By'), pht('Editable By'),
$descriptions[PhabricatorPolicyCapability::CAN_EDIT]); $descriptions[PhabricatorPolicyCapability::CAN_EDIT]);
if ($type->shouldRequireUsername()) {
$properties->addProperty( $properties->addProperty(
pht('Username'), pht('Username'),
$credential->getUsername()); $credential->getUsername());
}
$used_by_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( $used_by_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
$credential->getPHID(), $credential->getPHID(),

View file

@ -131,4 +131,8 @@ abstract class PassphraseCredentialType extends Phobject {
return $secret; return $secret;
} }
public function shouldRequireUsername() {
return true;
}
} }

View file

@ -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;
}
}

View file

@ -174,6 +174,10 @@ final class PassphraseCredentialTransactionEditor
} }
break; break;
case PassphraseCredentialTransaction::TYPE_USERNAME: case PassphraseCredentialTransaction::TYPE_USERNAME:
$credential_type = $object->getCredentialTypeImplementation();
if (!$credential_type->shouldRequireUsername()) {
break;
}
$missing = $this->validateIsEmptyTextField( $missing = $this->validateIsEmptyTextField(
$object->getUsername(), $object->getUsername(),
$xactions); $xactions);