001
014
015 package com.liferay.portlet.imagegallery.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.ActionKeys;
022 import com.liferay.portal.security.permission.PermissionChecker;
023 import com.liferay.portal.util.PortletKeys;
024 import com.liferay.portal.util.PropsValues;
025 import com.liferay.portlet.imagegallery.model.IGFolder;
026 import com.liferay.portlet.imagegallery.model.IGFolderConstants;
027 import com.liferay.portlet.imagegallery.model.IGImage;
028 import com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil;
029
030
033 public class IGImagePermission {
034
035 public static void check(
036 PermissionChecker permissionChecker, IGImage image, String actionId)
037 throws PortalException, SystemException {
038
039 if (!contains(permissionChecker, image, actionId)) {
040 throw new PrincipalException();
041 }
042 }
043
044 public static void check(
045 PermissionChecker permissionChecker, long imageId, String actionId)
046 throws PortalException, SystemException {
047
048 if (!contains(permissionChecker, imageId, actionId)) {
049 throw new PrincipalException();
050 }
051 }
052
053 public static boolean contains(
054 PermissionChecker permissionChecker, IGImage image, String actionId)
055 throws PortalException, SystemException {
056
057 Boolean hasPermission = StagingPermissionUtil.hasPermission(
058 permissionChecker, image.getGroupId(), IGImage.class.getName(),
059 image.getImageId(), PortletKeys.IMAGE_GALLERY, actionId);
060
061 if (hasPermission != null) {
062 return hasPermission.booleanValue();
063 }
064
065 if (PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE) {
066 if (image.getFolderId() !=
067 IGFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
068
069 IGFolder folder = image.getFolder();
070
071 if (!IGFolderPermission.contains(
072 permissionChecker, folder, ActionKeys.ACCESS) &&
073 !IGFolderPermission.contains(
074 permissionChecker, folder, ActionKeys.VIEW)) {
075
076 return false;
077 }
078 }
079 }
080
081 if (permissionChecker.hasOwnerPermission(
082 image.getCompanyId(), IGImage.class.getName(),
083 image.getImageId(), image.getUserId(), actionId)) {
084
085 return true;
086 }
087
088 return permissionChecker.hasPermission(
089 image.getGroupId(), IGImage.class.getName(), image.getImageId(),
090 actionId);
091 }
092
093 public static boolean contains(
094 PermissionChecker permissionChecker, long imageId, String actionId)
095 throws PortalException, SystemException {
096
097 IGImage image = IGImageLocalServiceUtil.getImage(imageId);
098
099 return contains(permissionChecker, image, actionId);
100 }
101
102 }