Example usage for com.liferay.portal.kernel.workflow.permission WorkflowPermissionUtil hasPermission

List of usage examples for com.liferay.portal.kernel.workflow.permission WorkflowPermissionUtil hasPermission

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.workflow.permission WorkflowPermissionUtil hasPermission.

Prototype

public static Boolean hasPermission(PermissionChecker permissionChecker, long groupId, String className,
            long classPK, String actionId) 

Source Link

Usage

From source file:ca.efendi.datafeeds.service.permission.CJProductPermission.java

License:Apache License

public static boolean contains(PermissionChecker permissionChecker, CJProduct entry, String actionId) {

    String portletId = PortletProviderUtil.getPortletId(CJProduct.class.getName(), PortletProvider.Action.EDIT);

    Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker, entry.getGroupId(),
            CJProduct.class.getName(), entry.getProductId(), portletId, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }/*from  www.  j  ava  2s.co  m*/

    if (entry.isDraft() || entry.isScheduled()) {
        if (actionId.equals(ActionKeys.VIEW) && !contains(permissionChecker, entry, ActionKeys.UPDATE)) {

            return false;
        }
    } else if (entry.isPending()) {
        hasPermission = WorkflowPermissionUtil.hasPermission(permissionChecker, entry.getGroupId(),
                CJProduct.class.getName(), entry.getProductId(), actionId);

        if (hasPermission != null) {
            return hasPermission.booleanValue();
        }
    }

    if (permissionChecker.hasOwnerPermission(entry.getCompanyId(), CJProduct.class.getName(),
            entry.getProductId(), entry.getUserId(), actionId)) {

        return true;
    }

    return permissionChecker.hasPermission(entry.getGroupId(), CJProduct.class.getName(), entry.getProductId(),
            actionId);
}

From source file:com.cd.learning.hook.MBMessagePermission.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker, MBMessage message, String actionId)
        throws PortalException, SystemException {

    if (MBBanLocalServiceUtil.hasBan(message.getGroupId(), permissionChecker.getUserId())) {

        return false;
    }/*from   w ww. java  2 s.  c  om*/

    Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker, message.getGroupId(),
            MBMessage.class.getName(), message.getMessageId(), PortletKeys.MESSAGE_BOARDS, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }

    if (message.isDraft() || message.isScheduled()) {
        if (actionId.equals(ActionKeys.VIEW) && !contains(permissionChecker, message, ActionKeys.UPDATE)) {

            return false;
        }
    } else if (message.isPending()) {
        hasPermission = WorkflowPermissionUtil.hasPermission(permissionChecker, message.getGroupId(),
                message.getWorkflowClassName(), message.getMessageId(), actionId);

        if (hasPermission != null) {
            return hasPermission.booleanValue();
        }
    }

    if (actionId.equals(ActionKeys.VIEW)
            && GetterUtil.getBoolean(PropsUtil.get(PropsKeys.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE))) {

        long categoryId = message.getCategoryId();

        if ((categoryId != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)
                && (categoryId != MBCategoryConstants.DISCUSSION_CATEGORY_ID)) {

            try {
                MBCategory category = MBCategoryLocalServiceUtil.getCategory(categoryId);

                if (!MBCategoryPermission.contains(permissionChecker, category, actionId)) {

                    return false;
                }
            } catch (NoSuchCategoryException nsce) {
                if (!message.isInTrash()) {
                    throw nsce;
                }
            }
        }
    }

    if (permissionChecker.hasOwnerPermission(message.getCompanyId(), MBMessage.class.getName(),
            message.getRootMessageId(), message.getUserId(), actionId)) {

        return true;
    }

    return permissionChecker.hasPermission(message.getGroupId(), MBMessage.class.getName(),
            message.getMessageId(), actionId);
}

