2014-01-14 20:05:45 +01:00
|
|
|
<?php
|
|
|
|
|
2015-01-02 05:20:08 +01:00
|
|
|
final class PhabricatorSessionsSettingsPanel extends PhabricatorSettingsPanel {
|
2014-01-14 20:05:45 +01:00
|
|
|
|
|
|
|
public function getPanelKey() {
|
|
|
|
return 'sessions';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPanelName() {
|
|
|
|
return pht('Sessions');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPanelGroup() {
|
2014-04-28 02:32:09 +02:00
|
|
|
return pht('Sessions and Logs');
|
2014-01-14 20:05:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isEnabled() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$accounts = id(new PhabricatorExternalAccountQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withUserPHIDs(array($viewer->getPHID()))
|
Introduce CAN_EDIT for ExternalAccount, and make CAN_VIEW more liberal
Summary:
Fixes T3732. Ref T1205. Ref T3116.
External accounts (like emails used as identities, Facebook accounts, LDAP accounts, etc.) are stored in "ExternalAccount" objects.
Currently, we have a very restrictive `CAN_VIEW` policy for ExternalAccounts, to add an extra layer of protection to make sure users can't use them in unintended ways. For example, it would be bad if a user could link their Phabricator account to a Facebook account without proper authentication. All of the controllers which do sensitive things have checks anyway, but a restrictive CAN_VIEW provided an extra layer of protection. Se T3116 for some discussion.
However, this means that when grey/external users take actions (via email, or via applications like Legalpad) other users can't load the account handles and can't see anything about the actor (they just see "Restricted External Account" or similar).
Balancing these concerns is mostly about not making a huge mess while doing it. This seems like a reasonable approach:
- Add `CAN_EDIT` on these objects.
- Make that very restricted, but open up `CAN_VIEW`.
- Require `CAN_EDIT` any time we're going to do something authentication/identity related.
This is slightly easier to get wrong (forget CAN_EDIT) than other approaches, but pretty simple, and we always have extra checks in place anyway -- this is just a safety net.
I'm not quite sure how we should identify external accounts, so for now we're just rendering "Email User" or similar -- clearly not a bug, but not identifying. We can figure out what to render in the long term elsewhere.
Test Plan:
- Viewed external accounts.
- Linked an external account.
- Refreshed an external account.
- Edited profile picture.
- Viewed sessions panel.
- Published a bunch of stuff to Asana/JIRA.
- Legalpad signature page now shows external accounts.
{F171595}
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T3732, T1205, T3116
Differential Revision: https://secure.phabricator.com/D9767
2014-07-10 19:18:10 +02:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
2014-01-14 20:05:45 +01:00
|
|
|
->execute();
|
|
|
|
|
|
|
|
$identity_phids = mpull($accounts, 'getPHID');
|
|
|
|
$identity_phids[] = $viewer->getPHID();
|
|
|
|
|
|
|
|
$sessions = id(new PhabricatorAuthSessionQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIdentityPHIDs($identity_phids)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$handles = id(new PhabricatorHandleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs($identity_phids)
|
|
|
|
->execute();
|
|
|
|
|
2014-01-23 23:01:35 +01:00
|
|
|
$current_key = PhabricatorHash::digest(
|
|
|
|
$request->getCookie(PhabricatorCookies::COOKIE_SESSION));
|
2014-01-14 20:05:45 +01:00
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
$rowc = array();
|
|
|
|
foreach ($sessions as $session) {
|
2015-09-02 00:52:44 +02:00
|
|
|
$is_current = phutil_hashes_are_identical(
|
|
|
|
$session->getSessionKey(),
|
|
|
|
$current_key);
|
|
|
|
if ($is_current) {
|
2014-01-14 20:05:45 +01:00
|
|
|
$rowc[] = 'highlighted';
|
2014-03-17 23:02:01 +01:00
|
|
|
$button = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'class' => 'small grey button disabled',
|
|
|
|
),
|
|
|
|
pht('Current'));
|
2014-01-14 20:05:45 +01:00
|
|
|
} else {
|
|
|
|
$rowc[] = null;
|
2014-03-17 23:02:01 +01:00
|
|
|
$button = javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '/auth/session/terminate/'.$session->getID().'/',
|
|
|
|
'class' => 'small grey button',
|
|
|
|
'sigil' => 'workflow',
|
|
|
|
),
|
|
|
|
pht('Terminate'));
|
2014-01-14 20:05:45 +01:00
|
|
|
}
|
|
|
|
|
2014-04-28 02:31:11 +02:00
|
|
|
$hisec = ($session->getHighSecurityUntil() - time());
|
|
|
|
|
2014-01-14 20:05:45 +01:00
|
|
|
$rows[] = array(
|
|
|
|
$handles[$session->getUserPHID()]->renderLink(),
|
2014-03-17 23:02:01 +01:00
|
|
|
substr($session->getSessionKey(), 0, 6),
|
2014-01-14 20:05:45 +01:00
|
|
|
$session->getType(),
|
2014-04-28 02:31:11 +02:00
|
|
|
($hisec > 0)
|
2014-07-13 04:03:17 +02:00
|
|
|
? phutil_format_relative_time($hisec)
|
2014-04-28 02:31:11 +02:00
|
|
|
: null,
|
2014-01-14 20:05:45 +01:00
|
|
|
phabricator_datetime($session->getSessionStart(), $viewer),
|
2014-03-17 23:02:01 +01:00
|
|
|
phabricator_date($session->getSessionExpires(), $viewer),
|
|
|
|
$button,
|
2014-01-14 20:05:45 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = new AphrontTableView($rows);
|
|
|
|
$table->setNoDataString(pht("You don't have any active sessions."));
|
|
|
|
$table->setRowClasses($rowc);
|
|
|
|
$table->setHeaders(
|
|
|
|
array(
|
|
|
|
pht('Identity'),
|
|
|
|
pht('Session'),
|
|
|
|
pht('Type'),
|
2014-04-28 02:31:11 +02:00
|
|
|
pht('HiSec'),
|
2014-01-14 20:05:45 +01:00
|
|
|
pht('Created'),
|
2014-01-15 22:56:16 +01:00
|
|
|
pht('Expires'),
|
2014-03-17 23:02:01 +01:00
|
|
|
pht(''),
|
2014-01-14 20:05:45 +01:00
|
|
|
));
|
|
|
|
$table->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'wide',
|
|
|
|
'n',
|
|
|
|
'',
|
|
|
|
'right',
|
2014-01-15 22:56:16 +01:00
|
|
|
'right',
|
2014-04-28 02:31:11 +02:00
|
|
|
'right',
|
2014-03-17 23:02:01 +01:00
|
|
|
'action',
|
2014-01-14 20:05:45 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
|
2014-03-17 23:02:01 +01:00
|
|
|
$terminate_icon = id(new PHUIIconView())
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIconFont('fa-exclamation-triangle');
|
2014-03-17 23:02:01 +01:00
|
|
|
$terminate_button = id(new PHUIButtonView())
|
|
|
|
->setText(pht('Terminate All Sessions'))
|
|
|
|
->setHref('/auth/session/terminate/all/')
|
|
|
|
->setTag('a')
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setIcon($terminate_icon);
|
|
|
|
|
2014-01-14 20:05:45 +01:00
|
|
|
$header = id(new PHUIHeaderView())
|
2014-03-17 23:02:01 +01:00
|
|
|
->setHeader(pht('Active Login Sessions'))
|
|
|
|
->addActionLink($terminate_button);
|
2014-01-14 20:05:45 +01:00
|
|
|
|
2014-04-28 02:31:11 +02:00
|
|
|
$hisec = ($viewer->getSession()->getHighSecurityUntil() - time());
|
|
|
|
if ($hisec > 0) {
|
|
|
|
$hisec_icon = id(new PHUIIconView())
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIconFont('fa-lock');
|
2014-04-28 02:31:11 +02:00
|
|
|
$hisec_button = id(new PHUIButtonView())
|
|
|
|
->setText(pht('Leave High Security'))
|
|
|
|
->setHref('/auth/session/downgrade/')
|
|
|
|
->setTag('a')
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setIcon($hisec_icon);
|
|
|
|
$header->addActionLink($hisec_button);
|
|
|
|
}
|
|
|
|
|
2014-01-14 20:05:45 +01:00
|
|
|
$panel = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
[Redesign] Add Table, Collapse support to ObjectBox
Summary: Converts most all tables to be directly set via `setTable` to an ObjectBox. I think this path is more flexible design wise, as we can change the box based on children, and not just CSS. We also already do this with PropertyList, Forms, ObjectList, and Header. `setCollapsed` is added to ObjectBox to all children objects to bleed to the edges (like diffs).
Test Plan: I did a grep of `appendChild($table)` as well as searches for `PHUIObjectBoxView`, also with manual opening of hundreds of files. I'm sure I missed 5-8 places. If you just appendChild($table) nothing breaks, it just looks a little funny.
Reviewers: epriestley, btrahan
Subscribers: Korvin, epriestley
Differential Revision: https://secure.phabricator.com/D12955
2015-05-20 21:43:34 +02:00
|
|
|
->setTable($table);
|
2014-01-14 20:05:45 +01:00
|
|
|
|
|
|
|
return $panel;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|