@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 AuthenticationProviderConfig to be enabled and disabled

Summary: Ref T1536. Nothing too exciting here, one TODO about tailoring error messages.

Test Plan:
{F46403}

{F46404}

{F46405}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1536

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

+136 -1
+2
src/__phutil_library_map__.php
··· 818 818 'PhabricatorAuthConfirmLinkController' => 'applications/auth/controller/PhabricatorAuthConfirmLinkController.php', 819 819 'PhabricatorAuthController' => 'applications/auth/controller/PhabricatorAuthController.php', 820 820 'PhabricatorAuthDAO' => 'applications/auth/storage/PhabricatorAuthDAO.php', 821 + 'PhabricatorAuthDisableController' => 'applications/auth/controller/config/PhabricatorAuthDisableController.php', 821 822 'PhabricatorAuthEditController' => 'applications/auth/controller/config/PhabricatorAuthEditController.php', 822 823 'PhabricatorAuthLinkController' => 'applications/auth/controller/PhabricatorAuthLinkController.php', 823 824 'PhabricatorAuthListController' => 'applications/auth/controller/config/PhabricatorAuthListController.php', ··· 2694 2695 'PhabricatorAuthConfirmLinkController' => 'PhabricatorAuthController', 2695 2696 'PhabricatorAuthController' => 'PhabricatorController', 2696 2697 'PhabricatorAuthDAO' => 'PhabricatorLiskDAO', 2698 + 'PhabricatorAuthDisableController' => 'PhabricatorAuthProviderConfigController', 2697 2699 'PhabricatorAuthEditController' => 'PhabricatorAuthProviderConfigController', 2698 2700 'PhabricatorAuthLinkController' => 'PhabricatorAuthController', 2699 2701 'PhabricatorAuthListController' =>
+2
src/applications/auth/application/PhabricatorApplicationAuth.php
··· 43 43 'new/' => 'PhabricatorAuthNewController', 44 44 'new/(?P<className>[^/]+)/' => 'PhabricatorAuthEditController', 45 45 'edit/(?P<id>\d+)/' => 'PhabricatorAuthEditController', 46 + '(?P<action>enable|disable)/(?P<id>\d+)/' => 47 + 'PhabricatorAuthDisableController', 46 48 ), 47 49 48 50 */
+95
src/applications/auth/controller/config/PhabricatorAuthDisableController.php
··· 1 + <?php 2 + 3 + final class PhabricatorAuthDisableController 4 + extends PhabricatorAuthProviderConfigController { 5 + 6 + private $configID; 7 + private $action; 8 + 9 + public function willProcessRequest(array $data) { 10 + $this->configID = idx($data, 'id'); 11 + $this->action = idx($data, 'action'); 12 + } 13 + 14 + public function processRequest() { 15 + $request = $this->getRequest(); 16 + $viewer = $request->getUser(); 17 + 18 + $config = id(new PhabricatorAuthProviderConfigQuery()) 19 + ->setViewer($viewer) 20 + ->requireCapabilities( 21 + array( 22 + PhabricatorPolicyCapability::CAN_VIEW, 23 + PhabricatorPolicyCapability::CAN_EDIT, 24 + )) 25 + ->withIDs(array($this->configID)) 26 + ->executeOne(); 27 + if (!$config) { 28 + return new Aphront404Response(); 29 + } 30 + 31 + $is_enable = ($this->action === 'enable'); 32 + 33 + if ($request->isDialogFormPost()) { 34 + $xactions = array(); 35 + 36 + $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) 37 + ->setTransactionType( 38 + PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE) 39 + ->setNewValue((int)$is_enable); 40 + 41 + $editor = id(new PhabricatorAuthProviderConfigEditor()) 42 + ->setActor($viewer) 43 + ->setContentSourceFromRequest($request) 44 + ->setContinueOnNoEffect(true) 45 + ->applyTransactions($config, $xactions); 46 + 47 + return id(new AphrontRedirectResponse())->setURI( 48 + $this->getApplicationURI()); 49 + } 50 + 51 + if ($is_enable) { 52 + $title = pht('Enable Provider?'); 53 + if ($config->getShouldAllowRegistration()) { 54 + $body = pht( 55 + 'Do you want to enable this provider? Users will be able to use '. 56 + 'their existing external accounts to register new Phabricator '. 57 + 'accounts and log in using linked accounts.'); 58 + } else { 59 + $body = pht( 60 + 'Do you want to enable this provider? Users will be able to log '. 61 + 'in to Phabricator using linked accounts.'); 62 + } 63 + $button = pht('Enable Provider'); 64 + } else { 65 + // TODO: We could tailor this a bit more. In particular, we could 66 + // check if this is the last provider and either prevent if from 67 + // being disabled or force the user through like 35 prompts. We could 68 + // also check if it's the last provider linked to the acting user's 69 + // account and pop a warning like "YOU WILL NO LONGER BE ABLE TO LOGIN 70 + // YOU GOOF, YOU PROBABLY DO NOT MEAN TO DO THIS". None of this is 71 + // critical and we can wait to see how users manage to shoot themselves 72 + // in the feet. Shortly, `bin/auth` will be able to recover from these 73 + // types of mistakes. 74 + 75 + $title = pht('Disable Provider?'); 76 + $body = pht( 77 + 'Do you want to disable this provider? Users will not be able to '. 78 + 'register or log in using linked accounts. If there are any users '. 79 + 'without other linked authentication mechanisms, they will no longer '. 80 + 'be able to log in. If you disable all providers, no one will be '. 81 + 'able to log in.'); 82 + $button = pht('Disable Provider'); 83 + } 84 + 85 + $dialog = id(new AphrontDialogView()) 86 + ->setUser($viewer) 87 + ->setTitle($title) 88 + ->appendChild($body) 89 + ->addCancelButton($this->getApplicationURI()) 90 + ->addSubmitButton($button); 91 + 92 + return id(new AphrontDialogResponse())->setDialog($dialog); 93 + } 94 + 95 + }
+16
src/applications/auth/controller/config/PhabricatorAuthEditController.php
··· 158 158 'existing Phabricator accounts. If you disable this, Phabricator '. 159 159 'accounts will be permanently bound to provider accounts.')); 160 160 161 + $status_tag = id(new PhabricatorTagView()) 162 + ->setType(PhabricatorTagView::TYPE_STATE); 163 + if ($config->getIsEnabled()) { 164 + $status_tag 165 + ->setName(pht('Enabled')) 166 + ->setBackgroundColor('green'); 167 + } else { 168 + $status_tag 169 + ->setName(pht('Disabled')) 170 + ->setBackgroundColor('red'); 171 + } 172 + 161 173 $form = id(new AphrontFormView()) 162 174 ->setUser($viewer) 163 175 ->setFlexible(true) ··· 165 177 id(new AphrontFormStaticControl()) 166 178 ->setLabel(pht('Provider')) 167 179 ->setValue($provider->getProviderName())) 180 + ->appendChild( 181 + id(new AphrontFormStaticControl()) 182 + ->setLabel(pht('Status')) 183 + ->setValue($status_tag)) 168 184 ->appendChild( 169 185 id(new AphrontFormCheckboxControl()) 170 186 ->setLabel(pht('Allow'))
+21 -1
src/applications/auth/controller/config/PhabricatorAuthListController.php
··· 28 28 foreach ($configs as $config) { 29 29 $item = new PhabricatorObjectItemView(); 30 30 31 - $edit_uri = $this->getApplicationURI('config/edit/'.$config->getID().'/'); 31 + $id = $config->getID(); 32 + 33 + $edit_uri = $this->getApplicationURI('config/edit/'.$id.'/'); 34 + $enable_uri = $this->getApplicationURI('config/enable/'.$id.'/'); 35 + $disable_uri = $this->getApplicationURI('config/disable/'.$id.'/'); 32 36 33 37 // TODO: Needs to be built out. 34 38 $item 35 39 ->setHeader($config->getProviderType()) 36 40 ->setHref($edit_uri); 41 + 42 + if ($config->getIsEnabled()) { 43 + $item->addAction( 44 + id(new PHUIListItemView()) 45 + ->setIcon('delete') 46 + ->setHref($disable_uri) 47 + ->addSigil('workflow')); 48 + } else { 49 + $item->setBarColor('grey'); 50 + $item->addIcon('delete-grey', pht('Disabled')); 51 + $item->addAction( 52 + id(new PHUIListItemView()) 53 + ->setIcon('new') 54 + ->setHref($enable_uri) 55 + ->addSigil('workflow')); 56 + } 37 57 38 58 $list->addItem($item); 39 59 }