1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 12:52:42 +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(
'(?:query/(?P<queryKey>[^/]+)/)?' => 'PhameBlogListController',
'archive/(?P<id>[^/]+)/' => 'PhameBlogArchiveController',
'edit/(?P<id>[^/]+)/' => 'PhameBlogEditController',
$this->getEditRoutePattern('edit/')
=> 'PhameBlogEditController',
'view/(?P<blogID>\d+)/' => 'PhameBlogViewController',
'manage/(?P<id>[^/]+)/' => 'PhameBlogManageController',
'feed/(?P<id>[^/]+)/' => 'PhameBlogFeedController',
'new/' => 'PhameBlogEditController',
'picture/(?P<id>[1-9]\d*)/' => 'PhameBlogProfilePictureController',
),
) + $this->getResourceSubroutes(),

View file

@ -6,6 +6,16 @@ final class PhameHomeController extends PhamePostController {
return true;
}
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
id(new PhameBlogEditEngine())
->setViewer($this->getViewer())
->addActionToCrumbs($crumbs);
return $crumbs;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
@ -44,7 +54,7 @@ final class PhameHomeController extends PhamePostController {
$create_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Create a Blog'))
->setHref('/phame/blog/new/')
->setHref('/phame/blog/edit/')
->setColor(PHUIButtonView::GREEN);
$post_list = id(new PHUIBigInfoView())
@ -116,27 +126,6 @@ final class PhameHomeController extends PhamePostController {
array(
$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) {
$query_key = $request->getURIData('queryKey');
$controller = id(new PhabricatorApplicationSearchController())
->setQueryKey($query_key)
->setSearchEngine(new PhameBlogSearchEngine())
->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller);
return id(new PhameBlogSearchEngine())
->setController($this)
->buildResponse();
}
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() {
$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));
id(new PhameBlogEditEngine())
->setViewer($this->getViewer())
->addActionToCrumbs($crumbs);
return $crumbs;
}

View file

@ -46,12 +46,24 @@ final class PhameBlogEditEngine
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) {
return $object->getManageURI();
}
protected function buildCustomEditFields($object) {
protected function getCreateNewObjectPolicy() {
return $this->getApplication()->getPolicy(
PhameBlogCreateCapability::CAPABILITY);
}
protected function buildCustomEditFields($object) {
return array(
id(new PhabricatorTextEditField())
->setKey('name')

View file

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