[英]SilverStripe hardcode permission setting EDIT_SITECONFIG
There is a specific PermissionCode
that's not granted to ContentAuthor
by default. 默认情况下,没有特定的
PermissionCode
未被授予ContentAuthor
。 It's about Permission code EDIT_SITECONFIG
(enables Content Authors to view and edit "Settings" section). 关于权限代码
EDIT_SITECONFIG
(使内容作者可以查看和编辑“设置”部分)。
This permission can be granted to roles
in: 可以将权限授予以下
roles
:
Security > Groups > Content Authors > Permissions
> Manage site configuration Security > Groups > Content Authors > Permissions
> 管理站点配置
How can you force this permission to be granted to ContentAuthors
by default? 默认情况下,如何强制将此权限授予
ContentAuthors
?
We can add an extension to the Group
class that calls requireDefaultRecords
to modify this variable. 我们可以将扩展添加到
Group
类,该扩展调用requireDefaultRecords
来修改此变量。
mysite/code/extensions/CustomGroup.php mysite的/代码/扩展/ CustomGroup.php
class CustomGroup extends DataExtension {
public function requireDefaultRecords() {
parent::requireDefaultRecords();
$contentAuthorGroup = Group::get()->filter('Code', 'content-authors')->first();
if ($contentAuthorGroup) {
Permission::grant($contentAuthorGroup->ID, 'EDIT_SITECONFIG');
}
}
}
We enable our Group
extension in our config.yml
file. 我们在
config.yml
文件中启用Group
扩展。
mysite/_config/config.yml mysite的/ _config / config.yml
Group:
extensions:
- CustomGroup
One thing to note with this solution is it will update the EDIT_SITECONFIG
permission setting every time dev/build
is called. 此解决方案要注意的一件事是,它将在每次调用
dev/build
时更新EDIT_SITECONFIG
权限设置。 This means if this permission is switched off through the CMS it will be switched back on the next time dev/build
is called. 这意味着,如果通过CMS关闭了此权限,则下次调用
dev/build
时将重新启用该权限。
An alternative is to create the content author group on the first database build. 一种替代方法是在第一个数据库版本上创建内容作者组。 This will only set
EDIT_SITECONFIG
once, allowing it to be overwritten through the CMS. 这将只设置一次
EDIT_SITECONFIG
,从而可以通过CMS覆盖它。
class CustomGroup extends DataExtension {
public function requireDefaultRecords() {
// Add default author group if no other group exists
$allGroups = Group::get();
if (!$allGroups->count()) {
$authorGroup = new Group();
$authorGroup->Code = 'content-authors';
$authorGroup->Title = _t('Group.DefaultGroupTitleContentAuthors', 'Content Authors');
$authorGroup->Sort = 1;
$authorGroup->write();
Permission::grant($authorGroup->ID, 'CMS_ACCESS_CMSMain');
Permission::grant($authorGroup->ID, 'CMS_ACCESS_AssetAdmin');
Permission::grant($authorGroup->ID, 'CMS_ACCESS_ReportAdmin');
Permission::grant($authorGroup->ID, 'SITETREE_REORGANISE');
Permission::grant($authorGroup->ID, 'EDIT_SITECONFIG');
}
parent::requireDefaultRecords();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.