mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 22:40:55 +01:00
Modernize Phame process handlers
Summary: Converts Phame to use handleRequest where appropriate. Test Plan: Write some blog posts, publish, edit, view. Reviewers: btrahan, epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T8628 Differential Revision: https://secure.phabricator.com/D13677
This commit is contained in:
parent
22740f1752
commit
1643685e72
5 changed files with 42 additions and 74 deletions
|
@ -2,19 +2,13 @@
|
|||
|
||||
final class PhamePostFramedController extends PhameController {
|
||||
|
||||
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) {
|
||||
$user = $request->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
$post = id(new PhamePostQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->withIDs(array($id))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
|
|
|
@ -2,60 +2,52 @@
|
|||
|
||||
final class PhamePostListController extends PhameController {
|
||||
|
||||
private $bloggername;
|
||||
private $filter;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->filter = idx($data, 'filter', 'blogger');
|
||||
$this->bloggername = idx($data, 'bloggername');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$filter = $request->getURIData('filter');
|
||||
$bloggername = $request->getURIData('bloggername');
|
||||
|
||||
$query = id(new PhamePostQuery())
|
||||
->setViewer($user);
|
||||
->setViewer($viewer);
|
||||
|
||||
$nav = $this->renderSideNavFilterView();
|
||||
$nodata = null;
|
||||
|
||||
switch ($this->filter) {
|
||||
switch ($filter) {
|
||||
case 'draft':
|
||||
$query->withBloggerPHIDs(array($user->getPHID()));
|
||||
$query->withBloggerPHIDs(array($viewer->getPHID()));
|
||||
$query->withVisibility(PhamePost::VISIBILITY_DRAFT);
|
||||
$nodata = pht('You have no unpublished drafts.');
|
||||
$title = pht('Unpublished Drafts');
|
||||
$nav->selectFilter('post/draft');
|
||||
break;
|
||||
case 'blogger':
|
||||
if ($this->bloggername) {
|
||||
$blogger = id(new PhabricatorUser())->loadOneWhere(
|
||||
'username = %s',
|
||||
$this->bloggername);
|
||||
if (!$blogger) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
} else {
|
||||
$blogger = $user;
|
||||
}
|
||||
|
||||
$query->withBloggerPHIDs(array($blogger->getPHID()));
|
||||
if ($blogger->getPHID() == $user->getPHID()) {
|
||||
$nav->selectFilter('post');
|
||||
$nodata = pht('You have not written any posts.');
|
||||
} else {
|
||||
$nodata = pht('%s has not written any posts.', $blogger);
|
||||
}
|
||||
$title = pht('Posts by %s', $blogger);
|
||||
break;
|
||||
case 'all':
|
||||
$nodata = pht('There are no visible posts.');
|
||||
$title = pht('Posts');
|
||||
$nav->selectFilter('post/all');
|
||||
break;
|
||||
default:
|
||||
throw new Exception(pht("Unknown filter '%s'!", $this->filter));
|
||||
case 'blogger':
|
||||
if ($bloggername) {
|
||||
$blogger = id(new PhabricatorUser())->loadOneWhere(
|
||||
'username = %s',
|
||||
$bloggername);
|
||||
if (!$blogger) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
} else {
|
||||
$blogger = $viewer;
|
||||
}
|
||||
|
||||
$query->withBloggerPHIDs(array($blogger->getPHID()));
|
||||
if ($blogger->getPHID() == $viewer->getPHID()) {
|
||||
$nav->selectFilter('post');
|
||||
$nodata = pht('You have not written any posts.');
|
||||
} else {
|
||||
$nodata = pht('%s has not written any posts.', $blogger);
|
||||
}
|
||||
$title = pht('Posts by %s', $blogger);
|
||||
break;
|
||||
}
|
||||
|
||||
$pager = id(new AphrontCursorPagerView())
|
||||
|
@ -64,7 +56,7 @@ final class PhamePostListController extends PhameController {
|
|||
$posts = $query->executeWithCursorPager($pager);
|
||||
|
||||
require_celerity_resource('phame-css');
|
||||
$post_list = $this->renderPostList($posts, $user, $nodata);
|
||||
$post_list = $this->renderPostList($posts, $viewer, $nodata);
|
||||
$post_list = id(new PHUIObjectBoxView())
|
||||
->setHeaderText($title)
|
||||
->appendChild($post_list);
|
||||
|
|
|
@ -2,19 +2,13 @@
|
|||
|
||||
final class PhamePostNotLiveController extends PhameController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = $data['id'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$user = $request->getUser();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
$post = id(new PhamePostQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->withIDs(array($id))
|
||||
->executeOne();
|
||||
if (!$post) {
|
||||
return new Aphront404Response();
|
||||
|
|
|
@ -2,19 +2,13 @@
|
|||
|
||||
final class PhamePostPublishController extends PhameController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = $data['id'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$user = $request->getUser();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
$post = id(new PhamePostQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->withIDs(array($id))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
|
|
|
@ -2,19 +2,13 @@
|
|||
|
||||
final class PhamePostUnpublishController extends PhameController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = $data['id'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$user = $request->getUser();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
$post = id(new PhamePostQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->withIDs(array($id))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
|
|
Loading…
Reference in a new issue