Differential D20117 Diff 48130 src/applications/settings/panel/PhabricatorExternalAccountsSettingsPanel.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/panel/PhabricatorExternalAccountsSettingsPanel.php
Show All 38 Lines | public function processRequest(AphrontRequest $request) { | ||||
$linked = id(new PHUIObjectItemListView()) | $linked = id(new PHUIObjectItemListView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setNoDataString(pht('You have no linked accounts.')); | ->setNoDataString(pht('You have no linked accounts.')); | ||||
foreach ($accounts as $account) { | foreach ($accounts as $account) { | ||||
$item = new PHUIObjectItemView(); | $item = new PHUIObjectItemView(); | ||||
$provider = idx($providers, $account->getProviderKey()); | $config = $account->getProviderConfig(); | ||||
if ($provider) { | $provider = $config->getProvider(); | ||||
$item->setHeader($provider->getProviderName()); | $item->setHeader($provider->getProviderName()); | ||||
$can_unlink = $provider->shouldAllowAccountUnlink(); | $can_unlink = $provider->shouldAllowAccountUnlink(); | ||||
if (!$can_unlink) { | if (!$can_unlink) { | ||||
$item->addAttribute(pht('Permanently Linked')); | $item->addAttribute(pht('Permanently Linked')); | ||||
} | } | ||||
} else { | |||||
$item->setHeader( | |||||
pht('Unknown Account ("%s")', $account->getProviderKey())); | |||||
$can_unlink = true; | |||||
} | |||||
$can_login = $account->isUsableForLogin(); | $can_login = $account->isUsableForLogin(); | ||||
if (!$can_login) { | if (!$can_login) { | ||||
$item->addAttribute( | $item->addAttribute( | ||||
pht( | pht( | ||||
'Disabled (an administrator has disabled login for this '. | 'Disabled (an administrator has disabled login for this '. | ||||
'account provider).')); | 'account provider).')); | ||||
} | } | ||||
$can_refresh = $provider && $provider->shouldAllowAccountRefresh(); | $can_refresh = $provider->shouldAllowAccountRefresh(); | ||||
if ($can_refresh) { | if ($can_refresh) { | ||||
$item->addAction( | $item->addAction( | ||||
id(new PHUIListItemView()) | id(new PHUIListItemView()) | ||||
->setIcon('fa-refresh') | ->setIcon('fa-refresh') | ||||
->setHref('/auth/refresh/'.$account->getProviderKey().'/')); | ->setHref('/auth/refresh/'.$config->getID().'/')); | ||||
} | } | ||||
$item->addAction( | $item->addAction( | ||||
id(new PHUIListItemView()) | id(new PHUIListItemView()) | ||||
->setIcon('fa-times') | ->setIcon('fa-times') | ||||
->setWorkflow(true) | ->setWorkflow(true) | ||||
->setDisabled(!$can_unlink) | ->setDisabled(!$can_unlink) | ||||
->setHref('/auth/unlink/'.$account->getID().'/')); | ->setHref('/auth/unlink/'.$account->getID().'/')); | ||||
if ($provider) { | if ($provider) { | ||||
$provider->willRenderLinkedAccount($viewer, $item, $account); | $provider->willRenderLinkedAccount($viewer, $item, $account); | ||||
} | } | ||||
$linked->addItem($item); | $linked->addItem($item); | ||||
} | } | ||||
$linkable_head = pht('Add External Account'); | $linkable_head = pht('Add External Account'); | ||||
$linkable = id(new PHUIObjectItemListView()) | $linkable = id(new PHUIObjectItemListView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setNoDataString( | ->setNoDataString( | ||||
pht('Your account is linked with all available providers.')); | pht('Your account is linked with all available providers.')); | ||||
$accounts = mpull($accounts, null, 'getProviderKey'); | |||||
$configs = id(new PhabricatorAuthProviderConfigQuery()) | $configs = id(new PhabricatorAuthProviderConfigQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withIsEnabled(true) | ->withIsEnabled(true) | ||||
->execute(); | ->execute(); | ||||
$configs = msort($configs, 'getSortVector'); | $configs = msort($configs, 'getSortVector'); | ||||
$account_map = mgroup($accounts, 'getProviderConfigPHID'); | |||||
foreach ($configs as $config) { | foreach ($configs as $config) { | ||||
$provider = $config->getProvider(); | $provider = $config->getProvider(); | ||||
if (!$provider->shouldAllowAccountLink()) { | if (!$provider->shouldAllowAccountLink()) { | ||||
continue; | continue; | ||||
} | } | ||||
// Don't show the user providers they already have linked. | // Don't show the user providers they already have linked. | ||||
$provider_key = $config->getProvider()->getProviderKey(); | if (isset($account_map[$config->getPHID()])) { | ||||
if (isset($accounts[$provider_key])) { | |||||
continue; | continue; | ||||
} | } | ||||
$link_uri = '/auth/link/'.$provider->getProviderKey().'/'; | $link_uri = '/auth/link/'.$config->getID().'/'; | ||||
$link_button = id(new PHUIButtonView()) | $link_button = id(new PHUIButtonView()) | ||||
->setTag('a') | ->setTag('a') | ||||
->setIcon('fa-link') | ->setIcon('fa-link') | ||||
->setHref($link_uri) | ->setHref($link_uri) | ||||
->setColor(PHUIButtonView::GREY) | ->setColor(PHUIButtonView::GREY) | ||||
->setText(pht('Link External Account')); | ->setText(pht('Link External Account')); | ||||
Show All 19 Lines |