From source file:com.liferay.blogs.service.permission.BlogsEntryPermission.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker, BlogsEntry entry, String actionId) {

    String portletId = PortletProviderUtil.getPortletId(BlogsEntry.class.getName(),
            PortletProvider.Action.EDIT);

    Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker, entry.getGroupId(),
            BlogsEntry.class.getName(), entry.getEntryId(), portletId, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }/*from  www. ja va  2s . co  m*/

    if (entry.isDraft() || entry.isScheduled()) {
        if (actionId.equals(ActionKeys.VIEW) && !contains(permissionChecker, entry, ActionKeys.UPDATE)) {

            return false;
        }
    } else if (entry.isPending()) {
        hasPermission = WorkflowPermissionUtil.hasPermission(permissionChecker, entry.getGroupId(),
                BlogsEntry.class.getName(), entry.getEntryId(), actionId);

        if (hasPermission != null) {
            return hasPermission.booleanValue();
        }
    }

    if (permissionChecker.hasOwnerPermission(entry.getCompanyId(), BlogsEntry.class.getName(),
            entry.getEntryId(), entry.getUserId(), actionId)) {

        return true;
    }

    return permissionChecker.hasPermission(entry.getGroupId(), BlogsEntry.class.getName(), entry.getEntryId(),
            actionId);
}

From source file:com.liferay.journal.service.permission.JournalArticlePermission.java

License:Open Source License

private static boolean _contains(PermissionChecker permissionChecker, JournalArticle article, String actionId) {

    String portletId = PortletProviderUtil.getPortletId(JournalArticle.class.getName(),
            PortletProvider.Action.EDIT);

    Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker, article.getGroupId(),
            JournalArticle.class.getName(), article.getResourcePrimKey(), portletId, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }//from  w  w  w.jav a2 s  .co  m

    if (article.isDraft()) {
        if (actionId.equals(ActionKeys.VIEW) && !contains(permissionChecker, article, ActionKeys.UPDATE)) {

            return false;
        }
    } else if (article.isPending()) {
        hasPermission = WorkflowPermissionUtil.hasPermission(permissionChecker, article.getGroupId(),
                JournalArticle.class.getName(), article.getResourcePrimKey(), actionId);

        if (hasPermission != null) {
            return hasPermission.booleanValue();
        }
    }

    if (actionId.equals(ActionKeys.VIEW)) {
        JournalServiceConfiguration journalServiceConfiguration = null;

        try {
            journalServiceConfiguration = _configurationProvider.getCompanyConfiguration(
                    JournalServiceConfiguration.class, permissionChecker.getCompanyId());
        } catch (ConfigurationException ce) {
            _log.error("Unable to get journal service configuration for company "
                    + permissionChecker.getCompanyId(), ce);

            return false;
        }

        if (!journalServiceConfiguration.articleViewPermissionsCheckEnabled()) {

            return true;
        }

        if (PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE) {
            long folderId = article.getFolderId();

            if (folderId == JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

                if (!JournalPermission.contains(permissionChecker, article.getGroupId(), actionId)) {

                    return false;
                }
            } else {
                JournalFolder folder = _journalFolderLocalService.fetchFolder(folderId);

                if (folder != null) {
                    if (!JournalFolderPermission.contains(permissionChecker, folder, ActionKeys.ACCESS)
                            && !JournalFolderPermission.contains(permissionChecker, folder, ActionKeys.VIEW)) {

                        return false;
                    }
                } else {
                    if (!article.isInTrash()) {
                        _log.error("Unable to get journal folder " + folderId);

                        return false;
                    }
                }
            }
        }
    }

    if (permissionChecker.hasOwnerPermission(article.getCompanyId(), JournalArticle.class.getName(),
            article.getResourcePrimKey(), article.getUserId(), actionId)) {

        return true;
    }

    return permissionChecker.hasPermission(article.getGroupId(), JournalArticle.class.getName(),
            article.getResourcePrimKey(), actionId);
}

From source file:com.liferay.message.boards.internal.service.permission.MBMessagePermission.java

License:Open Source License

