diff --git a/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentHistoryController.php b/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentHistoryController.php index dcff0d76e2..f292c0d9d4 100644 --- a/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentHistoryController.php +++ b/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentHistoryController.php @@ -1,88 +1,82 @@ phid = $data['phid']; - } - - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $this->getViewer(); + $phid = $request->getURIData('phid'); $xaction = id(new PhabricatorObjectQuery()) - ->withPHIDs(array($this->phid)) - ->setViewer($user) + ->withPHIDs(array($phid)) + ->setViewer($viewer) ->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) + ->setViewer($viewer) ->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) + ->setViewer($viewer) ->withPHIDs(array($obj_phid)) ->executeOne(); $view = id(new PhabricatorApplicationTransactionView()) - ->setUser($user) + ->setUser($viewer) ->setObjectPHID($obj_phid) ->setTransactions($xactions) ->setShowEditActions(false) ->setHideCommentOptions(true); $dialog = id(new AphrontDialogView()) - ->setUser($user) + ->setUser($viewer) ->setWidth(AphrontDialogView::WIDTH_FULL) ->setFlush(true) ->setTitle(pht('Comment History')); $dialog->appendChild($view); $dialog ->addCancelButton($obj_handle->getURI()); return id(new AphrontDialogResponse())->setDialog($dialog); } } diff --git a/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentQuoteController.php b/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentQuoteController.php index 01a40c14a0..d4bb7ccddd 100644 --- a/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentQuoteController.php +++ b/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentQuoteController.php @@ -1,68 +1,62 @@ phid = $data['phid']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $this->getViewer(); + $phid = $request->getURIData('phid'); $xaction = id(new PhabricatorObjectQuery()) - ->withPHIDs(array($this->phid)) + ->withPHIDs(array($phid)) ->setViewer($viewer) ->executeOne(); if (!$xaction) { return new Aphront404Response(); } if (!$xaction->getComment()) { return new Aphront404Response(); } if ($xaction->getComment()->getIsRemoved()) { return new Aphront400Response(); } if (!$xaction->hasComment()) { return new Aphront404Response(); } $content = $xaction->getComment()->getContent(); $content = rtrim($content, "\r\n"); $content = phutil_split_lines($content, true); foreach ($content as $key => $line) { if (strlen($line) && ($line[0] != '>')) { $content[$key] = '> '.$line; } else { $content[$key] = '>'.$line; } } $content = implode('', $content); $author = id(new PhabricatorHandleQuery()) ->setViewer($viewer) ->withPHIDs(array($xaction->getComment()->getAuthorPHID())) ->executeOne(); $ref = $request->getStr('ref'); if (strlen($ref)) { $quote = pht('In %s, %s wrote:', $ref, '@'.$author->getName()); } else { $quote = pht('%s wrote:', '@'.$author->getName()); } $content = ">>! {$quote}\n{$content}"; return id(new AphrontAjaxResponse())->setContent( array( 'quoteText' => $content, )); } } diff --git a/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentRawController.php b/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentRawController.php index a4a68259fa..6670c147fe 100644 --- a/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentRawController.php +++ b/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentRawController.php @@ -1,92 +1,86 @@ phid = $data['phid']; - } - - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $this->getViewer(); + $phid = $request->getURIData('phid'); $xaction = id(new PhabricatorObjectQuery()) - ->withPHIDs(array($this->phid)) - ->setViewer($user) + ->withPHIDs(array($phid)) + ->setViewer($viewer) ->executeOne(); if (!$xaction) { return new Aphront404Response(); } if (!$xaction->getComment()) { // You can't view a raw comment if there is no comment. return new Aphront404Response(); } if ($xaction->getComment()->getIsRemoved()) { // You can't view a raw comment if the comment is deleted. return new Aphront400Response(); } $obj_phid = $xaction->getObjectPHID(); $obj_handle = id(new PhabricatorHandleQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withPHIDs(array($obj_phid)) ->executeOne(); $title = pht('Raw Comment'); $body = $xaction->getComment()->getContent(); $addendum = null; if ($request->getExists('email')) { $content_source = $xaction->getContentSource(); $source_email = PhabricatorContentSource::SOURCE_EMAIL; if ($content_source->getSource() == $source_email) { $source_id = $content_source->getParam('id'); if ($source_id) { $message = id(new PhabricatorMetaMTAReceivedMail())->loadOneWhere( 'id = %d', $source_id); if ($message) { $title = pht('Email Body Text'); $body = $message->getRawTextBody(); $details_text = pht( 'For full details, run `/bin/mail show-outbound --id %d`', $source_id); $addendum = PhabricatorMarkupEngine::renderOneObject( id(new PhabricatorMarkupOneOff())->setContent($details_text), 'default', - $user); + $viewer); } } } } $dialog = id(new AphrontDialogView()) - ->setUser($user) + ->setUser($viewer) ->addCancelButton($obj_handle->getURI()) ->setTitle($title); $dialog ->addHiddenInput('anchor', $request->getStr('anchor')) ->appendChild( id(new PHUIFormLayoutView()) ->setFullWidth(true) ->appendChild( id(new AphrontFormTextAreaControl()) ->setReadOnly(true) ->setValue($body))); if ($addendum) { $dialog->appendParagraph($addendum); } return id(new AphrontDialogResponse())->setDialog($dialog); } public function shouldAllowPublic() { return true; } } diff --git a/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentRemoveController.php b/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentRemoveController.php index a4feff433d..c52b087273 100644 --- a/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentRemoveController.php +++ b/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentRemoveController.php @@ -1,79 +1,73 @@ phid = $data['phid']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $this->getViewer(); + $phid = $request->getURIData('phid'); $xaction = id(new PhabricatorObjectQuery()) - ->withPHIDs(array($this->phid)) + ->withPHIDs(array($phid)) ->setViewer($viewer) ->executeOne(); if (!$xaction) { return new Aphront404Response(); } if (!$xaction->getComment()) { return new Aphront404Response(); } if ($xaction->getComment()->getIsRemoved()) { // You can't remove an already-removed comment. return new Aphront400Response(); } $obj_phid = $xaction->getObjectPHID(); $obj_handle = id(new PhabricatorHandleQuery()) ->setViewer($viewer) ->withPHIDs(array($obj_phid)) ->executeOne(); if ($request->isDialogFormPost()) { $comment = $xaction->getApplicationTransactionCommentObject() ->setContent('') ->setIsRemoved(true); $editor = id(new PhabricatorApplicationTransactionCommentEditor()) ->setActor($viewer) ->setContentSource(PhabricatorContentSource::newFromRequest($request)) ->applyEdit($xaction, $comment); if ($request->isAjax()) { return id(new AphrontAjaxResponse())->setContent(array()); } else { return id(new AphrontReloadResponse())->setURI($obj_handle->getURI()); } } $form = id(new AphrontFormView()) ->setUser($viewer); $dialog = $this->newDialog() ->setTitle(pht('Remove Comment')); $dialog ->addHiddenInput('anchor', $request->getStr('anchor')) ->appendParagraph( pht( "Removing a comment prevents anyone (including you) from reading ". "it. Removing a comment also hides the comment's edit history ". "and prevents it from being edited.")) ->appendParagraph( pht('Really remove this comment?')); $dialog ->addSubmitButton(pht('Remove Comment')) ->addCancelButton($obj_handle->getURI()); return $dialog; } } diff --git a/src/applications/transactions/controller/PhabricatorApplicationTransactionShowOlderController.php b/src/applications/transactions/controller/PhabricatorApplicationTransactionShowOlderController.php index e5388184db..67cc3c63aa 100644 --- a/src/applications/transactions/controller/PhabricatorApplicationTransactionShowOlderController.php +++ b/src/applications/transactions/controller/PhabricatorApplicationTransactionShowOlderController.php @@ -1,56 +1,55 @@ getRequest(); - $viewer = $request->getUser(); + $viewer = $this->getViewer(); $object = id(new PhabricatorObjectQuery()) ->withPHIDs(array($request->getURIData('phid'))) ->setViewer($viewer) ->executeOne(); if (!$object) { return new Aphront404Response(); } if (!$object instanceof PhabricatorApplicationTransactionInterface) { return new Aphront404Response(); } $template = $object->getApplicationTransactionTemplate(); $queries = id(new PhutilClassMapQuery()) ->setAncestorClass('PhabricatorApplicationTransactionQuery') ->execute(); $object_query = null; foreach ($queries as $query) { if ($query->getTemplateApplicationTransaction() == $template) { $object_query = $query; break; } } if (!$object_query) { return new Aphront404Response(); } $timeline = $this->buildTransactionTimeline( $object, $query); $phui_timeline = $timeline->buildPHUITimelineView($with_hiding = false); $phui_timeline->setShouldAddSpacers(false); $events = $phui_timeline->buildEvents(); return id(new AphrontAjaxResponse()) ->setContent(array( 'timeline' => hsprintf('%s', $events), )); } } diff --git a/src/applications/transactions/controller/PhabricatorApplicationTransactionValueController.php b/src/applications/transactions/controller/PhabricatorApplicationTransactionValueController.php index 3a73a982e0..6808ed2af5 100644 --- a/src/applications/transactions/controller/PhabricatorApplicationTransactionValueController.php +++ b/src/applications/transactions/controller/PhabricatorApplicationTransactionValueController.php @@ -1,147 +1,145 @@ getRequest(); - $viewer = $request->getUser(); - + $viewer = $this->getViewer(); $phid = $request->getURIData('phid'); $type = $request->getURIData('value'); $xaction = id(new PhabricatorObjectQuery()) ->setViewer($viewer) ->withPHIDs(array($phid)) ->executeOne(); if (!$xaction) { return new Aphront404Response(); } // For now, this pathway only supports policy transactions // to show the details of custom policies. If / when this pathway // supports more transaction types, rendering coding should be moved // into PhabricatorTransactions e.g. feed rendering code. // TODO: This should be some kind of "hey do you support this?" thing on // the transactions themselves. switch ($xaction->getTransactionType()) { case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY: case PhabricatorTransactions::TYPE_JOIN_POLICY: case PhabricatorRepositoryTransaction::TYPE_PUSH_POLICY: break; default: return new Aphront404Response(); break; } if ($type == 'old') { $value = $xaction->getOldValue(); } else { $value = $xaction->getNewValue(); } $policy = id(new PhabricatorPolicyQuery()) ->setViewer($viewer) ->withPHIDs(array($value)) ->executeOne(); if (!$policy) { return new Aphront404Response(); } if ($policy->getType() != PhabricatorPolicyType::TYPE_CUSTOM) { return new Aphront404Response(); } $rule_objects = array(); foreach ($policy->getCustomRuleClasses() as $class) { $rule_objects[$class] = newv($class, array()); } $policy->attachRuleObjects($rule_objects); $this->requireResource('policy-transaction-detail-css'); $cancel_uri = $this->guessCancelURI($viewer, $xaction); return $this->newDialog() ->setTitle($policy->getFullName()) ->setWidth(AphrontDialogView::WIDTH_FORM) ->appendChild($this->renderPolicyDetails($policy, $rule_objects)) ->addCancelButton($cancel_uri, pht('Close')); } private function extractPHIDs( PhabricatorPolicy $policy, array $rule_objects) { $phids = array(); foreach ($policy->getRules() as $rule) { $rule_object = $rule_objects[$rule['rule']]; $phids[] = $rule_object->getRequiredHandlePHIDsForSummary($rule['value']); } return array_filter(array_mergev($phids)); } private function renderPolicyDetails( PhabricatorPolicy $policy, array $rule_objects) { $details = array(); $details[] = phutil_tag( 'p', array( 'class' => 'policy-transaction-detail-intro', ), pht('These rules are processed in order:')); foreach ($policy->getRules() as $index => $rule) { $rule_object = $rule_objects[$rule['rule']]; if ($rule['action'] == 'allow') { $icon = 'fa-check-circle green'; } else { $icon = 'fa-minus-circle red'; } $icon = id(new PHUIIconView()) ->setIconFont($icon) ->setText( ucfirst($rule['action']).' '.$rule_object->getRuleDescription()); $handle_phids = $rule_object->getRequiredHandlePHIDsForSummary( $rule['value']); if ($handle_phids) { $value = $this->getViewer() ->renderHandleList($handle_phids) ->setAsInline(true); } else { $value = $rule['value']; } $details[] = phutil_tag('div', array( 'class' => 'policy-transaction-detail-row', ), array( $icon, $value, )); } $details[] = phutil_tag( 'p', array( 'class' => 'policy-transaction-detail-end', ), pht( 'If no rules match, %s all other users.', phutil_tag('b', array(), $policy->getDefaultAction()))); return $details; } }