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

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

Introduction

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

Prototype

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

Source Link

Usage

From source file:com.liferay.asset.categories.admin.web.internal.portlet.configuration.icon.PermissionsPortletConfigurationIcon.java

License:Open Source License

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

    User user = themeDisplay.getUser();//from  w w w.  j  a  v  a2s.c  om

    if (user.isDefaultUser()) {
        return false;
    }

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    try {
        if (!AssetCategoriesPermission.contains(permissionChecker, themeDisplay.getSiteGroupId(),
                ActionKeys.PERMISSIONS)
                || !GroupPermissionUtil.contains(permissionChecker, themeDisplay.getSiteGroupId(),
                        ActionKeys.PERMISSIONS)) {

            return false;
        }
    } catch (Exception e) {
        return false;
    }

    return true;
}

From source file:com.liferay.asset.publisher.web.internal.util.AssetPublisherWebUtil.java

License:Open Source License

public boolean isScopeIdSelectable(PermissionChecker permissionChecker, String scopeId, long companyGroupId,
        Layout layout, boolean checkPermission) throws PortalException {

    long groupId = _assetPublisherUtil.getGroupIdFromScopeId(scopeId, layout.getGroupId(),
            layout.isPrivateLayout());//  w w w  . j  a v  a2  s  . c  o  m

    if (scopeId.startsWith(AssetPublisherUtil.SCOPE_ID_CHILD_GROUP_PREFIX)) {

        Group group = _groupLocalService.getGroup(groupId);

        if (!group.hasAncestor(layout.getGroupId())) {
            return false;
        }
    } else if (scopeId.startsWith(AssetPublisherUtil.SCOPE_ID_PARENT_GROUP_PREFIX)) {

        Group siteGroup = layout.getGroup();

        if (!siteGroup.hasAncestor(groupId)) {
            return false;
        }

        Group group = _groupLocalService.getGroup(groupId);

        if (SitesUtil.isContentSharingWithChildrenEnabled(group)) {
            return true;
        }

        if (!PrefsPropsUtil.getBoolean(layout.getCompanyId(),
                PropsKeys.SITES_CONTENT_SHARING_THROUGH_ADMINISTRATORS_ENABLED)) {

            return false;
        }

        if (checkPermission) {
            return GroupPermissionUtil.contains(permissionChecker, group, ActionKeys.UPDATE);
        }
    } else if ((groupId != companyGroupId) && checkPermission) {
        return GroupPermissionUtil.contains(permissionChecker, groupId, ActionKeys.UPDATE);
    }

    return true;
}

From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java

License:Open Source License

public static boolean isScopeIdSelectable(PermissionChecker permissionChecker, String scopeId,
        long companyGroupId, Layout layout, boolean checkPermission) throws PortalException {

    long groupId = getGroupIdFromScopeId(scopeId, layout.getGroupId(), layout.isPrivateLayout());

    if (scopeId.startsWith(SCOPE_ID_CHILD_GROUP_PREFIX)) {
        Group group = _groupLocalService.getGroup(groupId);

        if (!group.hasAncestor(layout.getGroupId())) {
            return false;
        }//from w ww . j a v a  2s  . com
    } else if (scopeId.startsWith(SCOPE_ID_PARENT_GROUP_PREFIX)) {
        Group siteGroup = layout.getGroup();

        if (!siteGroup.hasAncestor(groupId)) {
            return false;
        }

        Group group = _groupLocalService.getGroup(groupId);

        if (SitesUtil.isContentSharingWithChildrenEnabled(group)) {
            return true;
        }

        if (!PrefsPropsUtil.getBoolean(layout.getCompanyId(),
                PropsKeys.SITES_CONTENT_SHARING_THROUGH_ADMINISTRATORS_ENABLED)) {

            return false;
        }

        if (checkPermission) {
            return GroupPermissionUtil.contains(permissionChecker, group, ActionKeys.UPDATE);
        }
    } else if ((groupId != companyGroupId) && checkPermission) {
        return GroupPermissionUtil.contains(permissionChecker, groupId, ActionKeys.UPDATE);
    }

    return true;
}

From source file:com.liferay.bookmarks.web.internal.portlet.configuration.icon.PermissionsPortletConfigurationIcon.java

License:Open Source License

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

    User user = themeDisplay.getUser();/*from w  w  w  .java 2s  .co m*/

    if (user.isDefaultUser()) {
        return false;
    }

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    try {
        if (!GroupPermissionUtil.contains(permissionChecker, themeDisplay.getScopeGroupId(),
                ActionKeys.PERMISSIONS)) {

            return false;
        }
    } catch (PortalException pe) {
        return false;
    }

    return true;
}

From source file:com.liferay.exportimport.staging.StagingImpl.java

License:Open Source License

