最後,我能夠完成,修改爲Resource Permissions
勞力士和修改初始化users_admin portlet的JSP文件中,都使用掛鉤插件。
主要問題是Liferay沒有使用ResourcePermissions來啓用用戶所屬組織以外的組織管理。
尤其是在portal-trunk/portal-web/docroot/html/portlet/users_admin/init.jsp
有幾行代碼使之不僅爲公司管理員角色:
else if (permissionChecker.isCompanyAdmin()) {
filterManageableGroups = false;
filterManageableOrganizations = false;
filterManageableUserGroups = false;
}
所以我加了以下幾行init.jsp(你可以使用初始化-EXT。 JSP在掛機)來啓用它也爲勞力士:
if (MyUtils.isRoleX()) {
filterManageableGroups = false;
filterManageableOrganizations = false;
filterManageableUserGroups = false;
}
這樣的數據庫查詢不會過濾機構,用戶和組。
第二步是定義添加,更新,管理等權限。用戶和組織以及訪問控制面板中的portlet。
這是非常簡單的使用啓動動作鉤和ResourcePermisssionLocalService
API:
private static final String[] ORGANIZATION_ENTRY_ACTION_IDS = new String[] {
ActionKeys.VIEW, ActionKeys.UPDATE, ActionKeys.ASSIGN_USER_ROLES,
ActionKeys.DELETE, ActionKeys.MANAGE_USERS };
private static final String[] ORGANIZATION_CUSTOM_FIELDS_ENTRY_ACTION_IDS = new String[] {
ActionKeys.VIEW, ActionKeys.UPDATE };
public static final String[] ORGANIZATION_MODEL_ACTION_IDS = new String[] {
ActionKeys.ASSIGN_MEMBERS, ActionKeys.ASSIGN_USER_ROLES,
ActionKeys.DELETE, ActionKeys.MANAGE_ANNOUNCEMENTS,
ActionKeys.UPDATE, ActionKeys.VIEW, ActionKeys.MANAGE_USERS,
ActionKeys.MANAGE_SUBORGANIZATIONS };
public static final String[] ORGANIZATION_GROUP_ENTRY_ACTION_IDS = new String[] {
ActionKeys.ASSIGN_MEMBERS, ActionKeys.ASSIGN_USER_ROLES,
ActionKeys.UPDATE, ActionKeys.VIEW, ActionKeys.VIEW_MEMBERS };
private static final String[] PORTAL_ACTION_IDS = new String[] {
ActionKeys.ADD_USER, ActionKeys.ADD_ORGANIZATION,
ActionKeys.VIEW_CONTROL_PANEL };
private static final String[] USERS_ORG_ADMIN_ACTION_IDS = new String[] { ActionKeys.ACCESS_IN_CONTROL_PANEL };
... omissis ...
ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId,
Organization.class.getName(),
ResourceConstants.SCOPE_GROUP_TEMPLATE, "0", CiUtils
.getRoleX().getPrimaryKey(),
ORGANIZATION_MODEL_ACTION_IDS);
// ORGANIZATION MODEL COMPANY PERMISSIONS
ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId,
Organization.class.getName(), ResourceConstants.SCOPE_COMPANY,
Long.toString(companyId),
CiUtils.getRoleX().getPrimaryKey(),
ORGANIZATION_MODEL_ACTION_IDS);
// PORTAL (portlet 90) PERMISSIONS
ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId,
"90", ResourceConstants.SCOPE_COMPANY,
Long.toString(companyId),
CiUtils.getRoleX().getPrimaryKey(),
PORTAL_ACTION_IDS);
// USER_ORG_ADMINS PORTLET (125) PERMISSIONS
ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId,
"125", ResourceConstants.SCOPE_COMPANY,
Long.toString(companyId),
CiUtils.getRoleX().getPrimaryKey(),
USERS_ORG_ADMIN_ACTION_IDS);
和每個組織:
ResourcePermissionLocalServiceUtil.setResourcePermissions(organization.getCompanyId(),
Organization.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, Long .toString(organization.getPrimaryKey()),
MyUtils.getRoleX().getPrimaryKey(),
ORGANIZATION_ENTRY_ACTION_IDS);
long groupId = organization.getGroupId();
ResourcePermissionLocalServiceUtil.setResourcePermissions(
organization.getCompanyId(),Group.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL,Long.toString(groupId),
MyUtils.getRoleX().getPrimaryKey(),
ORGANIZATION_GROUP_ENTRY_ACTION_IDS);
希望這可以幫助別人。