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));
         }
     }
 }
 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;
 }
 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));
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $diff = null;
     $revision_id = $request->getValue('revision_id');
     $revision = id(new DifferentialRevision())->load($revision_id);
     if (!$revision) {
         throw new ConduitException('ERR_BAD_REVISION');
     }
     $revision->loadRelationships();
     $reviewer_phids = array_values($revision->getReviewers());
     $diffs = $revision->loadDiffs();
     $diff_dicts = array();
     foreach ($diffs as $diff) {
         $diff->attachChangesets($diff->loadChangesets());
         // TODO: We could batch this to improve performance.
         foreach ($diff->getChangesets() as $changeset) {
             $changeset->attachHunks($changeset->loadHunks());
         }
         $diff_dicts[] = $diff->getDiffDict();
     }
     $commit_dicts = array();
     $commit_phids = $revision->loadCommitPHIDs();
     $handles = id(new PhabricatorObjectHandleData($commit_phids))->loadHandles();
     foreach ($commit_phids as $commit_phid) {
         $commit_dicts[] = array('fullname' => $handles[$commit_phid]->getFullName(), 'dateCommitted' => $handles[$commit_phid]->getTimestamp());
     }
     $auxiliary_fields = $this->loadAuxiliaryFields($revision);
     $dict = array('id' => $revision->getID(), 'phid' => $revision->getPHID(), 'authorPHID' => $revision->getAuthorPHID(), 'uri' => PhabricatorEnv::getURI('/D' . $revision->getID()), 'title' => $revision->getTitle(), 'status' => $revision->getStatus(), 'statusName' => ArcanistDifferentialRevisionStatus::getNameForRevisionStatus($revision->getStatus()), 'summary' => $revision->getSummary(), 'testPlan' => $revision->getTestPlan(), 'lineCount' => $revision->getLineCount(), 'reviewerPHIDs' => $reviewer_phids, 'diffs' => $diff_dicts, 'commits' => $commit_dicts, 'auxiliary' => $auxiliary_fields);
     return $dict;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     if (!$request->isFormPost()) {
         return new Aphront400Response();
     }
     $question = id(new PonderQuestionQuery())->setViewer($viewer)->withIDs(array($id))->executeOne();
     if (!$question) {
         return new Aphront404Response();
     }
     $is_preview = $request->isPreviewRequest();
     //    $draft = PhabricatorDraft::buildFromRequest($request);
     $qid = $question->getID();
     $view_uri = "/Q{$qid}";
     $xactions = array();
     $xactions[] = id(new PonderQuestionTransaction())->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)->attachComment(id(new PonderQuestionTransactionComment())->setContent($request->getStr('comment')));
     $editor = id(new PonderQuestionEditor())->setActor($viewer)->setContinueOnNoEffect($request->isContinueRequest())->setContentSourceFromRequest($request)->setIsPreview($is_preview);
     try {
         $xactions = $editor->applyTransactions($question, $xactions);
     } catch (PhabricatorApplicationTransactionNoEffectException $ex) {
         return id(new PhabricatorApplicationTransactionNoEffectResponse())->setCancelURI($view_uri)->setException($ex);
     }
     //    if ($draft) {
     //      $draft->replaceOrDelete();
     //    }
     if ($request->isAjax() && $is_preview) {
         return id(new PhabricatorApplicationTransactionResponse())->setViewer($viewer)->setTransactions($xactions)->setIsPreview($is_preview);
     } else {
         return id(new AphrontRedirectResponse())->setURI($view_uri);
     }
 }
 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 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);
 }
 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;
 }
 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);
 }
 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();
     $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));
 }
 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));
 }
 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);
 }
 protected function willFilterPage(array $page)
 {
     if ($this->needSecrets) {
         $secret_ids = mpull($page, 'getSecretID');
         $secret_ids = array_filter($secret_ids);
         $secrets = array();
         if ($secret_ids) {
             $secret_objects = id(new PassphraseSecret())->loadAllWhere('id IN (%Ld)', $secret_ids);
             foreach ($secret_objects as $secret) {
                 $secret_data = $secret->getSecretData();
                 $secrets[$secret->getID()] = new PhutilOpaqueEnvelope($secret_data);
             }
         }
         foreach ($page as $key => $credential) {
             $secret_id = $credential->getSecretID();
             if (!$secret_id) {
                 $credential->attachSecret(null);
             } else {
                 if (isset($secrets[$secret_id])) {
                     $credential->attachSecret($secrets[$secret_id]);
                 } else {
                     unset($page[$key]);
                 }
             }
         }
     }
     return $page;
 }
 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);
 }
