3 final class PhabricatorOAuthServerAuthorizationsSettingsPanel
4 extends PhabricatorSettingsPanel
{
6 public function getPanelKey() {
7 return 'oauthorizations';
10 public function getPanelName() {
11 return pht('OAuth Authorizations');
14 public function getPanelMenuIcon() {
18 public function getPanelGroupKey() {
19 return PhabricatorSettingsLogsPanelGroup
::PANELGROUPKEY
;
22 public function isEnabled() {
23 return PhabricatorApplication
::isClassInstalled(
24 'PhabricatorOAuthServerApplication');
27 public function processRequest(AphrontRequest
$request) {
28 $viewer = $request->getUser();
30 // TODO: It would be nice to simply disable this panel, but we can't do
31 // viewer-based checks for enabled panels right now.
33 $app_class = 'PhabricatorOAuthServerApplication';
34 $installed = PhabricatorApplication
::isClassInstalledForViewer(
38 $dialog = id(new AphrontDialogView())
40 ->setTitle(pht('OAuth Not Available'))
42 pht('You do not have access to OAuth authorizations.'))
43 ->addCancelButton('/settings/');
44 return id(new AphrontDialogResponse())->setDialog($dialog);
47 $authorizations = id(new PhabricatorOAuthClientAuthorizationQuery())
49 ->withUserPHIDs(array($viewer->getPHID()))
51 $authorizations = mpull($authorizations, null, 'getID');
53 $panel_uri = $this->getPanelURI();
55 $revoke = $request->getInt('revoke');
57 if (empty($authorizations[$revoke])) {
58 return new Aphront404Response();
61 if ($request->isFormPost()) {
62 $authorizations[$revoke]->delete();
63 return id(new AphrontRedirectResponse())->setURI($panel_uri);
66 $dialog = id(new AphrontDialogView())
68 ->setTitle(pht('Revoke Authorization?'))
71 'This application will no longer be able to access this server '.
73 ->addSubmitButton(pht('Revoke Authorization'))
74 ->addCancelButton($panel_uri);
76 return id(new AphrontDialogResponse())->setDialog($dialog);
79 $highlight = $request->getInt('id');
83 foreach ($authorizations as $authorization) {
84 if ($highlight == $authorization->getID()) {
85 $rowc[] = 'highlighted';
90 $button = javelin_tag(
93 'href' => $this->getPanelURI('?revoke='.$authorization->getID()),
94 'class' => 'small button button-grey',
95 'sigil' => 'workflow',
103 'href' => $authorization->getClient()->getViewURI(),
105 $authorization->getClient()->getName()),
106 $authorization->getScopeString(),
107 phabricator_datetime($authorization->getDateCreated(), $viewer),
108 phabricator_datetime($authorization->getDateModified(), $viewer),
113 $table = new AphrontTableView($rows);
114 $table->setNoDataString(
115 pht("You haven't authorized any OAuth applications."));
117 $table->setRowClasses($rowc);
127 $table->setColumnClasses(
136 $header = id(new PHUIHeaderView())
137 ->setHeader(pht('OAuth Application Authorizations'));
139 $panel = id(new PHUIObjectBoxView())
141 ->setBackground(PHUIObjectBoxView
::WHITE_CONFIG
)
142 ->appendChild($table);