Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / settings / panel / PhabricatorExternalAccountsSettingsPanel.php
blobd20782d2b5b2c287b0b58613f1817b65439e5279
1 <?php
3 final class PhabricatorExternalAccountsSettingsPanel
4 extends PhabricatorSettingsPanel {
6 public function getPanelKey() {
7 return 'external';
10 public function getPanelName() {
11 return pht('External Accounts');
14 public function getPanelMenuIcon() {
15 return 'fa-users';
18 public function getPanelGroupKey() {
19 return PhabricatorSettingsAuthenticationPanelGroup::PANELGROUPKEY;
22 public function processRequest(AphrontRequest $request) {
23 $viewer = $request->getUser();
25 $providers = PhabricatorAuthProvider::getAllProviders();
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,
36 ->execute();
38 $linked_head = pht('Linked Accounts and Authentication');
40 $linked = id(new PHUIObjectItemListView())
41 ->setUser($viewer)
42 ->setNoDataString(pht('You have no linked accounts.'));
44 foreach ($accounts as $account) {
45 $item = new PHUIObjectItemView();
47 $config = $account->getProviderConfig();
48 $provider = $config->getProvider();
50 $item->setHeader($provider->getProviderName());
51 $can_unlink = $provider->shouldAllowAccountUnlink();
52 if (!$can_unlink) {
53 $item->addAttribute(pht('Permanently Linked'));
56 $can_login = $account->isUsableForLogin();
57 if (!$can_login) {
58 $item->addAttribute(
59 pht(
60 'Disabled (an administrator has disabled login for this '.
61 'account provider).'));
64 $can_refresh = $provider->shouldAllowAccountRefresh();
65 if ($can_refresh) {
66 $item->addAction(
67 id(new PHUIListItemView())
68 ->setIcon('fa-refresh')
69 ->setHref('/auth/refresh/'.$config->getID().'/'));
72 $item->addAction(
73 id(new PHUIListItemView())
74 ->setIcon('fa-times')
75 ->setWorkflow(true)
76 ->setDisabled(!$can_unlink)
77 ->setHref('/auth/unlink/'.$account->getID().'/'));
79 if ($provider) {
80 $provider->willRenderLinkedAccount($viewer, $item, $account);
83 $linked->addItem($item);
86 $linkable_head = pht('Add External Account');
88 $linkable = id(new PHUIObjectItemListView())
89 ->setUser($viewer)
90 ->setNoDataString(
91 pht('Your account is linked with all available providers.'));
93 $configs = id(new PhabricatorAuthProviderConfigQuery())
94 ->setViewer($viewer)
95 ->withIsEnabled(true)
96 ->execute();
97 $configs = msortv($configs, 'getSortVector');
99 $account_map = mgroup($accounts, 'getProviderConfigPHID');
102 foreach ($configs as $config) {
103 $provider = $config->getProvider();
105 if (!$provider->shouldAllowAccountLink()) {
106 continue;
109 // Don't show the user providers they already have linked.
110 if (isset($account_map[$config->getPHID()])) {
111 continue;
114 $link_uri = '/auth/link/'.$config->getID().'/';
116 $link_button = id(new PHUIButtonView())
117 ->setTag('a')
118 ->setIcon('fa-link')
119 ->setHref($link_uri)
120 ->setColor(PHUIButtonView::GREY)
121 ->setText(pht('Link External Account'));
123 $item = id(new PHUIObjectItemView())
124 ->setHeader($config->getDisplayName())
125 ->setHref($link_uri)
126 ->setImageIcon($config->newIconView())
127 ->setSideColumn($link_button);
129 $linkable->addItem($item);
132 $linked_box = $this->newBox($linked_head, $linked);
133 $linkable_box = $this->newBox($linkable_head, $linkable);
135 return array(
136 $linked_box,
137 $linkable_box,