[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorOAuthServerAuthorizationsSettingsPanel 4 extends PhabricatorSettingsPanel { 5 6 public function getPanelKey() { 7 return 'oauthorizations'; 8 } 9 10 public function getPanelName() { 11 return pht('OAuth Authorizations'); 12 } 13 14 public function getPanelGroup() { 15 return pht('Sessions and Logs'); 16 } 17 18 public function isEnabled() { 19 $app_name = 'PhabricatorOAuthServerApplication'; 20 return PhabricatorApplication::isClassInstalled($app_name); 21 } 22 23 public function processRequest(AphrontRequest $request) { 24 $viewer = $request->getUser(); 25 26 // TODO: It would be nice to simply disable this panel, but we can't do 27 // viewer-based checks for enabled panels right now. 28 29 $app_class = 'PhabricatorOAuthServerApplication'; 30 $installed = PhabricatorApplication::isClassInstalledForViewer( 31 $app_class, 32 $viewer); 33 if (!$installed) { 34 $dialog = id(new AphrontDialogView()) 35 ->setUser($viewer) 36 ->setTitle(pht('OAuth Not Available')) 37 ->appendParagraph( 38 pht('You do not have access to OAuth authorizations.')) 39 ->addCancelButton('/settings/'); 40 return id(new AphrontDialogResponse())->setDialog($dialog); 41 } 42 43 $authorizations = id(new PhabricatorOAuthClientAuthorizationQuery()) 44 ->setViewer($viewer) 45 ->withUserPHIDs(array($viewer->getPHID())) 46 ->execute(); 47 $authorizations = mpull($authorizations, null, 'getID'); 48 49 $panel_uri = $this->getPanelURI(); 50 51 $revoke = $request->getInt('revoke'); 52 if ($revoke) { 53 if (empty($authorizations[$revoke])) { 54 return new Aphront404Response(); 55 } 56 57 if ($request->isFormPost()) { 58 $authorizations[$revoke]->delete(); 59 return id(new AphrontRedirectResponse())->setURI($panel_uri); 60 } 61 62 $dialog = id(new AphrontDialogView()) 63 ->setUser($viewer) 64 ->setTitle(pht('Revoke Authorization?')) 65 ->appendParagraph( 66 pht( 67 'This application will no longer be able to access Phabricator '. 68 'on your behalf.')) 69 ->addSubmitButton(pht('Revoke Authorization')) 70 ->addCancelButton($panel_uri); 71 72 return id(new AphrontDialogResponse())->setDialog($dialog); 73 } 74 75 $highlight = $request->getInt('id'); 76 77 $rows = array(); 78 $rowc = array(); 79 foreach ($authorizations as $authorization) { 80 if ($highlight == $authorization->getID()) { 81 $rowc[] = 'highlighted'; 82 } else { 83 $rowc[] = null; 84 } 85 86 $button = javelin_tag( 87 'a', 88 array( 89 'href' => $this->getPanelURI('?revoke='.$authorization->getID()), 90 'class' => 'small grey button', 91 'sigil' => 'workflow', 92 ), 93 pht('Revoke')); 94 95 $rows[] = array( 96 phutil_tag( 97 'a', 98 array( 99 'href' => $authorization->getClient()->getViewURI(), 100 ), 101 $authorization->getClient()->getName()), 102 $authorization->getScopeString(), 103 phabricator_datetime($authorization->getDateCreated(), $viewer), 104 phabricator_datetime($authorization->getDateModified(), $viewer), 105 $button, 106 ); 107 } 108 109 $table = new AphrontTableView($rows); 110 $table->setNoDataString( 111 pht( 112 "You haven't authorized any OAuth applications.")); 113 114 $table->setRowClasses($rowc); 115 $table->setHeaders( 116 array( 117 pht('Application'), 118 pht('Scope'), 119 pht('Created'), 120 pht('Updated'), 121 null, 122 )); 123 124 $table->setColumnClasses( 125 array( 126 'pri', 127 'wide', 128 'right', 129 'right', 130 'action', 131 )); 132 133 $header = id(new PHUIHeaderView()) 134 ->setHeader(pht('OAuth Application Authorizations')); 135 136 $panel = id(new PHUIObjectBoxView()) 137 ->setHeader($header) 138 ->appendChild($table); 139 140 return $panel; 141 } 142 143 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |