Generate file attachment transactions for explicit Remarkup attachments on common...
[phabricator.git] / src / applications / oauthserver / panel / PhabricatorOAuthServerAuthorizationsSettingsPanel.php
blob21fb8913304844f7344298108dcdb87922482c65
1 <?php
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() {
15 return 'fa-exchange';
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(
35 $app_class,
36 $viewer);
37 if (!$installed) {
38 $dialog = id(new AphrontDialogView())
39 ->setUser($viewer)
40 ->setTitle(pht('OAuth Not Available'))
41 ->appendParagraph(
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())
48 ->setViewer($viewer)
49 ->withUserPHIDs(array($viewer->getPHID()))
50 ->execute();
51 $authorizations = mpull($authorizations, null, 'getID');
53 $panel_uri = $this->getPanelURI();
55 $revoke = $request->getInt('revoke');
56 if ($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())
67 ->setUser($viewer)
68 ->setTitle(pht('Revoke Authorization?'))
69 ->appendParagraph(
70 pht(
71 'This application will no longer be able to access this server '.
72 'on your behalf.'))
73 ->addSubmitButton(pht('Revoke Authorization'))
74 ->addCancelButton($panel_uri);
76 return id(new AphrontDialogResponse())->setDialog($dialog);
79 $highlight = $request->getInt('id');
81 $rows = array();
82 $rowc = array();
83 foreach ($authorizations as $authorization) {
84 if ($highlight == $authorization->getID()) {
85 $rowc[] = 'highlighted';
86 } else {
87 $rowc[] = null;
90 $button = javelin_tag(
91 'a',
92 array(
93 'href' => $this->getPanelURI('?revoke='.$authorization->getID()),
94 'class' => 'small button button-grey',
95 'sigil' => 'workflow',
97 pht('Revoke'));
99 $rows[] = array(
100 phutil_tag(
101 'a',
102 array(
103 'href' => $authorization->getClient()->getViewURI(),
105 $authorization->getClient()->getName()),
106 $authorization->getScopeString(),
107 phabricator_datetime($authorization->getDateCreated(), $viewer),
108 phabricator_datetime($authorization->getDateModified(), $viewer),
109 $button,
113 $table = new AphrontTableView($rows);
114 $table->setNoDataString(
115 pht("You haven't authorized any OAuth applications."));
117 $table->setRowClasses($rowc);
118 $table->setHeaders(
119 array(
120 pht('Application'),
121 pht('Scope'),
122 pht('Created'),
123 pht('Updated'),
124 null,
127 $table->setColumnClasses(
128 array(
129 'pri',
130 'wide',
131 'right',
132 'right',
133 'action',
136 $header = id(new PHUIHeaderView())
137 ->setHeader(pht('OAuth Application Authorizations'));
139 $panel = id(new PHUIObjectBoxView())
140 ->setHeader($header)
141 ->setBackground(PHUIObjectBoxView::WHITE_CONFIG)
142 ->appendChild($table);
144 return $panel;