SilverStripe default content author permissions

匆匆过客 提交于 2019-12-24 09:17:23

问题


The default value for Manage site configuration is off security > groups > content authors > permissions

Although it's possible to simply check the box and activate this, I would rather have this on by default for every SS installation.

How can the default value for this be set to on?


回答1:


This should do as required, make an extension of Group and add a requireDefaultRecords function, this is called on every dev build.

This function is to look for that permission and if not existing create it...

class GroupExtension extends DataExtension {

    function requireDefaultRecords() {

        //get the content-authors group
        if ($group = Group::get()->filter('Code','content-authors')->first()) {

            //expected permission record content
            $arrPermissionData = array(
                'Arg'       => 0,
                'Type'      => 1,
                'Code'      => 'EDIT_SITECONFIG',
                'GroupID'   => $group->ID
            );

            //if the permission is not found, then create it
            if (!Permission::get()->filter($arrPermissionData)->first())
                Permission::create($arrPermissionData)->write();
        }
    }

}

As ever to register the extension add this to your config.yml...

Group:
  extensions:
    - GroupExtension


来源:https://stackoverflow.com/questions/38613478/silverstripe-default-content-author-permissions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!