1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 19:40:55 +01:00

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
This commit is contained in:
Chad Little 2015-11-07 11:57:34 -08:00
parent 80327a550a
commit 37df419266
7 changed files with 45 additions and 7 deletions

View file

@ -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',

View file

@ -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',

View file

@ -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.'),
),
);
}
}

View file

@ -0,0 +1,16 @@
<?php
final class PhameBlogCreateCapability
extends PhabricatorPolicyCapability {
const CAPABILITY = 'phame.blog.default.create';
public function getCapabilityName() {
return pht('Can Create Blogs');
}
public function describeCapabilityRejection() {
return pht('You do not have permission to create a blog.');
}
}

View file

@ -92,15 +92,22 @@ abstract class PhameController extends PhabricatorController {
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'));
->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;
}

View file

@ -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');

View file

@ -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};
}