1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-25 06:50:55 +01:00

Convert Macro to handleRequest

Summary: Converts Macro app

Test Plan: Make Macro, Make meme

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T8628

Differential Revision: https://secure.phabricator.com/D13724
This commit is contained in:
Chad Little 2015-07-27 09:04:08 -07:00
parent 55b685d3fc
commit 18a9fe85c8
8 changed files with 53 additions and 89 deletions

View file

@ -2,26 +2,20 @@
final class PhabricatorMacroAudioController extends PhabricatorMacroController { final class PhabricatorMacroAudioController extends PhabricatorMacroController {
private $id; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() {
$this->requireApplicationCapability( $this->requireApplicationCapability(
PhabricatorMacroManageCapability::CAPABILITY); PhabricatorMacroManageCapability::CAPABILITY);
$request = $this->getRequest();
$viewer = $request->getUser();
$macro = id(new PhabricatorMacroQuery()) $macro = id(new PhabricatorMacroQuery())
->setViewer($viewer) ->setViewer($viewer)
->requireCapabilities( ->requireCapabilities(
array( array(
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,
)) ))
->withIDs(array($this->id)) ->withIDs(array($id))
->executeOne(); ->executeOne();
if (!$macro) { if (!$macro) {

View file

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

View file

@ -3,28 +3,22 @@
final class PhabricatorMacroDisableController final class PhabricatorMacroDisableController
extends PhabricatorMacroController { extends PhabricatorMacroController {
private $id; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$this->requireApplicationCapability( $this->requireApplicationCapability(
PhabricatorMacroManageCapability::CAPABILITY); PhabricatorMacroManageCapability::CAPABILITY);
$request = $this->getRequest();
$user = $request->getUser();
$macro = id(new PhabricatorMacroQuery()) $macro = id(new PhabricatorMacroQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->executeOne(); ->executeOne();
if (!$macro) { if (!$macro) {
return new Aphront404Response(); return new Aphront404Response();
} }
$view_uri = $this->getApplicationURI('/view/'.$this->id.'/'); $view_uri = $this->getApplicationURI('/view/'.$id.'/');
if ($request->isDialogFormPost() || $macro->getIsDisabled()) { if ($request->isDialogFormPost() || $macro->getIsDisabled()) {
$xaction = id(new PhabricatorMacroTransaction()) $xaction = id(new PhabricatorMacroTransaction())
@ -32,7 +26,7 @@ final class PhabricatorMacroDisableController
->setNewValue($macro->getIsDisabled() ? 0 : 1); ->setNewValue($macro->getIsDisabled() ? 0 : 1);
$editor = id(new PhabricatorMacroEditor()) $editor = id(new PhabricatorMacroEditor())
->setActor($user) ->setActor($viewer)
->setContentSourceFromRequest($request); ->setContentSourceFromRequest($request);
$xactions = $editor->applyTransactions($macro, array($xaction)); $xactions = $editor->applyTransactions($macro, array($xaction));
@ -52,7 +46,7 @@ final class PhabricatorMacroDisableController
'Really disable the much-beloved image macro %s? '. 'Really disable the much-beloved image macro %s? '.
'It will be sorely missed.', 'It will be sorely missed.',
$macro->getName()))) $macro->getName())))
->setSubmitURI($this->getApplicationURI('/disable/'.$this->id.'/')) ->setSubmitURI($this->getApplicationURI('/disable/'.$id.'/'))
->addSubmitButton(pht('Disable')) ->addSubmitButton(pht('Disable'))
->addCancelButton($view_uri); ->addCancelButton($view_uri);

View file

@ -2,23 +2,17 @@
final class PhabricatorMacroEditController extends PhabricatorMacroController { final class PhabricatorMacroEditController extends PhabricatorMacroController {
private $id; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() {
$this->requireApplicationCapability( $this->requireApplicationCapability(
PhabricatorMacroManageCapability::CAPABILITY); PhabricatorMacroManageCapability::CAPABILITY);
$request = $this->getRequest(); if ($id) {
$user = $request->getUser();
if ($this->id) {
$macro = id(new PhabricatorMacroQuery()) $macro = id(new PhabricatorMacroQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->needFiles(true) ->needFiles(true)
->executeOne(); ->executeOne();
if (!$macro) { if (!$macro) {
@ -26,7 +20,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController {
} }
} else { } else {
$macro = new PhabricatorFileImageMacro(); $macro = new PhabricatorFileImageMacro();
$macro->setAuthorPHID($user->getPHID()); $macro->setAuthorPHID($viewer->getPHID());
} }
$errors = array(); $errors = array();
@ -66,7 +60,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController {
$_FILES['file'], $_FILES['file'],
array( array(
'name' => $request->getStr('name'), 'name' => $request->getStr('name'),
'authorPHID' => $user->getPHID(), 'authorPHID' => $viewer->getPHID(),
'isExplicitUpload' => true, 'isExplicitUpload' => true,
'canCDN' => true, 'canCDN' => true,
)); ));
@ -75,7 +69,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController {
// Rate limit outbound fetches to make this mechanism less useful for // Rate limit outbound fetches to make this mechanism less useful for
// scanning networks and ports. // scanning networks and ports.
PhabricatorSystemActionEngine::willTakeAction( PhabricatorSystemActionEngine::willTakeAction(
array($user->getPHID()), array($viewer->getPHID()),
new PhabricatorFilesOutboundRequestAction(), new PhabricatorFilesOutboundRequestAction(),
1); 1);
@ -101,7 +95,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController {
$mime_type)); $mime_type));
} else { } else {
$file $file
->setAuthorPHID($user->getPHID()) ->setAuthorPHID($viewer->getPHID())
->save(); ->save();
} }
} catch (HTTPFutureHTTPResponseStatus $status) { } catch (HTTPFutureHTTPResponseStatus $status) {
@ -114,7 +108,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController {
} }
} else if ($request->getStr('phid')) { } else if ($request->getStr('phid')) {
$file = id(new PhabricatorFileQuery()) $file = id(new PhabricatorFileQuery())
->setViewer($user) ->setViewer($viewer)
->withPHIDs(array($request->getStr('phid'))) ->withPHIDs(array($request->getStr('phid')))
->executeOne(); ->executeOne();
} }
@ -152,7 +146,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController {
} }
$editor = id(new PhabricatorMacroEditor()) $editor = id(new PhabricatorMacroEditor())
->setActor($user) ->setActor($viewer)
->setContinueOnNoEffect(true) ->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request); ->setContentSourceFromRequest($request);

