Forums de discussion

Remove View Permission of Guest Role using API

thumbnail
Surodip Patra, modifié il y a 11 années.

Remove View Permission of Guest Role using API

Junior Member Publications: 29 Date d'inscription: 25/01/13 Publications récentes
Hi Liferay,

Can anyone tell me how to remove the view Permission of Guest Role for a Portlet using Liferay API by JAVA code?

Thanks & Regards,
Surodip Patra
thumbnail
Jitendra Rajput, modifié il y a 11 années.

RE: Remove View Permission of Guest Role using API

Liferay Master Publications: 875 Date d'inscription: 07/01/11 Publications récentes
If you are using permission algorithm or you are using Liferay 5.x then you need to use ResourceLocalServiceUtil and PermissionUtil to set and unset permission.
If you are using permission algorithm 6 which is default algorithm for Liferay 6.X then you need to use ResourcePermissionLocalServiceUtil to set and unset permission.
thumbnail
Surodip Patra, modifié il y a 11 années.

RE: Remove View Permission of Guest Role using API

Junior Member Publications: 29 Date d'inscription: 25/01/13 Publications récentes
Thanks Jitendra,
I have used ResourcePermissionLocalServiceUtil to remove the Guest View Permission.
But I have noticed that, if I manually check the View Permission checkbox from Portlet Configuration, then it cannot be unchecked or unset using API java code
and
If I set the view permission for Guest Role for a Portlet using API code, it can be unset using code.

Did you noticed that?
Any help will be good for me.

Thanks
thumbnail
Jitendra Rajput, modifié il y a 11 années.

RE: Remove View Permission of Guest Role using API

Liferay Master Publications: 875 Date d'inscription: 07/01/11 Publications récentes
If you are using ResourcePermissionLocalServiceUtil then you need to reduce bitwise value for that role on that particular resource.

See this link to set permission.

To unset permission



1) Get guest role object


Role guestRole = // Get guest user role



2) Get resource object by passing proper resource key (In my case i am playing with DLFileEntry)


       ResourcePermission resourcePermission = ResourcePermissionLocalServiceUtil
                                .getResourcePermission(companyId, DLFileEntry.class.getName(),
                                        ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(fileEntry.getPrimaryKey()),
                                        guestRole.getRoleId());
 


3) Guest resource action object to get bitwise value of that permission.
In my case i have passed DLFileEntry.class.getName() as a Name in your case you need to pass your class name.

ResourceAction resourceAction = ResourceActionLocalServiceUtil.getResourceAction(
                                DLFileEntry.class.getName(), ActionKeys.VIEW);



4)
 resourcePermission.setActionIds(resourcePermission.getActionIds()
                                    - resourceAction.getBitwiseValue());

  ResourcePermissionLocalServiceUtil.updateResourcePermission(resourcePermission);
thumbnail
Surodip Patra, modifié il y a 11 années.

RE: Remove View Permission of Guest Role using API

Junior Member Publications: 29 Date d'inscription: 25/01/13 Publications récentes
Thanks for the reply Jitendra. I will do that.
Can you tell me what is the job of getBitWiseValue()?
and
(resourcePermission.getActionIds() - resourceAction.getBitwiseValue())

returns what?
thumbnail
Jitendra Rajput, modifié il y a 11 années.

RE: Remove View Permission of Guest Role using API

Liferay Master Publications: 875 Date d'inscription: 07/01/11 Publications récentes
For each any every permission they have some weightage like for View - 1 , for ADD - 5 . , Delete - 10
let say if Guest user has permission for View , Add , Delete then in the for that resource permission action ids will be summation of bitwise valuee of Add , View and Delete (1+5+10).

So when you unset any permission you need to remove bitwise value for that particular permission only so that it should not affect any other permission.
I.e if you remove view permission then things will be like this (16-1). So that Add and Delete permissions wont be affected.
thumbnail
Surodip Patra, modifié il y a 11 années.

RE: Remove View Permission of Guest Role using API

Junior Member Publications: 29 Date d'inscription: 25/01/13 Publications récentes
Thank you very much Jitendra,

Can you help me in this post:
http://www.liferay.com/community/forums/-/message_boards/message/21307178

Thanks again
thumbnail
Jitendra Rajput, modifié il y a 11 années.

RE: Remove View Permission of Guest Role using API

Liferay Master Publications: 875 Date d'inscription: 07/01/11 Publications récentes
Did that solution worked for you to remove guest permission ?
thumbnail
Surodip Patra, modifié il y a 11 années.

RE: Remove View Permission of Guest Role using API

Junior Member Publications: 29 Date d'inscription: 25/01/13 Publications récentes
Yes it worked. But the problem is that If I manually (without API calling, by mouse click) add the VIEW permission of Guest Role for a portlet, after using your code it remains checked. AND if I manually uncheck the VIEW Permission of Guest Role for a portlet , then using API call and your code it sets and unset the VIEW Permission correctly.
I don't understand why?