public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $dblob = $request->getURIData('dblob');
     $fragment = id(new PhragmentFragmentQuery())->setViewer($viewer)->withPaths(array($dblob))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if ($fragment === null) {
         return new Aphront404Response();
     }
     $version = id(new PhragmentFragmentVersionQuery())->setViewer($viewer)->withFragmentPHIDs(array($fragment->getPHID()))->withIDs(array($id))->executeOne();
     if ($version === null) {
         return new Aphront404Response();
     }
     if ($request->isDialogFormPost()) {
         $file_phid = $version->getFilePHID();
         $file = null;
         if ($file_phid !== null) {
             $file = id(new PhabricatorFileQuery())->setViewer($viewer)->withPHIDs(array($file_phid))->executeOne();
             if ($file === null) {
                 throw new Exception(pht('The file associated with this version was not found.'));
             }
         }
         if ($file === null) {
             $fragment->deleteFile($viewer);
         } else {
             $fragment->updateFromFile($viewer, $file);
         }
         return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI('/history/' . $dblob));
     }
     return $this->createDialog($fragment, $version);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $phid = $request->getURIData('phid');
     $xaction = id(new PhabricatorObjectQuery())->withPHIDs(array($phid))->setViewer($viewer)->executeOne();
     if (!$xaction) {
         return new Aphront404Response();
     }
     if (!$xaction->getComment()) {
         return new Aphront404Response();
     }
     if ($xaction->getComment()->getIsRemoved()) {
         // You can't remove an already-removed comment.
         return new Aphront400Response();
     }
     $obj_phid = $xaction->getObjectPHID();
     $obj_handle = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs(array($obj_phid))->executeOne();
     if ($request->isDialogFormPost()) {
         $comment = $xaction->getApplicationTransactionCommentObject()->setContent('')->setIsRemoved(true);
         $editor = id(new PhabricatorApplicationTransactionCommentEditor())->setActor($viewer)->setContentSource(PhabricatorContentSource::newFromRequest($request))->applyEdit($xaction, $comment);
         if ($request->isAjax()) {
             return id(new AphrontAjaxResponse())->setContent(array());
         } else {
             return id(new AphrontReloadResponse())->setURI($obj_handle->getURI());
         }
     }
     $form = id(new AphrontFormView())->setUser($viewer);
     $dialog = $this->newDialog()->setTitle(pht('Remove Comment'));
     $dialog->addHiddenInput('anchor', $request->getStr('anchor'))->appendParagraph(pht("Removing a comment prevents anyone (including you) from reading " . "it. Removing a comment also hides the comment's edit history " . "and prevents it from being edited."))->appendParagraph(pht('Really remove this comment?'));
     $dialog->addSubmitButton(pht('Remove Comment'))->addCancelButton($obj_handle->getURI());
     return $dialog;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $e_file = true;
     $errors = array();
     if ($request->isDialogFormPost()) {
         $file_phids = $request->getStrList('filePHIDs');
         if ($file_phids) {
             $files = id(new PhabricatorFileQuery())->setViewer($viewer)->withPHIDs($file_phids)->setRaisePolicyExceptions(true)->execute();
         } else {
             $files = array();
         }
         if ($files) {
             $results = array();
             foreach ($files as $file) {
                 $results[] = $file->getDragAndDropDictionary();
             }
             $content = array('files' => $results);
             return id(new AphrontAjaxResponse())->setContent($content);
         } else {
             $e_file = pht('Required');
             $errors[] = pht('You must choose a file to upload.');
         }
     }
     if ($request->getURIData('single')) {
         $allow_multiple = false;
     } else {
         $allow_multiple = true;
     }
     $form = id(new AphrontFormView())->appendChild(id(new PHUIFormFileControl())->setName('filePHIDs')->setLabel(pht('Upload File'))->setAllowMultiple($allow_multiple)->setError($e_file));
     return $this->newDialog()->setTitle(pht('File'))->setErrors($errors)->appendForm($form)->addSubmitButton(pht('Upload'))->addCancelButton('/');
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $cancel_uri = $this->getApplicationURI('cache/');
     $opcode_cache = PhabricatorOpcodeCacheSpec::getActiveCacheSpec();
     $data_cache = PhabricatorDataCacheSpec::getActiveCacheSpec();
     $opcode_clearable = $opcode_cache->getClearCacheCallback();
     $data_clearable = $data_cache->getClearCacheCallback();
     if (!$opcode_clearable && !$data_clearable) {
         return $this->newDialog()->setTitle(pht('No Caches to Reset'))->appendParagraph(pht('None of the caches on this page can be cleared.'))->addCancelButton($cancel_uri);
     }
     if ($request->isDialogFormPost()) {
         if ($opcode_clearable) {
             call_user_func($opcode_cache->getClearCacheCallback());
         }
         if ($data_clearable) {
             call_user_func($data_cache->getClearCacheCallback());
         }
         return id(new AphrontRedirectResponse())->setURI($cancel_uri);
     }
     $caches = id(new PHUIPropertyListView())->setUser($viewer);
     if ($opcode_clearable) {
         $caches->addProperty(pht('Opcode'), $opcode_cache->getName());
     }
     if ($data_clearable) {
         $caches->addProperty(pht('Data'), $data_cache->getName());
     }
     return $this->newDialog()->setTitle(pht('Really Clear Cache?'))->setShortTitle(pht('Really Clear Cache'))->appendParagraph(pht('This will only affect the current web ' . 'frontend. Daemons and any other web frontends may continue ' . 'to use older, cached code from their opcache.'))->appendParagraph(pht('The following caches will be cleared:'))->appendChild($caches)->addSubmitButton(pht('Clear Cache'))->addCancelButton($cancel_uri);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $phid = head($request->getArr('macro'));
     $above = $request->getStr('above');
     $below = $request->getStr('below');
     $e_macro = true;
     $errors = array();
     if ($request->isDialogFormPost()) {
         if (!$phid) {
             $e_macro = pht('Required');
             $errors[] = pht('Macro name is required.');
         } else {
             $macro = id(new PhabricatorMacroQuery())->setViewer($viewer)->withPHIDs(array($phid))->executeOne();
             if (!$macro) {
                 $e_macro = pht('Invalid');
                 $errors[] = pht('No such macro.');
             }
         }
         if (!$errors) {
             $options = new PhutilSimpleOptions();
             $data = array('src' => $macro->getName(), 'above' => $above, 'below' => $below);
             $string = $options->unparse($data, $escape = '}');
             $result = array('text' => "{meme, {$string}}");
             return id(new AphrontAjaxResponse())->setContent($result);
         }
     }
     $view = id(new AphrontFormView())->setUser($viewer)->appendControl(id(new AphrontFormTokenizerControl())->setLabel(pht('Macro'))->setName('macro')->setLimit(1)->setDatasource(new PhabricatorMacroDatasource())->setError($e_macro))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Above'))->setName('above')->setValue($above))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Below'))->setName('below')->setValue($below));
     $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle(pht('Create Meme'))->appendForm($view)->addCancelButton('/')->addSubmitButton(pht('Llama Diorama'));
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $chrono_key = $request->getStr('chronoKey');
     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(), $viewer->getPHID(), $chrono_key);
         PhabricatorUserCache::clearCache(PhabricatorUserNotificationCountCacheType::KEY_COUNT, $viewer->getPHID());
         return id(new AphrontReloadResponse())->setURI('/notification/');
     }
     $dialog = new AphrontDialogView();
     $dialog->setUser($viewer);
     $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 handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $issue = $request->getURIData('key');
     $verb = $request->getURIData('verb');
     $issue_uri = $this->getApplicationURI('issue/' . $issue . '/');
     if ($request->isDialogFormPost()) {
         $this->manageApplication($issue);
         return id(new AphrontRedirectResponse())->setURI($issue_uri);
     }
     if ($verb == 'ignore') {
         $title = pht('Really ignore this setup issue?');
         $submit_title = pht('Ignore');
         $body = pht("You can ignore an issue if you don't want to fix it, or plan to " . "fix it later. Ignored issues won't appear on every page but will " . "still be shown in the list of open issues.");
     } else {
         if ($verb == 'unignore') {
             $title = pht('Unignore this setup issue?');
             $submit_title = pht('Unignore');
             $body = pht('This issue will no longer be suppressed, and will return to its ' . 'rightful place as a global setup warning.');
         } else {
             throw new Exception(pht('Unrecognized verb: %s', $verb));
         }
     }
     $dialog = id(new AphrontDialogView())->setUser($request->getUser())->setTitle($title)->appendChild($body)->addSubmitButton($submit_title)->addCancelButton($issue_uri);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $revision_id = $request->getURIData('id');
     $strategy_class = $request->getURIData('strategy');
     $revision = id(new DifferentialRevisionQuery())->withIDs(array($revision_id))->setViewer($viewer)->executeOne();
     if (!$revision) {
         return new Aphront404Response();
     }
     if (is_subclass_of($strategy_class, 'DifferentialLandingStrategy')) {
         $this->pushStrategy = newv($strategy_class, array());
     } else {
         throw new Exception(pht("Strategy type must be a valid class name and must subclass " . "%s. '%s' is not a subclass of %s", 'DifferentialLandingStrategy', $strategy_class, 'DifferentialLandingStrategy'));
     }
     if ($request->isDialogFormPost()) {
         $response = null;
         $text = '';
         try {
             $response = $this->attemptLand($revision, $request);
             $title = pht('Success!');
             $text = pht('Revision was successfully landed.');
         } catch (Exception $ex) {
             $title = pht('Failed to land revision');
             if ($ex instanceof PhutilProxyException) {
                 $text = hsprintf('%s:<br><pre>%s</pre>', $ex->getMessage(), $ex->getPreviousException()->getMessage());
             } else {
                 $text = phutil_tag('pre', array(), $ex->getMessage());
             }
             $text = id(new PHUIInfoView())->appendChild($text);
         }
         if ($response instanceof AphrontDialogView) {
             $dialog = $response;
         } else {
             $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle($title)->appendChild(phutil_tag('p', array(), $text))->addCancelButton('/D' . $revision_id, pht('Done'));
         }
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     $is_disabled = $this->pushStrategy->isActionDisabled($viewer, $revision, $revision->getRepository());
     if ($is_disabled) {
         if (is_string($is_disabled)) {
             $explain = $is_disabled;
         } else {
             $explain = pht('This action is not currently enabled.');
         }
         $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle(pht("Can't land revision"))->appendChild($explain)->addCancelButton('/D' . $revision_id);
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     $prompt = hsprintf('%s<br><br>%s', pht('This will squash and rebase revision %s, and push it to ' . 'the default / master branch.', $revision_id), pht('It is an experimental feature and may not work.'));
     $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle(pht('Land Revision %s?', $revision_id))->appendChild($prompt)->setSubmitURI($request->getRequestURI())->addSubmitButton(pht('Land it!'))->addCancelButton('/D' . $revision_id);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $key = $request->getURIData('queryKey');
     $engine_class = $request->getURIData('engine');
     $base_class = 'PhabricatorApplicationSearchEngine';
     if (!is_subclass_of($engine_class, $base_class)) {
         return new Aphront400Response();
     }
     $engine = newv($engine_class, array());
     $engine->setViewer($viewer);
     $named_query = id(new PhabricatorNamedQueryQuery())->setViewer($viewer)->withEngineClassNames(array($engine_class))->withQueryKeys(array($key))->withUserPHIDs(array($viewer->getPHID()))->executeOne();
     if (!$named_query && $engine->isBuiltinQuery($key)) {
         $named_query = $engine->getBuiltinQuery($key);
     }
     if (!$named_query) {
         return new Aphront404Response();
     }
     $builtin = null;
     if ($engine->isBuiltinQuery($key)) {
         $builtin = $engine->getBuiltinQuery($key);
     }
     $return_uri = $engine->getQueryManagementURI();
     if ($request->isDialogFormPost()) {
         if ($named_query->getIsBuiltin()) {
             $named_query->setIsDisabled((int) (!$named_query->getIsDisabled()));
             $named_query->save();
         } else {
             $named_query->delete();
         }
         return id(new AphrontRedirectResponse())->setURI($return_uri);
     }
     if ($named_query->getIsBuiltin()) {
         if ($named_query->getIsDisabled()) {
             $title = pht('Enable Query?');
             $desc = pht('Enable the built-in query "%s"? It will appear in your menu again.', $builtin->getQueryName());
             $button = pht('Enable Query');
         } else {
             $title = pht('Disable Query?');
             $desc = pht('This built-in query can not be deleted, but you can disable it so ' . 'it does not appear in your query menu. You can enable it again ' . 'later. Disable built-in query "%s"?', $builtin->getQueryName());
             $button = pht('Disable Query');
         }
     } else {
         $title = pht('Really Delete Query?');
         $desc = pht('Really delete the query "%s"? You can not undo this. Remember ' . 'all the great times you had filtering results together?', $named_query->getQueryName());
         $button = pht('Delete Query');
     }
     $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle($title)->appendChild($desc)->addCancelButton($return_uri)->addSubmitButton($button);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $action = $request->getURIData('action');
     $project = id(new PhabricatorProjectQuery())->setViewer($viewer)->withIDs(array($id))->needMembers(true)->needWatchers(true)->executeOne();
     if (!$project) {
         return new Aphront404Response();
     }
     $project_uri = $this->getApplicationURI('profile/' . $project->getID() . '/');
     // You must be a member of a project to
     if (!$project->isUserMember($viewer->getPHID())) {
         return new Aphront400Response();
     }
     if ($request->isDialogFormPost()) {
         $edge_action = null;
         switch ($action) {
             case 'watch':
                 $edge_action = '+';
                 $force_subscribe = true;
                 break;
             case 'unwatch':
                 $edge_action = '-';
                 $force_subscribe = false;
                 break;
         }
         $type_member = PhabricatorObjectHasWatcherEdgeType::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 'watch':
             $title = pht('Watch Project?');
             $body = pht('Watching a project will let you monitor it closely. You will ' . 'receive email and notifications about changes to every object ' . 'associated with projects you watch.');
             $submit = pht('Watch Project');
             break;
         case 'unwatch':
             $title = pht('Unwatch Project?');
             $body = pht('You will no longer receive email or notifications about every ' . 'object associated with this project.');
             $submit = pht('Unwatch Project');
             break;
         default:
             return new Aphront404Response();
     }
     return $this->newDialog()->setTitle($title)->appendParagraph($body)->addCancelButton($project_uri)->addSubmitButton($submit);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $snapshot = id(new PhragmentSnapshotQuery())->setViewer($viewer)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->withIDs(array($id))->executeOne();
     if ($snapshot === null) {
         return new Aphront404Response();
     }
     if ($request->isDialogFormPost()) {
         $fragment_uri = $snapshot->getPrimaryFragment()->getURI();
         $snapshot->delete();
         return id(new AphrontRedirectResponse())->setURI($fragment_uri);
     }
     return $this->createDialog();
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $id = $request->getURIData('id');
     $step = id(new HarbormasterBuildStepQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$step) {
         return new Aphront404Response();
     }
     $plan_id = $step->getBuildPlan()->getID();
     $done_uri = $this->getApplicationURI('plan/' . $plan_id . '/');
     if ($request->isDialogFormPost()) {
         $step->delete();
         return id(new AphrontRedirectResponse())->setURI($done_uri);
     }
     return $this->newDialog()->setTitle(pht('Really Delete Step?'))->appendParagraph(pht("Are you sure you want to delete this step? " . "This can't be undone!"))->addCancelButton($done_uri)->addSubmitButton(pht('Delete Build Step'));
 }
 public function processRequest(AphrontRequest $request)
 {
     $user = $request->getUser();
     if ($request->isFormPost()) {
         if (!$request->isDialogFormPost()) {
             $dialog = new AphrontDialogView();
             $dialog->setUser($user);
             $dialog->setTitle('Really regenerate session?');
             $dialog->setSubmitURI($this->getPanelURI());
             $dialog->addSubmitButton('Regenerate');
             $dialog->addCancelbutton($this->getPanelURI());
             $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($this->getPanelURI('?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($this->getPanelURI())->setWorkflow(true)->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 array($notice, $cert, $regen);
 }
 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 handleRequest(AphrontRequest $request)
 {
     $this->requireApplicationCapability(AuthManageProvidersCapability::CAPABILITY);
     $viewer = $request->getUser();
     $config_id = $request->getURIData('id');
     $action = $request->getURIData('action');
     $config = id(new PhabricatorAuthProviderConfigQuery())->setViewer($viewer)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->withIDs(array($config_id))->executeOne();
     if (!$config) {
         return new Aphront404Response();
     }
     $is_enable = $action === 'enable';
     if ($request->isDialogFormPost()) {
         $xactions = array();
         $xactions[] = id(new PhabricatorAuthProviderConfigTransaction())->setTransactionType(PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE)->setNewValue((int) $is_enable);
         $editor = id(new PhabricatorAuthProviderConfigEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->applyTransactions($config, $xactions);
         return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI());
     }
     if ($is_enable) {
         $title = pht('Enable Provider?');
         if ($config->getShouldAllowRegistration()) {
             $body = pht('Do you want to enable this provider? Users will be able to use ' . 'their existing external accounts to register new Phabricator ' . 'accounts and log in using linked accounts.');
         } else {
             $body = pht('Do you want to enable this provider? Users will be able to log ' . 'in to Phabricator using linked accounts.');
         }
         $button = pht('Enable Provider');
     } else {
         // TODO: We could tailor this a bit more. In particular, we could
         // check if this is the last provider and either prevent if from
         // being disabled or force the user through like 35 prompts. We could
         // also check if it's the last provider linked to the acting user's
         // account and pop a warning like "YOU WILL NO LONGER BE ABLE TO LOGIN
         // YOU GOOF, YOU PROBABLY DO NOT MEAN TO DO THIS". None of this is
         // critical and we can wait to see how users manage to shoot themselves
         // in the feet. Shortly, `bin/auth` will be able to recover from these
         // types of mistakes.
         $title = pht('Disable Provider?');
         $body = pht('Do you want to disable this provider? Users will not be able to ' . 'register or log in using linked accounts. If there are any users ' . 'without other linked authentication mechanisms, they will no longer ' . 'be able to log in. If you disable all providers, no one will be ' . 'able to log in.');
         $button = pht('Disable Provider');
     }
     $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle($title)->appendChild($body)->addCancelButton($this->getApplicationURI())->addSubmitButton($button);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 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 handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $this->providerKey = $request->getURIData('pkey');
     list($type, $domain) = explode(':', $this->providerKey, 2);
     // Check that this account link actually exists. We don't require the
     // provider to exist because we want users to be able to delete links to
     // dead accounts if they want.
     $account = id(new PhabricatorExternalAccount())->loadOneWhere('accountType = %s AND accountDomain = %s AND userPHID = %s', $type, $domain, $viewer->getPHID());
     if (!$account) {
         return $this->renderNoAccountErrorDialog();
     }
     // Check that the provider (if it exists) allows accounts to be unlinked.
     $provider_key = $this->providerKey;
     $provider = PhabricatorAuthProvider::getEnabledProviderByKey($provider_key);
     if ($provider) {
         if (!$provider->shouldAllowAccountUnlink()) {
             return $this->renderNotUnlinkableErrorDialog($provider);
         }
     }
     // Check that this account isn't the last account which can be used to
     // login. We prevent you from removing the last account.
     if ($account->isUsableForLogin()) {
         $other_accounts = id(new PhabricatorExternalAccount())->loadAllWhere('userPHID = %s', $viewer->getPHID());
         $valid_accounts = 0;
         foreach ($other_accounts as $other_account) {
             if ($other_account->isUsableForLogin()) {
                 $valid_accounts++;
             }
         }
         if ($valid_accounts < 2) {
             return $this->renderLastUsableAccountErrorDialog();
         }
     }
     if ($request->isDialogFormPost()) {
         $account->delete();
         id(new PhabricatorAuthSessionEngine())->terminateLoginSessions($viewer, $request->getCookie(PhabricatorCookies::COOKIE_SESSION));
         return id(new AphrontRedirectResponse())->setURI($this->getDoneURI());
     }
     return $this->renderConfirmDialog($account);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $this->action = $request->getURIData('action');
     $this->application = $request->getURIData('application');
     $selected = id(new PhabricatorApplicationQuery())->setViewer($viewer)->withClasses(array($this->application))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$selected) {
         return new Aphront404Response();
     }
     $view_uri = $this->getApplicationURI('view/' . $this->application);
     $prototypes_enabled = PhabricatorEnv::getEnvConfig('phabricator.show-prototypes');
     $dialog = id(new AphrontDialogView())->setUser($viewer)->addCancelButton($view_uri);
     if ($selected->isPrototype() && !$prototypes_enabled) {
         $dialog->setTitle(pht('Prototypes Not Enabled'))->appendChild(pht('To manage prototypes, enable them by setting %s in your ' . 'Phabricator configuration.', phutil_tag('tt', array(), 'phabricator.show-prototypes')));
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     if ($request->isDialogFormPost()) {
         $this->manageApplication();
         return id(new AphrontRedirectResponse())->setURI($view_uri);
     }
     if ($this->action == 'install') {
         if ($selected->canUninstall()) {
             $dialog->setTitle(pht('Confirmation'))->appendChild(pht('Install %s application?', $selected->getName()))->addSubmitButton(pht('Install'));
         } else {
             $dialog->setTitle(pht('Information'))->appendChild(pht('You cannot install an installed application.'));
         }
     } else {
         if ($selected->canUninstall()) {
             $dialog->setTitle(pht('Really Uninstall Application?'));
             if ($selected instanceof PhabricatorHomeApplication) {
                 $dialog->appendParagraph(pht('Are you absolutely certain you want to uninstall the Home ' . 'application?'))->appendParagraph(pht('This is very unusual and will leave you without any ' . 'content on the Phabricator home page. You should only ' . 'do this if you are certain you know what you are doing.'))->addSubmitButton(pht('Completely Break Phabricator'));
             } else {
                 $dialog->appendParagraph(pht('Really uninstall the %s application?', $selected->getName()))->addSubmitButton(pht('Uninstall'));
             }
         } else {
             $dialog->setTitle(pht('Information'))->appendChild(pht('This application cannot be uninstalled, ' . 'because it is required for Phabricator to work.'));
         }
     }
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $action = $request->getURIData('action');
     $project = id(new PhabricatorProjectQuery())->setViewer($viewer)->withIDs(array($id))->needMembers(true)->executeOne();
     if (!$project) {
         return new Aphront404Response();
     }
     $edge_type = PhabricatorProjectSilencedEdgeType::EDGECONST;
     $done_uri = "/project/members/{$id}/";
     $viewer_phid = $viewer->getPHID();
     if (!$project->isUserMember($viewer_phid)) {
         return $this->newDialog()->setTitle(pht('Not a Member'))->appendParagraph(pht('You are not a project member, so you do not receive mail sent ' . 'to members of this project.'))->addCancelButton($done_uri);
     }
     $silenced = PhabricatorEdgeQuery::loadDestinationPHIDs($project->getPHID(), $edge_type);
     $silenced = array_fuse($silenced);
     $is_silenced = isset($silenced[$viewer_phid]);
     if ($request->isDialogFormPost()) {
         if ($is_silenced) {
             $edge_action = '-';
         } else {
             $edge_action = '+';
         }
         $xactions = array();
         $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $edge_type)->setNewValue(array($edge_action => array($viewer_phid => $viewer_phid)));
         $editor = id(new PhabricatorProjectTransactionEditor($project))->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true)->applyTransactions($project, $xactions);
         return id(new AphrontRedirectResponse())->setURI($done_uri);
     }
     if ($is_silenced) {
         $title = pht('Enable Mail');
         $body = pht('When mail is sent to members of this project, you will receive a ' . 'copy.');
         $button = pht('Enable Project Mail');
     } else {
         $title = pht('Disable Mail');
         $body = pht('When mail is sent to members of this project, you will no longer ' . 'receive a copy.');
         $button = pht('Disable Project Mail');
     }
     return $this->newDialog()->setTitle($title)->appendParagraph($body)->addCancelButton($done_uri)->addSubmitButton($button);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $id = $request->getURIData('id');
     $is_all = $id === 'all';
     $query = id(new PhabricatorAuthSessionQuery())->setViewer($viewer)->withIdentityPHIDs(array($viewer->getPHID()));
     if (!$is_all) {
         $query->withIDs(array($id));
     }
     $current_key = PhabricatorHash::digest($request->getCookie(PhabricatorCookies::COOKIE_SESSION));
     $sessions = $query->execute();
     foreach ($sessions as $key => $session) {
         $is_current = phutil_hashes_are_identical($session->getSessionKey(), $current_key);
         if ($is_current) {
             // Don't terminate the current login session.
             unset($sessions[$key]);
         }
     }
     $panel_uri = '/settings/panel/sessions/';
     if (!$sessions) {
         return $this->newDialog()->setTitle(pht('No Matching Sessions'))->appendParagraph(pht('There are no matching sessions to terminate.'))->appendParagraph(pht('(You can not terminate your current login session. To ' . 'terminate it, log out.)'))->addCancelButton($panel_uri);
     }
     if ($request->isDialogFormPost()) {
         foreach ($sessions as $session) {
             $session->delete();
         }
         return id(new AphrontRedirectResponse())->setURI($panel_uri);
     }
     if ($is_all) {
         $title = pht('Terminate Sessions?');
         $short = pht('Terminate Sessions');
         $body = pht('Really terminate all sessions? (Your current login session will ' . 'not be terminated.)');
     } else {
         $title = pht('Terminate Session?');
         $short = pht('Terminate Session');
         $body = pht('Really terminate session %s?', phutil_tag('strong', array(), substr($session->getSessionKey(), 0, 6)));
     }
     return $this->newDialog()->setTitle($title)->setShortTitle($short)->appendParagraph($body)->addSubmitButton(pht('Terminate'))->addCancelButton($panel_uri);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $lease = id(new DrydockLeaseQuery())->setViewer($viewer)->withIDs(array($id))->executeOne();
     if (!$lease) {
         return new Aphront404Response();
     }
     $lease_uri = '/lease/' . $lease->getID() . '/';
     $lease_uri = $this->getApplicationURI($lease_uri);
     if ($lease->getStatus() != DrydockLeaseStatus::STATUS_ACTIVE) {
         $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle(pht('Lease Not Active'))->appendChild(phutil_tag('p', array(), pht('You can only release "active" leases.')))->addCancelButton($lease_uri);
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     if (!$request->isDialogFormPost()) {
         $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle(pht('Really release lease?'))->appendChild(phutil_tag('p', array(), pht('Releasing a lease may cause trouble for the lease holder and ' . 'trigger cleanup of the underlying resource. It can not be ' . 'undone. Continue?')))->addSubmitButton(pht('Release Lease'))->addCancelButton($lease_uri);
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     $resource = $lease->getResource();
     $blueprint = $resource->getBlueprint();
     $blueprint->releaseLease($resource, $lease);
     return id(new AphrontReloadResponse())->setURI($lease_uri);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $id = $request->getURIData('id');
     $is_all = $id === 'all';
     $query = id(new PhabricatorAuthTemporaryTokenQuery())->setViewer($viewer)->withObjectPHIDs(array($viewer->getPHID()));
     if (!$is_all) {
         $query->withIDs(array($id));
     }
     $tokens = $query->execute();
     foreach ($tokens as $key => $token) {
         if (!$token->isRevocable()) {
             // Don't revoke unrevocable tokens.
             unset($tokens[$key]);
         }
     }
     $panel_uri = '/settings/panel/tokens/';
     if (!$tokens) {
         return $this->newDialog()->setTitle(pht('No Matching Tokens'))->appendParagraph(pht('There are no matching tokens to revoke.'))->appendParagraph(pht('(Some types of token can not be revoked, and you can not revoke ' . 'tokens which have already expired.)'))->addCancelButton($panel_uri);
     }
     if ($request->isDialogFormPost()) {
         foreach ($tokens as $token) {
             $token->revokeToken();
         }
         return id(new AphrontRedirectResponse())->setURI($panel_uri);
     }
     if ($is_all) {
         $title = pht('Revoke Tokens?');
         $short = pht('Revoke Tokens');
         $body = pht('Really revoke all tokens? Among other temporary authorizations, ' . 'this will disable any outstanding password reset or account ' . 'recovery links.');
     } else {
         $title = pht('Revoke Token?');
         $short = pht('Revoke Token');
         $body = pht('Really revoke this token? Any temporary authorization it enables ' . 'will be disabled.');
     }
     return $this->newDialog()->setTitle($title)->setShortTitle($short)->appendParagraph($body)->addSubmitButton(pht('Revoke'))->addCancelButton($panel_uri);
 }
 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();
     }
     $current = id(new PhabricatorTokenGivenQuery())->setViewer($viewer)->withAuthorPHIDs(array($viewer->getPHID()))->withObjectPHIDs(array($handle->getPHID()))->execute();
     if ($current) {
         $is_give = false;
         $title = pht('Rescind Token');
     } else {
         $is_give = true;
         $title = pht('Give Token');
     }
     $done_uri = $handle->getURI();
     if ($request->isDialogFormPost()) {
         $content_source = PhabricatorContentSource::newFromRequest($request);
         $editor = id(new PhabricatorTokenGivenEditor())->setActor($viewer)->setContentSource($content_source);
         if ($is_give) {
             $token_phid = $request->getStr('tokenPHID');
             $editor->addToken($handle->getPHID(), $token_phid);
         } else {
             $editor->deleteToken($handle->getPHID());
         }
         return id(new AphrontReloadResponse())->setURI($done_uri);
     }
     if ($is_give) {
         $dialog = $this->buildGiveTokenDialog();
     } else {
         $dialog = $this->buildRescindTokenDialog(head($current));
     }
     $dialog->setUser($viewer);
     $dialog->addCancelButton($done_uri);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $xaction = id(new PhabricatorObjectQuery())->setViewer($viewer)->withPHIDs(array($request->getURIData('phid')))->executeOne();
     if (!$xaction) {
         return new Aphront404Response();
     }
     if (!$xaction->getComment()) {
         // You can't currently edit a transaction which doesn't have a comment.
         // Some day you may be able to edit the visibility.
         return new Aphront404Response();
     }
     if ($xaction->getComment()->getIsRemoved()) {
         // You can't edit history of a transaction with a removed comment.
         return new Aphront400Response();
     }
     $phid = $xaction->getObjectPHID();
     $handles = $viewer->loadHandles(array($phid));
     $obj_handle = $handles[$phid];
     if ($request->isDialogFormPost()) {
         $text = $request->getStr('text');
         $comment = $xaction->getApplicationTransactionCommentObject();
         $comment->setContent($text);
         if (!strlen($text)) {
             $comment->setIsDeleted(true);
         }
         $editor = id(new PhabricatorApplicationTransactionCommentEditor())->setActor($viewer)->setContentSource(PhabricatorContentSource::newFromRequest($request))->applyEdit($xaction, $comment);
         if ($request->isAjax()) {
             return id(new AphrontAjaxResponse())->setContent(array());
         } else {
             return id(new AphrontReloadResponse())->setURI($obj_handle->getURI());
         }
     }
     $form = id(new AphrontFormView())->setUser($viewer)->setFullWidth(true)->appendControl(id(new PhabricatorRemarkupControl())->setName('text')->setValue($xaction->getComment()->getContent()));
     return $this->newDialog()->setTitle(pht('Edit Comment'))->addHiddenInput('anchor', $request->getStr('anchor'))->appendForm($form)->addSubmitButton(pht('Save Changes'))->addCancelButton($obj_handle->getURI());
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $id = $request->getURIData('id');
     $action = $request->getURIData('action');
     $buildable = id(new HarbormasterBuildableQuery())->setViewer($viewer)->withIDs(array($id))->needBuilds(true)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$buildable) {
         return new Aphront404Response();
     }
     $issuable = array();
     foreach ($buildable->getBuilds() as $build) {
         switch ($action) {
             case HarbormasterBuildCommand::COMMAND_RESTART:
                 if ($build->canRestartBuild()) {
                     $issuable[] = $build;
                 }
                 break;
             case HarbormasterBuildCommand::COMMAND_PAUSE:
                 if ($build->canPauseBuild()) {
                     $issuable[] = $build;
                 }
                 break;
             case HarbormasterBuildCommand::COMMAND_RESUME:
                 if ($build->canResumeBuild()) {
                     $issuable[] = $build;
                 }
                 break;
             case HarbormasterBuildCommand::COMMAND_ABORT:
                 if ($build->canAbortBuild()) {
                     $issuable[] = $build;
                 }
                 break;
             default:
                 return new Aphront400Response();
         }
     }
     $return_uri = '/' . $buildable->getMonogram();
     if ($request->isDialogFormPost() && $issuable) {
         $editor = id(new HarbormasterBuildableTransactionEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true);
         $xaction = id(new HarbormasterBuildableTransaction())->setTransactionType(HarbormasterBuildableTransaction::TYPE_COMMAND)->setNewValue($action);
         $editor->applyTransactions($buildable, array($xaction));
         $build_editor = id(new HarbormasterBuildTransactionEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true);
         foreach ($issuable as $build) {
             $xaction = id(new HarbormasterBuildTransaction())->setTransactionType(HarbormasterBuildTransaction::TYPE_COMMAND)->setNewValue($action);
             $build_editor->applyTransactions($build, array($xaction));
         }
         return id(new AphrontRedirectResponse())->setURI($return_uri);
     }
     switch ($action) {
         case HarbormasterBuildCommand::COMMAND_RESTART:
             if ($issuable) {
                 $title = pht('Really restart all builds?');
                 $body = pht('Progress on all builds will be discarded, and all builds will ' . 'restart. Side effects of the builds will occur again. Really ' . 'restart all builds?');
                 $submit = pht('Restart All Builds');
             } else {
                 $title = pht('Unable to Restart Builds');
                 $body = pht('No builds can be restarted.');
             }
             break;
         case HarbormasterBuildCommand::COMMAND_PAUSE:
             if ($issuable) {
                 $title = pht('Really pause all builds?');
                 $body = pht('If you pause all builds, work will halt once the current steps ' . 'complete. You can resume the builds later.');
                 $submit = pht('Pause All Builds');
             } else {
                 $title = pht('Unable to Pause Builds');
                 $body = pht('No builds can be paused.');
             }
             break;
         case HarbormasterBuildCommand::COMMAND_ABORT:
             if ($issuable) {
                 $title = pht('Really abort all builds?');
                 $body = pht('If you abort all builds, work will halt immediately. Work ' . 'will be discarded, and builds must be completely restarted.');
                 $submit = pht('Abort All Builds');
             } else {
                 $title = pht('Unable to Abort Builds');
                 $body = pht('No builds can be aborted.');
             }
             break;
         case HarbormasterBuildCommand::COMMAND_RESUME:
             if ($issuable) {
                 $title = pht('Really resume all builds?');
                 $body = pht('Work will continue on all builds. Really resume?');
                 $submit = pht('Resume All Builds');
             } else {
                 $title = pht('Unable to Resume Builds');
                 $body = pht('No builds can be resumed.');
             }
             break;
     }
     $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle($title)->appendChild($body)->addCancelButton($return_uri);
     if ($issuable) {
         $dialog->addSubmitButton($submit);
     }
     return id(new AphrontDialogResponse())->setDialog($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);
 }
 private function returnNewAddressResponse(AphrontRequest $request, PhutilURI $uri, $new)
 {
     $user = $this->getUser();
     $viewer = $this->getViewer();
     $e_email = true;
     $email = null;
     $errors = array();
     if ($request->isDialogFormPost()) {
         $email = trim($request->getStr('email'));
         if ($new == 'verify') {
             // The user clicked "Done" from the "an email has been sent" dialog.
             return id(new AphrontReloadResponse())->setURI($uri);
         }
         PhabricatorSystemActionEngine::willTakeAction(array($viewer->getPHID()), new PhabricatorSettingsAddEmailAction(), 1);
         if (!strlen($email)) {
             $e_email = pht('Required');
             $errors[] = pht('Email is required.');
         } else {
             if (!PhabricatorUserEmail::isValidAddress($email)) {
                 $e_email = pht('Invalid');
                 $errors[] = PhabricatorUserEmail::describeValidAddresses();
             } else {
                 if (!PhabricatorUserEmail::isAllowedAddress($email)) {
                     $e_email = pht('Disallowed');
                     $errors[] = PhabricatorUserEmail::describeAllowedAddresses();
                 }
             }
         }
         if ($e_email === true) {
             $application_email = id(new PhabricatorMetaMTAApplicationEmailQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withAddresses(array($email))->executeOne();
             if ($application_email) {
                 $e_email = pht('In Use');
                 $errors[] = $application_email->getInUseMessage();
             }
         }
         if (!$errors) {
             $object = id(new PhabricatorUserEmail())->setAddress($email)->setIsVerified(0);
             // If an administrator is editing a mailing list, automatically verify
             // the address.
             if ($viewer->getPHID() != $user->getPHID()) {
                 if ($viewer->getIsAdmin()) {
                     $object->setIsVerified(1);
                 }
             }
             try {
                 id(new PhabricatorUserEditor())->setActor($viewer)->addEmail($user, $object);
                 if ($object->getIsVerified()) {
                     // If we autoverified the address, just reload the page.
                     return id(new AphrontReloadResponse())->setURI($uri);
                 }
                 $object->sendVerificationEmail($user);
                 $dialog = id(new AphrontDialogView())->setUser($user)->addHiddenInput('new', 'verify')->setTitle(pht('Verification Email Sent'))->appendChild(phutil_tag('p', array(), pht('A verification email has been sent. Click the link in the ' . 'email to verify your address.')))->setSubmitURI($uri)->addSubmitButton(pht('Done'));
                 return id(new AphrontDialogResponse())->setDialog($dialog);
             } catch (AphrontDuplicateKeyQueryException $ex) {
                 $e_email = pht('Duplicate');
                 $errors[] = pht('Another user already has this email.');
             }
         }
     }
     if ($errors) {
         $errors = id(new PHUIInfoView())->setErrors($errors);
     }
     $form = id(new PHUIFormLayoutView())->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Email'))->setName('email')->setValue($email)->setCaption(PhabricatorUserEmail::describeAllowedAddresses())->setError($e_email));
     $dialog = id(new AphrontDialogView())->setUser($viewer)->addHiddenInput('new', 'true')->setTitle(pht('New Address'))->appendChild($errors)->appendChild($form)->addSubmitButton(pht('Save'))->addCancelButton($uri);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 private function returnDeleteAddressResponse(AphrontRequest $request, PhutilURI $uri, $email_object_id)
 {
     $viewer = $this->getViewer();
     $email_object = id(new PhabricatorMetaMTAApplicationEmailQuery())->setViewer($viewer)->withIDs(array($email_object_id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$email_object) {
         return new Aphront404Response();
     }
     if ($request->isDialogFormPost()) {
         $engine = new PhabricatorDestructionEngine();
         $engine->destroyObject($email_object);
         return id(new AphrontRedirectResponse())->setURI($uri);
     }
     $dialog = id(new AphrontDialogView())->setUser($viewer)->addHiddenInput('delete', $email_object_id)->setTitle(pht('Delete Address'))->appendParagraph(pht('Are you sure you want to delete this email address?'))->addSubmitButton(pht('Delete'))->addCancelButton($uri);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $action = $request->getURIData('action');
     $project = id(new PhabricatorProjectQuery())->setViewer($viewer)->withIDs(array($id))->needMembers(true)->needWatchers(true)->executeOne();
     if (!$project) {
         return new Aphront404Response();
     }
     $via = $request->getStr('via');
     if ($via == 'profile') {
         $done_uri = "/project/profile/{$id}/";
     } else {
         $done_uri = "/project/members/{$id}/";
     }
     $is_watcher = $project->isUserWatcher($viewer->getPHID());
     $is_ancestor = $project->isUserAncestorWatcher($viewer->getPHID());
     if ($is_ancestor && !$is_watcher) {
         $ancestor_phid = $project->getWatchedAncestorPHID($viewer->getPHID());
         $handles = $viewer->loadHandles(array($ancestor_phid));
         $ancestor_handle = $handles[$ancestor_phid];
         return $this->newDialog()->setTitle(pht('Watching Ancestor'))->appendParagraph(pht('You are already watching %s, an ancestor of this project, and ' . 'are thus watching all of its subprojects.', $ancestor_handle->renderTag()->render()))->addCancelbutton($done_uri);
     }
     if ($request->isDialogFormPost()) {
         $edge_action = null;
         switch ($action) {
             case 'watch':
                 $edge_action = '+';
                 break;
             case 'unwatch':
                 $edge_action = '-';
                 break;
         }
         $type_watcher = PhabricatorObjectHasWatcherEdgeType::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_watcher)->setNewValue($member_spec);
         $editor = id(new PhabricatorProjectTransactionEditor($project))->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true)->applyTransactions($project, $xactions);
         return id(new AphrontRedirectResponse())->setURI($done_uri);
     }
     $dialog = null;
     switch ($action) {
         case 'watch':
             $title = pht('Watch Project?');
             $body = array();
             $body[] = pht('Watching a project will let you monitor it closely. You will ' . 'receive email and notifications about changes to every object ' . 'tagged with projects you watch.');
             $body[] = pht('Watching a project also watches all subprojects and milestones of ' . 'that project.');
             $submit = pht('Watch Project');
             break;
         case 'unwatch':
             $title = pht('Unwatch Project?');
             $body = pht('You will no longer receive email or notifications about every ' . 'object associated with this project.');
             $submit = pht('Unwatch Project');
             break;
         default:
             return new Aphront404Response();
     }
     $dialog = $this->newDialog()->setTitle($title)->addHiddenInput('via', $via)->addCancelButton($done_uri)->addSubmitButton($submit);
     foreach ((array) $body as $paragraph) {
         $dialog->appendParagraph($paragraph);
     }
     return $dialog;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $id = $request->getURIData('id');
     $action = $request->getURIData('action');
     $via = $request->getURIData('via');
     $build = id(new HarbormasterBuildQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$build) {
         return new Aphront404Response();
     }
     switch ($action) {
         case HarbormasterBuildCommand::COMMAND_RESTART:
             $can_issue = $build->canRestartBuild();
             break;
         case HarbormasterBuildCommand::COMMAND_PAUSE:
             $can_issue = $build->canPauseBuild();
             break;
         case HarbormasterBuildCommand::COMMAND_RESUME:
             $can_issue = $build->canResumeBuild();
             break;
         case HarbormasterBuildCommand::COMMAND_ABORT:
             $can_issue = $build->canAbortBuild();
             break;
         default:
             return new Aphront400Response();
     }
     $build->assertCanIssueCommand($viewer, $action);
     switch ($via) {
         case 'buildable':
             $return_uri = '/' . $build->getBuildable()->getMonogram();
             break;
         default:
             $return_uri = $this->getApplicationURI('/build/' . $build->getID() . '/');
             break;
     }
     if ($request->isDialogFormPost() && $can_issue) {
         $editor = id(new HarbormasterBuildTransactionEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true);
         $xaction = id(new HarbormasterBuildTransaction())->setTransactionType(HarbormasterBuildTransaction::TYPE_COMMAND)->setNewValue($action);
         $editor->applyTransactions($build, array($xaction));
         return id(new AphrontRedirectResponse())->setURI($return_uri);
     }
     switch ($action) {
         case HarbormasterBuildCommand::COMMAND_RESTART:
             if ($can_issue) {
                 $title = pht('Really restart build?');
                 $body = pht('Progress on this build will be discarded and the build will ' . 'restart. Side effects of the build will occur again. Really ' . 'restart build?');
                 $submit = pht('Restart Build');
             } else {
                 $title = pht('Unable to Restart Build');
                 if ($build->isRestarting()) {
                     $body = pht('This build is already restarting. You can not reissue a ' . 'restart command to a restarting build.');
                 } else {
                     $body = pht('You can not restart this build.');
                 }
             }
             break;
         case HarbormasterBuildCommand::COMMAND_ABORT:
             if ($can_issue) {
                 $title = pht('Really abort build?');
                 $body = pht('Progress on this build will be discarded. Really ' . 'abort build?');
                 $submit = pht('Abort Build');
             } else {
                 $title = pht('Unable to Abort Build');
                 $body = pht('You can not abort this build.');
             }
             break;
         case HarbormasterBuildCommand::COMMAND_PAUSE:
             if ($can_issue) {
                 $title = pht('Really pause build?');
                 $body = pht('If you pause this build, work will halt once the current steps ' . 'complete. You can resume the build later.');
                 $submit = pht('Pause Build');
             } else {
                 $title = pht('Unable to Pause Build');
                 if ($build->isComplete()) {
                     $body = pht('This build is already complete. You can not pause a completed ' . 'build.');
                 } else {
                     if ($build->isPaused()) {
                         $body = pht('This build is already paused. You can not pause a build which ' . 'has already been paused.');
                     } else {
                         if ($build->isPausing()) {
                             $body = pht('This build is already pausing. You can not reissue a pause ' . 'command to a pausing build.');
                         } else {
                             $body = pht('This build can not be paused.');
                         }
                     }
                 }
             }
             break;
         case HarbormasterBuildCommand::COMMAND_RESUME:
             if ($can_issue) {
                 $title = pht('Really resume build?');
                 $body = pht('Work will continue on the build. Really resume?');
                 $submit = pht('Resume Build');
             } else {
                 $title = pht('Unable to Resume Build');
                 if ($build->isResuming()) {
                     $body = pht('This build is already resuming. You can not reissue a resume ' . 'command to a resuming build.');
                 } else {
                     if (!$build->isPaused()) {
                         $body = pht('This build is not paused. You can only resume a paused ' . 'build.');
                     }
                 }
             }
             break;
     }
     $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle($title)->appendChild($body)->addCancelButton($return_uri);
     if ($can_issue) {
         $dialog->addSubmitButton($submit);
     }
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }