001
014
015 package com.liferay.portlet.documentlibrary.service.permission;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.staging.permission.StagingPermissionUtil;
020 import com.liferay.portal.security.auth.PrincipalException;
021 import com.liferay.portal.security.permission.PermissionChecker;
022 import com.liferay.portal.util.PortletKeys;
023 import com.liferay.portlet.documentlibrary.model.DLFileEntryType;
024 import com.liferay.portlet.documentlibrary.service.DLFileEntryTypeLocalServiceUtil;
025
026
029 public class DLFileEntryTypePermission {
030
031 public static void check(
032 PermissionChecker permissionChecker, DLFileEntryType fileEntryType,
033 String actionId)
034 throws PortalException {
035
036 if (!contains(permissionChecker, fileEntryType, actionId)) {
037 throw new PrincipalException();
038 }
039 }
040
041 public static void check(
042 PermissionChecker permissionChecker, long fileEntryTypeId,
043 String actionId)
044 throws PortalException, SystemException {
045
046 if (!contains(permissionChecker, fileEntryTypeId, actionId)) {
047 throw new PrincipalException();
048 }
049 }
050
051 public static boolean contains(
052 PermissionChecker permissionChecker, DLFileEntryType fileEntryType,
053 String actionId) {
054
055 Boolean hasPermission = StagingPermissionUtil.hasPermission(
056 permissionChecker, fileEntryType.getGroupId(),
057 DLFileEntryType.class.getName(), fileEntryType.getFileEntryTypeId(),
058 PortletKeys.DOCUMENT_LIBRARY, actionId);
059
060 if (hasPermission != null) {
061 return hasPermission.booleanValue();
062 }
063
064 if (permissionChecker.hasOwnerPermission(
065 fileEntryType.getCompanyId(), DLFileEntryType.class.getName(),
066 fileEntryType.getFileEntryTypeId(), fileEntryType.getUserId(),
067 actionId)) {
068
069 return true;
070 }
071
072 return permissionChecker.hasPermission(
073 fileEntryType.getGroupId(), DLFileEntryType.class.getName(),
074 fileEntryType.getFileEntryTypeId(), actionId);
075 }
076
077 public static boolean contains(
078 PermissionChecker permissionChecker, long fileEntryTypeId,
079 String actionId)
080 throws PortalException, SystemException {
081
082 DLFileEntryType fileEntryType =
083 DLFileEntryTypeLocalServiceUtil.getFileEntryType(fileEntryTypeId);
084
085 return contains(permissionChecker, fileEntryType, actionId);
086 }
087
088 }