1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-26 07:20:57 +01:00

Sync up UI with actual policy rules in Phame

Summary: Fixes T10504. The "Create Blog" buttons weren't generated by EditEngine, but should be, so that the UI and policies are in sync.

Test Plan:
  - Viewed blog list as user with and without permission to create blogs. Saw correct button state.
  - Tried to create blogs, saw correct result.
  - Viewed empty state of home, clicked "New Blog" buttons.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10504

Differential Revision: https://secure.phabricator.com/D15384
This commit is contained in:
epriestley 2016-03-02 11:38:59 -08:00
parent 86d6191633
commit e3ed8b5fe1
5 changed files with 33 additions and 57 deletions

View file

@ -60,11 +60,11 @@ final class PhabricatorPhameApplication extends PhabricatorApplication {
'blog/' => array( 'blog/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?' => 'PhameBlogListController', '(?:query/(?P<queryKey>[^/]+)/)?' => 'PhameBlogListController',
'archive/(?P<id>[^/]+)/' => 'PhameBlogArchiveController', 'archive/(?P<id>[^/]+)/' => 'PhameBlogArchiveController',
'edit/(?P<id>[^/]+)/' => 'PhameBlogEditController', $this->getEditRoutePattern('edit/')
=> 'PhameBlogEditController',
'view/(?P<blogID>\d+)/' => 'PhameBlogViewController', 'view/(?P<blogID>\d+)/' => 'PhameBlogViewController',
'manage/(?P<id>[^/]+)/' => 'PhameBlogManageController', 'manage/(?P<id>[^/]+)/' => 'PhameBlogManageController',
'feed/(?P<id>[^/]+)/' => 'PhameBlogFeedController', 'feed/(?P<id>[^/]+)/' => 'PhameBlogFeedController',
'new/' => 'PhameBlogEditController',
'picture/(?P<id>[1-9]\d*)/' => 'PhameBlogProfilePictureController', 'picture/(?P<id>[1-9]\d*)/' => 'PhameBlogProfilePictureController',
), ),
) + $this->getResourceSubroutes(), ) + $this->getResourceSubroutes(),

View file

@ -6,6 +6,16 @@ final class PhameHomeController extends PhamePostController {
return true; return true;
} }
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
id(new PhameBlogEditEngine())
->setViewer($this->getViewer())
->addActionToCrumbs($crumbs);
return $crumbs;
}
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer(); $viewer = $request->getViewer();
@ -44,7 +54,7 @@ final class PhameHomeController extends PhamePostController {
$create_button = id(new PHUIButtonView()) $create_button = id(new PHUIButtonView())
->setTag('a') ->setTag('a')
->setText(pht('Create a Blog')) ->setText(pht('Create a Blog'))
->setHref('/phame/blog/new/') ->setHref('/phame/blog/edit/')
->setColor(PHUIButtonView::GREEN); ->setColor(PHUIButtonView::GREEN);
$post_list = id(new PHUIBigInfoView()) $post_list = id(new PHUIBigInfoView())
@ -116,27 +126,6 @@ final class PhameHomeController extends PhamePostController {
array( array(
$phame_home, $phame_home,
)); ));
}
private function renderBlogs($viewer, $blogs) {}
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$can_create = $this->hasApplicationCapability(
PhameBlogCreateCapability::CAPABILITY);
$crumbs->addAction(
id(new PHUIListItemView())
->setName(pht('New Blog'))
->setHref($this->getApplicationURI('/blog/new/'))
->setIcon('fa-plus-square')
->setDisabled(!$can_create)
->setWorkflow(!$can_create));
return $crumbs;
} }
} }

View file

@ -7,43 +7,18 @@ final class PhameBlogListController extends PhameBlogController {
} }
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$query_key = $request->getURIData('queryKey'); return id(new PhameBlogSearchEngine())
$controller = id(new PhabricatorApplicationSearchController()) ->setController($this)
->setQueryKey($query_key) ->buildResponse();
->setSearchEngine(new PhameBlogSearchEngine())
->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller);
} }
public function buildSideNavView() {
$viewer = $this->getRequest()->getUser();
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
id(new PhameBlogSearchEngine())
->setViewer($viewer)
->addNavigationItems($nav->getMenu());
$nav->selectFilter(null);
return $nav;
}
protected function buildApplicationCrumbs() { protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs(); $crumbs = parent::buildApplicationCrumbs();
$can_create = $this->hasApplicationCapability( id(new PhameBlogEditEngine())
PhameBlogCreateCapability::CAPABILITY); ->setViewer($this->getViewer())
->addActionToCrumbs($crumbs);
$crumbs->addAction(
id(new PHUIListItemView())
->setName(pht('New Blog'))
->setHref($this->getApplicationURI('/blog/new/'))
->setIcon('fa-plus-square')
->setDisabled(!$can_create)
->setWorkflow(!$can_create));
return $crumbs; return $crumbs;
} }

View file

@ -46,12 +46,24 @@ final class PhameBlogEditEngine
return pht('Create Blog'); return pht('Create Blog');
} }
protected function getObjectCreateCancelURI($object) {
return $this->getApplication()->getApplicationURI('blog/');
}
protected function getEditorURI() {
return $this->getApplication()->getApplicationURI('blog/edit/');
}
protected function getObjectViewURI($object) { protected function getObjectViewURI($object) {
return $object->getManageURI(); return $object->getManageURI();
} }
protected function buildCustomEditFields($object) { protected function getCreateNewObjectPolicy() {
return $this->getApplication()->getPolicy(
PhameBlogCreateCapability::CAPABILITY);
}
protected function buildCustomEditFields($object) {
return array( return array(
id(new PhabricatorTextEditField()) id(new PhabricatorTextEditField())
->setKey('name') ->setKey('name')

View file

@ -72,7 +72,7 @@ final class PhameBlogListView extends AphrontTagView {
$list = phutil_tag( $list = phutil_tag(
'a', 'a',
array( array(
'href' => '/phame/blog/new/', 'href' => '/phame/blog/edit/',
), ),
pht('Create a Blog')); pht('Create a Blog'));
} }