1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 21:32:43 +01:00

Update Paste for handleRequest

Summary: Updates Paste

Test Plan: New paste, edit, view lists

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T8628

Differential Revision: https://secure.phabricator.com/D13766
This commit is contained in:
Chad Little 2015-08-01 15:42:47 -07:00
parent eea94aaf67
commit 917fa250d0
4 changed files with 39 additions and 57 deletions

View file

@ -3,23 +3,17 @@
final class PhabricatorPasteCommentController
extends PhabricatorPasteController {
private $id;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
if (!$request->isFormPost()) {
return new Aphront400Response();
}
$paste = id(new PhabricatorPasteQuery())
->setViewer($user)
->withIDs(array($this->id))
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$paste) {
return new Aphront404Response();
@ -38,7 +32,7 @@ final class PhabricatorPasteCommentController
->setContent($request->getStr('comment')));
$editor = id(new PhabricatorPasteEditor())
->setActor($user)
->setActor($viewer)
->setContinueOnNoEffect($request->isContinueRequest())
->setContentSourceFromRequest($request)
->setIsPreview($is_preview);
@ -57,7 +51,7 @@ final class PhabricatorPasteCommentController
if ($request->isAjax() && $is_preview) {
return id(new PhabricatorApplicationTransactionResponse())
->setViewer($user)
->setViewer($viewer)
->setTransactions($xactions)
->setIsPreview($is_preview);
} else {

View file

@ -2,29 +2,23 @@
final class PhabricatorPasteEditController extends PhabricatorPasteController {
private $id;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$parent = null;
$parent_id = null;
if (!$this->id) {
if (!$id) {
$is_create = true;
$paste = PhabricatorPaste::initializeNewPaste($user);
$paste = PhabricatorPaste::initializeNewPaste($viewer);
$parent_id = $request->getStr('parent');
if ($parent_id) {
// NOTE: If the Paste is forked from a paste which the user no longer
// has permission to see, we still let them edit it.
$parent = id(new PhabricatorPasteQuery())
->setViewer($user)
->setViewer($viewer)
->withIDs(array($parent_id))
->needContent(true)
->needRawContent(true)
@ -37,19 +31,19 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
}
}
$paste->setAuthorPHID($user->getPHID());
$paste->setAuthorPHID($viewer->getPHID());
$paste->attachRawContent('');
} else {
$is_create = false;
$paste = id(new PhabricatorPasteQuery())
->setViewer($user)
->setViewer($viewer)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($this->id))
->withIDs(array($id))
->needRawContent(true)
->executeOne();
if (!$paste) {
@ -97,7 +91,7 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
if ($is_create || ($v_text !== $paste->getRawContent())) {
$file = PhabricatorPasteEditor::initializeFileForPaste(
$user,
$viewer,
$v_title,
$v_text);
@ -129,7 +123,7 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
->setNewValue(array('=' => array_fuse($v_projects)));
$editor = id(new PhabricatorPasteEditor())
->setActor($user)
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true);
@ -148,7 +142,7 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
) + PhabricatorEnv::getEnvConfig('pygments.dropdown-choices');
$form
->setUser($user)
->setUser($viewer)
->addHiddenInput('parent', $parent_id)
->appendChild(
id(new AphrontFormTextControl())
@ -163,13 +157,13 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
->setOptions($langs));
$policies = id(new PhabricatorPolicyQuery())
->setViewer($user)
->setViewer($viewer)
->setObject($paste)
->execute();
$form->appendChild(
id(new AphrontFormPolicyControl())
->setUser($user)
->setUser($viewer)
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
->setPolicyObject($paste)
->setPolicies($policies)
@ -179,7 +173,7 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
$form->appendChild(
id(new AphrontFormPolicyControl())
->setUser($user)
->setUser($viewer)
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
->setPolicyObject($paste)
->setPolicies($policies)

View file

@ -2,19 +2,15 @@
final class PhabricatorPasteListController extends PhabricatorPasteController {
private $queryKey;
public function shouldAllowPublic() {
return true;
}
public function willProcessRequest(array $data) {
$this->queryKey = idx($data, 'queryKey');
}
public function handleRequest(AphrontRequest $request) {
$querykey = $request->getURIData('queryKey');
public function processRequest() {
$controller = id(new PhabricatorApplicationSearchController())
->setQueryKey($this->queryKey)
->setQueryKey($querykey)
->setSearchEngine(new PhabricatorPasteSearchEngine())
->setNavigation($this->buildSideNavView());

View file

@ -5,7 +5,6 @@
*/
final class PhabricatorPasteViewController extends PhabricatorPasteController {
private $id;
private $highlightMap;
public function shouldAllowPublic() {
@ -13,7 +12,6 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
}
public function willProcessRequest(array $data) {
$this->id = $data['id'];
$raw_lines = idx($data, 'lines');
$map = array();
if ($raw_lines) {
@ -31,13 +29,13 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
$this->highlightMap = $map;
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$paste = id(new PhabricatorPasteQuery())
->setViewer($user)
->withIDs(array($this->id))
->setViewer($viewer)
->withIDs(array($id))
->needContent(true)
->executeOne();
if (!$paste) {
@ -45,7 +43,7 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
}
$file = id(new PhabricatorFileQuery())
->setViewer($user)
->setViewer($viewer)
->withPHIDs(array($paste->getFilePHID()))
->executeOne();
if (!$file) {
@ -53,13 +51,13 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
}
$forks = id(new PhabricatorPasteQuery())
->setViewer($user)
->setViewer($viewer)
->withParentPHIDs(array($paste->getPHID()))
->execute();
$fork_phids = mpull($forks, 'getPHID');
$header = $this->buildHeaderView($paste);
$actions = $this->buildActionView($user, $paste, $file);
$actions = $this->buildActionView($viewer, $paste, $file);
$properties = $this->buildPropertyView($paste, $fork_phids, $actions);
$object_box = id(new PHUIObjectBoxView())
@ -90,10 +88,10 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
? pht('Add Comment')
: pht('Eat Paste');
$draft = PhabricatorDraft::newFromUserAndKey($user, $paste->getPHID());
$draft = PhabricatorDraft::newFromUserAndKey($viewer, $paste->getPHID());
$add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
->setUser($user)
->setUser($viewer)
->setObjectPHID($paste->getPHID())
->setDraft($draft)
->setHeaderText($add_comment_header)
@ -126,20 +124,20 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
}
private function buildActionView(
PhabricatorUser $user,
PhabricatorUser $viewer,
PhabricatorPaste $paste,
PhabricatorFile $file) {
$can_edit = PhabricatorPolicyFilter::hasCapability(
$user,
$viewer,
$paste,
PhabricatorPolicyCapability::CAN_EDIT);
$can_fork = $user->isLoggedIn();
$can_fork = $viewer->isLoggedIn();
$fork_uri = $this->getApplicationURI('/create/?parent='.$paste->getID());
return id(new PhabricatorActionListView())
->setUser($user)
->setUser($viewer)
->setObject($paste)
->setObjectURI($this->getRequest()->getRequestURI())
->addAction(