@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

+45 -7
+3 -3
resources/celerity/map.php
··· 7 7 */ 8 8 return array( 9 9 'names' => array( 10 - 'core.pkg.css' => 'e94665e4', 10 + 'core.pkg.css' => 'e4f1ea81', 11 11 'core.pkg.js' => '47dc9ebb', 12 12 'darkconsole.pkg.js' => 'e7393ebb', 13 13 'differential.pkg.css' => '2de124c9', ··· 125 125 'rsrc/css/phui/phui-badge.css' => 'f25c3476', 126 126 'rsrc/css/phui/phui-box.css' => 'a5bb366d', 127 127 'rsrc/css/phui/phui-button.css' => '16020a60', 128 - 'rsrc/css/phui/phui-crumbs-view.css' => 'd842f867', 128 + 'rsrc/css/phui/phui-crumbs-view.css' => '414406b5', 129 129 'rsrc/css/phui/phui-document-pro.css' => '4f2b42e3', 130 130 'rsrc/css/phui/phui-document.css' => 'f841ad0a', 131 131 'rsrc/css/phui/phui-feed-story.css' => 'b7b26d23', ··· 779 779 'phui-calendar-day-css' => 'd1cf6f93', 780 780 'phui-calendar-list-css' => 'c1c7f338', 781 781 'phui-calendar-month-css' => '476be7e0', 782 - 'phui-crumbs-view-css' => 'd842f867', 782 + 'phui-crumbs-view-css' => '414406b5', 783 783 'phui-document-view-css' => 'f841ad0a', 784 784 'phui-document-view-pro-css' => '4f2b42e3', 785 785 'phui-feed-story-css' => 'b7b26d23',
+2
src/__phutil_library_map__.php
··· 3248 3248 'PhameBasicTemplateBlogSkin' => 'applications/phame/skins/PhameBasicTemplateBlogSkin.php', 3249 3249 'PhameBlog' => 'applications/phame/storage/PhameBlog.php', 3250 3250 'PhameBlogController' => 'applications/phame/controller/blog/PhameBlogController.php', 3251 + 'PhameBlogCreateCapability' => 'applications/phame/capability/PhameBlogCreateCapability.php', 3251 3252 'PhameBlogDeleteController' => 'applications/phame/controller/blog/PhameBlogDeleteController.php', 3252 3253 'PhameBlogEditController' => 'applications/phame/controller/blog/PhameBlogEditController.php', 3253 3254 'PhameBlogEditor' => 'applications/phame/editor/PhameBlogEditor.php', ··· 7512 7513 'PhabricatorApplicationTransactionInterface', 7513 7514 ), 7514 7515 'PhameBlogController' => 'PhameController', 7516 + 'PhameBlogCreateCapability' => 'PhabricatorPolicyCapability', 7515 7517 'PhameBlogDeleteController' => 'PhameBlogController', 7516 7518 'PhameBlogEditController' => 'PhameBlogController', 7517 7519 'PhameBlogEditor' => 'PhabricatorApplicationTransactionEditor',
+9
src/applications/phame/application/PhabricatorPhameApplication.php
··· 102 102 ); 103 103 } 104 104 105 + protected function getCustomCapabilities() { 106 + return array( 107 + PhameBlogCreateCapability::CAPABILITY => array( 108 + 'default' => PhabricatorPolicies::POLICY_USER, 109 + 'caption' => pht('Default create policy for blogs.'), 110 + ), 111 + ); 112 + } 113 + 105 114 }
+16
src/applications/phame/capability/PhameBlogCreateCapability.php
··· 1 + <?php 2 + 3 + final class PhameBlogCreateCapability 4 + extends PhabricatorPolicyCapability { 5 + 6 + const CAPABILITY = 'phame.blog.default.create'; 7 + 8 + public function getCapabilityName() { 9 + return pht('Can Create Blogs'); 10 + } 11 + 12 + public function describeCapabilityRejection() { 13 + return pht('You do not have permission to create a blog.'); 14 + } 15 + 16 + }
+10 -3
src/applications/phame/controller/PhameController.php
··· 92 92 93 93 protected function buildApplicationCrumbs() { 94 94 $crumbs = parent::buildApplicationCrumbs(); 95 + 96 + $can_create = $this->hasApplicationCapability( 97 + PhameBlogCreateCapability::CAPABILITY); 98 + 95 99 $crumbs->addAction( 96 100 id(new PHUIListItemView()) 97 101 ->setName(pht('New Blog')) 98 - ->setHref($this->getApplicationURI('/blog/new')) 99 - ->setIcon('fa-plus-square')); 102 + ->setHref($this->getApplicationURI('/blog/new/')) 103 + ->setIcon('fa-plus-square') 104 + ->setDisabled(!$can_create) 105 + ->setWorkflow(!$can_create)); 106 + 100 107 $crumbs->addAction( 101 108 id(new PHUIListItemView()) 102 109 ->setName(pht('New Post')) 103 - ->setHref($this->getApplicationURI('/post/new')) 110 + ->setHref($this->getApplicationURI('/post/new/')) 104 111 ->setIcon('fa-pencil')); 105 112 return $crumbs; 106 113 }
+3
src/applications/phame/controller/blog/PhameBlogEditController.php
··· 30 30 $v_projects = array_reverse($v_projects); 31 31 32 32 } else { 33 + $this->requireApplicationCapability( 34 + PhameBlogCreateCapability::CAPABILITY); 35 + 33 36 $blog = PhameBlog::initializeNewBlog($viewer); 34 37 35 38 $submit_button = pht('Create Blog');
+2 -1
webroot/rsrc/css/phui/phui-crumbs-view.css
··· 25 25 padding-right: 0; 26 26 } 27 27 28 - .phui-crumbs-view a.phui-crumbs-action-disabled { 28 + .phui-crumbs-view a.phui-crumbs-action-disabled, 29 + .phui-crumbs-view a.phui-crumbs-action-disabled .phui-icon-view { 29 30 color: {$lightgreytext}; 30 31 } 31 32