private function sendErrorEmail($error, PhabricatorMetaMTAReceivedMail $mail)
 {
     $template = new PhabricatorMetaMTAMail();
     $template->setSubject('Exception: unable to process your mail request');
     $template->setBody($this->buildErrorMailBody($error, $mail));
     $template->setRelatedPHID($mail->getRelatedPHID());
     $phid = $this->getActor()->getPHID();
     $tos = array($phid => PhabricatorObjectHandleData::loadOneHandle($phid));
     $mails = $this->multiplexMail($template, $tos, array());
     foreach ($mails as $email) {
         $email->saveAndSend();
     }
     return true;
 }
 public function renderValueForMail($phase)
 {
     $status = $this->getRevision()->getStatus();
     if ($status != ArcanistDifferentialRevisionStatus::NEEDS_REVISION && $status != ArcanistDifferentialRevisionStatus::ACCEPTED) {
         return null;
     }
     $diff = $this->getRevision()->loadActiveDiff();
     if ($diff) {
         $phid = $diff->getArcanistProjectPHID();
         if ($phid) {
             $handle = PhabricatorObjectHandleData::loadOneHandle($phid);
             return "ARCANIST PROJECT\n  " . $handle->getName();
         }
     }
 }
 public function reindexAbstractDocument(PhabricatorSearchAbstractDocument $doc)
 {
     $type = $doc->getDocumentType();
     $phid = $doc->getPHID();
     $handle = PhabricatorObjectHandleData::loadOneHandle($phid);
     // URL is not used internally but it can be useful externally.
     $spec = array('title' => $doc->getDocumentTitle(), 'url' => PhabricatorEnv::getProductionURI($handle->getURI()), 'dateCreated' => $doc->getDocumentCreated(), '_timestamp' => $doc->getDocumentModified(), 'field' => array(), 'relationship' => array());
     foreach ($doc->getFieldData() as $field) {
         $spec['field'][] = array_combine(array('type', 'corpus', 'aux'), $field);
     }
     foreach ($doc->getRelationshipData() as $relationship) {
         list($rtype, $to_phid, $to_type, $time) = $relationship;
         $spec['relationship'][$rtype][] = array('phid' => $to_phid, 'phidType' => $to_type, 'when' => $time);
     }
     $this->executeRequest("/phabricator/{$type}/{$phid}/", $spec, $is_write = true);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $phid = $this->phid;
     $handle = PhabricatorObjectHandleData::loadOneHandle($phid);
     if (!$handle->isComplete()) {
         return new Aphront404Response();
     }
     $flag = PhabricatorFlagQuery::loadUserFlag($user, $phid);
     if (!$flag) {
         $flag = new PhabricatorFlag();
         $flag->setOwnerPHID($user->getPHID());
         $flag->setType($handle->getType());
         $flag->setObjectPHID($handle->getPHID());
         $flag->setReasonPHID($user->getPHID());
     }
     if ($request->isDialogFormPost()) {
         $flag->setColor($request->getInt('color'));
         $flag->setNote($request->getStr('note'));
         $flag->save();
         return id(new AphrontReloadResponse())->setURI('/flag/');
     }
     $type_name = $handle->getTypeName();
     $dialog = new AphrontDialogView();
     $dialog->setUser($user);
     $dialog->setTitle("Flag {$type_name}");
     require_celerity_resource('phabricator-flag-css');
     $form = new AphrontFormLayoutView();
     $is_new = !$flag->getID();
     if ($is_new) {
         $form->appendChild("<p>You can flag this {$type_name} if you want to remember to look " . "at it later.</p><br />");
     }
     $radio = new AphrontFormRadioButtonControl();
     foreach (PhabricatorFlagColor::getColorNameMap() as $color => $text) {
         $class = 'phabricator-flag-radio phabricator-flag-color-' . $color;
         $radio->addButton($color, $text, '', $class);
     }
     $form->appendChild($radio->setName('color')->setLabel('Flag Color')->setValue($flag->getColor()))->appendChild(id(new AphrontFormTextAreaControl())->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)->setName('note')->setLabel('Note')->setValue($flag->getNote()));
     $dialog->appendChild($form);
     $dialog->addCancelButton($handle->getURI());
     $dialog->addSubmitButton($is_new ? "Flag {$type_name}" : 'Save');
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     if (!$request->isFormPost()) {
         return new Aphront400Response();
     }
     switch ($this->action) {
         case 'add':
             $is_add = true;
             break;
         case 'delete':
             $is_add = false;
             break;
         default:
             return new Aphront400Response();
     }
     $user = $request->getUser();
     $phid = $this->phid;
     // TODO: This is a policy test because `loadObjects()` is not currently
     // policy-aware. Once it is, we can collapse this.
     $handle = PhabricatorObjectHandleData::loadOneHandle($phid, $user);
     if (!$handle->isComplete()) {
         return new Aphront404Response();
     }
     $objects = id(new PhabricatorObjectHandleData(array($phid)))->loadObjects();
     $object = idx($objects, $phid);
     if (!$object instanceof PhabricatorSubscribableInterface) {
         return $this->buildErrorResponse(pht('Bad Object'), pht('This object is not subscribable.'), $handle->getURI());
     }
     if ($object->isAutomaticallySubscribed($user->getPHID())) {
         return $this->buildErrorResponse(pht('Automatically Subscribed'), pht('You are automatically subscribed to this object.'), $handle->getURI());
     }
     $editor = id(new PhabricatorSubscriptionsEditor())->setUser($user)->setObject($object);
     if ($is_add) {
         $editor->subscribeExplicit(array($user->getPHID()), $explicit = true);
     } else {
         $editor->unsubscribe(array($user->getPHID()));
     }
     $editor->save();
     // TODO: We should just render the "Unsubscribe" action and swap it out
     // in the document for Ajax requests.
     return id(new AphrontReloadResponse())->setURI($handle->getURI());
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $paste = id(new PhabricatorPasteQuery())->setViewer($user)->withPasteIDs(array($this->id))->executeOne();
     if (!$paste) {
         return new Aphront404Response();
     }
     $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $paste->getFilePHID());
     if (!$file) {
         return new Aphront400Response();
     }
     $corpus = $this->buildCorpus($paste, $file);
     $paste_panel = new AphrontPanelView();
     $author_phid = $paste->getAuthorPHID();
     $header = 'Viewing Paste ' . $paste->getID() . ' by ' . PhabricatorObjectHandleData::loadOneHandle($author_phid)->renderLink();
     if (strlen($paste->getTitle())) {
         $header .= ' - ' . phutil_escape_html($paste->getTitle());
     }
     $paste_panel->setHeader($header);
     $paste_panel->setWidth(AphrontPanelView::WIDTH_FULL);
     $paste_panel->addButton(phutil_render_tag('a', array('href' => '/paste/?fork=' . $paste->getID(), 'class' => 'green button'), 'Fork This'));
     $raw_uri = $file->getBestURI();
     $paste_panel->addButton(phutil_render_tag('a', array('href' => $raw_uri, 'class' => 'button'), 'View Raw Text'));
     $paste_panel->appendChild($corpus);
     $forks_panel = null;
     $forks_of_this_paste = id(new PhabricatorPaste())->loadAllWhere('parentPHID = %s', $paste->getPHID());
     if ($forks_of_this_paste) {
         $forks_panel = new AphrontPanelView();
         $forks_panel->setHeader("Forks of this paste");
         $forks = array();
         foreach ($forks_of_this_paste as $fork) {
             $forks[] = array($fork->getID(), phutil_render_tag('a', array('href' => '/P' . $fork->getID()), phutil_escape_html($fork->getTitle())));
         }
         $forks_table = new AphrontTableView($forks);
         $forks_table->setHeaders(array('Paste ID', 'Title'));
         $forks_table->setColumnClasses(array(null, 'wide pri'));
         $forks_panel->appendChild($forks_table);
     }
     return $this->buildStandardPageResponse(array($paste_panel, $forks_panel), array('title' => 'Paste: ' . nonempty($paste->getTitle(), 'P' . $paste->getID()), 'tab' => 'view'));
 }
