public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $slug = PhabricatorSlug::normalize($request->getStr('slug'));
     if ($request->isFormPost()) {
         $document = id(new PhrictionDocumentQuery())->setViewer($user)->withSlugs(array($slug))->executeOne();
         $prompt = $request->getStr('prompt', 'no');
         $document_exists = $document && $document->getStatus() == PhrictionDocumentStatus::STATUS_EXISTS;
         if ($document_exists && $prompt == 'no') {
             $dialog = new AphrontDialogView();
             $dialog->setSubmitURI('/phriction/new/')->setTitle(pht('Edit Existing Document?'))->setUser($user)->appendChild(pht('The document %s already exists. Do you want to edit it instead?', phutil_tag('tt', array(), $slug)))->addHiddenInput('slug', $slug)->addHiddenInput('prompt', 'yes')->addCancelButton('/w/')->addSubmitButton(pht('Edit Document'));
             return id(new AphrontDialogResponse())->setDialog($dialog);
         } else {
             if (PhrictionDocument::isProjectSlug($slug)) {
                 $project = id(new PhabricatorProjectQuery())->setViewer($user)->withPhrictionSlugs(array(PhrictionDocument::getProjectSlugIdentifier($slug)))->executeOne();
                 if (!$project) {
                     $dialog = new AphrontDialogView();
                     $dialog->setSubmitURI('/w/')->setTitle(pht('Oops!'))->setUser($user)->appendChild(pht('You cannot create wiki pages under "projects/",
               because they are reserved as project pages.
               Create a new project with this name first.'))->addCancelButton('/w/', 'Okay');
                     return id(new AphrontDialogResponse())->setDialog($dialog);
                 }
             }
         }
         $uri = '/phriction/edit/?slug=' . $slug;
         return id(new AphrontRedirectResponse())->setURI($uri);
     }
     if ($slug == '/') {
         $slug = '';
     }
     $view = id(new PHUIFormLayoutView())->appendChild(id(new AphrontFormTextControl())->setLabel('/w/')->setValue($slug)->setName('slug'));
     $dialog = id(new AphrontDialogView())->setUser($user)->setTitle(pht('New Document'))->setSubmitURI('/phriction/new/')->appendChild(phutil_tag('p', array(), pht('Create a new document at')))->appendChild($view)->addSubmitButton(pht('Create'))->addCancelButton('/w/');
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function handleRequestException(AphrontRequest $request, Exception $ex)
 {
     $viewer = $this->getViewer($request);
     // Some types of uninteresting request exceptions don't get logged, usually
     // because they are caused by the background radiation of bot traffic on
     // the internet. These include requests with bad CSRF tokens and
     // questionable "Host" headers.
     $should_log = true;
     if ($ex instanceof AphrontMalformedRequestException) {
         $should_log = !$ex->getIsUnlogged();
     }
     if ($should_log) {
         phlog($ex);
     }
     $class = get_class($ex);
     $message = $ex->getMessage();
     if ($ex instanceof AphrontSchemaQueryException) {
         $message .= "\n\n" . pht("NOTE: This usually indicates that the MySQL schema has not been " . "properly upgraded. Run '%s' to ensure your schema is up to date.", 'bin/storage upgrade');
     }
     if (PhabricatorEnv::getEnvConfig('phabricator.developer-mode')) {
         $trace = id(new AphrontStackTraceView())->setUser($viewer)->setTrace($ex->getTrace());
     } else {
         $trace = null;
     }
     $content = phutil_tag('div', array('class' => 'aphront-unhandled-exception'), array(phutil_tag('div', array('class' => 'exception-message'), $message), $trace));
     $dialog = new AphrontDialogView();
     $dialog->setTitle(pht('Unhandled Exception ("%s")', $class))->setClass('aphront-exception-dialog')->setUser($viewer)->appendChild($content);
     if ($request->isAjax()) {
         $dialog->addCancelButton('/', pht('Close'));
     }
     return id(new AphrontDialogResponse())->setDialog($dialog)->setHTTPResponseCode(500);
 }
 public function handleException(Exception $ex)
 {
     // Always log the unhandled exception.
     phlog($ex);
     $class = phutil_escape_html(get_class($ex));
     $message = phutil_escape_html($ex->getMessage());
     if (PhabricatorEnv::getEnvConfig('phabricator.show-stack-traces')) {
         $trace = $this->renderStackTrace($ex->getTrace());
     } else {
         $trace = null;
     }
     $content = '<div class="aphront-unhandled-exception">' . '<div class="exception-message">' . $message . '</div>' . $trace . '</div>';
     $user = $this->getRequest()->getUser();
     if (!$user) {
         // If we hit an exception very early, we won't have a user.
         $user = new PhabricatorUser();
     }
     $dialog = new AphrontDialogView();
     $dialog->setTitle('Unhandled Exception ("' . $class . '")')->setClass('aphront-exception-dialog')->setUser($user)->appendChild($content);
     if ($this->getRequest()->isAjax()) {
         $dialog->addCancelButton('/', 'Close');
     }
     $response = new AphrontDialogResponse();
     $response->setDialog($dialog);
     return $response;
 }
 private function buildRescindTokenDialog(PhabricatorTokenGiven $token_given)
 {
     $dialog = new AphrontDialogView();
     $dialog->setTitle(pht('Rescind Token'));
     $dialog->appendChild(pht('Really rescind this lovely token?'));
     $dialog->addSubmitButton(pht('Rescind Token'));
     return $dialog;
 }
 public function processRequest()
 {
     $rule = id(new HeraldRule())->load($this->id);
     if (!$rule) {
         return new Aphront404Response();
     }
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($user->getPHID() != $rule->getAuthorPHID()) {
         return new Aphront400Response();
     }
     if ($request->isFormPost()) {
         $rule->delete();
         if ($request->isAjax()) {
             return new AphrontRedirectResponse();
         } else {
             return id(new AphrontRedirectResponse())->setURI('/herald/');
         }
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($request->getUser());
     $dialog->setTitle('Really delete this rule?');
     $dialog->appendChild("Are you sure you want to delete the rule " . "'<strong>" . phutil_escape_html($rule->getName()) . "</strong>'?");
     $dialog->addSubmitButton('Delete');
     $dialog->addCancelButton('/herald/');
     $dialog->setSubmitURI($request->getPath());
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $rule = id(new HeraldRule())->load($this->id);
     if (!$rule) {
         return new Aphront404Response();
     }
     $request = $this->getRequest();
     $user = $request->getUser();
     // Anyone can delete a global rule, but only the rule owner can delete a
     // personal one.
     if ($rule->getRuleType() == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL) {
         if ($user->getPHID() != $rule->getAuthorPHID()) {
             return new Aphront400Response();
         }
     }
     if ($request->isFormPost()) {
         $rule->openTransaction();
         $rule->logEdit($user->getPHID(), 'delete');
         $rule->delete();
         $rule->saveTransaction();
         return id(new AphrontReloadResponse())->setURI('/herald/');
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($request->getUser());
     $dialog->setTitle('Really delete this rule?');
     $dialog->appendChild("Are you sure you want to delete the rule " . "'<strong>" . phutil_escape_html($rule->getName()) . "</strong>'?");
     $dialog->addSubmitButton('Delete');
     $dialog->addCancelButton('/herald/');
     $dialog->setSubmitURI($request->getPath());
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $macro = id(new PhabricatorFileImageMacro())->load($this->id);
     if (!$macro) {
         return new Aphront404Response();
     }
     $request = $this->getRequest();
     if ($request->isDialogFormPost()) {
         $macro->delete();
         return id(new AphrontRedirectResponse())->setURI('/file/macro/');
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($request->getUser())->setTitle('Really delete macro?')->appendChild('<p>Really delete the much-beloved image macro "' . phutil_escape_html($macro->getName()) . '"? It will be sorely missed.' . '</p>')->setSubmitURI('/file/macro/delete/' . $this->id . '/')->addSubmitButton('Delete')->addCancelButton('/file/macro/');
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $arc_project = id(new PhabricatorRepositoryArcanistProject())->load($this->id);
     if (!$arc_project) {
         return new Aphront404Response();
     }
     $request = $this->getRequest();
     if ($request->isDialogFormPost()) {
         $arc_project->delete();
         return id(new AphrontRedirectResponse())->setURI('/repository/');
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($request->getUser())->setTitle('Really delete this arcanist project?')->appendChild(hsprintf('<p>Really delete the "%s" arcanist project? ' . 'This operation can not be undone.</p>', $arc_project->getName()))->setSubmitURI('/repository/project/delete/' . $this->id . '/')->addSubmitButton('Delete Arcanist Project')->addCancelButton('/repository/');
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $repository = id(new PhabricatorRepository())->load($this->id);
     if (!$repository) {
         return new Aphront404Response();
     }
     $request = $this->getRequest();
     if ($request->isDialogFormPost()) {
         $repository->delete();
         return id(new AphrontRedirectResponse())->setURI('/repository/');
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($request->getUser())->setTitle('Really delete repository?')->appendChild('<p>Really delete the "' . phutil_escape_html($repository->getName()) . '" (' . phutil_escape_html($repository->getCallsign()) . ') repository? ' . 'This operation can not be undone.</p>')->setSubmitURI('/repository/delete/' . $this->id . '/')->addSubmitButton('Delete Repository')->addCancelButton('/repository/');
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $phid = $this->getClientPHID();
     $title = 'Delete OAuth Client';
     $request = $this->getRequest();
     $current_user = $request->getUser();
     $client = id(new PhabricatorOAuthServerClient())->loadOneWhere('phid = %s', $phid);
     if (empty($client)) {
         return new Aphront404Response();
     }
     if ($client->getCreatorPHID() != $current_user->getPHID()) {
         $message = 'Access denied to client with phid ' . $phid . '. ' . 'Only the user who created the client has permission to ' . 'delete the client.';
         return id(new Aphront403Response())->setForbiddenText($message);
     }
     if ($request->isFormPost()) {
         $client->delete();
         return id(new AphrontRedirectResponse())->setURI('/oauthserver/client/?deleted=1');
     }
     $client_name = phutil_escape_html($client->getName());
     $title .= ' ' . $client_name;
     $dialog = new AphrontDialogView();
     $dialog->setUser($current_user);
     $dialog->setTitle($title);
     $dialog->appendChild('<p>Are you sure you want to delete this client?</p>');
     $dialog->addSubmitButton();
     $dialog->addCancelButton($client->getEditURI());
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $provider = $this->provider;
     if ($provider->isProviderLinkPermanent()) {
         throw new Exception("You may not unlink accounts from this OAuth provider.");
     }
     $provider_key = $provider->getProviderKey();
     $oauth_info = id(new PhabricatorUserOAuthInfo())->loadOneWhere('userID = %d AND oauthProvider = %s', $user->getID(), $provider_key);
     if (!$oauth_info) {
         return new Aphront400Response();
     }
     if (!$request->isDialogFormPost()) {
         $dialog = new AphrontDialogView();
         $dialog->setUser($user);
         $dialog->setTitle('Really unlink account?');
         $dialog->appendChild('<p><strong>You will not be able to login</strong> using this account ' . 'once you unlink it. Continue?</p>');
         $dialog->addSubmitButton('Unlink Account');
         $dialog->addCancelButton('/settings/page/' . $provider_key . '/');
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     $oauth_info->delete();
     return id(new AphrontRedirectResponse())->setURI('/settings/page/' . $provider_key . '/');
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $revision = id(new DifferentialRevision())->load($this->id);
     if (!$revision) {
         return new Aphront404Response();
     }
     if (!$request->isFormPost()) {
         $dialog = new AphrontDialogView();
         switch ($this->action) {
             case 'add':
                 $button = 'Subscribe';
                 $title = 'Subscribe to Revision';
                 $prompt = 'Really subscribe to this revision?';
                 break;
             case 'rem':
                 $button = 'Unsubscribe';
                 $title = 'Unsubscribe from Revision';
                 // TODO: Once herald is in, add a notice about not getting any more
                 // herald notifications.
                 $prompt = 'Really unsubscribe from this revision?';
                 break;
             default:
                 return new Aphront400Response();
         }
         $dialog->setUser($user)->setTitle($title)->appendChild('<p>' . $prompt . '</p>')->setSubmitURI($request->getRequestURI())->addSubmitButton($button)->addCancelButton('/D' . $revision->getID());
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     $revision->loadRelationships();
     $phid = $user->getPHID();
     switch ($this->action) {
         case 'add':
             DifferentialRevisionEditor::addCCAndUpdateRevision($revision, $phid, $phid);
             break;
         case 'rem':
             DifferentialRevisionEditor::removeCCAndUpdateRevision($revision, $phid, $phid);
             break;
         default:
             return new Aphront400Response();
     }
     return id(new AphrontRedirectResponse())->setURI('/D' . $revision->getID());
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $this->requireApplicationCapability(PhabricatorMacroManageCapability::CAPABILITY);
     $macro = id(new PhabricatorMacroQuery())->setViewer($viewer)->withIDs(array($id))->executeOne();
     if (!$macro) {
         return new Aphront404Response();
     }
     $view_uri = $this->getApplicationURI('/view/' . $id . '/');
     if ($request->isDialogFormPost() || $macro->getIsDisabled()) {
         $xaction = id(new PhabricatorMacroTransaction())->setTransactionType(PhabricatorMacroTransaction::TYPE_DISABLED)->setNewValue($macro->getIsDisabled() ? 0 : 1);
         $editor = id(new PhabricatorMacroEditor())->setActor($viewer)->setContentSourceFromRequest($request);
         $xactions = $editor->applyTransactions($macro, array($xaction));
         return id(new AphrontRedirectResponse())->setURI($view_uri);
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($request->getUser())->setTitle(pht('Really disable macro?'))->appendChild(phutil_tag('p', array(), pht('Really disable the much-beloved image macro %s? ' . 'It will be sorely missed.', $macro->getName())))->setSubmitURI($this->getApplicationURI('/disable/' . $id . '/'))->addSubmitButton(pht('Disable'))->addCancelButton($view_uri);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $this->requireApplicationCapability(HarbormasterManagePlansCapability::CAPABILITY);
     $id = $this->id;
     $step = id(new HarbormasterBuildStepQuery())->setViewer($viewer)->withIDs(array($id))->executeOne();
     if ($step === null) {
         throw new Exception('Build step not found!');
     }
     $plan_id = $step->getBuildPlan()->getID();
     $done_uri = $this->getApplicationURI('plan/' . $plan_id . '/');
     if ($request->isDialogFormPost()) {
         $step->delete();
         return id(new AphrontRedirectResponse())->setURI($done_uri);
     }
     $dialog = new AphrontDialogView();
     $dialog->setTitle(pht('Really Delete Step?'))->setUser($viewer)->addSubmitButton(pht('Delete Build Step'))->addCancelButton($done_uri);
     $dialog->appendChild(phutil_tag('p', array(), pht('Are you sure you want to delete this ' . 'step? This can\'t be undone!')));
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function handleException(Exception $ex)
 {
     // Always log the unhandled exception.
     phlog($ex);
     $class = phutil_escape_html(get_class($ex));
     $message = phutil_escape_html($ex->getMessage());
     $string = (string) $ex;
     $string = phutil_escape_html($string);
     $string = str_replace("\n", '<br />', $string);
     $content = '<div class="aphront-unhandled-exception">' . '<h1>Unhandled Exception "' . $class . '": ' . $message . '</h1>' . '<code>' . $string . '</code>' . '</div>';
     $user = $this->getRequest()->getUser();
     if (!$user) {
         // If we hit an exception very early, we won't have a user.
         $user = new PhabricatorUser();
     }
     $dialog = new AphrontDialogView();
     $dialog->setTitle('Exception!')->setClass('aphront-exception-dialog')->setUser($user)->appendChild($content)->addCancelButton('/');
     $response = new AphrontDialogResponse();
     $response->setDialog($dialog);
     return $response;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     if (!$request->isFormPost()) {
         return new Aphront400Response();
     }
     $user = $request->getUser();
     $question_id = $request->getInt('question_id');
     $question = PonderQuestionQuery::loadSingle($user, $question_id);
     if (!$question) {
         return new Aphront404Response();
     }
     $target = $request->getStr('target');
     $objects = id(new PhabricatorObjectHandleData(array($target)))->loadHandles();
     if (!$objects) {
         return new Aphront404Response();
     }
     $content = $request->getStr('content');
     if (!strlen(trim($content))) {
         $dialog = new AphrontDialogView();
         $dialog->setUser($request->getUser());
         $dialog->setTitle('Empty comment');
         $dialog->appendChild('<p>Your comment must not be empty.</p>');
         $dialog->addCancelButton('/Q' . $question_id);
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     $res = new PonderComment();
     $res->setContent($content)->setAuthorPHID($user->getPHID())->setTargetPHID($target);
     id(new PonderCommentEditor())->setQuestion($question)->setComment($res)->setTargetPHID($target)->setUser($user)->save();
     return id(new AphrontRedirectResponse())->setURI(id(new PhutilURI('/Q' . $question->getID())));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $task = id(new PhabricatorWorkerTask())->load($this->id);
     if (!$task) {
         return new Aphront404Response();
     }
     if ($request->isFormPost()) {
         switch ($this->action) {
             case 'delete':
                 $task->delete();
                 break;
             case 'release':
                 $task->setLeaseOwner(null);
                 $task->setLeaseExpires(time());
                 $task->save();
                 break;
         }
         return id(new AphrontRedirectResponse())->setURI('/daemon/');
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($user);
     switch ($this->action) {
         case 'delete':
             $dialog->setTitle('Really delete task?');
             $dialog->appendChild('<p>The work this task represents will never be performed if you ' . 'delete it. Are you sure you want to delete it?</p>');
             $dialog->addSubmitButton('Delete Task');
             break;
         case 'release':
             $dialog->setTitle('Really free task lease?');
             $dialog->appendChild('<p>If the process which owns the task lease is still doing work ' . 'on it, the work may be performed twice. Are you sure you ' . 'want to free the lease?</p>');
             $dialog->addSubmitButton('Free Lease');
             break;
         default:
             return new Aphront404Response();
     }
     $dialog->addCancelButton('/daemon/');
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     if (!$request->isFormPost()) {
         return new Aphront400Response();
     }
     $user = $request->getUser();
     $question_id = $request->getInt('question_id');
     $question = PonderQuestionQuery::loadSingle($user, $question_id);
     if (!$question) {
         return new Aphront404Response();
     }
     $answer = $request->getStr('answer');
     // Only want answers with some non whitespace content
     if (!strlen(trim($answer))) {
         $dialog = new AphrontDialogView();
         $dialog->setUser($request->getUser());
         $dialog->setTitle('Empty answer');
         $dialog->appendChild('<p>Your answer must not be empty.</p>');
         $dialog->addCancelButton('/Q' . $question_id);
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_WEB, array('ip' => $request->getRemoteAddr()));
     $res = new PonderAnswer();
     $res->setContent($answer)->setAuthorPHID($user->getPHID())->setVoteCount(0)->setQuestionID($question_id)->setContentSource($content_source);
     id(new PonderAnswerEditor())->setUser($user)->setQuestion($question)->setAnswer($res)->saveAnswer();
     return id(new AphrontRedirectResponse())->setURI(id(new PhutilURI('/Q' . $question->getID())));
 }
 public function renderExample()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $notices = array();
     if ($request->isFormPost()) {
         $notices[] = 'You just submitted a valid form POST.';
     }
     if ($request->isJavelinWorkflow()) {
         $notices[] = 'You just submitted a Workflow request.';
     }
     if ($notices) {
         $notices = id(new AphrontErrorView())->setSeverity(AphrontErrorView::SEVERITY_NOTICE)->setErrors($notices);
     } else {
         $notices = null;
     }
     if ($request->isJavelinWorkflow()) {
         $dialog = new AphrontDialogView();
         $dialog->setUser($user);
         $dialog->setTitle('Request Information');
         $dialog->appendChild($notices);
         $dialog->addCancelButton($request->getRequestURI(), 'Close');
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     $view = new PhabricatorActionListView();
     $view->setUser($user);
     $view->addAction(id(new PhabricatorActionView())->setUser($user)->setHref($request->getRequestURI())->setName('Normal Action')->setIcon('file'));
     $view->addAction(id(new PhabricatorActionView())->setUser($user)->setHref($request->getRequestURI())->setDisabled(true)->setName('Disabled Action')->setIcon('file'));
     $view->addAction(id(new PhabricatorActionView())->setUser($user)->setHref($request->getRequestURI())->setRenderAsForm(true)->setName('Form Action')->setIcon('file'));
     $view->addAction(id(new PhabricatorActionView())->setUser($user)->setHref($request->getRequestURI())->setRenderAsForm(true)->setDisabled(true)->setName('Disabled Form Action')->setIcon('file'));
     $view->addAction(id(new PhabricatorActionView())->setUser($user)->setHref($request->getRequestURI())->setWorkflow(true)->setName('Workflow Action')->setIcon('file'));
     $view->addAction(id(new PhabricatorActionView())->setUser($user)->setHref($request->getRequestURI())->setRenderAsForm(true)->setWorkflow(true)->setName('Form + Workflow Action')->setIcon('file'));
     return array($view, '<div style="clear: both;"></div>', $notices);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $capabilities = array(PhabricatorPolicyCapability::CAN_VIEW);
     $process_action = false;
     switch ($this->action) {
         case 'join':
             $capabilities[] = PhabricatorPolicyCapability::CAN_JOIN;
             $process_action = $request->isFormPost();
             break;
         case 'leave':
             $process_action = $request->isDialogFormPost();
             break;
         default:
             return new Aphront404Response();
     }
     $project = id(new PhabricatorProjectQuery())->setViewer($user)->withIDs(array($this->id))->needMembers(true)->requireCapabilities($capabilities)->executeOne();
     if (!$project) {
         return new Aphront404Response();
     }
     $project_uri = '/project/view/' . $project->getID() . '/';
     if ($process_action) {
         $edge_action = null;
         switch ($this->action) {
             case 'join':
                 $edge_action = '+';
                 break;
             case 'leave':
                 $edge_action = '-';
                 break;
         }
         $type_member = PhabricatorEdgeConfig::TYPE_PROJ_MEMBER;
         $member_spec = array($edge_action => array($user->getPHID() => $user->getPHID()));
         $xactions = array();
         $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $type_member)->setNewValue($member_spec);
         $editor = id(new PhabricatorProjectTransactionEditor($project))->setActor($user)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true)->applyTransactions($project, $xactions);
         return id(new AphrontRedirectResponse())->setURI($project_uri);
     }
     $dialog = null;
     switch ($this->action) {
         case 'leave':
             $dialog = new AphrontDialogView();
             $dialog->setUser($user);
             $dialog->setTitle(pht('Really leave project?'));
             $dialog->appendChild(phutil_tag('p', array(), pht('Your tremendous contributions to this project will be sorely ' . 'missed. Are you sure you want to leave?')));
             $dialog->addCancelButton($project_uri);
             $dialog->addSubmitButton(pht('Leave Project'));
             break;
         default:
             return new Aphront404Response();
     }
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function handleRequestException(AphrontRequest $request, Exception $ex)
 {
     $viewer = $this->getViewer($request);
     // Always log the unhandled exception.
     phlog($ex);
     $class = get_class($ex);
     $message = $ex->getMessage();
     if ($ex instanceof AphrontSchemaQueryException) {
         $message .= "\n\n" . pht("NOTE: This usually indicates that the MySQL schema has not been " . "properly upgraded. Run '%s' to ensure your schema is up to date.", 'bin/storage upgrade');
     }
     if (PhabricatorEnv::getEnvConfig('phabricator.developer-mode')) {
         $trace = id(new AphrontStackTraceView())->setUser($viewer)->setTrace($ex->getTrace());
     } else {
         $trace = null;
     }
     $content = phutil_tag('div', array('class' => 'aphront-unhandled-exception'), array(phutil_tag('div', array('class' => 'exception-message'), $message), $trace));
     $dialog = new AphrontDialogView();
     $dialog->setTitle(pht('Unhandled Exception ("%s")', $class))->setClass('aphront-exception-dialog')->setUser($viewer)->appendChild($content);
     if ($request->isAjax()) {
         $dialog->addCancelButton('/', pht('Close'));
     }
     return id(new AphrontDialogResponse())->setDialog($dialog)->setHTTPResponseCode(500);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $slug = PhabricatorSlug::normalize($request->getStr('slug'));
     if ($request->isFormPost()) {
         $document = id(new PhrictionDocumentQuery())->setViewer($viewer)->withSlugs(array($slug))->executeOne();
         $prompt = $request->getStr('prompt', 'no');
         $document_exists = $document && $document->getStatus() == PhrictionDocumentStatus::STATUS_EXISTS;
         if ($document_exists && $prompt == 'no') {
             $dialog = new AphrontDialogView();
             $dialog->setSubmitURI('/phriction/new/')->setTitle(pht('Edit Existing Document?'))->setUser($viewer)->appendChild(pht('The document %s already exists. Do you want to edit it instead?', phutil_tag('tt', array(), $slug)))->addHiddenInput('slug', $slug)->addHiddenInput('prompt', 'yes')->addCancelButton('/w/')->addSubmitButton(pht('Edit Document'));
             return id(new AphrontDialogResponse())->setDialog($dialog);
         }
         $uri = '/phriction/edit/?slug=' . $slug;
         return id(new AphrontRedirectResponse())->setURI($uri);
     }
     if ($slug == '/') {
         $slug = '';
     }
     $view = id(new PHUIFormLayoutView())->appendChild(id(new AphrontFormTextControl())->setLabel('/w/')->setValue($slug)->setName('slug'));
     $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle(pht('New Document'))->setSubmitURI('/phriction/new/')->appendChild(phutil_tag('p', array(), pht('Create a new document at')))->appendChild($view)->addSubmitButton(pht('Create'))->addCancelButton('/w/');
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($request->isFormPost()) {
         if (!$request->isDialogFormPost()) {
             $dialog = new AphrontDialogView();
             $dialog->setUser($user);
             $dialog->setTitle('Really regenerate session?');
             $dialog->setSubmitURI('/settings/page/conduit/');
             $dialog->addSubmitButton('Regenerate');
             $dialog->addCancelbutton('/settings/page/conduit/');
             $dialog->appendChild('<p>Really destroy the old certificate? Any established ' . 'sessions will be terminated.');
             return id(new AphrontDialogResponse())->setDialog($dialog);
         }
         $conn = $user->establishConnection('w');
         queryfx($conn, 'DELETE FROM %T WHERE userPHID = %s AND type LIKE %>', PhabricatorUser::SESSION_TABLE, $user->getPHID(), 'conduit');
         // This implicitly regenerates the certificate.
         $user->setConduitCertificate(null);
         $user->save();
         return id(new AphrontRedirectResponse())->setURI('/settings/page/conduit/?regenerated=true');
     }
     if ($request->getStr('regenerated')) {
         $notice = new AphrontErrorView();
         $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
         $notice->setTitle('Certificate Regenerated');
         $notice->appendChild('<p>Your old certificate has been destroyed and you have been issued ' . 'a new certificate. Sessions established under the old certificate ' . 'are no longer valid.</p>');
         $notice = $notice->render();
     } else {
         $notice = null;
     }
     $cert_form = new AphrontFormView();
     $cert_form->setUser($user)->appendChild('<p class="aphront-form-instructions">This certificate allows you to ' . 'authenticate over Conduit, the Phabricator API. Normally, you just ' . 'run <tt>arc install-certificate</tt> to install it.')->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Certificate')->setHeight(AphrontFormTextAreaControl::HEIGHT_SHORT)->setValue($user->getConduitCertificate()));
     $cert = new AphrontPanelView();
     $cert->setHeader('Arcanist Certificate');
     $cert->appendChild($cert_form);
     $cert->setWidth(AphrontPanelView::WIDTH_FORM);
     $regen_form = new AphrontFormView();
     $regen_form->setUser($user)->setAction('/settings/page/conduit/')->appendChild('<p class="aphront-form-instructions">You can regenerate this ' . 'certificate, which will invalidate the old certificate and create ' . 'a new one.</p>')->appendChild(id(new AphrontFormSubmitControl())->setValue('Regenerate Certificate'));
     $regen = new AphrontPanelView();
     $regen->setHeader('Regenerate Certificate');
     $regen->appendChild($regen_form);
     $regen->setWidth(AphrontPanelView::WIDTH_FORM);
     return id(new AphrontNullView())->appendChild(array($notice, $cert, $regen));
 }
 public function processRequest(AphrontRequest $request)
 {
     $user = $this->getUser();
     $viewer = $request->getUser();
     id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession($viewer, $request, '/settings/');
     if ($request->isFormPost()) {
         if (!$request->isDialogFormPost()) {
             $dialog = new AphrontDialogView();
             $dialog->setUser($viewer);
             $dialog->setTitle(pht('Really regenerate session?'));
             $dialog->setSubmitURI($this->getPanelURI());
             $dialog->addSubmitButton(pht('Regenerate'));
             $dialog->addCancelbutton($this->getPanelURI());
             $dialog->appendChild(phutil_tag('p', array(), pht('Really destroy the old certificate? Any established ' . 'sessions will be terminated.')));
             return id(new AphrontDialogResponse())->setDialog($dialog);
         }
         $sessions = id(new PhabricatorAuthSessionQuery())->setViewer($user)->withIdentityPHIDs(array($user->getPHID()))->withSessionTypes(array(PhabricatorAuthSession::TYPE_CONDUIT))->execute();
         foreach ($sessions as $session) {
             $session->delete();
         }
         // This implicitly regenerates the certificate.
         $user->setConduitCertificate(null);
         $user->save();
         return id(new AphrontRedirectResponse())->setURI($this->getPanelURI('?regenerated=true'));
     }
     if ($request->getStr('regenerated')) {
         $notice = new AphrontErrorView();
         $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
         $notice->setTitle(pht('Certificate Regenerated'));
         $notice->appendChild(phutil_tag('p', array(), pht('Your old certificate has been destroyed and you have been issued ' . 'a new certificate. Sessions established under the old certificate ' . 'are no longer valid.')));
         $notice = $notice->render();
     } else {
         $notice = null;
     }
     Javelin::initBehavior('select-on-click');
     $cert_form = new AphrontFormView();
     $cert_form->setUser($viewer)->appendChild(phutil_tag('p', array('class' => 'aphront-form-instructions'), pht('This certificate allows you to authenticate over Conduit, ' . 'the Phabricator API. Normally, you just run %s to install it.', phutil_tag('tt', array(), 'arc install-certificate'))))->appendChild(id(new AphrontFormTextAreaControl())->setLabel(pht('Certificate'))->setHeight(AphrontFormTextAreaControl::HEIGHT_SHORT)->setReadonly(true)->setSigil('select-on-click')->setValue($user->getConduitCertificate()));
     $cert_form = id(new PHUIObjectBoxView())->setHeaderText(pht('Arcanist Certificate'))->setForm($cert_form);
     $regen_instruction = pht('You can regenerate this certificate, which ' . 'will invalidate the old certificate and create a new one.');
     $regen_form = new AphrontFormView();
     $regen_form->setUser($viewer)->setAction($this->getPanelURI())->setWorkflow(true)->appendChild(phutil_tag('p', array('class' => 'aphront-form-instructions'), $regen_instruction))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Regenerate Certificate')));
     $regen_form = id(new PHUIObjectBoxView())->setHeaderText(pht('Regenerate Certificate'))->setForm($regen_form);
     return array($notice, $cert_form, $regen_form);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $capabilities = array(PhabricatorPolicyCapability::CAN_VIEW);
     $process_action = false;
     switch ($this->action) {
         case 'join':
             $capabilities[] = PhabricatorPolicyCapability::CAN_JOIN;
             $process_action = $request->isFormPost();
             break;
         case 'leave':
             $process_action = $request->isDialogFormPost();
             break;
         default:
             return new Aphront404Response();
     }
     $project = id(new PhabricatorProjectQuery())->setViewer($user)->withIDs(array($this->id))->needMembers(true)->requireCapabilities($capabilities)->executeOne();
     if (!$project) {
         return new Aphront404Response();
     }
     $project_uri = '/project/view/' . $project->getID() . '/';
     if ($process_action) {
         switch ($this->action) {
             case 'join':
                 PhabricatorProjectEditor::applyJoinProject($project, $user);
                 break;
             case 'leave':
                 PhabricatorProjectEditor::applyLeaveProject($project, $user);
                 break;
         }
         return id(new AphrontRedirectResponse())->setURI($project_uri);
     }
     $dialog = null;
     switch ($this->action) {
         case 'leave':
             $dialog = new AphrontDialogView();
             $dialog->setUser($user);
             $dialog->setTitle('Really leave project?');
             $dialog->appendChild('<p>Your tremendous contributions to this project will be sorely ' . 'missed. Are you sure you want to leave?</p>');
             $dialog->addCancelButton($project_uri);
             $dialog->addSubmitButton('Leave Project');
             break;
         default:
             return new Aphront404Response();
     }
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $category = id(new PhabricatorDirectoryCategory())->load($this->id);
     if (!$category) {
         return new Aphront404Response();
     }
     $request = $this->getRequest();
     if ($request->isFormPost()) {
         $category->delete();
         return id(new AphrontRedirectResponse())->setURI('/directory/category/');
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($request->getUser());
     $dialog->setTitle('Really delete this category?');
     $dialog->appendChild("Are you sure you want to delete this category?");
     $dialog->addSubmitButton('Delete');
     $dialog->addCancelButton('/directory/category/');
     $dialog->setSubmitURI($request->getPath());
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($request->isDialogFormPost()) {
         $table = new PhabricatorFeedStoryNotification();
         queryfx($table->establishConnection('w'), 'UPDATE %T SET hasViewed = 1 WHERE
       userPHID = %s AND hasViewed = 0', $table->getTableName(), $user->getPHID());
         return id(new AphrontReloadResponse())->setURI('/notification/');
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($user);
     $dialog->setTitle('Really mark all notifications as read?');
     $dialog->appendChild("You can't ignore your problems forever, you know.");
     $dialog->addCancelButton('/notification/');
     $dialog->addSubmitButton('Mark All Read');
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $countdown = id(new PhabricatorCountdownQuery())->setViewer($user)->withIDs(array($this->id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$countdown) {
         return new Aphront404Response();
     }
     if ($request->isFormPost()) {
         $countdown->delete();
         return id(new AphrontRedirectResponse())->setURI('/countdown/');
     }
     $inst = pht('Are you sure you want to delete the countdown %s?', $countdown->getTitle());
     $dialog = new AphrontDialogView();
     $dialog->setUser($request->getUser());
     $dialog->setTitle(pht('Really delete this countdown?'));
     $dialog->appendChild(phutil_tag('p', array(), $inst));
     $dialog->addSubmitButton(pht('Delete'));
     $dialog->addCancelButton('/countdown/');
     $dialog->setSubmitURI($request->getPath());
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $phid = $this->phid;
     $handle = PhabricatorObjectHandleData::loadOneHandle($phid);
     if (!$handle->isComplete()) {
         return new Aphront404Response();
     }
     $flag = PhabricatorFlagQuery::loadUserFlag($user, $phid);
     if (!$flag) {
         $flag = new PhabricatorFlag();
         $flag->setOwnerPHID($user->getPHID());
         $flag->setType($handle->getType());
         $flag->setObjectPHID($handle->getPHID());
         $flag->setReasonPHID($user->getPHID());
     }
     if ($request->isDialogFormPost()) {
         $flag->setColor($request->getInt('color'));
         $flag->setNote($request->getStr('note'));
         $flag->save();
         return id(new AphrontReloadResponse())->setURI('/flag/');
     }
     $type_name = $handle->getTypeName();
     $dialog = new AphrontDialogView();
     $dialog->setUser($user);
     $dialog->setTitle("Flag {$type_name}");
     require_celerity_resource('phabricator-flag-css');
     $form = new AphrontFormLayoutView();
     $is_new = !$flag->getID();
     if ($is_new) {
         $form->appendChild("<p>You can flag this {$type_name} if you want to remember to look " . "at it later.</p><br />");
     }
     $radio = new AphrontFormRadioButtonControl();
     foreach (PhabricatorFlagColor::getColorNameMap() as $color => $text) {
         $class = 'phabricator-flag-radio phabricator-flag-color-' . $color;
         $radio->addButton($color, $text, '', $class);
     }
     $form->appendChild($radio->setName('color')->setLabel('Flag Color')->setValue($flag->getColor()))->appendChild(id(new AphrontFormTextAreaControl())->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)->setName('note')->setLabel('Note')->setValue($flag->getNote()));
     $dialog->appendChild($form);
     $dialog->addCancelButton($handle->getURI());
     $dialog->addSubmitButton($is_new ? "Flag {$type_name}" : 'Save');
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 private function appendStrengthInformation(AphrontDialogView $dialog, PhabricatorPolicyInterface $object, PhabricatorPolicy $policy, $capability)
 {
     $viewer = $this->getViewer();
     $default_policy = PhabricatorPolicyQuery::getDefaultPolicyForObject($viewer, $object, $capability);
     if (!$default_policy) {
         return;
     }
     if ($default_policy->getPHID() == $policy->getPHID()) {
         return;
     }
     if ($default_policy->isStrongerThan($policy)) {
         $info = pht('This object has a less restrictive policy ("%s") than the default ' . 'policy for similar objects (which is "%s").', $policy->getShortName(), $default_policy->getShortName());
     } else {
         if ($policy->isStrongerThan($default_policy)) {
             $info = pht('This object has a more restrictive policy ("%s") than the default ' . 'policy for similar objects (which is "%s").', $policy->getShortName(), $default_policy->getShortName());
         } else {
             $info = pht('This object has a different policy ("%s") than the default policy ' . 'for similar objects (which is "%s").', $policy->getShortName(), $default_policy->getShortName());
         }
     }
     $dialog->appendParagraph($info);
 }