Message Boards

Assign permissions on creating web content

A G, modified 3 Years ago.

Assign permissions on creating web content

New Member Posts: 14 Join Date: 2/1/17 Recent Posts
Hello,
I am looking for some information about how to programatically assign permissions to a web content at the same time it is created by certain user. The main goal is that the user do not have to configure them manually.  These permissions could be ,for example, those which are assigned to  the web content's containing folder .
I am using Liferay 7.0.3 but soon I will migrate to 7.3.Could  you please help me ??Thanks in advance!
Andrea
thumbnail
Christoph Rabel, modified 3 Years ago.

RE: Assign permissions on creating web content

Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
You can either do this in a JournalArticleServiceWrapper or in a workflow.
https://help.liferay.com/hc/en-us/articles/360018159951-Overriding-Liferay-Services-Service-Wrappers-
To set permissions you can use ResourcePermissionLocalService
https://docs.liferay.com/portal/7.0/javadocs/portal-kernel/com/liferay/portal/kernel/service/ResourcePermissionLocalService.html
Map<Long, String[]> roleIdsToActionIds = new HashMap<>();
// Determine ids of roles to give e.g. View rights and put them in the map.
roleIdsToActionIds.put(roleId, new String[] { ActionKeys.VIEW });
ResourcePermissionLocalServiceUtil.setResourcePermissions(article.getCompanyId(), JournalArticle.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(article.getResourcePrimKey()), roleIdsToActionIds);
A G, modified 3 Years ago.

RE: Assign permissions on creating web content

New Member Posts: 14 Join Date: 2/1/17 Recent Posts
Ok! Thank you very much. I am going to try it!