Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Nilesh Gundecha
Define permissions for Organization Role
March 26, 2012 3:52 AM
Answer

Nilesh Gundecha

Rank: Regular Member

Posts: 189

Join Date: November 30, 2009

Recent Posts

Dear Friends,

I want to define permissions for Organization Role. I am using the below api for this -

1
2Role orgMentorRole = RoleLocalServiceUtil.fetchRole(companyId, "Organization Mentor");
3try{
4    setRolePermissions(orgMentorRole , AnnouncementsEntry.class.getName(), new String[] {ActionKeys.UPDATE, ActionKeys.VIEW});
5}catch(Exception e){
6    e.printStackTrace();
7}


Here is my setRolePermissions method -

 1
 2protected static void setRolePermissions(
 3            Role role, String name, String[] actionIds)
 4        throws Exception {
 5
 6        long roleId = role.getRoleId();
 7        long companyId = role.getCompanyId();
 8        int scope = ResourceConstants.SCOPE_COMPANY;
 9        String primKey = String.valueOf(companyId);
10
11        if (_PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
12            System.out.println(">_PERMISSIONS_USER_CHECK_ALGORITHM is 6");
13            ResourcePermissionLocalServiceUtil.setResourcePermissions(
14                companyId, name, scope, primKey, roleId, actionIds);
15        }
16        else {
17            System.out.println(">_PERMISSIONS_USER_CHECK_ALGORITHM is not 6");
18            PermissionLocalServiceUtil.setRolePermissions(
19                roleId, companyId, name, scope, primKey, actionIds);
20        }
21    }


But the above code does not define permissions. Also, there is no exception being thrown. Plz lemme know what I am missing here.

Note: - The above code works fine if it is Regular Role.

Regards,
Nilesh
Nilesh Gundecha
RE: Define permissions for Organization Role
March 26, 2012 10:09 PM
Answer

Nilesh Gundecha

Rank: Regular Member

Posts: 189

Join Date: November 30, 2009

Recent Posts

Any help please?

Regards,
Nilesh
Dhrutika Vyas
RE: Define permissions for Organization Role
March 27, 2012 11:44 PM
Answer

Dhrutika Vyas

Rank: Expert

Posts: 435

Join Date: February 9, 2009

Recent Posts

Hi,

Please try out this way..

ResourcePermissionLocalServiceUtil.addResourcePermission(
themeDisplay.getCompanyId(), AnnouncementsEntry.class.getName(),,
ResourceConstants.SCOPE_COMPANY,
String.valueOf(companyId), orgMentorRole.getRoleId(),
ActionKeys.VIEW);

ResourcePermissionLocalServiceUtil.addResourcePermission(
themeDisplay.getCompanyId(), AnnouncementsEntry.class.getName(),
ResourceConstants.SCOPE_COMPANY,
String.valueOf(companyId) ,orgMentorRole.getRoleId(),
ActionKeys.UPDATE);

ResourcePermissionServiceUtil.setIndividualResourcePermissions(
themeDisplay.getScopeGroupId(), themeDisplay.getCompanyId(),
AnnouncementsEntry.class.getName(),
String.valueOf(companyId), orgMentorRole.getRoleId(),,
new String[] {ActionKeys.UPDATE, ActionKeys.VIEW});

Regards,
Dhrutika