Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F450784
PhabricatorExternalAccountsSettingsPanel.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
PhabricatorExternalAccountsSettingsPanel.php
View Options
<?php
final
class
PhabricatorExternalAccountsSettingsPanel
extends
PhabricatorSettingsPanel
{
public
function
getPanelKey
()
{
return
'external'
;
}
public
function
getPanelName
()
{
return
pht
(
'External Accounts'
);
}
public
function
getPanelMenuIcon
()
{
return
'fa-users'
;
}
public
function
getPanelGroupKey
()
{
return
PhabricatorSettingsAuthenticationPanelGroup
::
PANELGROUPKEY
;
}
public
function
processRequest
(
AphrontRequest
$request
)
{
$viewer
=
$request
->
getUser
();
$providers
=
PhabricatorAuthProvider
::
getAllProviders
();
$accounts
=
id
(
new
PhabricatorExternalAccountQuery
())
->
setViewer
(
$viewer
)
->
withUserPHIDs
(
array
(
$viewer
->
getPHID
()))
->
needImages
(
true
)
->
requireCapabilities
(
array
(
PhabricatorPolicyCapability
::
CAN_VIEW
,
PhabricatorPolicyCapability
::
CAN_EDIT
,
))
->
execute
();
$linked_head
=
pht
(
'Linked Accounts and Authentication'
);
$linked
=
id
(
new
PHUIObjectItemListView
())
->
setUser
(
$viewer
)
->
setNoDataString
(
pht
(
'You have no linked accounts.'
));
foreach
(
$accounts
as
$account
)
{
$item
=
new
PHUIObjectItemView
();
$provider
=
idx
(
$providers
,
$account
->
getProviderKey
());
if
(
$provider
)
{
$item
->
setHeader
(
$provider
->
getProviderName
());
$can_unlink
=
$provider
->
shouldAllowAccountUnlink
();
if
(!
$can_unlink
)
{
$item
->
addAttribute
(
pht
(
'Permanently Linked'
));
}
}
else
{
$item
->
setHeader
(
pht
(
'Unknown Account ("%s")'
,
$account
->
getProviderKey
()));
$can_unlink
=
true
;
}
$can_login
=
$account
->
isUsableForLogin
();
if
(!
$can_login
)
{
$item
->
addAttribute
(
pht
(
'Disabled (an administrator has disabled login for this '
.
'account provider).'
));
}
$can_refresh
=
$provider
&&
$provider
->
shouldAllowAccountRefresh
();
if
(
$can_refresh
)
{
$item
->
addAction
(
id
(
new
PHUIListItemView
())
->
setIcon
(
'fa-refresh'
)
->
setHref
(
'/auth/refresh/'
.
$account
->
getProviderKey
().
'/'
));
}
$item
->
addAction
(
id
(
new
PHUIListItemView
())
->
setIcon
(
'fa-times'
)
->
setWorkflow
(
true
)
->
setDisabled
(!
$can_unlink
)
->
setHref
(
'/auth/unlink/'
.
$account
->
getProviderKey
().
'/'
));
if
(
$provider
)
{
$provider
->
willRenderLinkedAccount
(
$viewer
,
$item
,
$account
);
}
$linked
->
addItem
(
$item
);
}
$linkable_head
=
pht
(
'Add External Account'
);
$linkable
=
id
(
new
PHUIObjectItemListView
())
->
setUser
(
$viewer
)
->
setNoDataString
(
pht
(
'Your account is linked with all available providers.'
));
$accounts
=
mpull
(
$accounts
,
null
,
'getProviderKey'
);
$configs
=
id
(
new
PhabricatorAuthProviderConfigQuery
())
->
setViewer
(
$viewer
)
->
withIsEnabled
(
true
)
->
execute
();
$configs
=
msort
(
$configs
,
'getSortVector'
);
foreach
(
$configs
as
$config
)
{
$provider
=
$config
->
getProvider
();
if
(!
$provider
->
shouldAllowAccountLink
())
{
continue
;
}
// Don't show the user providers they already have linked.
$provider_key
=
$config
->
getProvider
()->
getProviderKey
();
if
(
isset
(
$accounts
[
$provider_key
]))
{
continue
;
}
$link_uri
=
'/auth/link/'
.
$provider
->
getProviderKey
().
'/'
;
$link_button
=
id
(
new
PHUIButtonView
())
->
setTag
(
'a'
)
->
setIcon
(
'fa-link'
)
->
setHref
(
$link_uri
)
->
setColor
(
PHUIButtonView
::
GREY
)
->
setText
(
pht
(
'Link External Account'
));
$item
=
id
(
new
PHUIObjectItemView
())
->
setHeader
(
$config
->
getDisplayName
())
->
setHref
(
$link_uri
)
->
setImageIcon
(
$config
->
newIconView
())
->
setSideColumn
(
$link_button
);
$linkable
->
addItem
(
$item
);
}
$linked_box
=
$this
->
newBox
(
$linked_head
,
$linked
);
$linkable_box
=
$this
->
newBox
(
$linkable_head
,
$linkable
);
return
array
(
$linked_box
,
$linkable_box
,
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, May 4, 9:02 PM (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
56712
Default Alt Text
PhabricatorExternalAccountsSettingsPanel.php (3 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment