@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add a credential selection control to Passphrase

Summary: Ref T4122. Adds a control for choosing credentials.

Test Plan: See screenshots.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran, lsave

Maniphest Tasks: T4122

Differential Revision: https://secure.phabricator.com/D7617

+185 -9
+14
src/__celerity_resource_map__.php
··· 1980 1980 ), 1981 1981 'disk' => '/rsrc/js/application/owners/owners-path-editor.js', 1982 1982 ), 1983 + 'javelin-behavior-passphrase-credential-control' => 1984 + array( 1985 + 'uri' => '/res/b599c028/rsrc/js/application/passphrase/phame-credential-control.js', 1986 + 'type' => 'js', 1987 + 'requires' => 1988 + array( 1989 + 0 => 'javelin-behavior', 1990 + 1 => 'javelin-dom', 1991 + 2 => 'javelin-stratcom', 1992 + 3 => 'javelin-workflow', 1993 + 4 => 'javelin-util', 1994 + ), 1995 + 'disk' => '/rsrc/js/application/passphrase/phame-credential-control.js', 1996 + ), 1983 1997 'javelin-behavior-persona-login' => 1984 1998 array( 1985 1999 'uri' => '/res/128fdf56/rsrc/js/application/auth/behavior-persona-login.js',
+2
src/__phutil_library_map__.php
··· 946 946 'PackageModifyMail' => 'applications/owners/mail/PackageModifyMail.php', 947 947 'PassphraseController' => 'applications/passphrase/controller/PassphraseController.php', 948 948 'PassphraseCredential' => 'applications/passphrase/storage/PassphraseCredential.php', 949 + 'PassphraseCredentialControl' => 'applications/passphrase/view/PassphraseCredentialControl.php', 949 950 'PassphraseCredentialCreateController' => 'applications/passphrase/controller/PassphraseCredentialCreateController.php', 950 951 'PassphraseCredentialDestroyController' => 'applications/passphrase/controller/PassphraseCredentialDestroyController.php', 951 952 'PassphraseCredentialEditController' => 'applications/passphrase/controller/PassphraseCredentialEditController.php', ··· 3329 3330 0 => 'PassphraseDAO', 3330 3331 1 => 'PhabricatorPolicyInterface', 3331 3332 ), 3333 + 'PassphraseCredentialControl' => 'AphrontFormControl', 3332 3334 'PassphraseCredentialCreateController' => 'PassphraseController', 3333 3335 'PassphraseCredentialDestroyController' => 'PassphraseController', 3334 3336 'PassphraseCredentialEditController' => 'PassphraseController',
+35 -9
src/applications/passphrase/controller/PassphraseCredentialEditController.php
··· 129 129 130 130 $credential->saveTransaction(); 131 131 132 - return id(new AphrontRedirectResponse()) 133 - ->setURI('/K'.$credential->getID()); 132 + if ($request->isAjax()) { 133 + return id(new AphrontAjaxResponse())->setContent( 134 + array( 135 + 'phid' => $credential->getPHID(), 136 + 'name' => 'K'.$credential->getID().' '.$credential->getName(), 137 + )); 138 + } else { 139 + return id(new AphrontRedirectResponse()) 140 + ->setURI('/K'.$credential->getID()); 141 + } 134 142 } catch (PhabricatorApplicationTransactionValidationException $ex) { 135 143 $credential->killTransaction(); 136 144 ··· 151 159 152 160 $secret_control = $type->newSecretControl(); 153 161 154 - $form = id(new AphrontFormView()) 155 - ->setUser($viewer) 162 + if ($request->isAjax()) { 163 + $form = new PHUIFormLayoutView(); 164 + } else { 165 + $form = id(new AphrontFormView()) 166 + ->setUser($viewer); 167 + } 168 + 169 + $form 156 170 ->appendChild( 157 171 id(new AphrontFormTextControl()) 158 172 ->setName('name') ··· 197 211 ->setLabel($type->getSecretLabel()) 198 212 ->setValue($v_secret)); 199 213 200 - $form->appendChild( 201 - id(new AphrontFormSubmitControl()) 202 - ->setValue(pht('Save')) 203 - ->addCancelButton($this->getApplicationURI())); 204 - 205 214 $crumbs = $this->buildApplicationCrumbs(); 206 215 207 216 if ($is_new) { ··· 221 230 id(new PhabricatorCrumbView()) 222 231 ->setName(pht('Edit'))); 223 232 } 233 + 234 + if ($request->isAjax()) { 235 + $dialog = id(new AphrontDialogView()) 236 + ->setUser($viewer) 237 + ->setWidth(AphrontDialogView::WIDTH_FORM) 238 + ->setTitle($title) 239 + ->appendChild($form) 240 + ->addSubmitButton(pht('Create Credential')) 241 + ->addCancelButton($this->getApplicationURI()); 242 + 243 + return id(new AphrontDialogResponse())->setDialog($dialog); 244 + } 245 + 246 + $form->appendChild( 247 + id(new AphrontFormSubmitControl()) 248 + ->setValue(pht('Save')) 249 + ->addCancelButton($this->getApplicationURI())); 224 250 225 251 $box = id(new PHUIObjectBoxView()) 226 252 ->setHeaderText($header)
+79
src/applications/passphrase/view/PassphraseCredentialControl.php
··· 1 + <?php 2 + 3 + final class PassphraseCredentialControl extends AphrontFormControl { 4 + 5 + private $options; 6 + private $credentialType; 7 + 8 + public function setCredentialType($credential_type) { 9 + $this->credentialType = $credential_type; 10 + return $this; 11 + } 12 + 13 + public function getCredentialType() { 14 + return $this->credentialType; 15 + } 16 + 17 + public function setOptions(array $options) { 18 + assert_instances_of($options, 'PassphraseCredential'); 19 + $this->options = $options; 20 + return $this; 21 + } 22 + 23 + protected function getCustomControlClass() { 24 + return 'passphrase-credential-control'; 25 + } 26 + 27 + protected function renderInput() { 28 + 29 + $options_map = array(); 30 + foreach ($this->options as $option) { 31 + $options_map[$option->getPHID()] = pht( 32 + "%s %s", 33 + 'K'.$option->getID(), 34 + $option->getName()); 35 + } 36 + 37 + $disabled = $this->getDisabled(); 38 + if (!$options_map) { 39 + $options_map[''] = pht('(No Existing Credentials)'); 40 + $disabled = true; 41 + } 42 + 43 + Javelin::initBehavior('passphrase-credential-control'); 44 + 45 + $options = AphrontFormSelectControl::renderSelectTag( 46 + $this->getValue(), 47 + $options_map, 48 + array( 49 + 'id' => $this->getControlID(), 50 + 'name' => $this->getName(), 51 + 'disabled' => $disabled ? 'disabled' : null, 52 + 'sigil' => 'passphrase-credential-select', 53 + )); 54 + 55 + $button = javelin_tag( 56 + 'a', 57 + array( 58 + 'href' => '#', 59 + 'class' => 'button grey', 60 + 'sigil' => 'passphrase-credential-add', 61 + 'mustcapture' => true, 62 + ), 63 + pht('Add Credential')); 64 + 65 + return javelin_tag( 66 + 'div', 67 + array( 68 + 'sigil' => 'passphrase-credential-control', 69 + 'meta' => array( 70 + 'type' => $this->getCredentialType(), 71 + ), 72 + ), 73 + array( 74 + $options, 75 + $button, 76 + )); 77 + } 78 + 79 + }
+11
src/applications/uiexample/examples/PhabricatorFormExample.php
··· 38 38 $null_value = $null_time->readValueFromRequest($request); 39 39 } 40 40 41 + $divider_control = new AphrontFormDividerControl(); 42 + 43 + $credentials = array(); 44 + $password_control = id(new PassphraseCredentialControl()) 45 + ->setName('credentialPHID') 46 + ->setLabel(pht('Password')) 47 + ->setCredentialType('password') 48 + ->setOptions($credentials); 49 + 41 50 $form = id(new AphrontFormView()) 42 51 ->setUser($user) 43 52 ->appendChild($start_time) 44 53 ->appendChild($end_time) 45 54 ->appendChild($null_time) 55 + ->appendChild($divider_control) 56 + ->appendChild($password_control) 46 57 ->appendChild( 47 58 id(new AphrontFormSubmitControl()) 48 59 ->setValue('Submit'));
+44
webroot/rsrc/js/application/passphrase/phame-credential-control.js
··· 1 + /** 2 + * @provides javelin-behavior-passphrase-credential-control 3 + * @requires javelin-behavior 4 + * javelin-dom 5 + * javelin-stratcom 6 + * javelin-workflow 7 + * javelin-util 8 + */ 9 + 10 + JX.behavior('passphrase-credential-control', function(config) { 11 + 12 + JX.Stratcom.listen( 13 + 'click', 14 + 'passphrase-credential-add', 15 + function(e) { 16 + var control = e.getNode('passphrase-credential-control'); 17 + var data = e.getNodeData('passphrase-credential-control'); 18 + 19 + new JX.Workflow('/passphrase/edit/?type=' + data.type) 20 + .setHandler(JX.bind(null, onadd, control)) 21 + .start(); 22 + 23 + e.kill(); 24 + }); 25 + 26 + function onadd(control, response) { 27 + var select = JX.DOM.find(control, 'select', 'passphrase-credential-select'); 28 + 29 + for (var ii = 0; ii < select.options.length; ii++) { 30 + if (!select.options[ii].value) { 31 + select.remove(ii); 32 + break; 33 + } 34 + } 35 + 36 + select.add( 37 + JX.$N('option', {value: response.phid}, response.name), 38 + select.options[0] || null); 39 + 40 + select.value = response.phid; 41 + select.disabled = null; 42 + } 43 + 44 + });