Exemplo n.º 7
0
 public static function applyFlagEffect(HeraldEffect $effect, $phid)
 {
     $color = $effect->getTarget();
     // TODO: Silly that we need to load this again here.
     $rule = id(new HeraldRule())->load($effect->getRuleID());
     $user = id(new PhabricatorUser())->loadOneWhere('phid = %s', $rule->getAuthorPHID());
     $flag = PhabricatorFlagQuery::loadUserFlag($user, $phid);
     if ($flag) {
         return new HeraldApplyTranscript($effect, false, 'Object already flagged.');
     }
     $handle = PhabricatorObjectHandleData::loadOneHandle($phid);
     $flag = new PhabricatorFlag();
     $flag->setOwnerPHID($user->getPHID());
     $flag->setType($handle->getType());
     $flag->setObjectPHID($handle->getPHID());
     // TOOD: Should really be transcript PHID, but it doesn't exist yet.
     $flag->setReasonPHID($user->getPHID());
     $flag->setColor($color);
     $flag->setNote('Flagged by Herald Rule "' . $rule->getName() . '".');
     $flag->save();
     return new HeraldApplyTranscript($effect, true, 'Added flag.');
 }
 protected final function updateCommitData($author, $message, $committer = null)
 {
     $commit = $this->commit;
     $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere('commitID = %d', $commit->getID());
     if (!$data) {
         $data = new PhabricatorRepositoryCommitData();
     }
     $data->setCommitID($commit->getID());
     $data->setAuthorName($author);
     $data->setCommitMessage($message);
     if ($committer) {
         $data->setCommitDetail('committer', $committer);
     }
     $repository = $this->repository;
     $detail_parser = $repository->getDetail('detail-parser', 'PhabricatorRepositoryDefaultCommitMessageDetailParser');
     if ($detail_parser) {
         $parser_obj = newv($detail_parser, array($commit, $data));
         $parser_obj->parseCommitDetails();
     }
     $author_phid = $this->lookupUser($commit, $data->getAuthorName(), $data->getCommitDetail('authorPHID'));
     $data->setCommitDetail('authorPHID', $author_phid);
     $committer_phid = $this->lookupUser($commit, $data->getCommitDetail('committer'), $data->getCommitDetail('committerPHID'));
     $data->setCommitDetail('committerPHID', $committer_phid);
     if ($author_phid != $commit->getAuthorPHID()) {
         $commit->setAuthorPHID($author_phid);
         $commit->save();
     }
     $conn_w = id(new DifferentialRevision())->establishConnection('w');
     // NOTE: The `differential_commit` table has a unique ID on `commitPHID`,
     // preventing more than one revision from being associated with a commit.
     // Generally this is good and desirable, but with the advent of hash
     // tracking we may end up in a situation where we match several different
     // revisions. We just kind of ignore this and pick one, we might want to
     // revisit this and do something differently. (If we match several revisions
     // someone probably did something very silly, though.)
     $revision_id = $data->getCommitDetail('differential.revisionID');
     if (!$revision_id) {
         $hashes = $this->getCommitHashes($this->repository, $this->commit);
         if ($hashes) {
             $query = new DifferentialRevisionQuery();
             $query->withCommitHashes($hashes);
             $revisions = $query->execute();
             if (!empty($revisions)) {
                 $revision = $this->identifyBestRevision($revisions);
                 $revision_id = $revision->getID();
             }
         }
     }
     if ($revision_id) {
         $revision = id(new DifferentialRevision())->load($revision_id);
         if ($revision) {
             queryfx($conn_w, 'INSERT IGNORE INTO %T (revisionID, commitPHID) VALUES (%d, %s)', DifferentialRevision::TABLE_COMMIT, $revision->getID(), $commit->getPHID());
             $committer_phid = $data->getCommitDetail('committerPHID');
             if ($committer_phid) {
                 $handle = PhabricatorObjectHandleData::loadOneHandle($committer_phid);
                 $committer_name = '@' . $handle->getName();
             } else {
                 $committer_name = $data->getCommitDetail('committer');
             }
             $author_phid = $data->getCommitDetail('authorPHID');
             if ($author_phid) {
                 $handle = PhabricatorObjectHandleData::loadOneHandle($author_phid);
                 $author_name = '@' . $handle->getName();
             } else {
                 $author_name = $data->getAuthorName();
             }
             $commit_name = $repository->formatCommitName($commit->getCommitIdentifier());
             $info = array();
             $info[] = "authored by {$author_name}";
             if ($committer_name && $committer_name != $author_name) {
                 $info[] = "committed by {$committer_name}";
             }
             $info = implode(', ', $info);
             $message = "Closed by commit {$commit_name} ({$info}).";
             $actor_phid = nonempty($committer_phid, $author_phid, $revision->getAuthorPHID());
             $status_closed = ArcanistDifferentialRevisionStatus::CLOSED;
             $should_close = $revision->getStatus() != $status_closed && $repository->shouldAutocloseCommit($commit, $data);
             if ($should_close) {
                 $diff = $this->attachToRevision($revision, $actor_phid);
                 $revision->setDateCommitted($commit->getEpoch());
                 $editor = new DifferentialCommentEditor($revision, $actor_phid, DifferentialAction::ACTION_CLOSE);
                 $editor->setIsDaemonWorkflow(true);
                 $vs_diff = $this->loadChangedByCommit($diff);
                 if ($vs_diff) {
                     $data->setCommitDetail('vsDiff', $vs_diff->getID());
                     $changed_by_commit = PhabricatorEnv::getProductionURI('/D' . $revision->getID() . '?vs=' . $vs_diff->getID() . '&id=' . $diff->getID() . '#toc');
                     $editor->setChangedByCommit($changed_by_commit);
                 }
                 $editor->setMessage($message)->save();
             }
         }
     }
     $data->save();
 }
 private function loadUserName($user_phid, $default)
 {
     if (!$user_phid) {
         return $default;
     }
     $handle = PhabricatorObjectHandleData::loadOneHandle($user_phid);
     return '@' . $handle->getName();
 }
