@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.

Allow MFA enrollment guidance to be customized

Summary: Depends on D20039. Ref T13242. If installs want users to install a specific application, reference particular help, etc., let them customize the MFA enrollment message so they can make it say "if you have issues, see this walkthrough on the corporate wiki" or whatever.

Test Plan:
{F6164340}

{F6164341}

{F6164342}

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13242

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

+160 -2
+4
src/__phutil_library_map__.php
··· 2235 2235 'PhabricatorAuthFactorProviderEditController' => 'applications/auth/controller/mfa/PhabricatorAuthFactorProviderEditController.php', 2236 2236 'PhabricatorAuthFactorProviderEditEngine' => 'applications/auth/editor/PhabricatorAuthFactorProviderEditEngine.php', 2237 2237 'PhabricatorAuthFactorProviderEditor' => 'applications/auth/editor/PhabricatorAuthFactorProviderEditor.php', 2238 + 'PhabricatorAuthFactorProviderEnrollMessageTransaction' => 'applications/auth/xaction/PhabricatorAuthFactorProviderEnrollMessageTransaction.php', 2238 2239 'PhabricatorAuthFactorProviderListController' => 'applications/auth/controller/mfa/PhabricatorAuthFactorProviderListController.php', 2239 2240 'PhabricatorAuthFactorProviderMFAEngine' => 'applications/auth/engine/PhabricatorAuthFactorProviderMFAEngine.php', 2241 + 'PhabricatorAuthFactorProviderMessageController' => 'applications/auth/controller/mfa/PhabricatorAuthFactorProviderMessageController.php', 2240 2242 'PhabricatorAuthFactorProviderNameTransaction' => 'applications/auth/xaction/PhabricatorAuthFactorProviderNameTransaction.php', 2241 2243 'PhabricatorAuthFactorProviderQuery' => 'applications/auth/query/PhabricatorAuthFactorProviderQuery.php', 2242 2244 'PhabricatorAuthFactorProviderStatus' => 'applications/auth/constants/PhabricatorAuthFactorProviderStatus.php', ··· 7975 7977 'PhabricatorAuthFactorProviderEditController' => 'PhabricatorAuthFactorProviderController', 7976 7978 'PhabricatorAuthFactorProviderEditEngine' => 'PhabricatorEditEngine', 7977 7979 'PhabricatorAuthFactorProviderEditor' => 'PhabricatorApplicationTransactionEditor', 7980 + 'PhabricatorAuthFactorProviderEnrollMessageTransaction' => 'PhabricatorAuthFactorProviderTransactionType', 7978 7981 'PhabricatorAuthFactorProviderListController' => 'PhabricatorAuthProviderController', 7979 7982 'PhabricatorAuthFactorProviderMFAEngine' => 'PhabricatorEditEngineMFAEngine', 7983 + 'PhabricatorAuthFactorProviderMessageController' => 'PhabricatorAuthFactorProviderController', 7980 7984 'PhabricatorAuthFactorProviderNameTransaction' => 'PhabricatorAuthFactorProviderTransactionType', 7981 7985 'PhabricatorAuthFactorProviderQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 7982 7986 'PhabricatorAuthFactorProviderStatus' => 'Phobject',
+2
src/applications/auth/application/PhabricatorAuthApplication.php
··· 95 95 'PhabricatorAuthFactorProviderEditController', 96 96 '(?P<id>[1-9]\d*)/' => 97 97 'PhabricatorAuthFactorProviderViewController', 98 + 'message/(?P<id>[1-9]\d*)/' => 99 + 'PhabricatorAuthFactorProviderMessageController', 98 100 ), 99 101 100 102 'message/' => array(
+84
src/applications/auth/controller/mfa/PhabricatorAuthFactorProviderMessageController.php
··· 1 + <?php 2 + 3 + final class PhabricatorAuthFactorProviderMessageController 4 + extends PhabricatorAuthFactorProviderController { 5 + 6 + public function handleRequest(AphrontRequest $request) { 7 + $this->requireApplicationCapability( 8 + AuthManageProvidersCapability::CAPABILITY); 9 + 10 + $viewer = $request->getViewer(); 11 + $id = $request->getURIData('id'); 12 + 13 + $provider = id(new PhabricatorAuthFactorProviderQuery()) 14 + ->setViewer($viewer) 15 + ->withIDs(array($id)) 16 + ->requireCapabilities( 17 + array( 18 + PhabricatorPolicyCapability::CAN_VIEW, 19 + PhabricatorPolicyCapability::CAN_EDIT, 20 + )) 21 + ->executeOne(); 22 + if (!$provider) { 23 + return new Aphront404Response(); 24 + } 25 + 26 + $cancel_uri = $provider->getURI(); 27 + $enroll_key = 28 + PhabricatorAuthFactorProviderEnrollMessageTransaction::TRANSACTIONTYPE; 29 + 30 + $message = $provider->getEnrollMessage(); 31 + 32 + if ($request->isFormOrHisecPost()) { 33 + $message = $request->getStr('message'); 34 + 35 + $xactions = array(); 36 + 37 + $xactions[] = id(new PhabricatorAuthFactorProviderTransaction()) 38 + ->setTransactionType($enroll_key) 39 + ->setNewValue($message); 40 + 41 + $editor = id(new PhabricatorAuthFactorProviderEditor()) 42 + ->setActor($viewer) 43 + ->setContentSourceFromRequest($request) 44 + ->setContinueOnNoEffect(true) 45 + ->setContinueOnMissingFields(true) 46 + ->setCancelURI($cancel_uri); 47 + 48 + $editor->applyTransactions($provider, $xactions); 49 + 50 + return id(new AphrontRedirectResponse())->setURI($cancel_uri); 51 + } 52 + 53 + $default_message = $provider->getEnrollDescription($viewer); 54 + $default_message = new PHUIRemarkupView($viewer, $default_message); 55 + 56 + $form = id(new AphrontFormView()) 57 + ->setViewer($viewer) 58 + ->appendRemarkupInstructions( 59 + pht( 60 + 'When users add a factor for this provider, they are given this '. 61 + 'enrollment guidance by default:')) 62 + ->appendControl( 63 + id(new AphrontFormMarkupControl()) 64 + ->setLabel(pht('Default Message')) 65 + ->setValue($default_message)) 66 + ->appendRemarkupInstructions( 67 + pht( 68 + 'You may optionally customize the enrollment message users are '. 69 + 'presented with by providing a replacement message below:')) 70 + ->appendControl( 71 + id(new PhabricatorRemarkupControl()) 72 + ->setLabel(pht('Custom Message')) 73 + ->setName('message') 74 + ->setValue($message)); 75 + 76 + return $this->newDialog() 77 + ->setTitle(pht('Change Enroll Message')) 78 + ->setWidth(AphrontDialogView::WIDTH_FORM) 79 + ->appendForm($form) 80 + ->addCancelButton($cancel_uri) 81 + ->addSubmitButton(pht('Save')); 82 + } 83 + 84 + }
+18
src/applications/auth/controller/mfa/PhabricatorAuthFactorProviderViewController.php
··· 81 81 pht('Factor Type'), 82 82 $provider->getFactor()->getFactorName()); 83 83 84 + 85 + $custom_enroll = $provider->getEnrollMessage(); 86 + if (strlen($custom_enroll)) { 87 + $view->addSectionHeader( 88 + pht('Custom Enroll Message'), 89 + PHUIPropertyListView::ICON_SUMMARY); 90 + $view->addTextContent( 91 + new PHUIRemarkupView($viewer, $custom_enroll)); 92 + } 93 + 84 94 return $view; 85 95 } 86 96 ··· 102 112 ->setHref($this->getApplicationURI("mfa/edit/{$id}/")) 103 113 ->setDisabled(!$can_edit) 104 114 ->setWorkflow(!$can_edit)); 115 + 116 + $curtain->addAction( 117 + id(new PhabricatorActionView()) 118 + ->setName(pht('Customize Enroll Message')) 119 + ->setIcon('fa-commenting-o') 120 + ->setHref($this->getApplicationURI("mfa/message/{$id}/")) 121 + ->setDisabled(!$can_edit) 122 + ->setWorkflow(true)); 105 123 106 124 return $curtain; 107 125 }
+8
src/applications/auth/storage/PhabricatorAuthFactorProvider.php
··· 57 57 return $this; 58 58 } 59 59 60 + public function getEnrollMessage() { 61 + return $this->getAuthFactorProviderProperty('enroll-message'); 62 + } 63 + 64 + public function setEnrollMessage($message) { 65 + return $this->setAuthFactorProviderProperty('enroll-message', $message); 66 + } 67 + 60 68 public function attachFactor(PhabricatorAuthFactor $factor) { 61 69 $this->factor = $factor; 62 70 return $this;
+39
src/applications/auth/xaction/PhabricatorAuthFactorProviderEnrollMessageTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorAuthFactorProviderEnrollMessageTransaction 4 + extends PhabricatorAuthFactorProviderTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'enroll-message'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getEnrollMessage(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setEnrollMessage($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s updated the enroll message.', 19 + $this->renderAuthor()); 20 + } 21 + 22 + public function hasChangeDetailView() { 23 + return true; 24 + } 25 + 26 + public function getMailDiffSectionHeader() { 27 + return pht('CHANGES TO ENROLL MESSAGE'); 28 + } 29 + 30 + public function newChangeDetailView() { 31 + $viewer = $this->getViewer(); 32 + 33 + return id(new PhabricatorApplicationTransactionTextDiffDetailView()) 34 + ->setViewer($viewer) 35 + ->setOldText($this->getOldValue()) 36 + ->setNewText($this->getNewValue()); 37 + } 38 + 39 + }
+5 -2
src/applications/settings/panel/PhabricatorMultiFactorSettingsPanel.php
··· 256 256 // sometimes requires us to push a challenge to them as a side effect (for 257 257 // example, with SMS). 258 258 if (!$request->isFormPost() || !$request->getBool('mfa.start')) { 259 - $description = $selected_provider->getEnrollDescription($viewer); 259 + $enroll = $selected_provider->getEnrollMessage(); 260 + if (!strlen($enroll)) { 261 + $enroll = $selected_provider->getEnrollDescription($viewer); 262 + } 260 263 261 264 return $this->newDialog() 262 265 ->addHiddenInput('providerPHID', $selected_provider->getPHID()) 263 266 ->addHiddenInput('mfa.start', 1) 264 267 ->setTitle(pht('Add Authentication Factor')) 265 - ->appendChild(new PHUIRemarkupView($viewer, $description)) 268 + ->appendChild(new PHUIRemarkupView($viewer, $enroll)) 266 269 ->addCancelButton($cancel_uri) 267 270 ->addSubmitButton($selected_provider->getEnrollButtonText($viewer)); 268 271 }