mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +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:
parent
55b685d3fc
commit
18a9fe85c8
8 changed files with 53 additions and 89 deletions
|
@ -2,26 +2,20 @@
|
|||
|
||||
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(
|
||||
PhabricatorMacroManageCapability::CAPABILITY);
|
||||
|
||||
$request = $this->getRequest();
|
||||
$viewer = $request->getUser();
|
||||
|
||||
$macro = id(new PhabricatorMacroQuery())
|
||||
->setViewer($viewer)
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
))
|
||||
->withIDs(array($this->id))
|
||||
->withIDs(array($id))
|
||||
->executeOne();
|
||||
|
||||
if (!$macro) {
|
||||
|
|
|
@ -3,23 +3,17 @@
|
|||
final class PhabricatorMacroCommentController
|
||||
extends PhabricatorMacroController {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
$macro = id(new PhabricatorMacroQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->executeOne();
|
||||
if (!$macro) {
|
||||
return new Aphront404Response();
|
||||
|
@ -38,7 +32,7 @@ final class PhabricatorMacroCommentController
|
|||
->setContent($request->getStr('comment')));
|
||||
|
||||
$editor = id(new PhabricatorMacroEditor())
|
||||
->setActor($user)
|
||||
->setActor($viewer)
|
||||
->setContinueOnNoEffect($request->isContinueRequest())
|
||||
->setContentSourceFromRequest($request)
|
||||
->setIsPreview($is_preview);
|
||||
|
@ -57,7 +51,7 @@ final class PhabricatorMacroCommentController
|
|||
|
||||
if ($request->isAjax() && $is_preview) {
|
||||
return id(new PhabricatorApplicationTransactionResponse())
|
||||
->setViewer($user)
|
||||
->setViewer($viewer)
|
||||
->setTransactions($xactions)
|
||||
->setIsPreview($is_preview);
|
||||
} else {
|
||||
|
|
|
@ -3,28 +3,22 @@
|
|||
final class PhabricatorMacroDisableController
|
||||
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(
|
||||
PhabricatorMacroManageCapability::CAPABILITY);
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$macro = id(new PhabricatorMacroQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->executeOne();
|
||||
if (!$macro) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$view_uri = $this->getApplicationURI('/view/'.$this->id.'/');
|
||||
$view_uri = $this->getApplicationURI('/view/'.$id.'/');
|
||||
|
||||
if ($request->isDialogFormPost() || $macro->getIsDisabled()) {
|
||||
$xaction = id(new PhabricatorMacroTransaction())
|
||||
|
@ -32,7 +26,7 @@ final class PhabricatorMacroDisableController
|
|||
->setNewValue($macro->getIsDisabled() ? 0 : 1);
|
||||
|
||||
$editor = id(new PhabricatorMacroEditor())
|
||||
->setActor($user)
|
||||
->setActor($viewer)
|
||||
->setContentSourceFromRequest($request);
|
||||
|
||||
$xactions = $editor->applyTransactions($macro, array($xaction));
|
||||
|
@ -52,7 +46,7 @@ final class PhabricatorMacroDisableController
|
|||
'Really disable the much-beloved image macro %s? '.
|
||||
'It will be sorely missed.',
|
||||
$macro->getName())))
|
||||
->setSubmitURI($this->getApplicationURI('/disable/'.$this->id.'/'))
|
||||
->setSubmitURI($this->getApplicationURI('/disable/'.$id.'/'))
|
||||
->addSubmitButton(pht('Disable'))
|
||||
->addCancelButton($view_uri);
|
||||
|
||||
|
|
|
@ -2,23 +2,17 @@
|
|||
|
||||
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(
|
||||
PhabricatorMacroManageCapability::CAPABILITY);
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
if ($this->id) {
|
||||
if ($id) {
|
||||
$macro = id(new PhabricatorMacroQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->needFiles(true)
|
||||
->executeOne();
|
||||
if (!$macro) {
|
||||
|
@ -26,7 +20,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController {
|
|||
}
|
||||
} else {
|
||||
$macro = new PhabricatorFileImageMacro();
|
||||
$macro->setAuthorPHID($user->getPHID());
|
||||
$macro->setAuthorPHID($viewer->getPHID());
|
||||
}
|
||||
|
||||
$errors = array();
|
||||
|
@ -66,7 +60,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController {
|
|||
$_FILES['file'],
|
||||
array(
|
||||
'name' => $request->getStr('name'),
|
||||
'authorPHID' => $user->getPHID(),
|
||||
'authorPHID' => $viewer->getPHID(),
|
||||
'isExplicitUpload' => true,
|
||||
'canCDN' => true,
|
||||
));
|
||||
|
@ -75,7 +69,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController {
|
|||
// Rate limit outbound fetches to make this mechanism less useful for
|
||||
// scanning networks and ports.
|
||||
PhabricatorSystemActionEngine::willTakeAction(
|
||||
array($user->getPHID()),
|
||||
array($viewer->getPHID()),
|
||||
new PhabricatorFilesOutboundRequestAction(),
|
||||
1);
|
||||
|
||||
|
@ -101,7 +95,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController {
|
|||
$mime_type));
|
||||
} else {
|
||||
$file
|
||||
->setAuthorPHID($user->getPHID())
|
||||
->setAuthorPHID($viewer->getPHID())
|
||||
->save();
|
||||
}
|
||||
} catch (HTTPFutureHTTPResponseStatus $status) {
|
||||
|
@ -114,7 +108,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController {
|
|||
}
|
||||
} else if ($request->getStr('phid')) {
|
||||
$file = id(new PhabricatorFileQuery())
|
||||
->setViewer($user)
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($request->getStr('phid')))
|
||||
->executeOne();
|
||||
}
|
||||
|
@ -152,7 +146,7 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController {
|
|||
}
|
||||
|
||||
$editor = id(new PhabricatorMacroEditor())
|
||||
->setActor($user)
|
||||
->setActor($viewer)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setContentSourceFromRequest($request);
|
||||
|
||||
|
|
|
@ -2,19 +2,15 @@
|
|||
|
||||
final class PhabricatorMacroListController extends PhabricatorMacroController {
|
||||
|
||||
private $key;
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->key = idx($data, 'key');
|
||||
}
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$key = $request->getURIData('key');
|
||||
|
||||
public function processRequest() {
|
||||
$controller = id(new PhabricatorApplicationSearchController())
|
||||
->setQueryKey($this->key)
|
||||
->setQueryKey($key)
|
||||
->setSearchEngine(new PhabricatorMacroSearchEngine())
|
||||
->setNavigation($this->buildSideNavView());
|
||||
|
||||
|
|
|
@ -7,14 +7,13 @@ final class PhabricatorMacroMemeController
|
|||
return true;
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$macro_name = $request->getStr('macro');
|
||||
$upper_text = $request->getStr('uppertext');
|
||||
$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);
|
||||
if ($uri === false) {
|
||||
return new Aphront404Response();
|
||||
|
@ -24,10 +23,10 @@ final class PhabricatorMacroMemeController
|
|||
->setURI($uri);
|
||||
}
|
||||
|
||||
public static function generateMacro($user, $macro_name, $upper_text,
|
||||
public static function generateMacro($viewer, $macro_name, $upper_text,
|
||||
$lower_text) {
|
||||
$macro = id(new PhabricatorMacroQuery())
|
||||
->setViewer($user)
|
||||
->setViewer($viewer)
|
||||
->withNames(array($macro_name))
|
||||
->needFiles(true)
|
||||
->executeOne();
|
||||
|
@ -46,7 +45,7 @@ final class PhabricatorMacroMemeController
|
|||
|
||||
if ($xform) {
|
||||
$memefile = id(new PhabricatorFileQuery())
|
||||
->setViewer($user)
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($xform->getTransformedPHID()))
|
||||
->executeOne();
|
||||
if ($memefile) {
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
final class PhabricatorMacroMemeDialogController
|
||||
extends PhabricatorMacroController {
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
|
||||
$phid = head($request->getArr('macro'));
|
||||
$above = $request->getStr('above');
|
||||
|
@ -19,7 +18,7 @@ final class PhabricatorMacroMemeDialogController
|
|||
$errors[] = pht('Macro name is required.');
|
||||
} else {
|
||||
$macro = id(new PhabricatorMacroQuery())
|
||||
->setViewer($user)
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($phid))
|
||||
->executeOne();
|
||||
if (!$macro) {
|
||||
|
@ -45,7 +44,7 @@ final class PhabricatorMacroMemeDialogController
|
|||
}
|
||||
|
||||
$view = id(new AphrontFormView())
|
||||
->setUser($user)
|
||||
->setUser($viewer)
|
||||
->appendControl(
|
||||
id(new AphrontFormTokenizerControl())
|
||||
->setLabel(pht('Macro'))
|
||||
|
@ -65,7 +64,7 @@ final class PhabricatorMacroMemeDialogController
|
|||
->setValue($below));
|
||||
|
||||
$dialog = id(new AphrontDialogView())
|
||||
->setUser($user)
|
||||
->setUser($viewer)
|
||||
->setTitle(pht('Create Meme'))
|
||||
->appendForm($view)
|
||||
->addCancelButton('/')
|
||||
|
|
|
@ -3,23 +3,17 @@
|
|||
final class PhabricatorMacroViewController
|
||||
extends PhabricatorMacroController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = $data['id'];
|
||||
}
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
$macro = id(new PhabricatorMacroQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->needFiles(true)
|
||||
->executeOne();
|
||||
if (!$macro) {
|
||||
|
@ -55,7 +49,7 @@ final class PhabricatorMacroViewController
|
|||
new PhabricatorMacroTransactionQuery());
|
||||
|
||||
$header = id(new PHUIHeaderView())
|
||||
->setUser($user)
|
||||
->setUser($viewer)
|
||||
->setPolicyObject($macro)
|
||||
->setHeader($title_long);
|
||||
|
||||
|
@ -71,10 +65,10 @@ final class PhabricatorMacroViewController
|
|||
? pht('Add Comment')
|
||||
: pht('Grovel in Awe');
|
||||
|
||||
$draft = PhabricatorDraft::newFromUserAndKey($user, $macro->getPHID());
|
||||
$draft = PhabricatorDraft::newFromUserAndKey($viewer, $macro->getPHID());
|
||||
|
||||
$add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
|
||||
->setUser($user)
|
||||
->setUser($viewer)
|
||||
->setObjectPHID($macro->getPHID())
|
||||
->setDraft($draft)
|
||||
->setHeaderText($comment_header)
|
||||
|
|
Loading…
Reference in a new issue