mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-25 06:50: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 {
|
final class PhamePostFramedController extends PhameController {
|
||||||
|
|
||||||
private $id;
|
public function handleRequest(AphrontRequest $request) {
|
||||||
|
$user = $request->getViewer();
|
||||||
public function willProcessRequest(array $data) {
|
$id = $request->getURIData('id');
|
||||||
$this->id = $data['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function processRequest() {
|
|
||||||
$request = $this->getRequest();
|
|
||||||
$user = $request->getUser();
|
|
||||||
|
|
||||||
$post = id(new PhamePostQuery())
|
$post = id(new PhamePostQuery())
|
||||||
->setViewer($user)
|
->setViewer($user)
|
||||||
->withIDs(array($this->id))
|
->withIDs(array($id))
|
||||||
->requireCapabilities(
|
->requireCapabilities(
|
||||||
array(
|
array(
|
||||||
PhabricatorPolicyCapability::CAN_EDIT,
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
|
|
@ -2,60 +2,52 @@
|
||||||
|
|
||||||
final class PhamePostListController extends PhameController {
|
final class PhamePostListController extends PhameController {
|
||||||
|
|
||||||
private $bloggername;
|
public function handleRequest(AphrontRequest $request) {
|
||||||
private $filter;
|
$viewer = $request->getViewer();
|
||||||
|
$filter = $request->getURIData('filter');
|
||||||
public function willProcessRequest(array $data) {
|
$bloggername = $request->getURIData('bloggername');
|
||||||
$this->filter = idx($data, 'filter', 'blogger');
|
|
||||||
$this->bloggername = idx($data, 'bloggername');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function processRequest() {
|
|
||||||
$request = $this->getRequest();
|
|
||||||
$user = $request->getUser();
|
|
||||||
|
|
||||||
$query = id(new PhamePostQuery())
|
$query = id(new PhamePostQuery())
|
||||||
->setViewer($user);
|
->setViewer($viewer);
|
||||||
|
|
||||||
$nav = $this->renderSideNavFilterView();
|
$nav = $this->renderSideNavFilterView();
|
||||||
$nodata = null;
|
$nodata = null;
|
||||||
|
|
||||||
switch ($this->filter) {
|
switch ($filter) {
|
||||||
case 'draft':
|
case 'draft':
|
||||||
$query->withBloggerPHIDs(array($user->getPHID()));
|
$query->withBloggerPHIDs(array($viewer->getPHID()));
|
||||||
$query->withVisibility(PhamePost::VISIBILITY_DRAFT);
|
$query->withVisibility(PhamePost::VISIBILITY_DRAFT);
|
||||||
$nodata = pht('You have no unpublished drafts.');
|
$nodata = pht('You have no unpublished drafts.');
|
||||||
$title = pht('Unpublished Drafts');
|
$title = pht('Unpublished Drafts');
|
||||||
$nav->selectFilter('post/draft');
|
$nav->selectFilter('post/draft');
|
||||||
break;
|
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':
|
case 'all':
|
||||||
$nodata = pht('There are no visible posts.');
|
$nodata = pht('There are no visible posts.');
|
||||||
$title = pht('Posts');
|
$title = pht('Posts');
|
||||||
$nav->selectFilter('post/all');
|
$nav->selectFilter('post/all');
|
||||||
break;
|
break;
|
||||||
default:
|
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())
|
$pager = id(new AphrontCursorPagerView())
|
||||||
|
@ -64,7 +56,7 @@ final class PhamePostListController extends PhameController {
|
||||||
$posts = $query->executeWithCursorPager($pager);
|
$posts = $query->executeWithCursorPager($pager);
|
||||||
|
|
||||||
require_celerity_resource('phame-css');
|
require_celerity_resource('phame-css');
|
||||||
$post_list = $this->renderPostList($posts, $user, $nodata);
|
$post_list = $this->renderPostList($posts, $viewer, $nodata);
|
||||||
$post_list = id(new PHUIObjectBoxView())
|
$post_list = id(new PHUIObjectBoxView())
|
||||||
->setHeaderText($title)
|
->setHeaderText($title)
|
||||||
->appendChild($post_list);
|
->appendChild($post_list);
|
||||||
|
|
|
@ -2,19 +2,13 @@
|
||||||
|
|
||||||
final class PhamePostNotLiveController extends PhameController {
|
final class PhamePostNotLiveController extends PhameController {
|
||||||
|
|
||||||
private $id;
|
public function handleRequest(AphrontRequest $request) {
|
||||||
|
|
||||||
public function willProcessRequest(array $data) {
|
|
||||||
$this->id = $data['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function processRequest() {
|
|
||||||
$request = $this->getRequest();
|
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
$id = $request->getURIData('id');
|
||||||
|
|
||||||
$post = id(new PhamePostQuery())
|
$post = id(new PhamePostQuery())
|
||||||
->setViewer($user)
|
->setViewer($user)
|
||||||
->withIDs(array($this->id))
|
->withIDs(array($id))
|
||||||
->executeOne();
|
->executeOne();
|
||||||
if (!$post) {
|
if (!$post) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
|
|
|
@ -2,19 +2,13 @@
|
||||||
|
|
||||||
final class PhamePostPublishController extends PhameController {
|
final class PhamePostPublishController extends PhameController {
|
||||||
|
|
||||||
private $id;
|
public function handleRequest(AphrontRequest $request) {
|
||||||
|
|
||||||
public function willProcessRequest(array $data) {
|
|
||||||
$this->id = $data['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function processRequest() {
|
|
||||||
$request = $this->getRequest();
|
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
$id = $request->getURIData('id');
|
||||||
|
|
||||||
$post = id(new PhamePostQuery())
|
$post = id(new PhamePostQuery())
|
||||||
->setViewer($user)
|
->setViewer($user)
|
||||||
->withIDs(array($this->id))
|
->withIDs(array($id))
|
||||||
->requireCapabilities(
|
->requireCapabilities(
|
||||||
array(
|
array(
|
||||||
PhabricatorPolicyCapability::CAN_EDIT,
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
|
|
@ -2,19 +2,13 @@
|
||||||
|
|
||||||
final class PhamePostUnpublishController extends PhameController {
|
final class PhamePostUnpublishController extends PhameController {
|
||||||
|
|
||||||
private $id;
|
public function handleRequest(AphrontRequest $request) {
|
||||||
|
|
||||||
public function willProcessRequest(array $data) {
|
|
||||||
$this->id = $data['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function processRequest() {
|
|
||||||
$request = $this->getRequest();
|
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
$id = $request->getURIData('id');
|
||||||
|
|
||||||
$post = id(new PhamePostQuery())
|
$post = id(new PhamePostQuery())
|
||||||
->setViewer($user)
|
->setViewer($user)
|
||||||
->withIDs(array($this->id))
|
->withIDs(array($id))
|
||||||
->requireCapabilities(
|
->requireCapabilities(
|
||||||
array(
|
array(
|
||||||
PhabricatorPolicyCapability::CAN_EDIT,
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
|
Loading…
Reference in a new issue