Programmatically assign permissions to a User Group
Permalink
Not having much luck finding anything in the developer docs, so wondering if anyone here can help?
I've programmatically created a user group and been able to assign users to the group, but how do i now assign permissions to that group?
I want to assign to all the types eg:
Search User Group
Edit Group
Assign Group
Add Child Group
Edit Group Permissions
Any help appreciated even just pointing me to the right place in the elusive documentation
I've programmatically created a user group and been able to assign users to the group, but how do i now assign permissions to that group?
I want to assign to all the types eg:
Search User Group
Edit Group
Assign Group
Add Child Group
Edit Group Permissions
Any help appreciated even just pointing me to the right place in the elusive documentation
Is this what you need?https://documentation.concrete5.org/developers/permissions-access-se...
hmm, that seems to be talking about changing permissions on a file.
What I want to do is change/add permissions on a user group.
Not really getting anywhere as yet though.
What I want to do is change/add permissions on a user group.
Not really getting anywhere as yet though.
assigning a permission to a group only means something if you know what kind of permission it is. In the link I sent you, if you look at the middle of the code you will see this
That part will not change whether you want to assign a group permission to view a file a page, a file folder... All you'll need to do is modify the first part so instead of a file you have any other kind of entity you want the group to access and you will have to modify the permission type to whatever it is you want instead of view_file
// enable access by a group $g = UserGroup::getByName('VIPs'); if (is_object($g)) { $pae = GroupPermissionAccessEntity::getOrCreate($g); $pa->addListItem($pae, false, PermissionKey::ACCESS_TYPE_INCLUDE); }
That part will not change whether you want to assign a group permission to view a file a page, a file folder... All you'll need to do is modify the first part so instead of a file you have any other kind of entity you want the group to access and you will have to modify the permission type to whatever it is you want instead of view_file
yeah but that starts with a file $f you assign the permissions to, i want to assign the permissions to a group.
So if the new user group is created under an existing group using:
what am I assigning persmissions to?
Do i get the new group as an object after creating it...
and adding things to that?
So if the new user group is created under an existing group using:
$group = \Group::getByPath('/Custom Group/Custom Group Level 2/'); $newGroup = \Group::add('Custom Group Level 3', '', $group);
what am I assigning persmissions to?
Do i get the new group as an object after creating it...
$newGroupObject = \Group::getByPath('/Custom Group/Custom Group Level 2/Custom Group Level 3/');
and adding things to that?
you say you "want to assign permissions to a group". OK. What permissions? Permissions to do what?
You can't assign permissions to a group if you don't know what permission you are trying to assign and what that permission applies to.
No matter how you look at it you have to decide:
1- what permission you need (e.g. view_file)
2- what object it will apply to (e.g. permission to view which files)
3- who gets to use that permission (e.g. which user group)
So you see, assigning a permission to a group is the last step, not the first one.
You can't assign permissions to a group if you don't know what permission you are trying to assign and what that permission applies to.
No matter how you look at it you have to decide:
1- what permission you need (e.g. view_file)
2- what object it will apply to (e.g. permission to view which files)
3- who gets to use that permission (e.g. which user group)
So you see, assigning a permission to a group is the last step, not the first one.
Yeah I think you're correct I don't understand fully how permissions are working on groups.
I'm just referring to to how it works in the dashboard when you're doing it manually as i haven't worked out how to do it programmaticily.
/dashboard/users/groups
For example..
I create a new user group in the back-end under a current user group
Then right click it, press override permissions.
Then click on each of the permission groups inside it either:
- Search User Group
- Edit Group
- Assign Group
- Add Child Group
and add and remove entities there such as a Group, User, Group Set or Group Combination. (in my case i only need group as ill assign my super users group and a few other admin user groups i've created)
---
Thats what im trying to do with code
I'm just referring to to how it works in the dashboard when you're doing it manually as i haven't worked out how to do it programmaticily.
/dashboard/users/groups
For example..
I create a new user group in the back-end under a current user group
Then right click it, press override permissions.
Then click on each of the permission groups inside it either:
- Search User Group
- Edit Group
- Assign Group
- Add Child Group
and add and remove entities there such as a Group, User, Group Set or Group Combination. (in my case i only need group as ill assign my super users group and a few other admin user groups i've created)
---
Thats what im trying to do with code
Still pulling my hair out over this, been at it since last Thursday with very little progress made.
Is pretty much the last bit i need to finish off my back-end customisation's.
Any one who can help or explain how to add the permission entities (other groups) to the current group programatically would be really helpfull, there is nothing on this in the documentation that i can find.
I've been able to apply permissions to other objects (users, pages, files) no problem but cant seem to work out what i add to for a group.
How i'd do it manually is in the post above, but i dont want to do this over and over for 100s of groups.
Thanks
Is pretty much the last bit i need to finish off my back-end customisation's.
Any one who can help or explain how to add the permission entities (other groups) to the current group programatically would be really helpfull, there is nothing on this in the documentation that i can find.
I've been able to apply permissions to other objects (users, pages, files) no problem but cant seem to work out what i add to for a group.
How i'd do it manually is in the post above, but i dont want to do this over and over for 100s of groups.
Thanks
Hey eudemonics,
Don't know if you're still at this & probably for GDPR I'm guessing...
I'm looking into this too - seems the best option is looking at the following: app/concrete/src/Package/StartingPointPackage.php
@ line 416 in C5 v7.5.13 @ public function set_site_permissions()
Gives you an idea how the C5 guys get it done initially, my plan is to build on that.
You need the group &| user + the page || asset || whatever
e.g. line 419+
Many examples in there.
a.)
Don't know if you're still at this & probably for GDPR I'm guessing...
I'm looking into this too - seems the best option is looking at the following: app/concrete/src/Package/StartingPointPackage.php
@ line 416 in C5 v7.5.13 @ public function set_site_permissions()
Gives you an idea how the C5 guys get it done initially, my plan is to build on that.
You need the group &| user + the page || asset || whatever
$pageOrAssetOrWhatever->assignPermissions(groupOrUser, array(permissions));
e.g. line 419+
$g1 = Group::getByID(GUEST_GROUP_ID); $home = Page::getByID(1, "RECENT"); $home->assignPermissions($g1, array('view_page'));
Many examples in there.
a.)