From 37df419266d452961b641cdaf02f273be2198a3a Mon Sep 17 00:00:00 2001 From: Chad Little Date: Sat, 7 Nov 2015 11:57:34 -0800 Subject: [PATCH] Add Can Create Policy Capability to Phame Blogs Summary: Larger (open) installs may want to restrict Blog to formal entities, like with Phriction. Test Plan: Set policy to administrators, have notchad try to create a blog. See error. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D14433 --- resources/celerity/map.php | 6 +++--- src/__phutil_library_map__.php | 2 ++ .../application/PhabricatorPhameApplication.php | 9 +++++++++ .../capability/PhameBlogCreateCapability.php | 16 ++++++++++++++++ .../phame/controller/PhameController.php | 13 ++++++++++--- .../controller/blog/PhameBlogEditController.php | 3 +++ webroot/rsrc/css/phui/phui-crumbs-view.css | 3 ++- 7 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 src/applications/phame/capability/PhameBlogCreateCapability.php diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 8f8209b309..1ca4df907d 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -7,7 +7,7 @@ */ return array( 'names' => array( - 'core.pkg.css' => 'e94665e4', + 'core.pkg.css' => 'e4f1ea81', 'core.pkg.js' => '47dc9ebb', 'darkconsole.pkg.js' => 'e7393ebb', 'differential.pkg.css' => '2de124c9', @@ -125,7 +125,7 @@ return array( 'rsrc/css/phui/phui-badge.css' => 'f25c3476', 'rsrc/css/phui/phui-box.css' => 'a5bb366d', 'rsrc/css/phui/phui-button.css' => '16020a60', - 'rsrc/css/phui/phui-crumbs-view.css' => 'd842f867', + 'rsrc/css/phui/phui-crumbs-view.css' => '414406b5', 'rsrc/css/phui/phui-document-pro.css' => '4f2b42e3', 'rsrc/css/phui/phui-document.css' => 'f841ad0a', 'rsrc/css/phui/phui-feed-story.css' => 'b7b26d23', @@ -779,7 +779,7 @@ return array( 'phui-calendar-day-css' => 'd1cf6f93', 'phui-calendar-list-css' => 'c1c7f338', 'phui-calendar-month-css' => '476be7e0', - 'phui-crumbs-view-css' => 'd842f867', + 'phui-crumbs-view-css' => '414406b5', 'phui-document-view-css' => 'f841ad0a', 'phui-document-view-pro-css' => '4f2b42e3', 'phui-feed-story-css' => 'b7b26d23', diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index fa57f18743..65fab9c53b 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3248,6 +3248,7 @@ phutil_register_library_map(array( 'PhameBasicTemplateBlogSkin' => 'applications/phame/skins/PhameBasicTemplateBlogSkin.php', 'PhameBlog' => 'applications/phame/storage/PhameBlog.php', 'PhameBlogController' => 'applications/phame/controller/blog/PhameBlogController.php', + 'PhameBlogCreateCapability' => 'applications/phame/capability/PhameBlogCreateCapability.php', 'PhameBlogDeleteController' => 'applications/phame/controller/blog/PhameBlogDeleteController.php', 'PhameBlogEditController' => 'applications/phame/controller/blog/PhameBlogEditController.php', 'PhameBlogEditor' => 'applications/phame/editor/PhameBlogEditor.php', @@ -7512,6 +7513,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationTransactionInterface', ), 'PhameBlogController' => 'PhameController', + 'PhameBlogCreateCapability' => 'PhabricatorPolicyCapability', 'PhameBlogDeleteController' => 'PhameBlogController', 'PhameBlogEditController' => 'PhameBlogController', 'PhameBlogEditor' => 'PhabricatorApplicationTransactionEditor', diff --git a/src/applications/phame/application/PhabricatorPhameApplication.php b/src/applications/phame/application/PhabricatorPhameApplication.php index ec98087adf..f4636d758c 100644 --- a/src/applications/phame/application/PhabricatorPhameApplication.php +++ b/src/applications/phame/application/PhabricatorPhameApplication.php @@ -102,4 +102,13 @@ final class PhabricatorPhameApplication extends PhabricatorApplication { ); } + protected function getCustomCapabilities() { + return array( + PhameBlogCreateCapability::CAPABILITY => array( + 'default' => PhabricatorPolicies::POLICY_USER, + 'caption' => pht('Default create policy for blogs.'), + ), + ); + } + } diff --git a/src/applications/phame/capability/PhameBlogCreateCapability.php b/src/applications/phame/capability/PhameBlogCreateCapability.php new file mode 100644 index 0000000000..e86f2327ab --- /dev/null +++ b/src/applications/phame/capability/PhameBlogCreateCapability.php @@ -0,0 +1,16 @@ +hasApplicationCapability( + PhameBlogCreateCapability::CAPABILITY); + $crumbs->addAction( id(new PHUIListItemView()) ->setName(pht('New Blog')) - ->setHref($this->getApplicationURI('/blog/new')) - ->setIcon('fa-plus-square')); + ->setHref($this->getApplicationURI('/blog/new/')) + ->setIcon('fa-plus-square') + ->setDisabled(!$can_create) + ->setWorkflow(!$can_create)); + $crumbs->addAction( id(new PHUIListItemView()) ->setName(pht('New Post')) - ->setHref($this->getApplicationURI('/post/new')) + ->setHref($this->getApplicationURI('/post/new/')) ->setIcon('fa-pencil')); return $crumbs; } diff --git a/src/applications/phame/controller/blog/PhameBlogEditController.php b/src/applications/phame/controller/blog/PhameBlogEditController.php index 24c5681583..659f33ae3d 100644 --- a/src/applications/phame/controller/blog/PhameBlogEditController.php +++ b/src/applications/phame/controller/blog/PhameBlogEditController.php @@ -30,6 +30,9 @@ final class PhameBlogEditController $v_projects = array_reverse($v_projects); } else { + $this->requireApplicationCapability( + PhameBlogCreateCapability::CAPABILITY); + $blog = PhameBlog::initializeNewBlog($viewer); $submit_button = pht('Create Blog'); diff --git a/webroot/rsrc/css/phui/phui-crumbs-view.css b/webroot/rsrc/css/phui/phui-crumbs-view.css index 2f38e0ca47..71113dadc9 100644 --- a/webroot/rsrc/css/phui/phui-crumbs-view.css +++ b/webroot/rsrc/css/phui/phui-crumbs-view.css @@ -25,7 +25,8 @@ padding-right: 0; } -.phui-crumbs-view a.phui-crumbs-action-disabled { +.phui-crumbs-view a.phui-crumbs-action-disabled, +.phui-crumbs-view a.phui-crumbs-action-disabled .phui-icon-view { color: {$lightgreytext}; }