1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-03 12:12:43 +01:00

Add "allow null" and username hinting to the Passphrase credential control

Summary:
Ref T4122.

  - For Diffusion, we need "allow null" (permits selection of "No Credential") for anonymous HTTP repositories.
  - For Diffusion, we can make things a little easier to configure by prefilling the username.

Test Plan: Used UIExample form. These featuers are used in a future revision.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4122

Differential Revision: https://secure.phabricator.com/D7624
This commit is contained in:
epriestley 2013-11-22 14:35:35 -08:00
parent 7c3cb5948c
commit 572567b85d
4 changed files with 48 additions and 7 deletions

View file

@ -1982,7 +1982,7 @@ celerity_register_resource_map(array(
), ),
'javelin-behavior-passphrase-credential-control' => 'javelin-behavior-passphrase-credential-control' =>
array( array(
'uri' => '/res/e606ad52/rsrc/js/application/passphrase/phame-credential-control.js', 'uri' => '/res/70823662/rsrc/js/application/passphrase/phame-credential-control.js',
'type' => 'js', 'type' => 'js',
'requires' => 'requires' =>
array( array(
@ -1991,6 +1991,7 @@ celerity_register_resource_map(array(
2 => 'javelin-stratcom', 2 => 'javelin-stratcom',
3 => 'javelin-workflow', 3 => 'javelin-workflow',
4 => 'javelin-util', 4 => 'javelin-util',
5 => 'javelin-uri',
), ),
'disk' => '/rsrc/js/application/passphrase/phame-credential-control.js', 'disk' => '/rsrc/js/application/passphrase/phame-credential-control.js',
), ),

View file

@ -45,6 +45,9 @@ final class PassphraseCredentialEditController extends PassphraseController {
->setProvidesType($type->getProvidesType()); ->setProvidesType($type->getProvidesType());
$is_new = true; $is_new = true;
// Prefill username if provided.
$credential->setUsername($request->getStr('username'));
} }
$errors = array(); $errors = array();

View file

@ -4,6 +4,18 @@ final class PassphraseCredentialControl extends AphrontFormControl {
private $options; private $options;
private $credentialType; private $credentialType;
private $defaultUsername;
private $allowNull;
public function setAllowNull($allow_null) {
$this->allowNull = $allow_null;
return $this;
}
public function setDefaultUsername($default_username) {
$this->defaultUsername = $default_username;
return $this;
}
public function setCredentialType($credential_type) { public function setCredentialType($credential_type) {
$this->credentialType = $credential_type; $this->credentialType = $credential_type;
@ -35,9 +47,13 @@ final class PassphraseCredentialControl extends AphrontFormControl {
} }
$disabled = $this->getDisabled(); $disabled = $this->getDisabled();
if (!$options_map) { if ($this->allowNull) {
$options_map[''] = pht('(No Existing Credentials)'); $options_map = array('' => pht('(No Credentials)')) + $options_map;
$disabled = true; } else {
if (!$options_map) {
$options_map[''] = pht('(No Existing Credentials)');
$disabled = true;
}
} }
Javelin::initBehavior('passphrase-credential-control'); Javelin::initBehavior('passphrase-credential-control');
@ -68,6 +84,8 @@ final class PassphraseCredentialControl extends AphrontFormControl {
'sigil' => 'passphrase-credential-control', 'sigil' => 'passphrase-credential-control',
'meta' => array( 'meta' => array(
'type' => $this->getCredentialType(), 'type' => $this->getCredentialType(),
'username' => $this->defaultUsername,
'allowNull' => $this->allowNull,
), ),
), ),
array( array(

View file

@ -5,6 +5,8 @@
* javelin-stratcom * javelin-stratcom
* javelin-workflow * javelin-workflow
* javelin-util * javelin-util
* javelin-uri
* @javelin
*/ */
JX.behavior('passphrase-credential-control', function(config) { JX.behavior('passphrase-credential-control', function(config) {
@ -16,7 +18,11 @@ JX.behavior('passphrase-credential-control', function(config) {
var control = e.getNode('passphrase-credential-control'); var control = e.getNode('passphrase-credential-control');
var data = e.getNodeData('passphrase-credential-control'); var data = e.getNodeData('passphrase-credential-control');
new JX.Workflow('/passphrase/edit/?type=' + data.type) var uri = JX.$U('/passphrase/edit/');
uri.setQueryParam('type', data.type);
uri.setQueryParam('username', data.username);
new JX.Workflow(uri)
.setHandler(JX.bind(null, onadd, control)) .setHandler(JX.bind(null, onadd, control))
.start(); .start();
@ -26,16 +32,29 @@ JX.behavior('passphrase-credential-control', function(config) {
function onadd(control, response) { function onadd(control, response) {
var select = JX.DOM.find(control, 'select', 'passphrase-credential-select'); var select = JX.DOM.find(control, 'select', 'passphrase-credential-select');
var data = JX.Stratcom.getData(control);
// If this allows the user to select "No Credential" (`allowNull`),
// put the new credential in the menu below the "No Credential" option.
// Otherwise, remove the "(No Existing Credentials)" if it exists and
// put the new credential at the top.
var target = 0;
for (var ii = 0; ii < select.options.length; ii++) { for (var ii = 0; ii < select.options.length; ii++) {
if (!select.options[ii].value) { if (!select.options[ii].value) {
select.remove(ii); if (!data.allowNull) {
select.remove(ii);
} else {
target = ii + 1;
}
break; break;
} }
} }
select.add( select.add(
JX.$N('option', {value: response.phid}, response.name), JX.$N('option', {value: response.phid}, response.name),
select.options[0] || null); select.options[target] || null);
select.value = response.phid; select.value = response.phid;
select.disabled = null; select.disabled = null;