Note that there are some explanatory texts on larger screens.

plurals
  1. POLiferay 6.0.5 - Set Permissions in a new page programatically
    primarykey
    data
    text
    <p>I'm creating a new liferay page dynamically (Which is called layout in Liferay). But, it is created with default user permissions. </p> <p>What I need is to set the permissions for the new page: The Power User has only the permission VIEW, but I want to add the permissions DELETE, UPDATE and PERMISSIONS.</p> <p>One method that I checked in the internet is:</p> <pre><code>long userRoleId = RoleLocalServiceUtil.getRole(companyId, RoleConstants.POWER_USER).getRoleId(); ResourcePermissionLocalServiceUtil.addResourcePermission ( CompanyID, layout.getModelClassName (). ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf (layout.getPrimaryKey ()) userRoleId, ActionKeys.DELETE); </code></pre> <p>And other one is:</p> <pre><code>ResourcePermissionServiceUtil.setIndividualResourcePermissions(groupId, companyId, layout.getName(Locale.FRANCE), String.valueOf(layout.getPrimaryKey()), userRoleId, new String[] { ActionKeys.DELETE }); </code></pre> <p>Since my liferay version is 6.0.6, the layout object has no method layout.getModelClassName(), so I tried with the methods layout.getClass().getName() and layout.getName(Locale.FRANCE), and the result was:</p> <p>NoSuchResourceException</p> <p>So, I'd be very thankful if someone knows how to change the permission of a page programatically.</p> <p>Here's the code I'm using to create new pages (without the code that add the permissions):</p> <pre><code>private void createPage(ThemeDisplay themeDisplay, String name) throws Exception { _log.info("createPage:" + name); long userId = themeDisplay.getUserId(); long groupId = themeDisplay.getScopeGroupId(); long companyId = themeDisplay.getCompanyId(); boolean privateLayout = false; long parentLayoutId = 0; String title = null; String description = null; String type = LayoutConstants.TYPE_PORTLET; boolean hidden = true; String friendlyURL = "/cngwallboard/" + name; ServiceContext serviceContext = new ServiceContext(); serviceContext.setScopeGroupId(groupId); Layout layout = LayoutLocalServiceUtil.addLayout(userId, groupId, privateLayout, parentLayoutId, name, title, description, type, hidden, friendlyURL, serviceContext); LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout .getLayoutType(); layoutTypePortlet.setLayoutTemplateId(userId, "3_pages2"); _log.info("setThemeId"); layout.setThemeId("wallboardconfiguration_WAR_wallboardconfigurationtheme"); LayoutSetLocalServiceUtil.updateLookAndFeel(layout.getGroupId(), false, "wallboardconfiguration_WAR_wallboardconfigurationtheme", "01", "", false); PortletPreferences prefs = PortletPreferencesFactoryUtil .getPortletSetup(layout, "118_INSTANCE_pg01", ""); prefs.setValue("layout-template-id", "2_windows_model_1"); prefs.setValue("portlet-setup-show-borders", "true"); prefs.store(); LayoutLocalServiceUtil.updateLayout(layout); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload