2

我正在动态创建一个新的 liferay 页面(在 Liferay 中称为布局)。但是,它是使用默认用户权限创建的。

我需要为新页面设置权限:高级用户只有权限 VIEW,但我想添加权限 DELETE、UPDATE 和 PERMISSIONS。

我在互联网上检查的一种方法是:

long userRoleId = RoleLocalServiceUtil.getRole(companyId,
                                RoleConstants.POWER_USER).getRoleId();

ResourcePermissionLocalServiceUtil.addResourcePermission (
CompanyID,
layout.getModelClassName ().
ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf (layout.getPrimaryKey ()) userRoleId,
ActionKeys.DELETE);

另一个是:

ResourcePermissionServiceUtil.setIndividualResourcePermissions(groupId,
                         companyId, layout.getName(Locale.FRANCE),
                         String.valueOf(layout.getPrimaryKey()), userRoleId,
                         new String[] { ActionKeys.DELETE });

由于我的liferay版本是6.0.6,所以布局对象没有layout.getModelClassName()方法,所以我尝试了layout.getClass().getName()和layout.getName(Locale.FRANCE)方法,结果是:

NoSuchResourceException

因此,如果有人知道如何以编程方式更改页面的权限,我将非常感激。

这是我用来创建新页面的代码(没有添加权限的代码):

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);

      }
4

1 回答 1

2

您可以使用此代码分配权限

Role userRole = RoleLocalServiceUtil.getRole(companyId, "POWER USER");

ResourcePermissionServiceUtil.setIndividualResourcePermissions(themeDisplay.getScopeGroupId(),
themeDisplay.getCompanyId(), Layout.class.getName(), "primKey",
userRole.getRoleId(), new String[] { ActionKeys.VIEW });

高温高压

于 2013-07-16T08:56:27.660 回答