Example usage for com.liferay.portal.kernel.security.membershippolicy SiteMembershipPolicyUtil isMembershipRequired

List of usage examples for com.liferay.portal.kernel.security.membershippolicy SiteMembershipPolicyUtil isMembershipRequired

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.security.membershippolicy SiteMembershipPolicyUtil isMembershipRequired.

Prototype

public static boolean isMembershipRequired(long userId, long groupId) throws PortalException 

Source Link

Usage

From source file:com.liferay.site.admin.web.internal.display.context.SiteAdminDisplayContext.java

License:Open Source License

public boolean hasEditAssignmentsPermission(Group group, boolean organizationUser, boolean userGroupUser)
        throws PortalException {

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

    User user = themeDisplay.getUser();//from w w w  .  ja v a2s.  c  o m

    if (!group.isCompany() && !(organizationUser || userGroupUser)
            && ((group.getType() == GroupConstants.TYPE_SITE_OPEN)
                    || (group.getType() == GroupConstants.TYPE_SITE_RESTRICTED))
            && GroupLocalServiceUtil.hasUserGroup(user.getUserId(), group.getGroupId())
            && !SiteMembershipPolicyUtil.isMembershipRequired(user.getUserId(), group.getGroupId())) {

        return true;
    }

    return false;
}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularGroupServiceImpl.java

License:Open Source License

public long[] checkGroups(long userId, long[] groupIds) throws PortalException {

    long[] oldGroupIds = null;

    PermissionChecker permissionChecker = getPermissionChecker();

    User user = null;/* w  w w . j a  v  a2 s  .  co m*/

    if (userId != CompanyConstants.SYSTEM) {

        // Add back any mandatory groups or groups that the administrator
        // does not have the rights to remove and check that he has the
        // permission to add a new group

        user = userPersistence.findByPrimaryKey(userId);

        List<Group> oldGroups = GroupLocalServiceUtil.getUserGroups(userId);

        oldGroupIds = new long[oldGroups.size()];

        for (int i = 0; i < oldGroups.size(); i++) {
            Group group = oldGroups.get(i);

            if (!ArrayUtil.contains(groupIds, group.getGroupId())
                    && (!GroupPermissionUtil.contains(permissionChecker, group, ActionKeys.ASSIGN_MEMBERS)
                            || SiteMembershipPolicyUtil.isMembershipProtected(permissionChecker,
                                    user.getUserId(), group.getGroupId())
                            || SiteMembershipPolicyUtil.isMembershipRequired(userId, group.getGroupId()))) {

                groupIds = ArrayUtil.append(groupIds, group.getGroupId());
            }

            oldGroupIds[i] = group.getGroupId();
        }
    }

    // Check that the administrator has the permission to add a new group
    // and that the group membership is allowed

    for (long groupId : groupIds) {
        if ((oldGroupIds != null) && ArrayUtil.contains(oldGroupIds, groupId)) {

            continue;
        }

        Group group = GroupLocalServiceUtil.getGroup(groupId);

        GroupPermissionUtil.check(permissionChecker, group, ActionKeys.ASSIGN_MEMBERS);
    }

    return groupIds;
}