public function buildResponseString()
 {
     if ($this->shouldStopForDebugging()) {
         $request = $this->getRequest();
         $viewer = $request->getUser();
         $view = new PhabricatorStandardPageView();
         $view->setRequest($this->getRequest());
         $view->setApplicationName(pht('Debug'));
         $view->setTitle(pht('Stopped on Redirect'));
         $dialog = new AphrontDialogView();
         $dialog->setUser($viewer);
         $dialog->setTitle(pht('Stopped on Redirect'));
         $dialog->appendParagraph(pht('You were stopped here because %s is set in your configuration.', phutil_tag('tt', array(), 'debug.stop-on-redirect')));
         $dialog->appendParagraph(pht('You are being redirected to: %s', phutil_tag('tt', array(), $this->getURI())));
         $dialog->addCancelButton($this->getURI(), pht('Continue'));
         $dialog->appendChild(phutil_tag('br'));
         $dialog->appendChild(id(new AphrontStackTraceView())->setUser($viewer)->setTrace($this->stackWhenCreated));
         $dialog->setIsStandalone(true);
         $dialog->setWidth(AphrontDialogView::WIDTH_FULL);
         $box = id(new PHUIBoxView())->addMargin(PHUI::MARGIN_LARGE)->appendChild($dialog);
         $view->appendChild($box);
         return $view->render();
     }
     return '';
 }
 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 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()
 {
     $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()
 {
     $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();
     $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();
     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 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;
 }
 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 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 processRequest()
 {
     $request = $this->getRequest();
     $chrono_key = $request->getStr('chronoKey');
     $user = $request->getUser();
     if ($request->isDialogFormPost()) {
         $table = new PhabricatorFeedStoryNotification();
         queryfx($table->establishConnection('w'), 'UPDATE %T SET hasViewed = 1 ' . 'WHERE userPHID = %s AND hasViewed = 0 and chronologicalKey <= %s', $table->getTableName(), $user->getPHID(), $chrono_key);
         return id(new AphrontReloadResponse())->setURI('/notification/');
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($user);
     $dialog->addCancelButton('/notification/');
     if ($chrono_key) {
         $dialog->setTitle(pht('Really mark all notifications as read?'));
         $dialog->addHiddenInput('chronoKey', $chrono_key);
         $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
         if ($is_serious) {
             $dialog->appendChild(pht('All unread notifications will be marked as read. You can not ' . 'undo this action.'));
         } else {
             $dialog->appendChild(pht("You can't ignore your problems forever, you know."));
         }
         $dialog->addSubmitButton(pht('Mark All Read'));
     } else {
         $dialog->setTitle(pht('No notifications to mark as read.'));
         $dialog->appendChild(pht('You have no unread notifications.'));
     }
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 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 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()
 {
     $request = $this->getRequest();
     if (!$request->isFormPost()) {
         return new Aphront400Response();
     }
     $revision_id = $request->getInt('revision_id');
     $revision = id(new DifferentialRevision())->load($revision_id);
     if (!$revision) {
         return new Aphront400Response();
     }
     $comment = $request->getStr('comment');
     $action = $request->getStr('action');
     $reviewers = $request->getArr('reviewers');
     $ccs = $request->getArr('ccs');
     $editor = new DifferentialCommentEditor($revision, $request->getUser()->getPHID(), $action);
     $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_WEB, array('ip' => $request->getRemoteAddr()));
     try {
         $editor->setMessage($comment)->setContentSource($content_source)->setAttachInlineComments(true)->setAddedReviewers($reviewers)->setAddedCCs($ccs)->save();
     } catch (DifferentialActionHasNoEffectException $no_effect) {
         $has_inlines = id(new DifferentialInlineComment())->loadAllWhere('authorPHID = %s AND revisionID = %d AND commentID IS NULL', $request->getUser()->getPHID(), $revision->getID());
         $dialog = new AphrontDialogView();
         $dialog->setUser($request->getUser());
         $dialog->addCancelButton('/D' . $revision_id);
         $dialog->addHiddenInput('revision_id', $revision_id);
         $dialog->addHiddenInput('action', 'none');
         $dialog->addHiddenInput('reviewers', $reviewers);
         $dialog->addHiddenInput('ccs', $ccs);
         $dialog->addHiddenInput('comment', $comment);
         $dialog->setTitle('Action Has No Effect');
         $dialog->appendChild('<p>' . phutil_escape_html($no_effect->getMessage()) . '</p>');
         if (strlen($comment) || $has_inlines) {
             $dialog->addSubmitButton('Post as Comment');
             $dialog->appendChild('<br />');
             $dialog->appendChild('<p>Do you want to post your feedback anyway, as a normal ' . 'comment?</p>');
         }
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     // TODO: Diff change detection?
     $draft = id(new PhabricatorDraft())->loadOneWhere('authorPHID = %s AND draftKey = %s', $request->getUser()->getPHID(), 'differential-comment-' . $revision->getID());
     if ($draft) {
         $draft->delete();
     }
     return id(new AphrontRedirectResponse())->setURI('/D' . $revision->getID());
 }
 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();
     $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);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $phid = $request->getURIData('phid');
     $handle = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs(array($phid))->executeOne();
     if (!$handle->isComplete()) {
         return new Aphront404Response();
     }
     $flag = PhabricatorFlagQuery::loadUserFlag($viewer, $phid);
     if (!$flag) {
         $flag = new PhabricatorFlag();
         $flag->setOwnerPHID($viewer->getPHID());
         $flag->setType($handle->getType());
         $flag->setObjectPHID($handle->getPHID());
         $flag->setReasonPHID($viewer->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($viewer);
     $dialog->setTitle(pht('Flag %s', $type_name));
     require_celerity_resource('phabricator-flag-css');
     $form = new PHUIFormLayoutView();
     $is_new = !$flag->getID();
     if ($is_new) {
         $form->appendChild(hsprintf('<p>%s</p><br />', pht('You can flag this %s if you want to remember to look ' . 'at it later.', $type_name)));
     }
     $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(pht('Flag Color'))->setValue($flag->getColor()))->appendChild(id(new AphrontFormTextAreaControl())->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)->setName('note')->setLabel(pht('Note'))->setValue($flag->getNote()));
     $dialog->appendChild($form);
     $dialog->addCancelButton($handle->getURI());
     $dialog->addSubmitButton($is_new ? pht('Create Flag') : pht('Save'));
     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();
     $ldap_info = id(new PhabricatorUserLDAPInfo())->loadOneWhere('userID = %d', $user->getID());
     if (!$ldap_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/panel/ldap/');
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     $ldap_info->delete();
     return id(new AphrontRedirectResponse())->setURI('/settings/panel/ldap/');
 }
 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();
     $user = $request->getUser();
     $status = id(new PhabricatorCalendarEventQuery())->setViewer($user)->withIDs(array($this->id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$status) {
         return new Aphront404Response();
     }
     if ($request->isFormPost()) {
         $status->delete();
         $uri = new PhutilURI($this->getApplicationURI());
         $uri->setQueryParams(array('deleted' => true));
         return id(new AphrontRedirectResponse())->setURI($uri);
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($user);
     $dialog->setTitle(pht('Really delete status?'));
     $dialog->appendChild(pht('Permanently delete this status? This action can not be undone.'));
     $dialog->addSubmitButton(pht('Delete'));
     $dialog->addCancelButton($this->getApplicationURI('event/'));
     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 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();
     $id = $request->getURIData('id');
     $file = id(new PhabricatorFileQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$file) {
         return new Aphront404Response();
     }
     if ($viewer->getPHID() != $file->getAuthorPHID() && !$viewer->getIsAdmin()) {
         return new Aphront403Response();
     }
     if ($request->isFormPost()) {
         $file->delete();
         return id(new AphrontRedirectResponse())->setURI('/file/');
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($viewer);
     $dialog->setTitle(pht('Really delete file?'));
     $dialog->appendChild(hsprintf('<p>%s</p>', pht("Permanently delete '%s'? This action can not be undone.", $file->getName())));
     $dialog->addSubmitButton(pht('Delete'));
     $dialog->addCancelButton($file->getInfoURI());
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $file = id(new PhabricatorFile())->loadOneWhere('id = %d', $this->id);
     if (!$file) {
         return new Aphront404Response();
     }
     if ($user->getPHID() != $file->getAuthorPHID() && !$user->getIsAdmin()) {
         return new Aphront403Response();
     }
     if ($request->isFormPost()) {
         $file->delete();
         return id(new AphrontRedirectResponse())->setURI('/file/');
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($user);
     $dialog->setTitle('Really delete file?');
     $dialog->appendChild("<p>Permanently delete '" . phutil_escape_html($file->getName()) . "'? This " . "action can not be undone.");
     $dialog->addSubmitButton('Delete');
     $dialog->addCancelButton($file->getInfoURI());
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $timer = id(new PhabricatorTimer())->load($this->id);
     if (!$timer) {
         return new Aphront404Response();
     }
     if ($timer->getAuthorPHID() !== $user->getPHID() && $user->getIsAdmin() === false) {
         return new Aphront404Response();
     }
     if ($request->isFormPost()) {
         $timer->delete();
         return id(new AphrontRedirectResponse())->setURI('/countdown/');
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($request->getUser());
     $dialog->setTitle('Really delete this countdown?');
     $dialog->appendChild('<p>Are you sure you want to delete the countdown "' . phutil_escape_html($timer->getTitle()) . '"?</p>');
     $dialog->addSubmitButton('Delete');
     $dialog->addCancelButton('/countdown/');
     $dialog->setSubmitURI($request->getPath());
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $phid = $this->getAuthorizationPHID();
     $title = 'Delete OAuth Client Authorization';
     $request = $this->getRequest();
     $current_user = $request->getUser();
     $authorization = id(new PhabricatorOAuthClientAuthorization())->loadOneWhere('phid = %s', $phid);
     if (empty($authorization)) {
         return new Aphront404Response();
     }
     if ($authorization->getUserPHID() != $current_user->getPHID()) {
         $message = 'Access denied to client authorization with phid ' . $phid . '. ' . 'Only the user who authorized the client has permission to ' . 'delete the authorization.';
         return id(new Aphront403Response())->setForbiddenText($message);
     }
     if ($request->isFormPost()) {
         $authorization->delete();
         return id(new AphrontRedirectResponse())->setURI('/oauthserver/clientauthorization/?notice=deleted');
     }
     $client_phid = $authorization->getClientPHID();
     $client = id(new PhabricatorOAuthServerClient())->loadOneWhere('phid = %s', $client_phid);
     if ($client) {
         $client_name = phutil_escape_html($client->getName());
         $title .= ' for ' . $client_name;
     } else {
         // the client does not exist so token is dead already (but
         // let's let the user clean this up anyway in that case)
         $client_name = '';
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($current_user);
     $dialog->setTitle($title);
     $dialog->appendChild('<p>Are you sure you want to delete this client authorization?</p>');
     $dialog->addSubmitButton();
     $dialog->addCancelButton($authorization->getEditURI());
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 private function processAjaxRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     // We end up here if the user clicks a workflow link that they need to
     // login to use. We give them a dialog saying "You need to login...".
     if ($request->isDialogFormPost()) {
         return id(new AphrontRedirectResponse())->setURI($request->getRequestURI());
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($viewer);
     $dialog->setTitle(pht('Login Required'));
     $dialog->appendChild(pht('You must login to continue.'));
     $dialog->addSubmitButton(pht('Login'));
     $dialog->addCancelButton('/');
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function buildDialog()
 {
     $user = $this->user;
     $filter_id = celerity_generate_unique_node_id();
     $query_id = celerity_generate_unique_node_id();
     $results_id = celerity_generate_unique_node_id();
     $current_id = celerity_generate_unique_node_id();
     $search_id = celerity_generate_unique_node_id();
     $form_id = celerity_generate_unique_node_id();
     require_celerity_resource('phabricator-object-selector-css');
     $options = array();
     foreach ($this->filters as $key => $label) {
         $options[] = phutil_tag('option', array('value' => $key, 'selected' => $key == $this->selectedFilter ? 'selected' : null), $label);
     }
     $instructions = null;
     if ($this->instructions) {
         $instructions = phutil_tag('p', array('class' => 'phabricator-object-selector-instructions'), $this->instructions);
     }
     $search_box = phabricator_form($user, array('method' => 'POST', 'action' => $this->submitURI, 'id' => $search_id), phutil_tag('table', array('class' => 'phabricator-object-selector-search'), phutil_tag('tr', array(), array(phutil_tag('td', array('class' => 'phabricator-object-selector-search-filter'), phutil_tag('select', array('id' => $filter_id), $options)), phutil_tag('td', array('class' => 'phabricator-object-selector-search-text'), phutil_tag('input', array('id' => $query_id, 'type' => 'text')))))));
     $result_box = phutil_tag('div', array('class' => 'phabricator-object-selector-results', 'id' => $results_id), '');
     $attached_box = phutil_tag_div('phabricator-object-selector-current', phutil_tag_div('phabricator-object-selector-currently-attached', array(phutil_tag_div('phabricator-object-selector-header', $this->header), phutil_tag('div', array('id' => $current_id)), $instructions)));
     $dialog = new AphrontDialogView();
     $dialog->setUser($this->user)->setTitle($this->title)->setClass('phabricator-object-selector-dialog')->appendChild($search_box)->appendChild($result_box)->appendChild($attached_box)->setRenderDialogAsDiv()->setFormID($form_id)->addSubmitButton($this->buttonText);
     if ($this->cancelURI) {
         $dialog->addCancelButton($this->cancelURI);
     }
     $handle_views = array();
     foreach ($this->handles as $handle) {
         $phid = $handle->getPHID();
         $view = new PhabricatorHandleObjectSelectorDataView($handle);
         $handle_views[$phid] = $view->renderData();
     }
     $dialog->addHiddenInput('phids', implode(';', array_keys($this->handles)));
     Javelin::initBehavior('phabricator-object-selector', array('filter' => $filter_id, 'query' => $query_id, 'search' => $search_id, 'results' => $results_id, 'current' => $current_id, 'form' => $form_id, 'exclude' => $this->excluded, 'uri' => $this->searchURI, 'handles' => $handle_views));
     return $dialog;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $action = $request->getURIData('action');
     $capabilities = array(PhabricatorPolicyCapability::CAN_VIEW);
     $process_action = false;
     switch ($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($viewer)->withIDs(array($id))->needMembers(true)->requireCapabilities($capabilities)->executeOne();
     if (!$project) {
         return new Aphront404Response();
     }
     $project_uri = $this->getApplicationURI('profile/' . $project->getID() . '/');
     if ($process_action) {
         $edge_action = null;
         switch ($action) {
             case 'join':
                 $edge_action = '+';
                 break;
             case 'leave':
                 $edge_action = '-';
                 break;
         }
         $type_member = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
         $member_spec = array($edge_action => array($viewer->getPHID() => $viewer->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($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true)->applyTransactions($project, $xactions);
         return id(new AphrontRedirectResponse())->setURI($project_uri);
     }
     $dialog = null;
     switch ($action) {
         case 'leave':
             $dialog = new AphrontDialogView();
             $dialog->setUser($viewer);
             if ($this->userCannotLeave($project)) {
                 $dialog->setTitle(pht('You can not leave this project.'));
                 $body = pht('The membership is locked for this project.');
             } else {
                 $dialog->setTitle(pht('Really leave project?'));
                 $body = pht('Your tremendous contributions to this project will be sorely ' . 'missed. Are you sure you want to leave?');
                 $dialog->addSubmitButton(pht('Leave Project'));
             }
             $dialog->appendParagraph($body);
             $dialog->addCancelButton($project_uri);
             break;
         default:
             return new Aphront404Response();
     }
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }