public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $ids = $args->getArg('id');
     if (!$ids) {
         throw new PhutilArgumentUsageException(pht("Use the '%s' flag to specify one or more SMS messages to show.", '--id'));
     }
     $messages = id(new PhabricatorSMS())->loadAllWhere('id IN (%Ld)', $ids);
     if ($ids) {
         $ids = array_fuse($ids);
         $missing = array_diff_key($ids, $messages);
         if ($missing) {
             throw new PhutilArgumentUsageException(pht('Some specified SMS messages do not exist: %s', implode(', ', array_keys($missing))));
         }
     }
     $last_key = last_key($messages);
     foreach ($messages as $message_key => $message) {
         $info = array();
         $info[] = pht('PROPERTIES');
         $info[] = pht('ID: %d', $message->getID());
         $info[] = pht('Status: %s', $message->getSendStatus());
         $info[] = pht('To: %s', $message->getToNumber());
         $info[] = pht('From: %s', $message->getFromNumber());
         $info[] = null;
         $info[] = pht('BODY');
         $info[] = $message->getBody();
         $info[] = null;
         $console->writeOut('%s', implode("\n", $info));
         if ($message_key != $last_key) {
             $console->writeOut("\n%s\n\n", str_repeat('-', 80));
         }
     }
 }
 protected function doWork()
 {
     $data = $this->getTaskData();
     $viewer = PhabricatorUser::getOmnipotentUser();
     $address = idx($data, 'address');
     $author_phid = idx($data, 'authorPHID');
     $author = id(new PhabricatorPeopleQuery())->setViewer($viewer)->withPHIDs(array($author_phid))->executeOne();
     if (!$author) {
         throw new PhabricatorWorkerPermanentFailureException(pht('Invite has invalid author PHID ("%s").', $author_phid));
     }
     $invite = id(new PhabricatorAuthInviteQuery())->setViewer($viewer)->withEmailAddresses(array($address))->executeOne();
     if ($invite) {
         // If we're inviting a user who has already been invited, we just
         // regenerate their invite code.
         $invite->regenerateVerificationCode();
     } else {
         // Otherwise, we're creating a new invite.
         $invite = id(new PhabricatorAuthInvite())->setEmailAddress($address);
     }
     // Whether this is a new invite or not, tag this most recent author as
     // the invite author.
     $invite->setAuthorPHID($author_phid);
     $code = $invite->getVerificationCode();
     $invite_uri = '/auth/invite/' . $code . '/';
     $invite_uri = PhabricatorEnv::getProductionURI($invite_uri);
     $template = idx($data, 'template');
     $template = str_replace('{$INVITE_URI}', $invite_uri, $template);
     $invite->save();
     $mail = id(new PhabricatorMetaMTAMail())->addRawTos(array($invite->getEmailAddress()))->setForceDelivery(true)->setSubject(pht('[Phabricator] %s has invited you to join Phabricator', $author->getFullName()))->setBody($template)->saveAndSend();
 }
 protected function buildApplicationCrumbs()
 {
     $crumbs = parent::buildApplicationCrumbs();
     $can_create = $this->hasApplicationCapability(HarbormasterManagePlansCapability::CAPABILITY);
     $crumbs->addAction(id(new PHUIListItemView())->setName(pht('New Build Plan'))->setHref($this->getApplicationURI('plan/edit/'))->setDisabled(!$can_create)->setWorkflow(!$can_create)->setIcon('fa-plus-square'));
     return $crumbs;
 }
 private function buildChartForm()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $table = new PhabricatorFactRaw();
     $conn_r = $table->establishConnection('r');
     $table_name = $table->getTableName();
     $facts = queryfx_all($conn_r, 'SELECT DISTINCT factType from %T', $table_name);
     $specs = PhabricatorFactSpec::newSpecsForFactTypes(PhabricatorFactEngine::loadAllEngines(), ipull($facts, 'factType'));
     $options = array();
     foreach ($specs as $spec) {
         if ($spec->getUnit() == PhabricatorFactSpec::UNIT_COUNT) {
             $options[$spec->getType()] = $spec->getName();
         }
     }
     if (!$options) {
         return id(new AphrontErrorView())->setSeverity(AphrontErrorView::SEVERITY_NOTICE)->setTitle(pht('No Chartable Facts'))->appendChild('<p>' . pht('There are no facts that can be plotted yet.') . '</p>');
     }
     $form = id(new AphrontFormView())->setUser($user)->appendChild(id(new AphrontFormSelectControl())->setLabel('Y-Axis')->setName('y1')->setOptions($options))->appendChild(id(new AphrontFormSubmitControl())->setValue('Plot Chart'));
     $panel = new AphrontPanelView();
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->setHeader('Plot Chart');
     return $panel;
 }
 private function renderItemCommonProperties(PhabricatorUser $viewer, NuanceItem $item, PHUIPropertyListView $view)
 {
     $complaint = $item->getNuanceProperty('complaint');
     $complaint = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($complaint), 'default', $viewer);
     $view->addSectionHeader(pht('Complaint'), 'fa-exclamation-circle');
     $view->addTextContent($complaint);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getUser();
     $file = PhabricatorFile::initializeNewFile();
     $e_file = true;
     $errors = array();
     if ($request->isFormPost()) {
         $view_policy = $request->getStr('viewPolicy');
         if (!$request->getFileExists('file')) {
             $e_file = pht('Required');
             $errors[] = pht('You must select a file to upload.');
         } else {
             $file = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'file'), array('name' => $request->getStr('name'), 'authorPHID' => $viewer->getPHID(), 'viewPolicy' => $view_policy, 'isExplicitUpload' => true));
         }
         if (!$errors) {
             return id(new AphrontRedirectResponse())->setURI($file->getInfoURI());
         }
         $file->setViewPolicy($view_policy);
     }
     $support_id = celerity_generate_unique_node_id();
     $instructions = id(new AphrontFormMarkupControl())->setControlID($support_id)->setControlStyle('display: none')->setValue(hsprintf('<br /><br /><strong>%s</strong> %s<br /><br />', pht('Drag and Drop:'), pht('You can also upload files by dragging and dropping them from your ' . 'desktop onto this page or the Phabricator home page.')));
     $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($file)->execute();
     $form = id(new AphrontFormView())->setUser($viewer)->setEncType('multipart/form-data')->appendChild(id(new AphrontFormFileControl())->setLabel(pht('File'))->setName('file')->setError($e_file))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setValue($request->getStr('name')))->appendChild(id(new AphrontFormPolicyControl())->setUser($viewer)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicyObject($file)->setPolicies($policies)->setName('viewPolicy'))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Upload'))->addCancelButton('/file/'))->appendChild($instructions);
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Upload'), $request->getRequestURI());
     $crumbs->setBorder(true);
     $title = pht('Upload File');
     $global_upload = id(new PhabricatorGlobalUploadTargetView())->setUser($viewer)->setShowIfSupportedID($support_id);
     $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('File'))->setFormErrors($errors)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setForm($form);
     $header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon('fa-upload');
     $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($form_box, $global_upload));
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
 public function getCustomFieldList($role)
 {
     if (empty($this->lists[$role])) {
         throw new PhabricatorCustomFieldNotAttachedException(pht("Role list '%s' is not available!", $role));
     }
     return $this->lists[$role];
 }
 public function handleRequest(AphrontRequest $request)
 {
     $response = $this->loadDiffusionContextForEdit();
     if ($response) {
         return $response;
     }
     $viewer = $this->getViewer();
     $drequest = $this->getDiffusionRequest();
     $repository = $drequest->getRepository();
     if (!$repository->supportsStaging()) {
         return new Aphront404Response();
     }
     $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
     $v_area = $repository->getHumanReadableDetail('staging-uri');
     if ($request->isFormPost()) {
         $v_area = $request->getStr('area');
         $xactions = array();
         $template = id(new PhabricatorRepositoryTransaction());
         $type_encoding = PhabricatorRepositoryTransaction::TYPE_STAGING_URI;
         $xactions[] = id(clone $template)->setTransactionType($type_encoding)->setNewValue($v_area);
         id(new PhabricatorRepositoryEditor())->setContinueOnNoEffect(true)->setContentSourceFromRequest($request)->setActor($viewer)->applyTransactions($repository, $xactions);
         return id(new AphrontRedirectResponse())->setURI($edit_uri);
     }
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Edit Staging'));
     $title = pht('Edit %s', $repository->getName());
     $form = id(new AphrontFormView())->setUser($viewer)->appendRemarkupInstructions(pht("To make it easier to run integration tests and builds on code " . "under review, you can configure a **Staging Area**. When `arc` " . "creates a diff, it will push a copy of the changes to the " . "configured staging area with a corresponding tag." . "\n\n" . "IMPORTANT: This feature is new, experimental, and not supported. " . "Use it at your own risk."))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Staging Area URI'))->setName('area')->setValue($v_area))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Save'))->addCancelButton($edit_uri));
     $object_box = id(new PHUIObjectBoxView())->setHeaderText($title)->setForm($form);
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($object_box);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $dashboard = id(new PhabricatorDashboardQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$dashboard) {
         return new Aphront404Response();
     }
     $view_uri = $this->getApplicationURI('manage/' . $dashboard->getID() . '/');
     if ($request->isFormPost()) {
         if ($dashboard->isArchived()) {
             $new_status = PhabricatorDashboard::STATUS_ACTIVE;
         } else {
             $new_status = PhabricatorDashboard::STATUS_ARCHIVED;
         }
         $xactions = array();
         $xactions[] = id(new PhabricatorDashboardTransaction())->setTransactionType(PhabricatorDashboardTransaction::TYPE_STATUS)->setNewValue($new_status);
         id(new PhabricatorDashboardTransactionEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true)->applyTransactions($dashboard, $xactions);
         return id(new AphrontRedirectResponse())->setURI($view_uri);
     }
     if ($dashboard->isArchived()) {
         $title = pht('Activate Dashboard');
         $body = pht('This dashboard will become active again.');
         $button = pht('Activate Dashboard');
     } else {
         $title = pht('Archive Dashboard');
         $body = pht('This dashboard will be marked as archived.');
         $button = pht('Archive Dashboard');
     }
     return $this->newDialog()->setTitle($title)->appendChild($body)->addCancelButton($view_uri)->addSubmitButton($button);
 }
 public function getQuickCreateItems(PhabricatorUser $viewer)
 {
     $items = array();
     $item = id(new PHUIListItemView())->setName(pht('Conpherence Room'))->setIcon('fa-comments')->setWorkflow(true)->setHref($this->getBaseURI() . 'new/');
     $items[] = $item;
     return $items;
 }
 private function attemptLand($revision, $request)
 {
     $status = $revision->getStatus();
     if ($status != ArcanistDifferentialRevisionStatus::ACCEPTED) {
         throw new Exception(pht('Only Accepted revisions can be landed.'));
     }
     $repository = $revision->getRepository();
     if ($repository === null) {
         throw new Exception(pht('Revision is not attached to a repository.'));
     }
     $can_push = PhabricatorPolicyFilter::hasCapability($request->getUser(), $repository, DiffusionPushCapability::CAPABILITY);
     if (!$can_push) {
         throw new Exception(pht('You do not have permission to push to this repository.'));
     }
     $lock = $this->lockRepository($repository);
     try {
         $response = $this->pushStrategy->processLandRequest($request, $revision, $repository);
     } catch (Exception $e) {
         $lock->unlock();
         throw $e;
     }
     $lock->unlock();
     $looksoon = new ConduitCall('diffusion.looksoon', array('callsigns' => array($repository->getCallsign())));
     $looksoon->setUser($request->getUser());
     $looksoon->execute();
     return $response;
 }
 public function buildCustomEditFields(PhabricatorEditEngine $engine, PhabricatorApplicationTransactionInterface $object)
 {
     $viewer = $engine->getViewer();
     $editor = $object->getApplicationTransactionEditor();
     $types = $editor->getTransactionTypesForObject($object);
     $types = array_fuse($types);
     $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($object)->execute();
     $map = array(PhabricatorTransactions::TYPE_VIEW_POLICY => array('key' => 'policy.view', 'aliases' => array('view'), 'capability' => PhabricatorPolicyCapability::CAN_VIEW, 'label' => pht('View Policy'), 'description' => pht('Controls who can view the object.'), 'edit' => 'view'), PhabricatorTransactions::TYPE_EDIT_POLICY => array('key' => 'policy.edit', 'aliases' => array('edit'), 'capability' => PhabricatorPolicyCapability::CAN_EDIT, 'label' => pht('Edit Policy'), 'description' => pht('Controls who can edit the object.'), 'edit' => 'edit'), PhabricatorTransactions::TYPE_JOIN_POLICY => array('key' => 'policy.join', 'aliases' => array('join'), 'capability' => PhabricatorPolicyCapability::CAN_JOIN, 'label' => pht('Join Policy'), 'description' => pht('Controls who can join the object.'), 'edit' => 'join'));
     $fields = array();
     foreach ($map as $type => $spec) {
         if (empty($types[$type])) {
             continue;
         }
         $capability = $spec['capability'];
         $key = $spec['key'];
         $aliases = $spec['aliases'];
         $label = $spec['label'];
         $description = $spec['description'];
         $edit = $spec['edit'];
         $policy_field = id(new PhabricatorPolicyEditField())->setKey($key)->setLabel($label)->setDescription($description)->setAliases($aliases)->setIsCopyable(true)->setCapability($capability)->setPolicies($policies)->setTransactionType($type)->setEditTypeKey($edit)->setValue($object->getPolicy($capability));
         $fields[] = $policy_field;
         if (!$object instanceof PhabricatorSpacesInterface) {
             if ($capability == PhabricatorPolicyCapability::CAN_VIEW) {
                 $type_space = PhabricatorTransactions::TYPE_SPACE;
                 if (isset($types[$type_space])) {
                     $space_field = id(new PhabricatorSpaceEditField())->setKey('spacePHID')->setLabel(pht('Space'))->setEditTypeKey('space')->setDescription(pht('Shifts the object in the Spaces application.'))->setIsCopyable(true)->setIsReorderable(false)->setAliases(array('space', 'policy.space'))->setTransactionType($type_space)->setValue($object->getSpacePHID());
                     $fields[] = $space_field;
                     $policy_field->setSpaceField($space_field);
                 }
             }
         }
     }
     return $fields;
 }
 private function buildActionList(PhabricatorUser $user)
 {
     $viewer = $this->getViewer();
     $actions = id(new PhabricatorActionListView())->setUser($viewer);
     $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $user, PhabricatorPolicyCapability::CAN_EDIT);
     $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-pencil')->setName(pht('Edit Profile'))->setHref($this->getApplicationURI('editprofile/' . $user->getID() . '/'))->setDisabled(!$can_edit)->setWorkflow(!$can_edit));
     $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-picture-o')->setName(pht('Edit Profile Picture'))->setHref($this->getApplicationURI('picture/' . $user->getID() . '/'))->setDisabled(!$can_edit)->setWorkflow(!$can_edit));
     $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-wrench')->setName(pht('Edit Settings'))->setDisabled(!$can_edit)->setWorkflow(!$can_edit)->setHref('/settings/' . $user->getID() . '/'));
     if ($user->getIsAdmin()) {
         $empower_icon = 'fa-arrow-circle-o-down';
         $empower_name = pht('Remove Administrator');
     } else {
         $empower_icon = 'fa-arrow-circle-o-up';
         $empower_name = pht('Make Administrator');
     }
     $is_admin = $viewer->getIsAdmin();
     $is_self = $user->getPHID() === $viewer->getPHID();
     $can_admin = $is_admin && !$is_self;
     $actions->addAction(id(new PhabricatorActionView())->setIcon($empower_icon)->setName($empower_name)->setDisabled(!$can_admin)->setWorkflow(true)->setHref($this->getApplicationURI('empower/' . $user->getID() . '/')));
     $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-tag')->setName(pht('Change Username'))->setDisabled(!$is_admin)->setWorkflow(true)->setHref($this->getApplicationURI('rename/' . $user->getID() . '/')));
     if ($user->getIsDisabled()) {
         $disable_icon = 'fa-check-circle-o';
         $disable_name = pht('Enable User');
     } else {
         $disable_icon = 'fa-ban';
         $disable_name = pht('Disable User');
     }
     $actions->addAction(id(new PhabricatorActionView())->setIcon($disable_icon)->setName($disable_name)->setDisabled(!$can_admin)->setWorkflow(true)->setHref($this->getApplicationURI('disable/' . $user->getID() . '/')));
     $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-times')->setName(pht('Delete User'))->setDisabled(!$can_admin)->setWorkflow(true)->setHref($this->getApplicationURI('delete/' . $user->getID() . '/')));
     $can_welcome = $is_admin && $user->canEstablishWebSessions();
     $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-envelope')->setName(pht('Send Welcome Email'))->setWorkflow(true)->setDisabled(!$can_welcome)->setHref($this->getApplicationURI('welcome/' . $user->getID() . '/')));
     return $actions;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($this->id) {
         $question = id(new PonderQuestionQuery())->setViewer($user)->withIDs(array($this->id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
         if (!$question) {
             return new Aphront404Response();
         }
         $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs($question->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
         $v_projects = array_reverse($v_projects);
     } else {
         $question = id(new PonderQuestion())->setStatus(PonderQuestionStatus::STATUS_OPEN)->setAuthorPHID($user->getPHID())->setVoteCount(0)->setAnswerCount(0)->setHeat(0.0);
         $v_projects = array();
     }
     $v_title = $question->getTitle();
     $v_content = $question->getContent();
     $errors = array();
     $e_title = true;
     if ($request->isFormPost()) {
         $v_title = $request->getStr('title');
         $v_content = $request->getStr('content');
         $v_projects = $request->getArr('projects');
         $len = phutil_utf8_strlen($v_title);
         if ($len < 1) {
             $errors[] = pht('Title must not be empty.');
             $e_title = pht('Required');
         } else {
             if ($len > 255) {
                 $errors[] = pht('Title is too long.');
                 $e_title = pht('Too Long');
             }
         }
         if (!$errors) {
             $template = id(new PonderQuestionTransaction());
             $xactions = array();
             $xactions[] = id(clone $template)->setTransactionType(PonderQuestionTransaction::TYPE_TITLE)->setNewValue($v_title);
             $xactions[] = id(clone $template)->setTransactionType(PonderQuestionTransaction::TYPE_CONTENT)->setNewValue($v_content);
             $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
             $xactions[] = id(new PonderQuestionTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $proj_edge_type)->setNewValue(array('=' => array_fuse($v_projects)));
             $editor = id(new PonderQuestionEditor())->setActor($user)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true);
             $editor->applyTransactions($question, $xactions);
             return id(new AphrontRedirectResponse())->setURI('/Q' . $question->getID());
         }
     }
     $form = id(new AphrontFormView())->setUser($user)->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Question'))->setName('title')->setValue($v_title)->setError($e_title))->appendChild(id(new PhabricatorRemarkupControl())->setUser($user)->setName('content')->setID('content')->setValue($v_content)->setLabel(pht('Description'))->setUser($user));
     $form->appendControl(id(new AphrontFormTokenizerControl())->setLabel(pht('Projects'))->setName('projects')->setValue($v_projects)->setDatasource(new PhabricatorProjectDatasource()));
     $form->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($this->getApplicationURI())->setValue(pht('Ask Away!')));
     $preview = id(new PHUIRemarkupPreviewPanel())->setHeader(pht('Question Preview'))->setControlID('content')->setPreviewURI($this->getApplicationURI('preview/'));
     $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Ask New Question'))->setFormErrors($errors)->setForm($form);
     $crumbs = $this->buildApplicationCrumbs();
     $id = $question->getID();
     if ($id) {
         $crumbs->addTextCrumb("Q{$id}", "/Q{$id}");
         $crumbs->addTextCrumb(pht('Edit'));
     } else {
         $crumbs->addTextCrumb(pht('Ask Question'));
     }
     return $this->buildApplicationPage(array($crumbs, $form_box, $preview), array('title' => pht('Ask New Question')));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $provider_config = id(new PhortunePaymentProviderConfigQuery())->setViewer($viewer)->withIDs(array($this->id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$provider_config) {
         return new Aphront404Response();
     }
     $merchant = $provider_config->getMerchant();
     $merchant_id = $merchant->getID();
     $cancel_uri = $this->getApplicationURI("merchant/{$merchant_id}/");
     $provider = $provider_config->buildProvider();
     if ($request->isFormPost()) {
         $new_status = !$provider_config->getIsEnabled();
         $xactions = array();
         $xactions[] = id(new PhortunePaymentProviderConfigTransaction())->setTransactionType(PhortunePaymentProviderConfigTransaction::TYPE_ENABLE)->setNewValue($new_status);
         $editor = id(new PhortunePaymentProviderConfigEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true);
         $editor->applyTransactions($provider_config, $xactions);
         return id(new AphrontRedirectResponse())->setURI($cancel_uri);
     }
     if ($provider_config->getIsEnabled()) {
         $title = pht('Disable Provider?');
         $body = pht('If you disable this payment provider, users will no longer be able ' . 'to use it to make new payments.');
         $button = pht('Disable Provider');
     } else {
         $title = pht('Enable Provider?');
         $body = pht('If you enable this payment provider, users will be able to use it to ' . 'make new payments.');
         $button = pht('Enable Provider');
     }
     return $this->newDialog()->setTitle($title)->appendParagraph($body)->addSubmitButton($button)->addCancelButton($cancel_uri);
 }
 private function buildPanels()
 {
     $panel_specs = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorSettingsPanel')->setConcreteOnly(true)->selectAndLoadSymbols();
     $panels = array();
     foreach ($panel_specs as $spec) {
         $class = newv($spec['name'], array());
         $panels[] = $class->buildPanels();
     }
     $panels = array_mergev($panels);
     $panels = mpull($panels, null, 'getPanelKey');
     $result = array();
     foreach ($panels as $key => $panel) {
         $panel->setUser($this->user);
         if (!$panel->isEnabled()) {
             continue;
         }
         if (!$this->isSelf()) {
             if (!$panel->isEditableByAdministrators()) {
                 continue;
             }
         }
         if (!empty($result[$key])) {
             throw new Exception(pht("Two settings panels share the same panel key ('%s'): %s, %s.", $key, get_class($panel), get_class($result[$key])));
         }
         $result[$key] = $panel;
     }
     $result = msort($result, 'getPanelSortKey');
     if (!$result) {
         throw new Exception(pht('No settings panels are available.'));
     }
     return $result;
 }
    protected function buildCustomEditFields($object)
    {
        $paths_help = pht(<<<EOTEXT
When updating the paths for a package, pass a list of dictionaries like
this as the `value` for the transaction:

```lang=json, name="Example Paths Value"
[
  {
    "repositoryPHID": "PHID-REPO-1234",
    "path": "/path/to/directory/",
    "excluded": false
  },
  {
    "repositoryPHID": "PHID-REPO-1234",
    "path": "/another/example/path/",
    "excluded": false
  }
]
```

This transaction will set the paths to the list you provide, overwriting any
previous paths.

Generally, you will call `owners.search` first to get a list of current paths
(which are provided in the same format), make changes, then update them by
applying a transaction of this type.
EOTEXT
);
        return array(id(new PhabricatorTextEditField())->setKey('name')->setLabel(pht('Name'))->setDescription(pht('Name of the package.'))->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_NAME)->setIsRequired(true)->setValue($object->getName()), id(new PhabricatorDatasourceEditField())->setKey('owners')->setLabel(pht('Owners'))->setDescription(pht('Users and projects which own the package.'))->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_OWNERS)->setDatasource(new PhabricatorProjectOrUserDatasource())->setIsCopyable(true)->setValue($object->getOwnerPHIDs()), id(new PhabricatorSelectEditField())->setKey('auditing')->setLabel(pht('Auditing'))->setDescription(pht('Automatically trigger audits for commits affecting files in ' . 'this package.'))->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_AUDITING)->setIsCopyable(true)->setValue($object->getAuditingEnabled())->setOptions(array('' => pht('Disabled'), '1' => pht('Enabled'))), id(new PhabricatorRemarkupEditField())->setKey('description')->setLabel(pht('Description'))->setDescription(pht('Human-readable description of the package.'))->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION)->setValue($object->getDescription()), id(new PhabricatorSelectEditField())->setKey('status')->setLabel(pht('Status'))->setDescription(pht('Archive or enable the package.'))->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_STATUS)->setIsConduitOnly(true)->setValue($object->getStatus())->setOptions($object->getStatusNameMap()), id(new PhabricatorConduitEditField())->setKey('paths.set')->setLabel(pht('Paths'))->setIsConduitOnly(true)->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_PATHS)->setConduitDescription(pht('Overwrite existing package paths with new paths.'))->setConduitTypeDescription(pht('List of dictionaries, each describing a path.'))->setConduitDocumentation($paths_help));
    }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $configs = id(new PhabricatorAuthProviderConfigQuery())->setViewer($viewer)->execute();
     $list = new PHUIObjectItemListView();
     $can_manage = $this->hasApplicationCapability(AuthManageProvidersCapability::CAPABILITY);
     foreach ($configs as $config) {
         $item = new PHUIObjectItemView();
         $id = $config->getID();
         $edit_uri = $this->getApplicationURI('config/edit/' . $id . '/');
         $enable_uri = $this->getApplicationURI('config/enable/' . $id . '/');
         $disable_uri = $this->getApplicationURI('config/disable/' . $id . '/');
         $provider = $config->getProvider();
         if ($provider) {
             $name = $provider->getProviderName();
         } else {
             $name = $config->getProviderType() . ' (' . $config->getProviderClass() . ')';
         }
         $item->setHeader($name);
         if ($provider) {
             $item->setHref($edit_uri);
         } else {
             $item->addAttribute(pht('Provider Implementation Missing!'));
         }
         $domain = null;
         if ($provider) {
             $domain = $provider->getProviderDomain();
             if ($domain !== 'self') {
                 $item->addAttribute($domain);
             }
         }
         if ($config->getShouldAllowRegistration()) {
             $item->addAttribute(pht('Allows Registration'));
         } else {
             $item->addAttribute(pht('Does Not Allow Registration'));
         }
         if ($config->getIsEnabled()) {
             $item->setStatusIcon('fa-check-circle green');
             $item->addAction(id(new PHUIListItemView())->setIcon('fa-times')->setHref($disable_uri)->setDisabled(!$can_manage)->addSigil('workflow'));
         } else {
             $item->setStatusIcon('fa-ban red');
             $item->addIcon('fa-ban grey', pht('Disabled'));
             $item->addAction(id(new PHUIListItemView())->setIcon('fa-plus')->setHref($enable_uri)->setDisabled(!$can_manage)->addSigil('workflow'));
         }
         $list->addItem($item);
     }
     $list->setNoDataString(pht('%s You have not added authentication providers yet. Use "%s" to add ' . 'a provider, which will let users register new Phabricator accounts ' . 'and log in.', phutil_tag('strong', array(), pht('No Providers Configured:')), phutil_tag('a', array('href' => $this->getApplicationURI('config/new/')), pht('Add Authentication Provider'))));
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Auth Providers'));
     $crumbs->setBorder(true);
     $guidance_context = new PhabricatorAuthProvidersGuidanceContext();
     $guidance = id(new PhabricatorGuidanceEngine())->setViewer($viewer)->setGuidanceContext($guidance_context)->newInfoView();
     $button = id(new PHUIButtonView())->setTag('a')->setColor(PHUIButtonView::SIMPLE)->setHref($this->getApplicationURI('config/new/'))->setIcon('fa-plus')->setDisabled(!$can_manage)->setText(pht('Add Provider'));
     $list->setFlush(true);
     $list = id(new PHUIObjectBoxView())->setHeaderText(pht('Providers'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->appendChild($list);
     $title = pht('Auth Providers');
     $header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon('fa-key')->addActionLink($button);
     $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($guidance, $list));
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
 public function execute(PhutilArgumentParser $args)
 {
     $can_recover = id(new PhabricatorPeopleQuery())->setViewer($this->getViewer())->withIsAdmin(true)->execute();
     if (!$can_recover) {
         throw new PhutilArgumentUsageException(pht('This Phabricator installation has no recoverable administrator ' . 'accounts. You can use `bin/accountadmin` to create a new ' . 'administrator account or make an existing user an administrator.'));
     }
     $can_recover = mpull($can_recover, 'getUsername');
     sort($can_recover);
     $can_recover = implode(', ', $can_recover);
     $usernames = $args->getArg('username');
     if (!$usernames) {
         throw new PhutilArgumentUsageException(pht('You must specify the username of the account to recover.'));
     } else {
         if (count($usernames) > 1) {
             throw new PhutilArgumentUsageException(pht('You can only recover the username for one account.'));
         }
     }
     $username = head($usernames);
     $user = id(new PhabricatorPeopleQuery())->setViewer($this->getViewer())->withUsernames(array($username))->executeOne();
     if (!$user) {
         throw new PhutilArgumentUsageException(pht('No such user "%s". Recoverable administrator accounts are: %s.', $username, $can_recover));
     }
     if (!$user->getIsAdmin()) {
         throw new PhutilArgumentUsageException(pht('You can only recover administrator accounts, but %s is not an ' . 'administrator. Recoverable administrator accounts are: %s.', $username, $can_recover));
     }
     $engine = new PhabricatorAuthSessionEngine();
     $onetime_uri = $engine->getOneTimeLoginURI($user, null, PhabricatorAuthSessionEngine::ONETIME_RECOVER);
     $console = PhutilConsole::getConsole();
     $console->writeOut(pht('Use this link to recover access to the "%s" account from the web ' . 'interface:', $username));
     $console->writeOut("\n\n");
     $console->writeOut('    %s', $onetime_uri);
     $console->writeOut("\n\n");
     $console->writeOut(pht('After logging in, you can use the "Auth" application to add or ' . 'restore authentication providers and allow normal logins to ' . 'succeed.') . "\n");
     return 0;
 }
 public function getConpherenceData()
 {
     if ($this->conpherenceData === null) {
         throw new Exception(pht('You must %s first!', 'execute()'));
     }
     return $this->conpherenceData;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $initiative = id(new FundInitiativeQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$initiative) {
         return new Aphront404Response();
     }
     $initiative_uri = '/' . $initiative->getMonogram();
     $is_close = !$initiative->isClosed();
     if ($request->isFormPost()) {
         $type_status = FundInitiativeTransaction::TYPE_STATUS;
         if ($is_close) {
             $new_status = FundInitiative::STATUS_CLOSED;
         } else {
             $new_status = FundInitiative::STATUS_OPEN;
         }
         $xaction = id(new FundInitiativeTransaction())->setTransactionType($type_status)->setNewValue($new_status);
         $editor = id(new FundInitiativeEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnMissingFields(true);
         $editor->applyTransactions($initiative, array($xaction));
         return id(new AphrontRedirectResponse())->setURI($initiative_uri);
     }
     if ($is_close) {
         $title = pht('Close Initiative?');
         $body = pht('Really close this initiative? Users will no longer be able to ' . 'back it.');
         $button_text = pht('Close Initiative');
     } else {
         $title = pht('Reopen Initiative?');
         $body = pht('Really reopen this initiative?');
         $button_text = pht('Reopen Initiative');
     }
     return $this->newDialog()->setTitle($title)->appendParagraph($body)->addCancelButton($initiative_uri)->addSubmitButton($button_text);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $xaction = id(new PhabricatorObjectQuery())->withPHIDs(array($this->phid))->setViewer($user)->executeOne();
     if (!$xaction) {
         return new Aphront404Response();
     }
     if (!$xaction->getComment()) {
         // You can't view history of a transaction with no comments.
         return new Aphront404Response();
     }
     if ($xaction->getComment()->getIsRemoved()) {
         // You can't view history of a transaction with a removed comment.
         return new Aphront400Response();
     }
     $comments = id(new PhabricatorApplicationTransactionTemplatedCommentQuery())->setViewer($user)->setTemplate($xaction->getApplicationTransactionCommentObject())->withTransactionPHIDs(array($xaction->getPHID()))->execute();
     if (!$comments) {
         return new Aphront404Response();
     }
     $comments = msort($comments, 'getCommentVersion');
     $xactions = array();
     foreach ($comments as $comment) {
         $xactions[] = id(clone $xaction)->makeEphemeral()->setCommentVersion($comment->getCommentVersion())->setContentSource($comment->getContentSource())->setDateCreated($comment->getDateCreated())->attachComment($comment);
     }
     $obj_phid = $xaction->getObjectPHID();
     $obj_handle = id(new PhabricatorHandleQuery())->setViewer($user)->withPHIDs(array($obj_phid))->executeOne();
     $view = id(new PhabricatorApplicationTransactionView())->setUser($user)->setObjectPHID($obj_phid)->setTransactions($xactions)->setShowEditActions(false)->setHideCommentOptions(true);
     $dialog = id(new AphrontDialogView())->setUser($user)->setWidth(AphrontDialogView::WIDTH_FULL)->setFlush(true)->setTitle(pht('Comment History'));
     $dialog->appendChild($view);
     $dialog->addCancelButton($obj_handle->getURI());
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $accounts = id(new PhortuneAccountQuery())->setViewer($viewer)->withMemberPHIDs(array($viewer->getPHID()))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->execute();
     $merchants = id(new PhortuneMerchantQuery())->setViewer($viewer)->withMemberPHIDs(array($viewer->getPHID()))->execute();
     $title = pht('Accounts');
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Accounts'));
     $crumbs->setBorder(true);
     $payment_list = id(new PHUIObjectItemListView())->setUser($viewer)->setNoDataString(pht('You are not a member of any payment accounts. Payment ' . 'accounts are used to make purchases.'));
     foreach ($accounts as $account) {
         $item = id(new PHUIObjectItemView())->setSubhead(pht('Account %d', $account->getID()))->setHeader($account->getName())->setHref($this->getApplicationURI($account->getID() . '/'))->setObject($account)->setIcon('fa-credit-card');
         $payment_list->addItem($item);
     }
     $payment_header = id(new PHUIHeaderView())->setHeader(pht('Payment Accounts'))->addActionLink(id(new PHUIButtonView())->setTag('a')->setHref($this->getApplicationURI('account/edit/'))->setIcon('fa-plus')->setText(pht('Create Account')));
     $payment_box = id(new PHUIObjectBoxView())->setHeader($payment_header)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setObjectList($payment_list);
     $merchant_list = id(new PHUIObjectItemListView())->setUser($viewer)->setNoDataString(pht('You do not control any merchant accounts. Merchant accounts are ' . 'used to receive payments.'));
     foreach ($merchants as $merchant) {
         $item = id(new PHUIObjectItemView())->setSubhead(pht('Merchant %d', $merchant->getID()))->setHeader($merchant->getName())->setHref($this->getApplicationURI('/merchant/' . $merchant->getID() . '/'))->setObject($merchant)->setIcon('fa-bank');
         $merchant_list->addItem($item);
     }
     $merchant_header = id(new PHUIHeaderView())->setHeader(pht('Merchant Accounts'))->addActionLink(id(new PHUIButtonView())->setTag('a')->setHref($this->getApplicationURI('merchant/'))->setIcon('fa-list')->setText(pht('View All Merchants')));
     $merchant_box = id(new PHUIObjectBoxView())->setHeader($merchant_header)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setObjectList($merchant_list);
     $header = id(new PHUIHeaderView())->setHeader(pht('Accounts'));
     $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($payment_box, $merchant_box));
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     // Load the project we're looking at, based on the project ID in the URL.
     $project = id(new PhabricatorProjectQuery())->setViewer($viewer)->withIDs(array($this->projectID))->executeOne();
     if (!$project) {
         return new Aphront404Response();
     }
     $error_box = false;
     $burndown_chart = false;
     $burndown_table = false;
     $tasks_table = false;
     $events_table = false;
     try {
         $data = new BurndownData($project, $viewer);
         $burndown_chart = $data->buildBurnDownChart();
         $burndown_table = $data->buildBurnDownTable();
         $tasks_table = $data->buildTasksTable();
         $events_table = $data->buildEventTable();
     } catch (BurndownException $e) {
         $error_box = id(new PHUIInfoView())->setTitle(pht('Burndown could not be rendered for this project'))->setErrors(array($e->getMessage()));
     }
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb($project->getName(), '/project/view/' . $project->getID());
     $crumbs->addTextCrumb(pht('Burndown'));
     return $this->buildApplicationPage(array($crumbs, $error_box, $burndown_chart, $burndown_table, $tasks_table, $events_table), array('title' => array(pht('Burndown'), $project->getName()), 'device' => true));
 }
 private function getBlockers(PhabricatorRepositoryCommit $commit, HarbormasterBuildPlan $plan, HarbormasterBuild $source)
 {
     $call = new ConduitCall('diffusion.commitparentsquery', array('commit' => $commit->getCommitIdentifier(), 'repository' => $commit->getRepository()->getPHID()));
     $call->setUser(PhabricatorUser::getOmnipotentUser());
     $parents = $call->execute();
     $parents = id(new DiffusionCommitQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withRepository($commit->getRepository())->withIdentifiers($parents)->execute();
     $blockers = array();
     $build_objects = array();
     foreach ($parents as $parent) {
         if (!$parent->isImported()) {
             $blockers[] = pht('Commit %s', $parent->getCommitIdentifier());
         } else {
             $build_objects[] = $parent->getPHID();
         }
     }
     if ($build_objects) {
         $buildables = id(new HarbormasterBuildableQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withBuildablePHIDs($build_objects)->withManualBuildables(false)->execute();
         $buildable_phids = mpull($buildables, 'getPHID');
         if ($buildable_phids) {
             $builds = id(new HarbormasterBuildQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withBuildablePHIDs($buildable_phids)->withBuildPlanPHIDs(array($plan->getPHID()))->execute();
             foreach ($builds as $build) {
                 if (!$build->isComplete()) {
                     $blockers[] = pht('Build %d', $build->getID());
                 }
             }
         }
     }
     return $blockers;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $book_name = $request->getURIData('book');
     $book = id(new DivinerBookQuery())->setViewer($viewer)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->needProjectPHIDs(true)->withNames(array($book_name))->executeOne();
     if (!$book) {
         return new Aphront404Response();
     }
     $view_uri = '/book/' . $book->getName() . '/';
     if ($request->isFormPost()) {
         $v_projects = $request->getArr('projectPHIDs');
         $v_view = $request->getStr('viewPolicy');
         $v_edit = $request->getStr('editPolicy');
         $xactions = array();
         $xactions[] = id(new DivinerLiveBookTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', PhabricatorProjectObjectHasProjectEdgeType::EDGECONST)->setNewValue(array('=' => array_fuse($v_projects)));
         $xactions[] = id(new DivinerLiveBookTransaction())->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)->setNewValue($v_view);
         $xactions[] = id(new DivinerLiveBookTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)->setNewValue($v_edit);
         id(new DivinerLiveBookEditor())->setContinueOnNoEffect(true)->setContentSourceFromRequest($request)->setActor($viewer)->applyTransactions($book, $xactions);
         return id(new AphrontRedirectResponse())->setURI($view_uri);
     }
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Edit Basics'));
     $title = pht('Edit %s', $book->getTitle());
     $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($book)->execute();
     $view_capability = PhabricatorPolicyCapability::CAN_VIEW;
     $edit_capability = PhabricatorPolicyCapability::CAN_EDIT;
     $form = id(new AphrontFormView())->setUser($viewer)->appendControl(id(new AphrontFormTokenizerControl())->setDatasource(new PhabricatorProjectDatasource())->setName('projectPHIDs')->setLabel(pht('Projects'))->setValue($book->getProjectPHIDs()))->appendControl(id(new AphrontFormTokenizerControl())->setDatasource(new DiffusionRepositoryDatasource())->setName('repositoryPHIDs')->setLabel(pht('Repository'))->setDisableBehavior(true)->setLimit(1)->setValue($book->getRepositoryPHID() ? array($book->getRepositoryPHID()) : null))->appendChild(id(new AphrontFormPolicyControl())->setName('viewPolicy')->setPolicyObject($book)->setCapability($view_capability)->setPolicies($policies)->setCaption($book->describeAutomaticCapability($view_capability)))->appendChild(id(new AphrontFormPolicyControl())->setName('editPolicy')->setPolicyObject($book)->setCapability($edit_capability)->setPolicies($policies)->setCaption($book->describeAutomaticCapability($edit_capability)))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Save'))->addCancelButton($view_uri));
     $object_box = id(new PHUIObjectBoxView())->setHeaderText($title)->setForm($form);
     $timeline = $this->buildTransactionTimeline($book, new DivinerLiveBookTransactionQuery());
     $timeline->setShouldTerminate(true);
     return $this->buildApplicationPage(array($crumbs, $object_box, $timeline), array('title' => $title));
 }
 private function renderActions(PhabricatorWorkerBulkJob $job)
 {
     $viewer = $this->getViewer();
     $actions = id(new PhabricatorActionListView())->setUser($viewer)->setObject($job);
     $actions->addAction(id(new PhabricatorActionView())->setHref($job->getDoneURI())->setIcon('fa-arrow-circle-o-right')->setName(pht('Continue')));
     return $actions;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($request->isFormPost()) {
         $log = PhabricatorUserLog::initializeNewLog($user, $user->getPHID(), PhabricatorUserLog::ACTION_LOGOUT);
         $log->save();
         // Destroy the user's session in the database so logout works even if
         // their cookies have some issues. We'll detect cookie issues when they
         // try to login again and tell them to clear any junk.
         $phsid = $request->getCookie(PhabricatorCookies::COOKIE_SESSION);
         if (strlen($phsid)) {
             $session = id(new PhabricatorAuthSessionQuery())->setViewer($user)->withSessionKeys(array($phsid))->executeOne();
             if ($session) {
                 $session->delete();
             }
         }
         $request->clearCookie(PhabricatorCookies::COOKIE_SESSION);
         return id(new AphrontRedirectResponse())->setURI('/auth/loggedout/');
     }
     if ($user->getPHID()) {
         $dialog = id(new AphrontDialogView())->setUser($user)->setTitle(pht('Log out of Phabricator?'))->appendChild(pht('Are you sure you want to log out?'))->addSubmitButton(pht('Logout'))->addCancelButton('/');
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     return id(new AphrontRedirectResponse())->setURI('/');
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $books = id(new DivinerBookQuery())->setViewer($viewer)->execute();
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->setBorder(true);
     $crumbs->addTextCrumb(pht('Books'));
     $query_button = id(new PHUIButtonView())->setTag('a')->setHref($this->getApplicationURI('query/'))->setText(pht('Advanced Search'))->setIcon('fa-search');
     $header = id(new PHUIHeaderView())->setHeader(pht('Documentation Books'))->addActionLink($query_button);
     $document = new PHUIDocumentViewPro();
     $document->setHeader($header);
     $document->addClass('diviner-view');
     if ($books) {
         $books = msort($books, 'getTitle');
         $list = array();
         foreach ($books as $book) {
             $item = id(new DivinerBookItemView())->setTitle($book->getTitle())->setHref('/book/' . $book->getName() . '/')->setSubtitle($book->getPreface());
             $list[] = $item;
         }
         $list = id(new PHUIBoxView())->addPadding(PHUI::PADDING_MEDIUM_TOP)->appendChild($list);
         $document->appendChild($list);
     } else {
         $text = pht("(NOTE) **Looking for Phabricator documentation?** " . "If you're looking for help and information about Phabricator, " . "you can [[https://secure.phabricator.com/diviner/ | " . "browse the public Phabricator documentation]] on the live site.\n\n" . "Diviner is the documentation generator used to build the " . "Phabricator documentation.\n\n" . "You haven't generated any Diviner documentation books yet, so " . "there's nothing to show here. If you'd like to generate your own " . "local copy of the Phabricator documentation and have it appear " . "here, run this command:\n\n" . "  %s\n\n", 'phabricator/ $ ./bin/diviner generate');
         $text = new PHUIRemarkupView($viewer, $text);
         $document->appendChild($text);
     }
     return $this->newPage()->setTitle(pht('Documentation Books'))->setCrumbs($crumbs)->appendChild(array($document));
 }
Example #30
0
 /**
  * Retrieve the authentic identity of the user making the request. If a
  * method requires authentication (the default) the user object will always
  * be available. If a method does not require authentication (i.e., overrides
  * shouldRequireAuthentication() to return false) the user object will NEVER
  * be available.
  *
  * @return PhabricatorUser Authentic user, available ONLY if the method
  *                         requires authentication.
  */
 public function getUser()
 {
     if (!$this->user) {
         throw new Exception(pht('You can not access the user inside the implementation of a Conduit ' . 'method which does not require authentication (as per %s).', 'shouldRequireAuthentication()'));
     }
     return $this->user;
 }