001
014
015 package com.liferay.portlet.blogs.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.workflow.permission.WorkflowPermissionUtil;
020 import com.liferay.portal.security.auth.PrincipalException;
021 import com.liferay.portal.security.permission.PermissionChecker;
022 import com.liferay.portlet.blogs.model.BlogsEntry;
023 import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
024
025
028 public class BlogsEntryPermission {
029
030 public static void check(
031 PermissionChecker permissionChecker, BlogsEntry entry,
032 String actionId)
033 throws PortalException {
034
035 if (!contains(permissionChecker, entry, actionId)) {
036 throw new PrincipalException();
037 }
038 }
039
040 public static void check(
041 PermissionChecker permissionChecker, long entryId, String actionId)
042 throws PortalException, SystemException {
043
044 if (!contains(permissionChecker, entryId, actionId)) {
045 throw new PrincipalException();
046 }
047 }
048
049 public static boolean contains(
050 PermissionChecker permissionChecker, BlogsEntry entry,
051 String actionId) {
052
053 if (entry.isPending()) {
054 Boolean hasPermission = WorkflowPermissionUtil.hasPermission(
055 permissionChecker, entry.getGroupId(),
056 BlogsEntry.class.getName(), entry.getEntryId(), actionId);
057
058 if (hasPermission != null) {
059 return hasPermission.booleanValue();
060 }
061 }
062
063 if (permissionChecker.hasOwnerPermission(
064 entry.getCompanyId(), BlogsEntry.class.getName(),
065 entry.getEntryId(), entry.getUserId(), actionId)) {
066
067 return true;
068 }
069
070 return permissionChecker.hasPermission(
071 entry.getGroupId(), BlogsEntry.class.getName(), entry.getEntryId(),
072 actionId);
073 }
074
075 public static boolean contains(
076 PermissionChecker permissionChecker, long entryId, String actionId)
077 throws PortalException, SystemException {
078
079 BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(entryId);
080
081 return contains(permissionChecker, entry, actionId);
082 }
083
084 }