Fórum

Problems with setRolePermissions for Custom Attributes

stephan t, modificado 12 Anos atrás.

Problems with setRolePermissions for Custom Attributes

Junior Member Postagens: 48 Data de Entrada: 19/10/10 Postagens Recentes
Hello good people,

I implemented a startup hook to create some custom attributes for user.
I like to set some permissions along with the creation, so GUEST can also see them, and USER can see and set them.

Here is my code, that worked in 5.2. but doesn't seem to be working in 6

// create table code is here
col = ExpandoColumnLocalServiceUtil.addColumn(table.getTableId(), attrName, 
// set permissions for guests and user 
Role guestRole = RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST);
Role userRole = RoleLocalServiceUtil.getRole(companyId, RoleConstants.USER);
String[] actionsRW = new String[]{ActionKeys.VIEW, ActionKeys.UPDATE};
String[] actionsR = new String[]{ActionKeys.VIEW};
Resource resource = ResourceLocalServiceUtil.addResource(
	companyId,
	ExpandoColumn.class.getName(),
	ResourceConstants.SCOPE_INDIVIDUAL,
	String.valueOf(col.getColumnId()));
PermissionLocalServiceUtil.setRolePermissions(guestRole.getRoleId(), actionsR, resource.getResourceId());
PermissionLocalServiceUtil.setRolePermissions(userRole.getRoleId(), actionsRW, resource.getResourceId());


After the code executed I verified the settings in the UI and the R and RW permissions have not been granted. The resourcepermission table has two new rows, where for both rows the actionIds value is 15 (which is weird, as the permissions should be different). When I then set the permissions by hand in the UI I get another two rows, where the actionIds are 1 and 9 respectively.

As I mentioned above, in 5.2 it worked an the permissions were set.
Am I making a mistake here?

thanks in advance for your answer
Have a good weekend
Stephan
stephan t, modificado 12 Anos atrás.

RE: Problems with setRolePermissions for Custom Attributes

Junior Member Postagens: 48 Data de Entrada: 19/10/10 Postagens Recentes
I found the solution. It is along the lines of: "If you need a hammer, don't use a screw driver" ;-)
In Liferay 6 Lines 14 and 15 of the above code should rather be (in Liferay 5.2 the above code seem to work):

ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, "com.liferay.portlet.expando.model.ExpandoColumn", resource.getScope(), resource.getPrimKey(), guestRole.getRoleId(), actionsR);
ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, "com.liferay.portlet.expando.model.ExpandoColumn", resource.getScope(), resource.getPrimKey(), userRole.getRoleId(), actionsRW);


Cheers
Stephan
thumbnail
Mika Koivisto, modificado 12 Anos atrás.

RE: Problems with setRolePermissions for Custom Attributes

Liferay Legend Postagens: 1519 Data de Entrada: 07/08/06 Postagens Recentes
Thanks for sharing Stephan. sevencogs-hook has great examples for many things how to use the API. It uses the API to create users, communities and content.