private boolean _contains(PermissionChecker permissionChecker, MBMessage message, String actionId)
        throws PortalException {

    if (_mbBanLocalService.hasBan(message.getGroupId(), permissionChecker.getUserId())) {

        return false;
    }/*from  w ww  .j ava  2  s. c  om*/

    String portletId = PortletProviderUtil.getPortletId(MBMessage.class.getName(), PortletProvider.Action.EDIT);

    Boolean hasPermission = _stagingPermission.hasPermission(permissionChecker, message.getGroupId(),
            MBMessage.class.getName(), message.getMessageId(), portletId, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }

    if (message.isDraft() || message.isScheduled()) {
        if (actionId.equals(ActionKeys.VIEW) && !_contains(permissionChecker, message, ActionKeys.UPDATE)) {

            return false;
        }
    } else if (message.isPending()) {
        hasPermission = WorkflowPermissionUtil.hasPermission(permissionChecker, message.getGroupId(),
                message.getWorkflowClassName(), message.getMessageId(), actionId);

        if (hasPermission != null) {
            return hasPermission.booleanValue();
        }
    }

    if (actionId.equals(ActionKeys.VIEW) && PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE) {

        long categoryId = message.getCategoryId();

        if ((categoryId == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)
                || (categoryId == MBCategoryConstants.DISCUSSION_CATEGORY_ID)) {

            if (!MBPermission.contains(permissionChecker, message.getGroupId(), actionId)) {

                return false;
            }
        } else {
            try {
                MBCategory category = _mbCategoryLocalService.getCategory(categoryId);

                if (!MBCategoryPermission.contains(permissionChecker, category, actionId)) {

                    return false;
                }
            } catch (NoSuchCategoryException nsce) {
                if (!message.isInTrash()) {
                    throw nsce;
                }
            }
        }
    }

    if (permissionChecker.hasOwnerPermission(message.getCompanyId(), MBMessage.class.getName(),
            message.getRootMessageId(), message.getUserId(), actionId)) {

        return true;
    }

    if (!permissionChecker.hasPermission(message.getGroupId(), MBMessage.class.getName(),
            message.getMessageId(), actionId)) {

        return false;
    }

    if (message.isRoot() || !actionId.equals(ActionKeys.VIEW)) {
        return true;
    }

    return _contains(permissionChecker, _mbMessageLocalService.getMessage(message.getParentMessageId()),
            actionId);
}

From source file:com.liferay.message.boards.service.permission.MBDiscussionPermission.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker, MBMessage message, String actionId)
        throws PortalException {

    String className = message.getClassName();

    if (className.equals(WorkflowInstance.class.getName())) {
        return permissionChecker.hasPermission(message.getGroupId(), PortletKeys.WORKFLOW_DEFINITION,
                message.getGroupId(), ActionKeys.VIEW);
    }/*from  w w  w. j a va2 s.  c om*/

    if (PropsValues.DISCUSSION_COMMENTS_ALWAYS_EDITABLE_BY_OWNER
            && (permissionChecker.getUserId() == message.getUserId())) {

        return true;
    }

    if (message.isPending()) {
        Boolean hasPermission = WorkflowPermissionUtil.hasPermission(permissionChecker, message.getGroupId(),
                message.getWorkflowClassName(), message.getMessageId(), actionId);

        if (hasPermission != null) {
            return hasPermission.booleanValue();
        }
    }

    return contains(permissionChecker, message.getCompanyId(), message.getGroupId(), className,
            message.getClassPK(), actionId);
}

From source file:com.liferay.portlet.blogs.service.permission.BlogsEntryPermission.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker, BlogsEntry entry, String actionId) {

    Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker, entry.getGroupId(),
            BlogsEntry.class.getName(), entry.getEntryId(), PortletKeys.BLOGS, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }/* w  w w. j  ava 2 s.c  o  m*/

    if (entry.isPending()) {
        hasPermission = WorkflowPermissionUtil.hasPermission(permissionChecker, entry.getGroupId(),
                BlogsEntry.class.getName(), entry.getEntryId(), actionId);

        if (hasPermission != null) {
            return hasPermission.booleanValue();
        }
    }

    if (permissionChecker.hasOwnerPermission(entry.getCompanyId(), BlogsEntry.class.getName(),
            entry.getEntryId(), entry.getUserId(), actionId)) {

        return true;
    }

    return permissionChecker.hasPermission(entry.getGroupId(), BlogsEntry.class.getName(), entry.getEntryId(),
            actionId);
}

