From e90379dd2d6606a8f4e3e11e122d6e724b67923d Mon Sep 17 00:00:00 2001 From: Chad Little Date: Mon, 27 Jul 2015 09:41:53 -0700 Subject: [PATCH] Update Files for handleRequest Summary: Update Files application Test Plan: Upload a file, edit a file, view details, transforms, delete file Reviewers: epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D13735 --- .../PhabricatorFileCommentController.php | 20 +++----- .../PhabricatorFileComposeController.php | 5 +- .../PhabricatorFileDataController.php | 14 ++---- .../PhabricatorFileDeleteController.php | 22 ++++----- .../PhabricatorFileDropUploadController.php | 5 +- .../PhabricatorFileEditController.php | 14 ++---- .../PhabricatorFileInfoController.php | 46 ++++++++----------- .../PhabricatorFileUploadDialogController.php | 7 ++- 8 files changed, 50 insertions(+), 83 deletions(-) diff --git a/src/applications/files/controller/PhabricatorFileCommentController.php b/src/applications/files/controller/PhabricatorFileCommentController.php index c527e6fc12..11833ea8d8 100644 --- a/src/applications/files/controller/PhabricatorFileCommentController.php +++ b/src/applications/files/controller/PhabricatorFileCommentController.php @@ -2,23 +2,17 @@ final class PhabricatorFileCommentController extends PhabricatorFileController { - 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(); } $file = id(new PhabricatorFileQuery()) - ->setViewer($user) - ->withIDs(array($this->id)) + ->setViewer($viewer) + ->withIDs(array($id)) ->executeOne(); if (!$file) { return new Aphront404Response(); @@ -37,7 +31,7 @@ final class PhabricatorFileCommentController extends PhabricatorFileController { ->setContent($request->getStr('comment'))); $editor = id(new PhabricatorFileEditor()) - ->setActor($user) + ->setActor($viewer) ->setContinueOnNoEffect($request->isContinueRequest()) ->setContentSourceFromRequest($request) ->setIsPreview($is_preview); @@ -56,7 +50,7 @@ final class PhabricatorFileCommentController extends PhabricatorFileController { if ($request->isAjax() && $is_preview) { return id(new PhabricatorApplicationTransactionResponse()) - ->setViewer($user) + ->setViewer($viewer) ->setTransactions($xactions) ->setIsPreview($is_preview); } else { diff --git a/src/applications/files/controller/PhabricatorFileComposeController.php b/src/applications/files/controller/PhabricatorFileComposeController.php index f3e450add5..de5a6757a4 100644 --- a/src/applications/files/controller/PhabricatorFileComposeController.php +++ b/src/applications/files/controller/PhabricatorFileComposeController.php @@ -3,9 +3,8 @@ final class PhabricatorFileComposeController extends PhabricatorFileController { - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); $colors = array( 'red' => pht('Verbillion'), diff --git a/src/applications/files/controller/PhabricatorFileDataController.php b/src/applications/files/controller/PhabricatorFileDataController.php index e528eb15f2..848560f099 100644 --- a/src/applications/files/controller/PhabricatorFileDataController.php +++ b/src/applications/files/controller/PhabricatorFileDataController.php @@ -7,19 +7,15 @@ final class PhabricatorFileDataController extends PhabricatorFileController { private $token; private $file; - public function willProcessRequest(array $data) { - $this->phid = $data['phid']; - $this->key = $data['key']; - $this->token = idx($data, 'token'); - } - public function shouldRequireLogin() { return false; } - public function processRequest() { - $request = $this->getRequest(); - $viewer = $this->getViewer(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $this->phid = $request->getURIData('phid'); + $this->key = $request->getURIData('key'); + $this->token = $request->getURIData('token'); $alt = PhabricatorEnv::getEnvConfig('security.alternate-file-domain'); $base_uri = PhabricatorEnv::getEnvConfig('phabricator.base-uri'); diff --git a/src/applications/files/controller/PhabricatorFileDeleteController.php b/src/applications/files/controller/PhabricatorFileDeleteController.php index ed245c5cba..a07fe2e91a 100644 --- a/src/applications/files/controller/PhabricatorFileDeleteController.php +++ b/src/applications/files/controller/PhabricatorFileDeleteController.php @@ -2,19 +2,13 @@ final class PhabricatorFileDeleteController extends PhabricatorFileController { - private $id; - - public function willProcessRequest(array $data) { - $this->id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); $file = id(new PhabricatorFileQuery()) - ->setViewer($user) - ->withIDs(array($this->id)) + ->setViewer($viewer) + ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, @@ -25,8 +19,8 @@ final class PhabricatorFileDeleteController extends PhabricatorFileController { return new Aphront404Response(); } - if (($user->getPHID() != $file->getAuthorPHID()) && - (!$user->getIsAdmin())) { + if (($viewer->getPHID() != $file->getAuthorPHID()) && + (!$viewer->getIsAdmin())) { return new Aphront403Response(); } @@ -36,7 +30,7 @@ final class PhabricatorFileDeleteController extends PhabricatorFileController { } $dialog = new AphrontDialogView(); - $dialog->setUser($user); + $dialog->setUser($viewer); $dialog->setTitle(pht('Really delete file?')); $dialog->appendChild(hsprintf( '

%s

', diff --git a/src/applications/files/controller/PhabricatorFileDropUploadController.php b/src/applications/files/controller/PhabricatorFileDropUploadController.php index 34f6bc81e8..fbc4daa93c 100644 --- a/src/applications/files/controller/PhabricatorFileDropUploadController.php +++ b/src/applications/files/controller/PhabricatorFileDropUploadController.php @@ -6,9 +6,8 @@ final class PhabricatorFileDropUploadController /** * @phutil-external-symbol class PhabricatorStartup */ - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); // NOTE: Throws if valid CSRF token is not present in the request. $request->validateCSRF(); diff --git a/src/applications/files/controller/PhabricatorFileEditController.php b/src/applications/files/controller/PhabricatorFileEditController.php index a496202093..9c416b588c 100644 --- a/src/applications/files/controller/PhabricatorFileEditController.php +++ b/src/applications/files/controller/PhabricatorFileEditController.php @@ -2,19 +2,13 @@ final class PhabricatorFileEditController extends PhabricatorFileController { - private $id; - - public function willProcessRequest(array $data) { - $this->id = $data['id']; - } - - public function processRequest() { - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); $file = id(new PhabricatorFileQuery()) ->setViewer($viewer) - ->withIDs(array($this->id)) + ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, diff --git a/src/applications/files/controller/PhabricatorFileInfoController.php b/src/applications/files/controller/PhabricatorFileInfoController.php index 0e3d041eac..d9b5de14ee 100644 --- a/src/applications/files/controller/PhabricatorFileInfoController.php +++ b/src/applications/files/controller/PhabricatorFileInfoController.php @@ -2,26 +2,19 @@ final class PhabricatorFileInfoController extends PhabricatorFileController { - private $phid; - private $id; - public function shouldAllowPublic() { return true; } - public function willProcessRequest(array $data) { - $this->phid = idx($data, 'phid'); - $this->id = idx($data, 'id'); - } + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $id = $request->getURIData('id'); + $phid = $request->getURIData('phid'); - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); - - if ($this->phid) { + if ($phid) { $file = id(new PhabricatorFileQuery()) - ->setViewer($user) - ->withPHIDs(array($this->phid)) + ->setViewer($viewer) + ->withPHIDs(array($phid)) ->executeOne(); if (!$file) { @@ -30,8 +23,8 @@ final class PhabricatorFileInfoController extends PhabricatorFileController { return id(new AphrontRedirectResponse())->setURI($file->getInfoURI()); } $file = id(new PhabricatorFileQuery()) - ->setViewer($user) - ->withIDs(array($this->id)) + ->setViewer($viewer) + ->withIDs(array($id)) ->executeOne(); if (!$file) { return new Aphront404Response(); @@ -40,7 +33,7 @@ final class PhabricatorFileInfoController extends PhabricatorFileController { $phid = $file->getPHID(); $header = id(new PHUIHeaderView()) - ->setUser($user) + ->setUser($viewer) ->setPolicyObject($file) ->setHeader($file->getName()); @@ -87,7 +80,7 @@ final class PhabricatorFileInfoController extends PhabricatorFileController { } private function buildTransactionView(PhabricatorFile $file) { - $user = $this->getRequest()->getUser(); + $viewer = $this->getViewer(); $timeline = $this->buildTransactionTimeline( $file, @@ -99,10 +92,10 @@ final class PhabricatorFileInfoController extends PhabricatorFileController { ? pht('Add Comment') : pht('Question File Integrity'); - $draft = PhabricatorDraft::newFromUserAndKey($user, $file->getPHID()); + $draft = PhabricatorDraft::newFromUserAndKey($viewer, $file->getPHID()); $add_comment_form = id(new PhabricatorApplicationTransactionCommentView()) - ->setUser($user) + ->setUser($viewer) ->setObjectPHID($file->getPHID()) ->setDraft($draft) ->setHeaderText($add_comment_header) @@ -116,8 +109,7 @@ final class PhabricatorFileInfoController extends PhabricatorFileController { } private function buildActionView(PhabricatorFile $file) { - $request = $this->getRequest(); - $viewer = $request->getUser(); + $viewer = $this->getViewer(); $id = $file->getID(); @@ -184,7 +176,7 @@ final class PhabricatorFileInfoController extends PhabricatorFileController { PhabricatorFile $file, PhabricatorActionListView $actions) { $request = $this->getRequest(); - $user = $request->getUser(); + $viewer = $request->getUser(); $properties = id(new PHUIPropertyListView()); $properties->setActionList($actions); @@ -193,12 +185,12 @@ final class PhabricatorFileInfoController extends PhabricatorFileController { if ($file->getAuthorPHID()) { $properties->addProperty( pht('Author'), - $user->renderHandle($file->getAuthorPHID())); + $viewer->renderHandle($file->getAuthorPHID())); } $properties->addProperty( pht('Created'), - phabricator_datetime($file->getDateCreated(), $user)); + phabricator_datetime($file->getDateCreated(), $viewer)); $finfo = id(new PHUIPropertyListView()); @@ -276,7 +268,7 @@ final class PhabricatorFileInfoController extends PhabricatorFileController { $attached->addProperty( pht('Attached To'), - $user->renderHandleList($phids)); + $viewer->renderHandleList($phids)); } if ($file->isViewableImage()) { @@ -330,7 +322,7 @@ final class PhabricatorFileInfoController extends PhabricatorFileController { $box->addPropertyList($chunkinfo, pht('Chunks')); $chunks = id(new PhabricatorFileChunkQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withChunkHandles(array($file->getStorageHandle())) ->execute(); $chunks = msort($chunks, 'getByteStart'); diff --git a/src/applications/files/controller/PhabricatorFileUploadDialogController.php b/src/applications/files/controller/PhabricatorFileUploadDialogController.php index e99910c430..dd22caa74a 100644 --- a/src/applications/files/controller/PhabricatorFileUploadDialogController.php +++ b/src/applications/files/controller/PhabricatorFileUploadDialogController.php @@ -3,12 +3,11 @@ final class PhabricatorFileUploadDialogController extends PhabricatorFileController { - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); $dialog = id(new AphrontDialogView()) - ->setUser($user) + ->setUser($viewer) ->setTitle(pht('Upload File')) ->appendChild(pht( 'To add files, drag and drop them into the comment text area.'))