Path: blob/master/src/aphront/handler/PhabricatorPolicyRequestExceptionHandler.php
12241 views
<?php12final class PhabricatorPolicyRequestExceptionHandler3extends PhabricatorRequestExceptionHandler {45public function getRequestExceptionHandlerPriority() {6return 320000;7}89public function getRequestExceptionHandlerDescription() {10return pht(11'Handles policy exceptions which occur when a user tries to '.12'do something they do not have permission to do.');13}1415public function canHandleRequestThrowable(16AphrontRequest $request,17$throwable) {1819if (!$this->isPhabricatorSite($request)) {20return false;21}2223return ($throwable instanceof PhabricatorPolicyException);24}2526public function handleRequestThrowable(27AphrontRequest $request,28$throwable) {2930$viewer = $this->getViewer($request);3132if (!$viewer->isLoggedIn()) {33// If the user isn't logged in, just give them a login form. This is34// probably a generally more useful response than a policy dialog that35// they have to click through to get a login form.36//37// Possibly we should add a header here like "you need to login to see38// the thing you are trying to look at".39$auth_app_class = 'PhabricatorAuthApplication';40$auth_app = PhabricatorApplication::getByClass($auth_app_class);4142return id(new PhabricatorAuthStartController())43->setRequest($request)44->setCurrentApplication($auth_app)45->handleRequest($request);46}4748$content = array(49phutil_tag(50'div',51array(52'class' => 'aphront-policy-rejection',53),54$throwable->getRejection()),55);5657$list = null;58if ($throwable->getCapabilityName()) {59$list = $throwable->getMoreInfo();60foreach ($list as $key => $item) {61$list[$key] = $item;62}6364$content[] = phutil_tag(65'div',66array(67'class' => 'aphront-capability-details',68),69pht(70'Users with the "%s" capability:',71$throwable->getCapabilityName()));7273}7475$dialog = id(new AphrontDialogView())76->setTitle($throwable->getTitle())77->setClass('aphront-access-dialog')78->setUser($viewer)79->appendChild($content);8081if ($list) {82$dialog->appendList($list);83}8485// If the install is in developer mode, include a stack trace for the86// exception. When debugging things, it isn't always obvious where a87// policy exception came from and this can make it easier to hunt down88// bugs or improve ambiguous/confusing messaging.8990$is_developer = PhabricatorEnv::getEnvConfig('phabricator.developer-mode');91if ($is_developer) {92$dialog->appendChild(93id(new AphrontStackTraceView())94->setTrace($throwable->getTrace()));95}9697if ($request->isAjax()) {98$dialog->addCancelButton('/', pht('Close'));99} else {100$dialog->addCancelButton('/', pht('OK'));101}102103return $dialog;104}105106}107108109