Example usage for com.liferay.portal.kernel.service.permission PortletPermissionUtil contains

List of usage examples for com.liferay.portal.kernel.service.permission PortletPermissionUtil contains

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service.permission PortletPermissionUtil contains.

Prototype

public static boolean contains(PermissionChecker permissionChecker, String portletId, String actionId)
            throws PortalException 

Source Link

Usage

From source file:com.liferay.users.admin.web.internal.portlet.action.ExportUsersMVCResourceCommand.java

License:Open Source License

protected List<User> getUsers(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    boolean exportAllUsers = PortalPermissionUtil.contains(permissionChecker, ActionKeys.EXPORT_USER);

    if (!exportAllUsers && !PortletPermissionUtil.contains(permissionChecker, UsersAdminPortletKeys.USERS_ADMIN,
            ActionKeys.EXPORT_USER)) {//  w  w  w .  java 2  s .c  o  m

        return Collections.emptyList();
    }

    LiferayPortletResponse liferayPortletResponse = _portal.getLiferayPortletResponse(resourceResponse);

    PortletURL portletURL = liferayPortletResponse.createRenderURL(UsersAdminPortletKeys.USERS_ADMIN);

    UserSearch userSearch = new UserSearch(resourceRequest, portletURL);

    UserSearchTerms searchTerms = (UserSearchTerms) userSearch.getSearchTerms();

    LinkedHashMap<String, Object> params = new LinkedHashMap<>();

    long organizationId = searchTerms.getOrganizationId();

    if (organizationId > 0) {
        params.put("usersOrgs", Long.valueOf(organizationId));
    } else if (!exportAllUsers) {
        User user = themeDisplay.getUser();

        Long[] organizationIds = ArrayUtil.toArray(user.getOrganizationIds(true));

        if (organizationIds.length > 0) {
            params.put("usersOrgs", organizationIds);
        }
    }

    long roleId = searchTerms.getRoleId();

    if (roleId > 0) {
        params.put("usersRoles", Long.valueOf(roleId));
    }

    long userGroupId = searchTerms.getUserGroupId();

    if (userGroupId > 0) {
        params.put("usersUserGroups", Long.valueOf(userGroupId));
    }

    Indexer<?> indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);

    if (indexer.isIndexerEnabled() && PropsValues.USERS_SEARCH_WITH_INDEX) {
        params.put("expandoAttributes", searchTerms.getKeywords());
    }

    if (searchTerms.isAdvancedSearch()) {
        return _userLocalService.search(themeDisplay.getCompanyId(), searchTerms.getFirstName(),
                searchTerms.getMiddleName(), searchTerms.getLastName(), searchTerms.getScreenName(),
                searchTerms.getEmailAddress(), searchTerms.getStatus(), params, searchTerms.isAndOperator(),
                QueryUtil.ALL_POS, QueryUtil.ALL_POS, (OrderByComparator<User>) null);
    } else {
        return _userLocalService.search(themeDisplay.getCompanyId(), searchTerms.getKeywords(),
                searchTerms.getStatus(), params, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                (OrderByComparator<User>) null);
    }
}

From source file:com.liferay.users.admin.web.internal.portlet.configuration.icon.ExportUsersPortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (PortalPermissionUtil.contains(permissionChecker, ActionKeys.EXPORT_USER)) {

        return true;
    }/* ww w  .  ja v  a  2s  .c  om*/

    try {
        return PortletPermissionUtil.contains(permissionChecker, UsersAdminPortletKeys.USERS_ADMIN,
                ActionKeys.EXPORT_USER);
    } catch (PortalException pe) {

        // LPS-52675

        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }
    }

    return false;
}