@Override
public Group getPermissionStagingGroup(Group group) {
    if (group == null) {
        return null;
    }/*from  w ww  . jav a  2s. com*/

    Group stagingGroup = group;

    if (!group.isStagedRemotely() && group.hasStagingGroup()) {
        try {
            PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

            long scopeGroupId = stagingGroup.getGroupId();

            boolean hasManageStagingPermission = GroupPermissionUtil.contains(permissionChecker, scopeGroupId,
                    ActionKeys.MANAGE_STAGING);
            boolean hasPublishStagingPermission = GroupPermissionUtil.contains(permissionChecker, scopeGroupId,
                    ActionKeys.PUBLISH_STAGING);
            boolean hasViewStagingPermission = GroupPermissionUtil.contains(permissionChecker, scopeGroupId,
                    ActionKeys.VIEW_STAGING);

            if (hasManageStagingPermission || hasPublishStagingPermission || hasViewStagingPermission) {

                stagingGroup = group.getStagingGroup();
            }
        } catch (Exception e) {
        }
    }

    return stagingGroup;
}

From source file:com.liferay.exportimport.staging.StagingImpl.java

License:Open Source License

/**
 * @deprecated As of 4.0.0, replaced by {@link
 *             com.liferay.staging.configuration.web.internal.portlet.StagingConfigurationPortlet#editStagingConfiguration(
 *             javax.portlet.ActionRequest, javax.portlet.ActionResponse)}
 *//* w  w  w .j  a  v a  2 s .c o  m*/
@Deprecated
@Override
public void updateStaging(PortletRequest portletRequest, Group liveGroup) throws PortalException {

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

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    long userId = permissionChecker.getUserId();

    if (!GroupPermissionUtil.contains(permissionChecker, liveGroup, ActionKeys.MANAGE_STAGING)) {

        return;
    }

    int stagingType = getStagingType(portletRequest, liveGroup);

    boolean branchingPublic = getBoolean(portletRequest, liveGroup, "branchingPublic");
    boolean branchingPrivate = getBoolean(portletRequest, liveGroup, "branchingPrivate");
    boolean forceDisable = ParamUtil.getBoolean(portletRequest, "forceDisable");

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    serviceContext.setAttribute("forceDisable", forceDisable);

    if (stagingType == StagingConstants.TYPE_NOT_STAGED) {
        if (liveGroup.hasStagingGroup() || liveGroup.isStagedRemotely()) {
            _stagingLocalService.disableStaging(portletRequest, liveGroup, serviceContext);
        }
    } else if (stagingType == StagingConstants.TYPE_LOCAL_STAGING) {
        _stagingLocalService.enableLocalStaging(userId, liveGroup, branchingPublic, branchingPrivate,
                serviceContext);
    } else if (stagingType == StagingConstants.TYPE_REMOTE_STAGING) {
        String remoteAddress = getString(portletRequest, liveGroup, "remoteAddress");

        remoteAddress = stripProtocolFromRemoteAddress(remoteAddress);

        int remotePort = getInteger(portletRequest, liveGroup, "remotePort");
        String remotePathContext = getString(portletRequest, liveGroup, "remotePathContext");
        boolean secureConnection = getBoolean(portletRequest, liveGroup, "secureConnection");
        long remoteGroupId = getLong(portletRequest, liveGroup, "remoteGroupId");

        _stagingLocalService.enableRemoteStaging(userId, liveGroup, branchingPublic, branchingPrivate,
                remoteAddress, remotePort, remotePathContext, secureConnection, remoteGroupId, serviceContext);
    }
}

From source file:com.liferay.exportimport.web.internal.portlet.configuration.icon.ExportImportPortletConfigurationIcon.java

License:Open Source License

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

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    if (!portletDisplay.isShowExportImportIcon()) {
        return false;
    }//w ww.j a va 2s.  co  m

    try {
        return GroupPermissionUtil.contains(themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroup(),
                ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
    } catch (PortalException pe) {

        // LPS-52675

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

        return false;
    }
}

From source file:com.liferay.exportimport.web.internal.portlet.ExportImportControlPanelEntry.java

License:Open Source License

@Override
protected boolean hasAccessPermissionExplicitlyGranted(PermissionChecker permissionChecker, Group group,
        Portlet portlet) throws PortalException {

    if (GroupPermissionUtil.contains(permissionChecker, group, ActionKeys.EXPORT_IMPORT_LAYOUTS)) {

        return true;
    }/*  w w w  . j  a  v  a 2 s . co m*/

    return super.hasAccessPermissionExplicitlyGranted(permissionChecker, group, portlet);
}

From source file:com.liferay.exportimport.web.internal.trash.ExportImportConfigurationTrashHandler.java

License:Open Source License

@Override
protected boolean hasPermission(PermissionChecker permissionChecker, long classPK, String actionId)
        throws PortalException {

    ExportImportConfiguration exportImportConfiguration = _exportImportConfigurationLocalService
            .getExportImportConfiguration(classPK);

    Group group = _groupLocalService.getGroup(exportImportConfiguration.getGroupId());

    return GroupPermissionUtil.contains(permissionChecker, group, actionId);
}

From source file:com.liferay.layout.admin.web.internal.display.context.LayoutsAdminDisplayContext.java

License:Open Source License

public boolean isShowAddRootLayoutButton() throws PortalException {
    return GroupPermissionUtil.contains(_themeDisplay.getPermissionChecker(), getSelGroup(),
            ActionKeys.ADD_LAYOUT);//w w  w. j  a v  a  2 s  . c  o  m
}