Пример #16
0
 public function render()
 {
     $leases = $this->leases;
     $viewer = $this->getUser();
     $view = new PHUIObjectItemListView();
     foreach ($leases as $lease) {
         $item = id(new PHUIObjectItemView())->setUser($viewer)->setHeader($lease->getLeaseName())->setHref('/drydock/lease/' . $lease->getID() . '/');
         if ($lease->hasAttachedResource()) {
             $resource = $lease->getResource();
             $resource_href = '/drydock/resource/' . $resource->getID() . '/';
             $resource_name = $resource->getName();
             $item->addAttribute(phutil_tag('a', array('href' => $resource_href), $resource_name));
         }
         $status = DrydockLeaseStatus::getNameForStatus($lease->getStatus());
         $item->addAttribute($status);
         $item->setEpoch($lease->getDateCreated());
         // TODO: Tailor this for clarity.
         if ($lease->isActivating()) {
             $item->setStatusIcon('fa-dot-circle-o yellow');
         } else {
             if ($lease->isActive()) {
                 $item->setStatusIcon('fa-dot-circle-o green');
             } else {
                 $item->setStatusIcon('fa-dot-circle-o red');
             }
         }
         $view->addItem($item);
     }
     return $view;
 }
 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();
     $timer = id(new PhabricatorTimer())->load($this->id);
     if (!$timer) {
         return new Aphront404Response();
     }
     require_celerity_resource('phabricator-countdown-css');
     $chrome_visible = $request->getBool('chrome', true);
     $chrome_new = $chrome_visible ? false : null;
     $chrome_link = phutil_render_tag('a', array('href' => $request->getRequestURI()->alter('chrome', $chrome_new), 'class' => 'phabricator-timer-chrome-link'), $chrome_visible ? 'Disable Chrome' : 'Enable Chrome');
     $content = '<div class="phabricator-timer">
     <h1 class="phabricator-timer-header">' . phutil_escape_html($timer->getTitle()) . ' &middot; ' . phabricator_datetime($timer->getDatePoint(), $user) . '</h1>
     <div class="phabricator-timer-pane">
       <table class="phabricator-timer-table">
         <tr>
           <th>Days</th>
           <th>Hours</th>
           <th>Minutes</th>
           <th>Seconds</th>
         </tr>
         <tr>
           <td id="phabricator-timer-days"></td>
           <td id="phabricator-timer-hours"></td>
           <td id="phabricator-timer-minutes"></td>
           <td id="phabricator-timer-seconds"></td>
       </table>
     </div>' . $chrome_link . '</div>';
     Javelin::initBehavior('countdown-timer', array('timestamp' => $timer->getDatepoint()));
     $panel = $content;
     return $this->buildStandardPageResponse($panel, array('title' => 'Countdown: ' . $timer->getTitle(), 'chrome' => $chrome_visible));
 }
 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);
 }
    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));
    }
 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 execute(HarbormasterBuild $build, HarbormasterBuildTarget $build_target)
 {
     $viewer = PhabricatorUser::getOmnipotentUser();
     $settings = $this->getSettings();
     $variables = $build_target->getVariables();
     $uri = $this->mergeVariables('vurisprintf', $settings['uri'], $variables);
     $method = nonempty(idx($settings, 'method'), 'POST');
     $future = id(new HTTPSFuture($uri))->setMethod($method)->setTimeout(60);
     $credential_phid = $this->getSetting('credential');
     if ($credential_phid) {
         $key = PassphrasePasswordKey::loadFromPHID($credential_phid, $viewer);
         $future->setHTTPBasicAuthCredentials($key->getUsernameEnvelope()->openEnvelope(), $key->getPasswordEnvelope());
     }
     $this->resolveFutures($build, $build_target, array($future));
     list($status, $body, $headers) = $future->resolve();
     $header_lines = array();
     // TODO: We don't currently preserve the entire "HTTP" response header, but
     // should. Once we do, reproduce it here faithfully.
     $status_code = $status->getStatusCode();
     $header_lines[] = "HTTP {$status_code}";
     foreach ($headers as $header) {
         list($head, $tail) = $header;
         $header_lines[] = "{$head}: {$tail}";
     }
     $header_lines = implode("\n", $header_lines);
     $build_target->newLog($uri, 'http.head')->append($header_lines);
     $build_target->newLog($uri, 'http.body')->append($body);
     if ($status->isError()) {
         throw new HarbormasterBuildFailureException();
     }
 }
 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;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $revision = id(new DifferentialRevisionQuery())->setViewer($viewer)->withIDs(array($request->getValue('revision_id')))->needReviewerStatus(true)->needReviewerAuthority(true)->executeOne();
     if (!$revision) {
         throw new ConduitException('ERR_BAD_REVISION');
     }
     $xactions = array();
     $action = $request->getValue('action');
     if ($action && $action != 'comment' && $action != 'none') {
         $xactions[] = id(new DifferentialTransaction())->setTransactionType(DifferentialTransaction::TYPE_ACTION)->setNewValue($action);
     }
     $content = $request->getValue('message');
     if (strlen($content)) {
         $xactions[] = id(new DifferentialTransaction())->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)->attachComment(id(new DifferentialTransactionComment())->setContent($content));
     }
     if ($request->getValue('attach_inlines')) {
         $type_inline = DifferentialTransaction::TYPE_INLINE;
         $inlines = DifferentialTransactionQuery::loadUnsubmittedInlineComments($viewer, $revision);
         foreach ($inlines as $inline) {
             $xactions[] = id(new DifferentialTransaction())->setTransactionType($type_inline)->attachComment($inline);
         }
     }
     $editor = id(new DifferentialTransactionEditor())->setActor($viewer)->setDisableEmail($request->getValue('silent'))->setContentSource($request->newContentSource())->setContinueOnNoEffect(true)->setContinueOnMissingFields(true);
     $editor->applyTransactions($revision, $xactions);
     return array('revisionid' => $revision->getID(), 'uri' => PhabricatorEnv::getURI('/D' . $revision->getID()));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $querykey = $request->getURIData('queryKey');
     $controller = id(new PhabricatorApplicationSearchController())->setQueryKey($querykey)->setSearchEngine(new DrydockLogSearchEngine())->setNavigation($this->buildSideNavView());
     return $this->delegateToController($controller);
 }
 private function buildErrorResponse($title, $message, $uri)
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle($title)->appendChild($message)->addCancelButton($uri);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 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 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 processRequest()
 {
     $can_edit = $this->requireApplicationCapability(NuanceSourceManageCapability::CAPABILITY);
     $request = $this->getRequest();
     $user = $request->getUser();
     $source_id = $this->getSourceID();
     $is_new = !$source_id;
     if ($is_new) {
         $source = NuanceSource::initializeNewSource($user);
     } else {
         $source = id(new NuanceSourceQuery())->setViewer($user)->withIDs(array($source_id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     }
     if (!$source) {
         return new Aphront404Response();
     }
     $definition = NuanceSourceDefinition::getDefinitionForSource($source);
     $definition->setActor($user);
     $response = $definition->buildEditLayout($request);
     if ($response instanceof AphrontResponse) {
         return $response;
     }
     $layout = $response;
     $crumbs = $this->buildApplicationCrumbs();
     return $this->buildApplicationPage(array($crumbs, $layout), array('title' => $definition->getEditTitle()));
 }
 public function showField()
 {
     static $show = null;
     $viewer = $this->getViewer();
     if ($show == null) {
         if ($this->getObject() instanceof ManiphestTask) {
             $id = $this->getObject()->getID();
             if ($id) {
                 $task = id(new ManiphestTaskQuery())->setViewer($viewer)->withIds(array($id))->needProjectPHIDs(true)->executeOne();
                 $projectphids = $task->getProjectPHIDs();
             }
         }
         if (empty($projectphids)) {
             return $show = false;
         }
         $show = false;
         foreach ($projectphids as $projectphid) {
             if ($this->isSprint($projectphid)) {
                 $show = true;
                 break;
             }
         }
     }
     return $show;
 }