Exemplo n.º 10
0
 private function renderAuthorFilter($phid)
 {
     if ($phid) {
         $handle = PhabricatorObjectHandleData::loadOneHandle($phid);
         $tokens = array($phid => $handle->getFullName());
     } else {
         $tokens = array();
     }
     $form = id(new AphrontFormView())->setUser($this->getRequest()->getUser())->appendChild(id(new AphrontFormTokenizerControl())->setName('set_phid')->setValue($tokens)->setLimit(1)->setLabel('Filter Author')->setDataSource('/typeahead/common/accounts/'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Apply Filter'));
     $filter = new AphrontListFilterView();
     $filter->appendChild($form);
     return $filter;
 }
Exemplo n.º 11
0
 protected function attachHandleToFlag($flag)
 {
     $flag->attachHandle(PhabricatorObjectHandleData::loadOneHandle($flag->getObjectPHID()));
 }
Exemplo n.º 12
0
 private function rejectObject($object, $policy, $capability)
 {
     if (!$this->raisePolicyExceptions) {
         return;
     }
     // TODO: clean this up
     $verb = $capability;
     $message = "You do not have permission to {$verb} this object.";
     switch ($policy) {
         case PhabricatorPolicies::POLICY_PUBLIC:
             $who = "This is curious, since anyone can {$verb} the object.";
             break;
         case PhabricatorPolicies::POLICY_USER:
             $who = "To {$verb} this object, you must be logged in.";
             break;
         case PhabricatorPolicies::POLICY_ADMIN:
             $who = "To {$verb} this object, you must be an administrator.";
             break;
         case PhabricatorPolicies::POLICY_NOONE:
             $who = "No one can {$verb} this object.";
             break;
         default:
             $type = phid_get_type($policy);
             if ($type == PhabricatorPHIDConstants::PHID_TYPE_PROJ) {
                 $handle = PhabricatorObjectHandleData::loadOneHandle($policy, $this->viewer);
                 $who = "To {$verb} this object, you must be a member of project " . "'" . $handle->getFullName() . "'.";
             } else {
                 $who = "It is unclear who can {$verb} this object.";
             }
             break;
     }
     throw new PhabricatorPolicyException("{$message} {$who}");
 }