Editing User Permissions by code
Permalink 1 user found helpful
Hi!
I need to edit User Permissions by code. I want to allow to "Access User Search" to a user group.
I have been analysing a lot of C5 core classes (TaskPermission, Concrete5_Model_PermissionKey, etc), but I have not seen any method similar to $page->assignPermissions.
I need to edit User Permissions by code. I want to allow to "Access User Search" to a user group.
I have been analysing a lot of C5 core classes (TaskPermission, Concrete5_Model_PermissionKey, etc), but I have not seen any method similar to $page->assignPermissions.
This is a good piece of code, but I'm afraid that it's not useful for me.
If you look at the attachment in my first post, there is a "User permissions" panel where you can add or remove permissions to users and groups. I want to manage that "User Permissions" panel by code, and enable its first functionality "Access User Search" to a given set of users or groups.
Anyway, I appreciate your help. A lot of thanks
If you look at the attachment in my first post, there is a "User permissions" panel where you can add or remove permissions to users and groups. I want to manage that "User Permissions" panel by code, and enable its first functionality "Access User Search" to a given set of users or groups.
Anyway, I appreciate your help. A lot of thanks
Am i'm right that you want to give access to .../dashboard/users/search/ ?
At the sitemap, you can activate display system pages under options and edit the permission to the user search. Add a group that you want have access to it, then the code posted above would work.
At the sitemap, you can activate display system pages under options and edit the permission to the user search. Add a group that you want have access to it, then the code posted above would work.
I have that code:
It works, but, when the popup appears and tries to load users, it raises a "You have no access to users" error.
Then, I have to login as Administrator, "System & Settings", "User Permissions", and enable "Access User Search" for a special user group that I have added. And this is what I want to get by code.
$form = Loader::helper('form/user_selector'); echo $form->selectMultipleUsers("recipients", $uID = false);
It works, but, when the popup appears and tries to load users, it raises a "You have no access to users" error.
Then, I have to login as Administrator, "System & Settings", "User Permissions", and enable "Access User Search" for a special user group that I have added. And this is what I want to get by code.
Before 5.6 it was like this:
But I'm not sure how it is now.
$g4 = Group::getByID($yourgroupid); $tp = TaskPermission::getByHandle('access_user_search'); $tp->addAccess($g4);
But I'm not sure how it is now.
It doesn't show how to handle Task Permissions though.
TaskPermissions are kind of legacy now. In this case this one is UserPermissionKey. Here's a snippet that might help you sort this one out.
Let me know if that one works for you.
Best Wishes,
Mike
$groupName = 'Superstars'; // change to the group you need $taskPermissionHandle = 'access_user_search'; $group = Group::getByName($groupName); $pk = UserPermissionKey::getByHandle($taskPermissionHandle); $pao = $pk->getPermissionAssignmentObject(); $pa = PermissionAccess::getByID($pk->getPermissionAccessID(), $pk)->duplicate(); $pae = GroupPermissionAccessEntity::getOrCreate($group); $pa->addListItem($pae, false, PermissionKey::ACCESS_TYPE_INCLUDE); $pa->save(array('paID' => $pa->getPermissionAccessID())); $pao->assignPermissionAccess($pa);
Let me know if that one works for you.
Best Wishes,
Mike
That's exactly what is needed for > 5.6. I tried it out and it works.
Thanks a million Mike :)
Thanks a million Mike :)
hope I'm getting you right, do you want to put a user into a group that has access to user search?
If so, this might help:
Greets