View file

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

View file

@ -7,14 +7,13 @@ final class PhabricatorMacroMemeController
return true; return true;
} }
public function processRequest() { public function handleRequest(AphrontRequest $request) {
$request = $this->getRequest();
$macro_name = $request->getStr('macro'); $macro_name = $request->getStr('macro');
$upper_text = $request->getStr('uppertext'); $upper_text = $request->getStr('uppertext');
$lower_text = $request->getStr('lowertext'); $lower_text = $request->getStr('lowertext');
$user = $request->getUser(); $viewer = $request->getViewer();
$uri = self::generateMacro($user, $macro_name, $uri = self::generateMacro($viewer, $macro_name,
$upper_text, $lower_text); $upper_text, $lower_text);
if ($uri === false) { if ($uri === false) {
return new Aphront404Response(); return new Aphront404Response();
@ -24,10 +23,10 @@ final class PhabricatorMacroMemeController
->setURI($uri); ->setURI($uri);
} }
public static function generateMacro($user, $macro_name, $upper_text, public static function generateMacro($viewer, $macro_name, $upper_text,
$lower_text) { $lower_text) {
$macro = id(new PhabricatorMacroQuery()) $macro = id(new PhabricatorMacroQuery())
->setViewer($user) ->setViewer($viewer)
->withNames(array($macro_name)) ->withNames(array($macro_name))
->needFiles(true) ->needFiles(true)
->executeOne(); ->executeOne();
@ -46,7 +45,7 @@ final class PhabricatorMacroMemeController
if ($xform) { if ($xform) {
$memefile = id(new PhabricatorFileQuery()) $memefile = id(new PhabricatorFileQuery())
->setViewer($user) ->setViewer($viewer)
->withPHIDs(array($xform->getTransformedPHID())) ->withPHIDs(array($xform->getTransformedPHID()))
->executeOne(); ->executeOne();
if ($memefile) { if ($memefile) {

View file

@ -3,9 +3,8 @@
final class PhabricatorMacroMemeDialogController final class PhabricatorMacroMemeDialogController
extends PhabricatorMacroController { extends PhabricatorMacroController {
public function processRequest() { public function handleRequest(AphrontRequest $request) {
$request = $this->getRequest(); $viewer = $request->getViewer();
$user = $request->getUser();
$phid = head($request->getArr('macro')); $phid = head($request->getArr('macro'));
$above = $request->getStr('above'); $above = $request->getStr('above');
@ -19,7 +18,7 @@ final class PhabricatorMacroMemeDialogController
$errors[] = pht('Macro name is required.'); $errors[] = pht('Macro name is required.');
} else { } else {
$macro = id(new PhabricatorMacroQuery()) $macro = id(new PhabricatorMacroQuery())
->setViewer($user) ->setViewer($viewer)
->withPHIDs(array($phid)) ->withPHIDs(array($phid))
->executeOne(); ->executeOne();
if (!$macro) { if (!$macro) {
@ -45,7 +44,7 @@ final class PhabricatorMacroMemeDialogController
} }
$view = id(new AphrontFormView()) $view = id(new AphrontFormView())
->setUser($user) ->setUser($viewer)
->appendControl( ->appendControl(
id(new AphrontFormTokenizerControl()) id(new AphrontFormTokenizerControl())
->setLabel(pht('Macro')) ->setLabel(pht('Macro'))
@ -65,7 +64,7 @@ final class PhabricatorMacroMemeDialogController
->setValue($below)); ->setValue($below));
$dialog = id(new AphrontDialogView()) $dialog = id(new AphrontDialogView())
->setUser($user) ->setUser($viewer)
->setTitle(pht('Create Meme')) ->setTitle(pht('Create Meme'))
->appendForm($view) ->appendForm($view)
->addCancelButton('/') ->addCancelButton('/')

View file

@ -3,23 +3,17 @@
final class PhabricatorMacroViewController final class PhabricatorMacroViewController
extends PhabricatorMacroController { extends PhabricatorMacroController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;
} }
public function processRequest() { public function handleRequest(AphrontRequest $request) {
$request = $this->getRequest(); $viewer = $request->getViewer();
$user = $request->getUser(); $id = $request->getURIData('id');
$macro = id(new PhabricatorMacroQuery()) $macro = id(new PhabricatorMacroQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->needFiles(true) ->needFiles(true)
->executeOne(); ->executeOne();
if (!$macro) { if (!$macro) {
@ -55,7 +49,7 @@ final class PhabricatorMacroViewController
new PhabricatorMacroTransactionQuery()); new PhabricatorMacroTransactionQuery());
$header = id(new PHUIHeaderView()) $header = id(new PHUIHeaderView())
->setUser($user) ->setUser($viewer)
->setPolicyObject($macro) ->setPolicyObject($macro)
->setHeader($title_long); ->setHeader($title_long);
@ -71,10 +65,10 @@ final class PhabricatorMacroViewController
? pht('Add Comment') ? pht('Add Comment')
: pht('Grovel in Awe'); : pht('Grovel in Awe');
$draft = PhabricatorDraft::newFromUserAndKey($user, $macro->getPHID()); $draft = PhabricatorDraft::newFromUserAndKey($viewer, $macro->getPHID());
$add_comment_form = id(new PhabricatorApplicationTransactionCommentView()) $add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
->setUser($user) ->setUser($viewer)
->setObjectPHID($macro->getPHID()) ->setObjectPHID($macro->getPHID())
->setDraft($draft) ->setDraft($draft)
->setHeaderText($comment_header) ->setHeaderText($comment_header)