本文整理汇总了PHP中Permission::grant方法的典型用法代码示例。如果您正苦于以下问题:PHP Permission::grant方法的具体用法?PHP Permission::grant怎么用?PHP Permission::grant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Permission
的用法示例。
在下文中一共展示了Permission::grant方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: requireDefaultRecords
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
// Add default author group if no other group exists
$frontend_group = Group::get()->filter("Code", "users-frontend");
if (!$frontend_group->exists()) {
$frontend_group = new Group();
$frontend_group->Code = 'users-frontend';
$frontend_group->Title = "Frontend Users";
$frontend_group->Sort = 1;
$frontend_group->write();
Permission::grant($frontend_group->ID, 'USERS_MANAGE_ACCOUNT');
DB::alteration_message('Front end users group created', 'created');
}
// Add a verified users group (only used if we turn on
// verification)
$verify_group = Group::get()->filter("Code", "users-verified");
if (!$verify_group->exists()) {
$verify_group = new Group();
$verify_group->Code = 'users-verified';
$verify_group->Title = "Verified Users";
$verify_group->Sort = 1;
$verify_group->write();
Permission::grant($verify_group->ID, 'USERS_VERIFIED');
DB::alteration_message('Verified users group created', 'created');
}
}
示例2: store
/**
* @param IMarketPlaceType $marketplace_type
* @return int|bool
*/
public function store(IMarketPlaceType $marketplace_type)
{
$repository = $this->repository;
$group_repository = $this->group_repository;
$res = false;
$this->tx_manager->transaction(function () use(&$res, &$marketplace_type, $repository, $group_repository) {
$query = new QueryObject();
$query->addAndCondition(QueryCriteria::equal('Name', $marketplace_type->getName()));
$query->addAndCondition(QueryCriteria::equal('Slug', $marketplace_type->getSlug()));
$query->addAndCondition(QueryCriteria::notEqual('ID', $marketplace_type->getIdentifier()));
$old = $repository->getBy($query);
if ($old) {
throw new EntityAlreadyExistsException('MarketPlaceType', sprintf('Name %s', $marketplace_type->getName()));
}
$repository->add($marketplace_type);
});
//reload from db...
$id = $marketplace_type->getIdentifier();
$marketplace_type = $this->repository->getById($id);
$g = $marketplace_type->getAdminGroup();
$permission_code = sprintf('MANAGE_MARKETPLACE_%s', str_replace(' ', '_', strtoupper($marketplace_type->getName())));
$groups = Permission::get_groups_by_permission($permission_code);
if (count($groups) == 0) {
Permission::grant($g->getIdentifier(), $permission_code);
}
return $res;
}
示例3: requireDefaultRecords
/**
* @throws ValidationException
* @throws null
*/
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
/**
* Add default site admin group if none with
* permission code SITE_ADMIN exists
*
* @var Group $siteAdminGroup
*/
$siteAdminGroups = DataObject::get('Group')->filter(array('Code' => 'site-administrators'));
if (!$siteAdminGroups->count()) {
$siteAdminGroup = Group::create();
$siteAdminGroup->Code = 'site-administrators';
$siteAdminGroup->Title = _t('BoilerplateGroupExtension.SiteAdminGroupTitle', 'Site Administrators');
$siteAdminGroup->Sort = 0;
$siteAdminGroup->write();
/** Default CMS permissions */
Permission::grant($siteAdminGroup->ID, 'CMS_ACCESS_LeftAndMain');
Permission::grant($siteAdminGroup->ID, 'SITETREE_VIEW_ALL');
Permission::grant($siteAdminGroup->ID, 'SITETREE_EDIT_ALL');
Permission::grant($siteAdminGroup->ID, 'SITETREE_REORGANISE');
Permission::grant($siteAdminGroup->ID, 'VIEW_DRAFT_CONTENT');
Permission::grant($siteAdminGroup->ID, 'SITETREE_GRANT_ACCESS');
Permission::grant($siteAdminGroup->ID, 'EDIT_SITECONFIG');
}
}
开发者ID:helpfulrobot,项目名称:ryanpotter-silverstripe-boilerplate,代码行数:30,代码来源:BoilerplateGroupExtension.php
示例4: default_group
/**
* Check for default group, and if it doesn't exist, create it
* Should be run under "requireDefaultRecords"
* @param string $code
* @param string $title
* @param string $parent
* @param array $permissions
*/
public static function default_group($code, $title, $parentCode = null, $permissions = array())
{
$group = null;
$action = null;
if (!DataObject::get_one('Group', "Code = '" . $code . "'")) {
$action = 'create';
$group = new Group();
} else {
$action = 'update';
$group = DataObject::get_one('Group', "Code = '" . $code . "'");
}
$group->Title = $title;
$group->Code = $code;
if ($parentCode) {
$parentObj = DataObject::get_one("Group", "Code = '" . $parentCode . "'");
$group->ParentID = $parentObj->ID;
}
$group->write();
if (!empty($permissions)) {
foreach ($permissions as $p) {
Permission::grant($group->ID, $p);
}
}
if ($action == 'create') {
DB::alteration_message('Group ' . $title . ' (' . $code . ') has been created.', "created");
}
if ($action == 'update') {
DB::alteration_message('Group ' . $title . ' (' . $code . ') has been updated.', "updated");
}
return $group;
}
示例5: requireDefaultRecords
/**
* Add a specific group in order to enable users/groups managemet
*/
public function requireDefaultRecords()
{
$group = DataObject::get('Group', "Code = 'users-manager'");
if (!$group->count()) {
$usersManagerGroup = new Group();
$usersManagerGroup->Code = 'users-manager';
$usersManagerGroup->Title = _t('Group.DefaultGroupTitleUsersManager', 'Users Manager');
$usersManagerGroup->Sort = 0;
$usersManagerGroup->write();
Permission::grant($usersManagerGroup->ID, 'CMS_ACCESS_SecurityAdmin');
}
}
示例6: doUp
function doUp()
{
global $database;
if (intval(Group::get()->filter('Code', 'SUMMIT_FRONT_END_ADMINISTRATORS')->count()) > 0) {
return;
}
$g = Group::create();
$g->setTitle('Summit Front End Administrators');
$g->setDescription('Allows to Access to summit-admin application');
$g->setSlug('SUMMIT_FRONT_END_ADMINISTRATORS');
$g->write();
Permission::grant($g->getIdentifier(), 'ADMIN_SUMMIT_APP_FRONTEND_ADMIN');
}
示例7: requireDefaultRecords
function requireDefaultRecords()
{
parent::requireDefaultRecords();
//Create a new group for customers
$allGroups = DataObject::get('Group');
$existingCustomerGroup = $allGroups->find('Title', 'Customers');
if (!$existingCustomerGroup) {
$customerGroup = new Group();
$customerGroup->Title = 'Customers';
$customerGroup->setCode($customerGroup->Title);
$customerGroup->write();
Permission::grant($customerGroup->ID, 'VIEW_ORDER');
}
}
示例8: requireDefaultRecords
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
$groups = Config::inst()->get('Group', 'default_groups');
foreach ($groups as $group) {
$groupObj = Group::singleton()->findOrCreate(array('Code' => $group['code']));
$groupObj->Title = $group['title'];
$groupObj->write();
if (!empty($group['permissions'])) {
foreach ($group['permissions'] as $permission) {
if (!in_array($permission, $groupObj->Permissions()->column('Code'))) {
Permission::grant($groupObj->ID, $permission);
DB::alteration_message('Permission ' . $permission . ' has been granted to group ' . $groupObj->Title, 'created');
}
}
}
}
}
示例9: up
function up()
{
echo "Starting Migration Proc ...<BR>";
//check if migration already had ran ...
$migration = Migration::get()->filter('Name', $this->title)->first();
if (!$migration) {
$g = new Group();
$g->setTitle('CCLA Admin');
$g->setDescription('Company CCLA Admin');
$g->setSlug(ICLAMemberDecorator::CCLAGroupSlug);
$g->write();
Permission::grant($g->getIdentifier(), ICLAMemberDecorator::CCLAPermissionSlug);
$migration = new Migration();
$migration->Name = $this->title;
$migration->Description = $this->description;
$migration->Write();
}
echo "Ending Migration Proc ...<BR>";
}
示例10: requireDefaultRecords
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
$intranetGroup = Group::get()->filter(array("Code" => $this->Config()->get("group_code")))->first();
if ($intranetGroup && $intranetGroup->exists()) {
//do nothing
} else {
$intranetGroup = new Group();
DB::alteration_message($this->Config()->get("group_name") . ' group created', "created");
}
if ($intranetGroup) {
$intranetGroup->Code = $this->Config()->get("group_code");
$intranetGroup->Title = $this->Config()->get("group_name");
$intranetGroup->write();
Permission::grant($intranetGroup->ID, $this->Config()->get("permission_code"));
if (DB::query("\r\n\t\t\t\tSELECT *\r\n\t\t\t\tFROM Permission\r\n\t\t\t\tWHERE \"GroupID\" = '" . $intranetGroup->ID . "'\r\n\t\t\t\t\tAND \"Code\" LIKE '" . $this->Config()->get("permission_code") . "'")->numRecords() == 0) {
Permission::grant($intranetGroup->ID, $this->Config()->get("permission_code"));
DB::alteration_message($this->Config()->get("group_name") . ' permissions granted', "created");
}
}
}
示例11: requireDefaultRecords
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
// Add default FrontendMember group if none with permission code ADMIN exists
if (!defined('CreateDefaultGroupsOnce')) {
define('CreateDefaultGroupsOnce', true);
$authorGroup = Group::get_one("Group", "Code='content-authors'");
if (!$authorGroup) {
$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, 'ACCESS_CONTENT');
DB::alteration_message('Content Authors Group Permissions added', "created");
}
}
示例12: requireDefaultRecords
/**
* Add default records to database.
*
* This function is called whenever the database is built, after the
* database tables have all been created.
*/
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
// Add default poster group if it doesn't exist
$poster = Group::get()->filter("Code", 'discussions-posters')->first();
if (!$poster) {
$poster = new Group();
$poster->Code = 'discussions-posters';
$poster->Title = _t('Discussions.DefaultGroupTitlePosters', 'Discussion Posters');
$poster->Sort = 1;
$poster->write();
Permission::grant($poster->ID, 'DISCUSSIONS_REPLY');
DB::alteration_message('Discussion Poster Group Created', 'created');
}
// Add default modrator group if none exists
$moderator = Permission::get_groups_by_permission('DISCUSSIONS_MODERATION')->first();
if (!$moderator) {
$moderator = new Group();
$moderator->Code = 'discussions-moderators';
$moderator->Title = _t('Discussions.DefaultGroupTitleModerators', 'Discussion Moderators');
$moderator->Sort = 0;
$moderator->write();
Permission::grant($moderator->ID, 'DISCUSSIONS_MODERATION');
DB::alteration_message('Discussion Moderator Group Created', 'created');
}
// Now add these groups to a discussion holder (if one exists)
foreach (DiscussionHolder::get() as $page) {
if (!$page->PosterGroups()->count()) {
$page->PosterGroups()->add($poster);
$page->write();
DB::alteration_message('Added Poster Group to Discussions Holder', 'created');
}
if (!$page->ModeratorGroups()->count()) {
$page->ModeratorGroups()->add($moderator);
$page->write();
DB::alteration_message('Added Moderator Group to Discussions Holder', 'created');
}
}
}
示例13: requireDefaultRecords
/**
* Create the default Groups
* and add default admin to admin group
*/
public function requireDefaultRecords()
{
// Readers
$readersGroup = DataObject::get('Group')->filter(array('Code' => 'restfulapi-readers'));
if (!$readersGroup->count()) {
$readerGroup = new Group();
$readerGroup->Code = 'restfulapi-readers';
$readerGroup->Title = 'RESTful API Readers';
$readerGroup->Sort = 0;
$readerGroup->write();
Permission::grant($readerGroup->ID, 'RESTfulAPI_VIEW');
}
// Editors
$editorsGroup = DataObject::get('Group')->filter(array('Code' => 'restfulapi-editors'));
if (!$editorsGroup->count()) {
$editorGroup = new Group();
$editorGroup->Code = 'restfulapi-editors';
$editorGroup->Title = 'RESTful API Editors';
$editorGroup->Sort = 0;
$editorGroup->write();
Permission::grant($editorGroup->ID, 'RESTfulAPI_VIEW');
Permission::grant($editorGroup->ID, 'RESTfulAPI_EDIT');
Permission::grant($editorGroup->ID, 'RESTfulAPI_CREATE');
}
// Admins
$adminsGroup = DataObject::get('Group')->filter(array('Code' => 'restfulapi-administrators'));
if (!$adminsGroup->count()) {
$adminGroup = new Group();
$adminGroup->Code = 'restfulapi-administrators';
$adminGroup->Title = 'RESTful API Administrators';
$adminGroup->Sort = 0;
$adminGroup->write();
Permission::grant($adminGroup->ID, 'RESTfulAPI_VIEW');
Permission::grant($adminGroup->ID, 'RESTfulAPI_EDIT');
Permission::grant($adminGroup->ID, 'RESTfulAPI_CREATE');
Permission::grant($adminGroup->ID, 'RESTfulAPI_DELETE');
}
}
示例14: run
/**
* run the task
*/
function run($request)
{
$approvedCustomerGroup = EcommerceCorporateGroupGroupDecorator::get_approved_customer_group();
$approveCustomerPermissionCode = EcommerceCorporateGroupGroupDecorator::get_permission_code();
if (!$approvedCustomerGroup) {
$approvedCustomerGroup = new Group();
$approvedCustomerGroup->Code = EcommerceCorporateGroupGroupDecorator::get_code();
$approvedCustomerGroup->Title = EcommerceCorporateGroupGroupDecorator::get_name();
//$approvedCustomerGroup->ParentID = $parentGroup->ID;
$approvedCustomerGroup->write();
Permission::grant($approvedCustomerGroup->ID, $approveCustomerPermissionCode);
DB::alteration_message(EcommerceCorporateGroupGroupDecorator::get_name() . ' Group created', "created");
} elseif (DB::query("SELECT * FROM \"Permission\" WHERE \"GroupID\" = '" . $approvedCustomerGroup->ID . "' AND \"Code\" LIKE '" . $approveCustomerPermissionCode . "'")->numRecords() == 0) {
Permission::grant($approvedCustomerGroup->ID, $approveCustomerPermissionCode);
DB::alteration_message(EcommerceCorporateGroupGroupDecorator::get_name() . ' permissions granted', "created");
}
$approvedCustomerGroup = EcommerceCorporateGroupGroupDecorator::get_approved_customer_group();
if (!$approvedCustomerGroup) {
user_error("could not create user group");
} else {
DB::alteration_message(EcommerceCorporateGroupGroupDecorator::get_name() . ' is ready for use', "created");
}
}
开发者ID:helpfulrobot,项目名称:sunnysideup-ecommerce-corporate-account,代码行数:26,代码来源:CreateEcommerceApprovedCustomerGroup.php
示例15: requireDefaultRecords
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
if ($this->config()->create_default_pages) {
$groupHolder = DataObject::get_one('ScoutGroupHolder');
if (!$groupHolder) {
$groupHolder = new ScoutGroupHolder();
$groupHolder->Title = "Groups";
$groupHolder->URLSegment = 'groups';
$groupHolder->Status = 'Published';
$groupHolder->write();
$groupHolder->publish('Stage', 'Live');
DB::alteration_message('Scout Group Holder page created', 'created');
}
}
$districtAdmin = DataObject::get_one('Group', "Code = 'scout-district-admin'");
if (!$districtAdmin) {
$districtAdmin = new Group();
$districtAdmin->Code = 'scout-district-admin';
$districtAdmin->Title = _t('ScoutDistrict.Groups.SCOUTDISTRICTADMIN', 'Scout District Admin');
$districtAdmin->write();
Permission::grant($districtAdmin->ID, ScoutDistrictPermissions::$district_admin);
DB::alteration_message('Scout District Admin group created', 'created');
}
$groupManager = DataObject::get_one('Group', "Code = 'scout-group-manager'");
if (!$groupManager) {
$groupManager = new Group();
$groupManager->Code = 'scout-group-manager';
$groupManager->Title = _t('ScoutDistrict.Groups.SCOUTGROUPMANAGER', 'Scout Group Manager');
$groupManager->write();
Permission::grant($groupManager->ID, ScoutDistrictPermissions::$group_manager);
Permission::grant($groupManager->ID, "CMS_ACCESS_CMSMain");
DB::alteration_message('Scout Group Manager group created', 'created');
}
}