[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorSettingsPanelExternalAccounts 4 extends PhabricatorSettingsPanel { 5 6 public function getPanelKey() { 7 return 'external'; 8 } 9 10 public function getPanelName() { 11 return pht('External Accounts'); 12 } 13 14 public function getPanelGroup() { 15 return pht('Authentication'); 16 } 17 18 public function isEnabled() { 19 return true; 20 } 21 22 public function processRequest(AphrontRequest $request) { 23 $viewer = $request->getUser(); 24 25 $providers = PhabricatorAuthProvider::getAllProviders(); 26 27 $accounts = id(new PhabricatorExternalAccountQuery()) 28 ->setViewer($viewer) 29 ->withUserPHIDs(array($viewer->getPHID())) 30 ->needImages(true) 31 ->requireCapabilities( 32 array( 33 PhabricatorPolicyCapability::CAN_VIEW, 34 PhabricatorPolicyCapability::CAN_EDIT, 35 )) 36 ->execute(); 37 38 $linked_head = id(new PHUIHeaderView()) 39 ->setHeader(pht('Linked Accounts and Authentication')); 40 41 $linked = id(new PHUIObjectItemListView()) 42 ->setUser($viewer) 43 ->setFlush(true) 44 ->setNoDataString(pht('You have no linked accounts.')); 45 46 $login_accounts = 0; 47 foreach ($accounts as $account) { 48 if ($account->isUsableForLogin()) { 49 $login_accounts++; 50 } 51 } 52 53 foreach ($accounts as $account) { 54 $item = id(new PHUIObjectItemView()); 55 56 $provider = idx($providers, $account->getProviderKey()); 57 if ($provider) { 58 $item->setHeader($provider->getProviderName()); 59 $can_unlink = $provider->shouldAllowAccountUnlink(); 60 if (!$can_unlink) { 61 $item->addAttribute(pht('Permanently Linked')); 62 } 63 } else { 64 $item->setHeader( 65 pht('Unknown Account ("%s")', $account->getProviderKey())); 66 $can_unlink = true; 67 } 68 69 $can_login = $account->isUsableForLogin(); 70 if (!$can_login) { 71 $item->addAttribute( 72 pht( 73 'Disabled (an administrator has disabled login for this '. 74 'account provider).')); 75 } 76 77 $can_unlink = $can_unlink && (!$can_login || ($login_accounts > 1)); 78 79 $can_refresh = $provider && $provider->shouldAllowAccountRefresh(); 80 if ($can_refresh) { 81 $item->addAction( 82 id(new PHUIListItemView()) 83 ->setIcon('fa-refresh') 84 ->setHref('/auth/refresh/'.$account->getProviderKey().'/')); 85 } 86 87 $item->addAction( 88 id(new PHUIListItemView()) 89 ->setIcon('fa-times') 90 ->setWorkflow(true) 91 ->setDisabled(!$can_unlink) 92 ->setHref('/auth/unlink/'.$account->getProviderKey().'/')); 93 94 if ($provider) { 95 $provider->willRenderLinkedAccount($viewer, $item, $account); 96 } 97 98 $linked->addItem($item); 99 } 100 101 $linkable_head = id(new PHUIHeaderView()) 102 ->setHeader(pht('Add External Account')); 103 104 $linkable = id(new PHUIObjectItemListView()) 105 ->setUser($viewer) 106 ->setFlush(true) 107 ->setNoDataString( 108 pht('Your account is linked with all available providers.')); 109 110 $accounts = mpull($accounts, null, 'getProviderKey'); 111 112 $providers = PhabricatorAuthProvider::getAllEnabledProviders(); 113 $providers = msort($providers, 'getProviderName'); 114 foreach ($providers as $key => $provider) { 115 if (isset($accounts[$key])) { 116 continue; 117 } 118 119 if (!$provider->shouldAllowAccountLink()) { 120 continue; 121 } 122 123 $link_uri = '/auth/link/'.$provider->getProviderKey().'/'; 124 125 $item = id(new PHUIObjectItemView()); 126 $item->setHeader($provider->getProviderName()); 127 $item->setHref($link_uri); 128 $item->addAction( 129 id(new PHUIListItemView()) 130 ->setIcon('fa-link') 131 ->setHref($link_uri)); 132 133 $linkable->addItem($item); 134 } 135 136 $linked_box = id(new PHUIObjectBoxView()) 137 ->setHeader($linked_head) 138 ->appendChild($linked); 139 140 $linkable_box = id(new PHUIObjectBoxView()) 141 ->setHeader($linkable_head) 142 ->appendChild($linkable); 143 144 return array( 145 $linked_box, 146 $linkable_box, 147 ); 148 } 149 150 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |