liferayliferay-6.2

Liferay 6.2: change one role´s permission to view roles or assign roles to users


I´m coding a script to change several users´s permissions and, in one step, I need to check some boxes in the matrix located in Roles -> Permissions. In order words, I need to redefine which users will be able to view or assign some other roles and it´s kind of a massive change, so the manual approach should be as avoided as possible.

Do you know what function should I apply to do this? Maybe something similar to "ResourcePermissionLocalServiceUtil.setResourcePermissions" but I´m not sure there is a proper "action" here or if there is actually a "resource" in this case.

Thanks in advance.


Solution

  • I finally solved this. It was, indeed, using the function setResourcePermission. Just for helping the people around here, I´ll explain the arguments briefly, in order:

    So, for instance, a call like this:

    PermissionResourceLocalServiceUtil.setResourcePermissions(10000,"com.liferay.portal.model.Role",4,"20150",22000, {"VIEW", "ASSIGN_MEMBERS"});
    

    Will grant permissions to the role 22000 of View and a assignation of users to the role "20150" in the portal instance whose id is 10000.

    Edit: another version of the same function is setOwnerResourcePermissions, which is the same but gives you the possibility to specify the ownerId of the permission.