Search in sources :

Example 1 with Scope

use of com.liferay.imex.role.model.Scope in project liferay-imex by jpdacunha.

the class ExportRolePermissionsServiceImpl method getResource.

private Resource getResource(long companyId, long roleId, String resource, List<String> actions, boolean allActions) throws PortalException, SystemException {
    Resource r = new Resource();
    r.setResourceName(resource);
    Company company = companyLocalService.getCompany(companyId);
    Role role = roleLocalService.getRole(roleId);
    for (String actionId : actions) {
        Action action = new Action();
        action.setActionId(actionId);
        Scope scope = getScope(company, role, resource, actionId);
        action.setScope(scope);
        if (allActions || !scope.equals(Scope.NONE)) {
            r.getActionList().add(action);
            if (scope.equals(Scope.GROUP)) {
                LinkedHashMap<String, Object> groupParams = new LinkedHashMap<String, Object>();
                @SuppressWarnings("rawtypes") List<Comparable> rolePermissions = new ArrayList<Comparable>();
                rolePermissions.add(resource);
                rolePermissions.add(new Integer(ResourceConstants.SCOPE_GROUP));
                rolePermissions.add(actionId);
                rolePermissions.add(new Long(role.getRoleId()));
                groupParams.put("rolePermissions", rolePermissions);
                List<Group> groups = groupLocalService.search(company.getCompanyId(), null, null, groupParams, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
                for (Group group : groups) {
                    if (group.isSite()) {
                        action.getSitesNames().add(group.getName());
                    }
                /*else {
								_log.error("Group identified by [" + group.getFriendlyURL() + "] is not a site");
								throw new IllegalStateException();
							}*/
                }
            }
        }
    }
    return r;
}
Also used : Group(com.liferay.portal.kernel.model.Group) Company(com.liferay.portal.kernel.model.Company) Action(com.liferay.imex.role.model.Action) Resource(com.liferay.imex.role.model.Resource) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Role(com.liferay.portal.kernel.model.Role) Scope(com.liferay.imex.role.model.Scope)

Example 2 with Scope

use of com.liferay.imex.role.model.Scope in project liferay-imex by jpdacunha.

the class ExportRolePermissionsServiceImpl method getScope.

private Scope getScope(Company company, Role role, String curResource, String actionId) throws PortalException, SystemException {
    boolean hasCompanyScope = false;
    boolean hasGroupTemplateScope = false;
    boolean hasGroupScope = false;
    hasCompanyScope = (role.getType() == RoleConstants.TYPE_REGULAR) && resourcePermissionLocalService.hasScopeResourcePermission(company.getCompanyId(), curResource, ResourceConstants.SCOPE_COMPANY, role.getRoleId(), actionId);
    hasGroupTemplateScope = ((role.getType() == RoleConstants.TYPE_SITE) || (role.getType() == RoleConstants.TYPE_ORGANIZATION)) && resourcePermissionLocalService.hasScopeResourcePermission(company.getCompanyId(), curResource, ResourceConstants.SCOPE_GROUP_TEMPLATE, role.getRoleId(), actionId);
    hasGroupScope = (role.getType() == RoleConstants.TYPE_REGULAR) && resourcePermissionLocalService.hasScopeResourcePermission(company.getCompanyId(), curResource, ResourceConstants.SCOPE_GROUP, role.getRoleId(), actionId);
    Scope result = null;
    if (hasCompanyScope) {
        result = Scope.COMPANY;
    } else if (hasGroupTemplateScope) {
        result = Scope.GROUP_TEMPLATE;
    } else if (hasGroupScope) {
        result = Scope.GROUP;
    } else {
        result = Scope.NONE;
    }
    return result;
}
Also used : Scope(com.liferay.imex.role.model.Scope)

Aggregations

Scope (com.liferay.imex.role.model.Scope)2 Action (com.liferay.imex.role.model.Action)1 Resource (com.liferay.imex.role.model.Resource)1 Company (com.liferay.portal.kernel.model.Company)1 Group (com.liferay.portal.kernel.model.Group)1 Role (com.liferay.portal.kernel.model.Role)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1