001
014
015 package com.liferay.portlet.calendar.service.permission;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.security.auth.PrincipalException;
019 import com.liferay.portal.security.permission.PermissionChecker;
020 import com.liferay.portlet.calendar.model.CalEvent;
021 import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
022
023
026 public class CalEventPermission {
027
028 public static void check(
029 PermissionChecker permissionChecker, CalEvent event,
030 String actionId)
031 throws PortalException {
032
033 if (!contains(permissionChecker, event, actionId)) {
034 throw new PrincipalException();
035 }
036 }
037
038 public static void check(
039 PermissionChecker permissionChecker, long eventId, String actionId)
040 throws PortalException {
041
042 if (!contains(permissionChecker, eventId, actionId)) {
043 throw new PrincipalException();
044 }
045 }
046
047 public static boolean contains(
048 PermissionChecker permissionChecker, CalEvent event, String actionId) {
049
050 if (permissionChecker.hasOwnerPermission(
051 event.getCompanyId(), CalEvent.class.getName(),
052 event.getEventId(), event.getUserId(), actionId)) {
053
054 return true;
055 }
056
057 return permissionChecker.hasPermission(
058 event.getGroupId(), CalEvent.class.getName(), event.getEventId(),
059 actionId);
060 }
061
062 public static boolean contains(
063 PermissionChecker permissionChecker, long eventId, String actionId)
064 throws PortalException {
065
066 CalEvent event = CalEventLocalServiceUtil.getEvent(eventId);
067
068 return contains(permissionChecker, event, actionId);
069 }
070
071 }