From source file:com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker, DLFileEntry dlFileEntry, String actionId)
        throws PortalException, SystemException {

    Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker, dlFileEntry.getGroupId(),
            DLFileEntry.class.getName(), dlFileEntry.getFileEntryId(), PortletKeys.DOCUMENT_LIBRARY, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }//w w w.j a  v a2 s .  c om

    DLFileVersion latestDLFileVersion = dlFileEntry.getLatestFileVersion(false);

    if (latestDLFileVersion.isPending()) {
        hasPermission = WorkflowPermissionUtil.hasPermission(permissionChecker, dlFileEntry.getGroupId(),
                DLFileEntry.class.getName(), dlFileEntry.getFileEntryId(), actionId);

        if (hasPermission != null) {
            return hasPermission.booleanValue();
        }
    }

    if (PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE) {
        if (dlFileEntry.getFolderId() != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

            DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(dlFileEntry.getFolderId());

            if (!DLFolderPermission.contains(permissionChecker, dlFolder, ActionKeys.ACCESS)
                    && !DLFolderPermission.contains(permissionChecker, dlFolder, ActionKeys.VIEW)) {

                return false;
            }
        }
    }

    if (permissionChecker.hasOwnerPermission(dlFileEntry.getCompanyId(), DLFileEntry.class.getName(),
            dlFileEntry.getFileEntryId(), dlFileEntry.getUserId(), actionId)) {

        return true;
    }

    return permissionChecker.hasPermission(dlFileEntry.getGroupId(), DLFileEntry.class.getName(),
            dlFileEntry.getFileEntryId(), actionId);
}

From source file:com.liferay.portlet.journal.service.permission.JournalArticlePermission.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker, JournalArticle article, String actionId) {

    Boolean hasPermission = StagingPermissionUtil.hasPermission(permissionChecker, article.getGroupId(),
            JournalArticle.class.getName(), article.getResourcePrimKey(), PortletKeys.JOURNAL, actionId);

    if (hasPermission != null) {
        return hasPermission.booleanValue();
    }/* www  .  jav  a  2s  .  c om*/

    if (article.isPending()) {
        hasPermission = WorkflowPermissionUtil.hasPermission(permissionChecker, article.getGroupId(),
                JournalArticle.class.getName(), article.getResourcePrimKey(), actionId);

        if (hasPermission != null) {
            return hasPermission.booleanValue();
        }
    }

    if (permissionChecker.hasOwnerPermission(article.getCompanyId(), JournalArticle.class.getName(),
            article.getResourcePrimKey(), article.getUserId(), actionId)) {

        return true;
    }

    return permissionChecker.hasPermission(article.getGroupId(), JournalArticle.class.getName(),
            article.getResourcePrimKey(), actionId);
}

From source file:com.liferay.portlet.messageboards.service.permission.MBDiscussionPermission.java

License:Open Source License

public static boolean contains(PermissionChecker permissionChecker, long companyId, long groupId,
        String className, long classPK, long messageId, long ownerId, String actionId)
        throws PortalException, SystemException {

    MBMessage message = MBMessageLocalServiceUtil.getMessage(messageId);

    if (PropsValues.DISCUSSION_COMMENTS_ALWAYS_EDITABLE_BY_OWNER
            && (permissionChecker.getUserId() == message.getUserId())) {

        return true;
    }//from w w  w  . j a  v a2s .c o m

    if (message.isPending()) {
        Boolean hasPermission = WorkflowPermissionUtil.hasPermission(permissionChecker, message.getGroupId(),
                message.getWorkflowClassName(), message.getMessageId(), actionId);

        if (hasPermission != null) {
            return hasPermission.booleanValue();
        }
    }

    return contains(permissionChecker, companyId, groupId, className, classPK, ownerId, actionId);
}