0

I am creating a portlet to grep all url which has been accessed and creating bookmark entry for that and having no issue in that. But while giving permission to some specific role and team, I am getting the problem.

Can anyone help me how can we set permission for bookmark entry programmatically. I am using following code:

BookmarksEntry entry = BookmarksEntryLocalServiceUtil.addEntry(user.getUserId(), 
                                        GroupLocalServiceUtil.getGroup(user.getCompanyId(), "SPACE").getGroupId(),0,
                                        wikiResource,url,wikiResource+" Accessed on "+viewedDate , new ServiceContext());
long groupId = entry.getGroupId();
long companyId = entry.getCompanyId();
String name = BookmarksEntry.class.getName();
String primKey = entry.getPrimaryKey() + "";

// For Role : "Role_XYZ"
try {
    Role sp_View_Prod_role = RoleLocalServiceUtil.getRole(companyId,"Role_XYZ");
    ResourcePermissionServiceUtil.setIndividualResourcePermissions(
            groupId, companyId, name, primKey,
            sp_View_Prod_role.getRoleId(),
            new String[] { ActionKeys.VIEW });

    PMLogger.logging("[INFO] Document uploaded with view permission added for sp_View Prod,sp_View All -ROLES");
} catch (Exception e) {
    e.printStackTrace();
    PMLogger.logging(e.getMessage());
}

Thanks in advance.

Prakash K
  • 11,669
  • 6
  • 51
  • 109
  • What you have done? what you exactly want? what is not working? Show us some code and some more explanation. Please. Thanks. – Prakash K Dec 09 '14 at 08:10
  • Hey Prakash,I am sorry that i could not explain it very well.I edited my post now and you check what i have done.I am creating BookmarksEntry and trying to give some role permission.I am not getting any exception or error which means code executed completely.But while verifying from control panel book mark portlet,i am not getting proper role permission for created bookmark entry. – vikash kumar Dec 09 '14 at 12:56
  • The above code is same as what you have posted in the question. Makes no difference. Can you update in the question as to how you are verifying from the control panel? – Prakash K Dec 10 '14 at 09:06

1 Answers1

0

The code seems to be fine to me. But the problem might be that you are verifying in the wrong place.

Since you are adding permission for an individual BookmarksEntry, here is how you can verify it:

  1. Check if the ResourcePermission table has the entry for the given roleId with the name and primKey column having the same data as yours. And the scope column having value 4.

  2. I think you should check the permission in the Bookmarks portlet alongside the entry itself.

  3. Here is the screen-shot as to where you can check the permissions you have entered:

    Bookmarks Permissions

Hope this helps.

Community
  • 1
  • 1
Prakash K
  • 11,669
  • 6
  • 51
  • 109
  • Thank you Prakash.I veryfied permission in same way.But it was not working with the initial code.When I changed the API it is working fine for me.I think BookmarksEntryLocalServiceUtil is the correct one to assign permission for the same.Correct me i am wrong. – vikash kumar Dec 12 '14 at 08:54
  • 1
    ResourceBlockLocalServiceUtil.addIndividualScopePermission( groupId,companyId,"com.liferay.portlet.bookmarks.model.BookmarksEntry", entry.getPrimaryKey(), sp_View_All_role.getRoleId(), ActionKeys.VIEW); – vikash kumar Dec 12 '14 at 08:57
  • Oh I overlooked using `ResourceBlockLocalServiceUtil` instead of `ResourcePermissionServiceUtil`. Yup I think the one in the comment is correct. You can include that in your answer instead of in the comments for other users. Thanks. – Prakash K Dec 12 '14 at 09:45