Page MenuHomePhabricator

D14936.diff
No OneTemporary

D14936.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1538,6 +1538,7 @@
'PassphraseCredentialCreateController' => 'applications/passphrase/controller/PassphraseCredentialCreateController.php',
'PassphraseCredentialDestroyController' => 'applications/passphrase/controller/PassphraseCredentialDestroyController.php',
'PassphraseCredentialEditController' => 'applications/passphrase/controller/PassphraseCredentialEditController.php',
+ 'PassphraseCredentialEditEngine' => 'applications/passphrase/editor/PassphraseCredentialEditEngine.php',
'PassphraseCredentialFulltextEngine' => 'applications/passphrase/search/PassphraseCredentialFulltextEngine.php',
'PassphraseCredentialListController' => 'applications/passphrase/controller/PassphraseCredentialListController.php',
'PassphraseCredentialLockController' => 'applications/passphrase/controller/PassphraseCredentialLockController.php',
@@ -1555,6 +1556,7 @@
'PassphraseDAO' => 'applications/passphrase/storage/PassphraseDAO.php',
'PassphraseDefaultEditCapability' => 'applications/passphrase/capability/PassphraseDefaultEditCapability.php',
'PassphraseDefaultViewCapability' => 'applications/passphrase/capability/PassphraseDefaultViewCapability.php',
+ 'PassphraseEditConduitAPIMethod' => 'applications/passphrase/conduit/PassphraseEditConduitAPIMethod.php',
'PassphraseNoteCredentialType' => 'applications/passphrase/credentialtype/PassphraseNoteCredentialType.php',
'PassphrasePasswordCredentialType' => 'applications/passphrase/credentialtype/PassphrasePasswordCredentialType.php',
'PassphrasePasswordKey' => 'applications/passphrase/keys/PassphrasePasswordKey.php',
@@ -1566,6 +1568,7 @@
'PassphraseSSHPrivateKeyFileCredentialType' => 'applications/passphrase/credentialtype/PassphraseSSHPrivateKeyFileCredentialType.php',
'PassphraseSSHPrivateKeyTextCredentialType' => 'applications/passphrase/credentialtype/PassphraseSSHPrivateKeyTextCredentialType.php',
'PassphraseSchemaSpec' => 'applications/passphrase/storage/PassphraseSchemaSpec.php',
+ 'PassphraseSearchConduitAPIMethod' => 'applications/passphrase/conduit/PassphraseSearchConduitAPIMethod.php',
'PassphraseSecret' => 'applications/passphrase/storage/PassphraseSecret.php',
'PasteConduitAPIMethod' => 'applications/paste/conduit/PasteConduitAPIMethod.php',
'PasteCreateConduitAPIMethod' => 'applications/paste/conduit/PasteCreateConduitAPIMethod.php',
@@ -1806,6 +1809,7 @@
'PhabricatorBcryptPasswordHasher' => 'infrastructure/util/password/PhabricatorBcryptPasswordHasher.php',
'PhabricatorBinariesSetupCheck' => 'applications/config/check/PhabricatorBinariesSetupCheck.php',
'PhabricatorBitbucketAuthProvider' => 'applications/auth/provider/PhabricatorBitbucketAuthProvider.php',
+ 'PhabricatorBooleanEditField' => 'applications/transactions/editfield/PhabricatorBooleanEditField.php',
'PhabricatorBot' => 'infrastructure/daemon/bot/PhabricatorBot.php',
'PhabricatorBotChannel' => 'infrastructure/daemon/bot/target/PhabricatorBotChannel.php',
'PhabricatorBotDebugLogHandler' => 'infrastructure/daemon/bot/handler/PhabricatorBotDebugLogHandler.php',
@@ -2676,6 +2680,7 @@
'PhabricatorPagerUIExample' => 'applications/uiexample/examples/PhabricatorPagerUIExample.php',
'PhabricatorPassphraseApplication' => 'applications/passphrase/application/PhabricatorPassphraseApplication.php',
'PhabricatorPasswordAuthProvider' => 'applications/auth/provider/PhabricatorPasswordAuthProvider.php',
+ 'PhabricatorPasswordEditField' => 'applications/transactions/editfield/PhabricatorPasswordEditField.php',
'PhabricatorPasswordHasher' => 'infrastructure/util/password/PhabricatorPasswordHasher.php',
'PhabricatorPasswordHasherTestCase' => 'infrastructure/util/password/__tests__/PhabricatorPasswordHasherTestCase.php',
'PhabricatorPasswordHasherUnavailableException' => 'infrastructure/util/password/PhabricatorPasswordHasherUnavailableException.php',
@@ -5663,6 +5668,7 @@
'PassphraseCredentialCreateController' => 'PassphraseController',
'PassphraseCredentialDestroyController' => 'PassphraseController',
'PassphraseCredentialEditController' => 'PassphraseController',
+ 'PassphraseCredentialEditEngine' => 'PhabricatorEditEngine',
'PassphraseCredentialFulltextEngine' => 'PhabricatorFulltextEngine',
'PassphraseCredentialListController' => 'PassphraseController',
'PassphraseCredentialLockController' => 'PassphraseController',
@@ -5680,6 +5686,7 @@
'PassphraseDAO' => 'PhabricatorLiskDAO',
'PassphraseDefaultEditCapability' => 'PhabricatorPolicyCapability',
'PassphraseDefaultViewCapability' => 'PhabricatorPolicyCapability',
+ 'PassphraseEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
'PassphraseNoteCredentialType' => 'PassphraseCredentialType',
'PassphrasePasswordCredentialType' => 'PassphraseCredentialType',
'PassphrasePasswordKey' => 'PassphraseAbstractKey',
@@ -5691,6 +5698,7 @@
'PassphraseSSHPrivateKeyFileCredentialType' => 'PassphraseSSHPrivateKeyCredentialType',
'PassphraseSSHPrivateKeyTextCredentialType' => 'PassphraseSSHPrivateKeyCredentialType',
'PassphraseSchemaSpec' => 'PhabricatorConfigSchemaSpec',
+ 'PassphraseSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
'PassphraseSecret' => 'PassphraseDAO',
'PasteConduitAPIMethod' => 'ConduitAPIMethod',
'PasteCreateConduitAPIMethod' => 'PasteConduitAPIMethod',
@@ -5970,6 +5978,7 @@
'PhabricatorBcryptPasswordHasher' => 'PhabricatorPasswordHasher',
'PhabricatorBinariesSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorBitbucketAuthProvider' => 'PhabricatorOAuth1AuthProvider',
+ 'PhabricatorBooleanEditField' => 'PhabricatorEditField',
'PhabricatorBot' => 'PhabricatorDaemon',
'PhabricatorBotChannel' => 'PhabricatorBotTarget',
'PhabricatorBotDebugLogHandler' => 'PhabricatorBotHandler',
@@ -6978,6 +6987,7 @@
'PhabricatorPagerUIExample' => 'PhabricatorUIExample',
'PhabricatorPassphraseApplication' => 'PhabricatorApplication',
'PhabricatorPasswordAuthProvider' => 'PhabricatorAuthProvider',
+ 'PhabricatorPasswordEditField' => 'PhabricatorEditField',
'PhabricatorPasswordHasher' => 'Phobject',
'PhabricatorPasswordHasherTestCase' => 'PhabricatorTestCase',
'PhabricatorPasswordHasherUnavailableException' => 'Exception',
diff --git a/src/applications/passphrase/conduit/PassphraseEditConduitAPIMethod.php b/src/applications/passphrase/conduit/PassphraseEditConduitAPIMethod.php
new file mode 100644
--- /dev/null
+++ b/src/applications/passphrase/conduit/PassphraseEditConduitAPIMethod.php
@@ -0,0 +1,19 @@
+<?php
+
+final class PassphraseEditConduitAPIMethod
+ extends PhabricatorEditEngineAPIMethod {
+
+ public function getAPIMethodName() {
+ return 'passphrase.edit';
+ }
+
+ public function newEditEngine() {
+ return new PassphraseCredentialEditEngine();
+ }
+
+ public function getMethodSummary() {
+ return pht(
+ 'Apply transactions to create a new credential or edit an existing one.');
+ }
+
+}
diff --git a/src/applications/passphrase/conduit/PassphraseSearchConduitAPIMethod.php b/src/applications/passphrase/conduit/PassphraseSearchConduitAPIMethod.php
new file mode 100644
--- /dev/null
+++ b/src/applications/passphrase/conduit/PassphraseSearchConduitAPIMethod.php
@@ -0,0 +1,18 @@
+<?php
+
+final class PassphraseSearchConduitAPIMethod
+ extends PhabricatorSearchEngineAPIMethod {
+
+ public function getAPIMethodName() {
+ return 'passphrase.search';
+ }
+
+ public function newSearchEngine() {
+ return new PassphraseCredentialSearchEngine();
+ }
+
+ public function getMethodSummary() {
+ return pht('Read information about credentials.');
+ }
+
+}
diff --git a/src/applications/passphrase/controller/PassphraseCredentialEditController.php b/src/applications/passphrase/controller/PassphraseCredentialEditController.php
--- a/src/applications/passphrase/controller/PassphraseCredentialEditController.php
+++ b/src/applications/passphrase/controller/PassphraseCredentialEditController.php
@@ -3,376 +3,10 @@
final class PassphraseCredentialEditController extends PassphraseController {
public function handleRequest(AphrontRequest $request) {
- $viewer = $request->getViewer();
- $id = $request->getURIData('id');
-
- if ($id) {
- $credential = id(new PassphraseCredentialQuery())
- ->setViewer($viewer)
- ->withIDs(array($id))
- ->requireCapabilities(
- array(
- PhabricatorPolicyCapability::CAN_VIEW,
- PhabricatorPolicyCapability::CAN_EDIT,
- ))
- ->executeOne();
- if (!$credential) {
- return new Aphront404Response();
- }
-
- $type = $this->getCredentialType($credential->getCredentialType());
-
- $is_new = false;
- } else {
- $type_const = $request->getStr('type');
- $type = $this->getCredentialType($type_const);
-
- if (!$type->isCreateable()) {
- throw new Exception(
- pht(
- 'Credential has noncreateable type "%s"!',
- $type_const));
- }
-
- $credential = PassphraseCredential::initializeNewCredential($viewer)
- ->setCredentialType($type->getCredentialType())
- ->setProvidesType($type->getProvidesType());
-
- $is_new = true;
-
- // Prefill username if provided.
- $credential->setUsername((string)$request->getStr('username'));
-
- if (!$request->getStr('isInitialized')) {
- $type->didInitializeNewCredential($viewer, $credential);
- }
- }
-
- $errors = array();
-
- $v_name = $credential->getName();
- $e_name = true;
-
- $v_desc = $credential->getDescription();
- $v_space = $credential->getSpacePHID();
-
- $v_username = $credential->getUsername();
- $e_username = true;
-
- $v_is_locked = false;
-
- $bullet = "\xE2\x80\xA2";
-
- $v_secret = $credential->getSecretID() ? str_repeat($bullet, 32) : null;
- if ($is_new && ($v_secret === null)) {
- // If we're creating a new credential, the credential type may have
- // populated the secret for us (for example, generated an SSH key). In
- // this case,
- try {
- $v_secret = $credential->getSecret()->openEnvelope();
- } catch (Exception $ex) {
- // Ignore this.
- }
- }
-
- $validation_exception = null;
- $errors = array();
- $e_password = null;
- if ($request->isFormPost()) {
-
- $v_name = $request->getStr('name');
- $v_desc = $request->getStr('description');
- $v_username = $request->getStr('username');
- $v_view_policy = $request->getStr('viewPolicy');
- $v_edit_policy = $request->getStr('editPolicy');
- $v_is_locked = $request->getStr('lock');
-
- $v_secret = $request->getStr('secret');
- $v_space = $request->getStr('spacePHID');
- $v_password = $request->getStr('password');
- $v_decrypt = $v_secret;
-
- $env_secret = new PhutilOpaqueEnvelope($v_secret);
- $env_password = new PhutilOpaqueEnvelope($v_password);
-
- if ($type->requiresPassword($env_secret)) {
- if (strlen($v_password)) {
- $v_decrypt = $type->decryptSecret($env_secret, $env_password);
- if ($v_decrypt === null) {
- $e_password = pht('Incorrect');
- $errors[] = pht(
- 'This key requires a password, but the password you provided '.
- 'is incorrect.');
- } else {
- $v_decrypt = $v_decrypt->openEnvelope();
- }
- } else {
- $e_password = pht('Required');
- $errors[] = pht(
- 'This key requires a password. You must provide the password '.
- 'for the key.');
- }
- }
-
- if (!$errors) {
- $type_name = PassphraseCredentialTransaction::TYPE_NAME;
- $type_desc = PassphraseCredentialTransaction::TYPE_DESCRIPTION;
- $type_username = PassphraseCredentialTransaction::TYPE_USERNAME;
- $type_destroy = PassphraseCredentialTransaction::TYPE_DESTROY;
- $type_secret_id = PassphraseCredentialTransaction::TYPE_SECRET_ID;
- $type_is_locked = PassphraseCredentialTransaction::TYPE_LOCK;
- $type_view_policy = PhabricatorTransactions::TYPE_VIEW_POLICY;
- $type_edit_policy = PhabricatorTransactions::TYPE_EDIT_POLICY;
- $type_space = PhabricatorTransactions::TYPE_SPACE;
-
- $xactions = array();
-
- $xactions[] = id(new PassphraseCredentialTransaction())
- ->setTransactionType($type_name)
- ->setNewValue($v_name);
-
- $xactions[] = id(new PassphraseCredentialTransaction())
- ->setTransactionType($type_desc)
- ->setNewValue($v_desc);
-
- $xactions[] = id(new PassphraseCredentialTransaction())
- ->setTransactionType($type_view_policy)
- ->setNewValue($v_view_policy);
-
- $xactions[] = id(new PassphraseCredentialTransaction())
- ->setTransactionType($type_edit_policy)
- ->setNewValue($v_edit_policy);
-
- $xactions[] = id(new PassphraseCredentialTransaction())
- ->setTransactionType($type_space)
- ->setNewValue($v_space);
-
- // Open a transaction in case we're writing a new secret; this limits
- // the amount of code which handles secret plaintexts.
- $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
- // the username is a secret token which covers both identity and
- // authentication.
-
- if (!preg_match('/^('.$bullet.')+$/', trim($v_decrypt))) {
- // If the credential was previously destroyed, restore it when it is
- // edited if a secret is provided.
- $xactions[] = id(new PassphraseCredentialTransaction())
- ->setTransactionType($type_destroy)
- ->setNewValue(0);
-
- $new_secret = id(new PassphraseSecret())
- ->setSecretData($v_decrypt)
- ->save();
- $xactions[] = id(new PassphraseCredentialTransaction())
- ->setTransactionType($type_secret_id)
- ->setNewValue($new_secret->getID());
- }
-
- $xactions[] = id(new PassphraseCredentialTransaction())
- ->setTransactionType($type_is_locked)
- ->setNewValue($v_is_locked);
- }
-
- try {
- $editor = id(new PassphraseCredentialTransactionEditor())
- ->setActor($viewer)
- ->setContinueOnNoEffect(true)
- ->setContentSourceFromRequest($request)
- ->applyTransactions($credential, $xactions);
-
- $credential->saveTransaction();
-
- if ($request->isAjax()) {
- return id(new AphrontAjaxResponse())->setContent(
- array(
- 'phid' => $credential->getPHID(),
- 'name' => 'K'.$credential->getID().' '.$credential->getName(),
- ));
- } else {
- return id(new AphrontRedirectResponse())
- ->setURI('/K'.$credential->getID());
- }
- } catch (PhabricatorApplicationTransactionValidationException $ex) {
- $credential->killTransaction();
-
- $validation_exception = $ex;
-
- $e_name = $ex->getShortMessage($type_name);
- $e_username = $ex->getShortMessage($type_username);
-
- $credential->setViewPolicy($v_view_policy);
- $credential->setEditPolicy($v_edit_policy);
- }
- }
- }
-
- $policies = id(new PhabricatorPolicyQuery())
- ->setViewer($viewer)
- ->setObject($credential)
- ->execute();
-
- $secret_control = $type->newSecretControl();
- $credential_is_locked = $credential->getIsLocked();
-
- $form = id(new AphrontFormView())
- ->setUser($viewer)
- ->addHiddenInput('isInitialized', true)
- ->appendChild(
- id(new AphrontFormTextControl())
- ->setName('name')
- ->setLabel(pht('Name'))
- ->setValue($v_name)
- ->setError($e_name))
- ->appendChild(
- id(new AphrontFormTextAreaControl())
- ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)
- ->setName('description')
- ->setLabel(pht('Description'))
- ->setValue($v_desc))
- ->appendChild(
- id(new AphrontFormMarkupControl())
- ->setLabel(pht('Credential Type'))
- ->setValue($type->getCredentialTypeName()))
- ->appendChild(
- id(new AphrontFormDividerControl()))
- ->appendControl(
- id(new AphrontFormPolicyControl())
- ->setName('viewPolicy')
- ->setPolicyObject($credential)
- ->setSpacePHID($v_space)
- ->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
- ->setPolicies($policies))
- ->appendControl(
- id(new AphrontFormPolicyControl())
- ->setName('editPolicy')
- ->setPolicyObject($credential)
- ->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
- ->setPolicies($policies))
- ->appendChild(
- id(new AphrontFormDividerControl()));
-
- if ($credential_is_locked) {
- $form->appendRemarkupInstructions(
- pht('This credential is permanently locked and can not be edited.'));
- }
-
- if ($type->shouldRequireUsername()) {
- $form
- ->appendChild(
- id(new AphrontFormTextControl())
- ->setName('username')
- ->setLabel(pht('Login/Username'))
- ->setValue($v_username)
- ->setDisabled($credential_is_locked)
- ->setError($e_username));
- }
- $form
- ->appendChild(
- $secret_control
- ->setName('secret')
- ->setLabel($type->getSecretLabel())
- ->setDisabled($credential_is_locked)
- ->setValue($v_secret));
-
- if ($type->shouldShowPasswordField()) {
- $form->appendChild(
- id(new AphrontFormPasswordControl())
- ->setDisableAutocomplete(true)
- ->setName('password')
- ->setLabel($type->getPasswordLabel())
- ->setDisabled($credential_is_locked)
- ->setError($e_password));
- }
-
- if ($is_new) {
- $form->appendChild(
- id(new AphrontFormCheckboxControl())
- ->addCheckbox(
- 'lock',
- 1,
- array(
- phutil_tag('strong', array(), pht('Lock Permanently:')),
- ' ',
- pht('Prevent the secret from being revealed or changed.'),
- ),
- $v_is_locked)
- ->setDisabled($credential_is_locked));
- }
-
- $crumbs = $this->buildApplicationCrumbs();
-
- if ($is_new) {
- $title = pht('Create Credential');
- $header = pht('Create New Credential');
- $crumbs->addTextCrumb(pht('Create'));
- $cancel_uri = $this->getApplicationURI();
- } else {
- $title = pht('Edit Credential');
- $header = pht('Edit Credential %s', 'K'.$credential->getID());
- $crumbs->addTextCrumb(
- 'K'.$credential->getID(),
- '/K'.$credential->getID());
- $crumbs->addTextCrumb(pht('Edit'));
- $cancel_uri = '/K'.$credential->getID();
- }
-
- if ($request->isAjax()) {
- if ($errors) {
- $errors = id(new PHUIInfoView())->setErrors($errors);
- }
-
- $dialog = id(new AphrontDialogView())
- ->setUser($viewer)
- ->setWidth(AphrontDialogView::WIDTH_FORM)
- ->setTitle($title)
- ->appendChild($errors)
- ->appendChild($form->buildLayoutView())
- ->addSubmitButton(pht('Create Credential'))
- ->addCancelButton($cancel_uri);
-
- return id(new AphrontDialogResponse())->setDialog($dialog);
- }
-
- $form->appendChild(
- id(new AphrontFormSubmitControl())
- ->setValue(pht('Save'))
- ->addCancelButton($cancel_uri));
-
- $box = id(new PHUIObjectBoxView())
- ->setHeaderText($header)
- ->setFormErrors($errors)
- ->setValidationException($validation_exception)
- ->setForm($form);
-
- return $this->buildApplicationPage(
- array(
- $crumbs,
- $box,
- ),
- array(
- 'title' => $title,
- ));
- }
-
- private function getCredentialType($type_const) {
- $type = PassphraseCredentialType::getTypeByConstant($type_const);
-
- if (!$type) {
- throw new Exception(
- pht('Credential has invalid type "%s"!', $type_const));
- }
-
- return $type;
+ return id(new PassphraseCredentialEditEngine())
+ ->setController($this)
+ ->addContextParameter('type')
+ ->buildResponse();
}
}
diff --git a/src/applications/passphrase/credentialtype/PassphraseCredentialType.php b/src/applications/passphrase/credentialtype/PassphraseCredentialType.php
--- a/src/applications/passphrase/credentialtype/PassphraseCredentialType.php
+++ b/src/applications/passphrase/credentialtype/PassphraseCredentialType.php
@@ -11,8 +11,8 @@
abstract public function getCredentialTypeDescription();
abstract public function getSecretLabel();
- public function newSecretControl() {
- return new AphrontFormTextAreaControl();
+ public function newSecretField() {
+ return new PhabricatorTextEditField();
}
public static function getAllTypes() {
diff --git a/src/applications/passphrase/credentialtype/PassphraseNoteCredentialType.php b/src/applications/passphrase/credentialtype/PassphraseNoteCredentialType.php
--- a/src/applications/passphrase/credentialtype/PassphraseNoteCredentialType.php
+++ b/src/applications/passphrase/credentialtype/PassphraseNoteCredentialType.php
@@ -26,8 +26,8 @@
return pht('Note');
}
- public function newSecretControl() {
- return id(new AphrontFormTextAreaControl());
+ public function newSecretField() {
+ return id(new PhabricatorTextEditField());
}
public function shouldRequireUsername() {
diff --git a/src/applications/passphrase/credentialtype/PassphrasePasswordCredentialType.php b/src/applications/passphrase/credentialtype/PassphrasePasswordCredentialType.php
--- a/src/applications/passphrase/credentialtype/PassphrasePasswordCredentialType.php
+++ b/src/applications/passphrase/credentialtype/PassphrasePasswordCredentialType.php
@@ -26,9 +26,8 @@
return pht('Password');
}
- public function newSecretControl() {
- return id(new AphrontFormPasswordControl())
- ->setDisableAutocomplete(true);
+ public function newSecretField() {
+ return new PhabricatorPasswordEditField();
}
}
diff --git a/src/applications/passphrase/credentialtype/PassphraseSSHPrivateKeyFileCredentialType.php b/src/applications/passphrase/credentialtype/PassphraseSSHPrivateKeyFileCredentialType.php
--- a/src/applications/passphrase/credentialtype/PassphraseSSHPrivateKeyFileCredentialType.php
+++ b/src/applications/passphrase/credentialtype/PassphraseSSHPrivateKeyFileCredentialType.php
@@ -21,8 +21,8 @@
return pht('Path On Disk');
}
- public function newSecretControl() {
- return new AphrontFormTextControl();
+ public function newSecretField() {
+ return new PhabricatorTextEditField();
}
public function isCreateable() {
diff --git a/src/applications/passphrase/editor/PassphraseCredentialEditEngine.php b/src/applications/passphrase/editor/PassphraseCredentialEditEngine.php
new file mode 100644
--- /dev/null
+++ b/src/applications/passphrase/editor/PassphraseCredentialEditEngine.php
@@ -0,0 +1,123 @@
+<?php
+
+final class PassphraseCredentialEditEngine
+ extends PhabricatorEditEngine {
+
+ const ENGINECONST = 'passphrase.credential';
+
+ public function getEngineName() {
+ return pht('Credentials');
+ }
+
+ public function getEngineApplicationClass() {
+ return 'PhabricatorPassphraseApplication';
+ }
+
+ public function getSummaryHeader() {
+ return pht('Configure Passphrase Forms');
+ }
+
+ public function getSummaryText() {
+ return pht('Configure creation and editing forms in Passphrase.');
+ }
+
+ protected function newEditableObject() {
+ return PassphraseCredential::initializeNewCredential($this->getViewer());
+ }
+
+ protected function newObjectQuery() {
+ return new PassphraseCredentialQuery();
+ }
+
+ protected function getObjectCreateTitleText($object) {
+ return pht('Create New Credential');
+ }
+
+ protected function getObjectEditTitleText($object) {
+ return pht('Edit %s', $object->getName());
+ }
+
+ protected function getObjectEditShortText($object) {
+ return $object->getName();
+ }
+
+ protected function getObjectCreateShortText() {
+ return pht('Create Credential');
+ }
+
+ protected function getCommentViewHeaderText($object) {
+ return pht('Add Comment');
+ }
+
+ protected function getCommentViewButtonText($object) {
+ return pht('Submit');
+ }
+
+ protected function getObjectViewURI($object) {
+ return $object->getViewURI();
+ }
+
+ protected function buildCustomEditFields($object) {
+ $controller = $this->getController();
+ $request = $controller->getRequest();
+
+ $type = $this->getCredentialType($request->getStr('type'));
+
+ $fields = array(
+ id(new PhabricatorSelectEditField())
+ ->setKey('type')
+ ->setLabel(pht('Type'))
+ ->setOptions(PassphraseCredentialType::getAllCreateableTypes())
+ ->setIsLockable(false),
+ id(new PhabricatorTextEditField())
+ ->setKey('name')
+ ->setLabel(pht('Name'))
+ ->setDescription(pht('Credential name.'))
+ ->setTransactionType(PassphraseCredentialTransaction::TYPE_NAME)
+ ->setValue($object->getName()),
+ id(new PhabricatorRemarkupEditField())
+ ->setKey('description')
+ ->setLabel(pht('Description'))
+ ->setDescription(pht('Credential long description.'))
+ ->setTransactionType(PassphraseCredentialTransaction::TYPE_DESCRIPTION)
+ ->setValue($object->getDescription()),
+ );
+
+ if ($type->shouldRequireUsername()) {
+ $fields[] = id(new PhabricatorTextEditField())
+ ->setKey('username')
+ ->setLabel(pht('Login/Username'))
+ ->setDescription(pht('Credential username.'))
+ ->setTransactionType(PassphraseCredentialTransaction::TYPE_USERNAME)
+ ->setValue($object->getUsername());
+ }
+
+ $fields[] = $type->newSecretField()
+ ->setKey('secret')
+ ->setLabel($type->getSecretLabel())
+ ->setDescription(pht('TODO.'))
+ ->setTransactionType(PassphraseCredentialTransaction::TYPE_SECRET_ID)
+ ->setValue(
+ $object->getSecretID() ? str_repeat("\xE2\x80\xA2", 32) : null);
+
+ $fields[] = id(new PhabricatorBooleanEditField())
+ ->setKey('lock')
+ ->setLabel(pht('Lock Permanently'))
+ ->setDescription(pht('TODO.'))
+ ->setTransactionType(PassphraseCredentialTransaction::TYPE_LOCK);
+
+ return $fields;
+ }
+
+ private function getCredentialType($type_const) {
+ $type = PassphraseCredentialType::getTypeByConstant($type_const);
+
+ if (!$type) {
+ throw new Exception(
+ pht('Credential has invalid type "%s"!', $type_const));
+ }
+
+ return $type;
+ }
+
+}
diff --git a/src/applications/passphrase/storage/PassphraseCredential.php b/src/applications/passphrase/storage/PassphraseCredential.php
--- a/src/applications/passphrase/storage/PassphraseCredential.php
+++ b/src/applications/passphrase/storage/PassphraseCredential.php
@@ -98,6 +98,10 @@
return PassphraseCredentialType::getTypeByConstant($type);
}
+ public function getViewURI() {
+ return '/'.$this->getMonogram();
+ }
+
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
diff --git a/src/applications/transactions/editengine/PhabricatorEditEngine.php b/src/applications/transactions/editengine/PhabricatorEditEngine.php
--- a/src/applications/transactions/editengine/PhabricatorEditEngine.php
+++ b/src/applications/transactions/editengine/PhabricatorEditEngine.php
@@ -1,6 +1,5 @@
<?php
-
/**
* @task fields Managing Fields
* @task text Display Text
diff --git a/src/applications/transactions/editfield/PhabricatorBooleanEditField.php b/src/applications/transactions/editfield/PhabricatorBooleanEditField.php
new file mode 100644
--- /dev/null
+++ b/src/applications/transactions/editfield/PhabricatorBooleanEditField.php
@@ -0,0 +1,14 @@
+<?php
+
+final class PhabricatorBooleanEditField
+ extends PhabricatorEditField {
+
+ protected function newControl() {
+ return new AphrontFormCheckboxControl();
+ }
+
+ protected function newConduitParameterType() {
+ return new ConduitBoolParameterType();
+ }
+
+}
diff --git a/src/applications/transactions/editfield/PhabricatorPasswordEditField.php b/src/applications/transactions/editfield/PhabricatorPasswordEditField.php
new file mode 100644
--- /dev/null
+++ b/src/applications/transactions/editfield/PhabricatorPasswordEditField.php
@@ -0,0 +1,15 @@
+<?php
+
+final class PhabricatorPasswordEditField
+ extends PhabricatorEditField {
+
+ protected function newControl() {
+ return id(new AphrontFormPasswordControl())
+ ->setDisableAutocomplete(true);
+ }
+
+ protected function newConduitParameterType() {
+ return new ConduitStringParameterType();
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Wed, Jun 5, 8:33 AM (2 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6275031
Default Alt Text
D14936.diff (29 KB)

Event Timeline