Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Assign permissions on creating web content
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
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
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);
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);
Ok! Thank you very much. I am going to try it!
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™