001
014
015 package com.liferay.portlet.journal.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.journal.model.JournalTemplate;
024
025
029 public class JournalTemplatePermission {
030
031 public static void check(
032 PermissionChecker permissionChecker, JournalTemplate template,
033 String actionId)
034 throws PortalException {
035
036 if (!contains(permissionChecker, template, actionId)) {
037 throw new PrincipalException();
038 }
039 }
040
041 public static void check(
042 PermissionChecker permissionChecker, long groupId,
043 String templateId, String actionId)
044 throws PortalException, SystemException {
045
046 if (!contains(permissionChecker, groupId, templateId, actionId)) {
047 throw new PrincipalException();
048 }
049 }
050
051 public static boolean contains(
052 PermissionChecker permissionChecker, JournalTemplate template,
053 String actionId) {
054
055 Boolean hasPermission = StagingPermissionUtil.hasPermission(
056 permissionChecker, template.getGroupId(),
057 JournalTemplate.class.getName(), template.getId(),
058 PortletKeys.JOURNAL, actionId);
059
060 if (hasPermission != null) {
061 return hasPermission.booleanValue();
062 }
063
064 if (permissionChecker.hasOwnerPermission(
065 template.getCompanyId(), JournalTemplate.class.getName(),
066 template.getId(), template.getUserId(), actionId)) {
067
068 return true;
069 }
070
071 return permissionChecker.hasPermission(
072 template.getGroupId(), JournalTemplate.class.getName(),
073 template.getId(), actionId);
074 }
075
076 public static boolean contains(
077 PermissionChecker permissionChecker, long groupId,
078 String templateId, String actionId)
079 throws PortalException, SystemException {
080
081 @SuppressWarnings("deprecation")
082 JournalTemplate template =
083 com.liferay.portlet.journal.service.
084 JournalTemplateLocalServiceUtil.getTemplate(
085 groupId, templateId, true);
086
087 return contains(permissionChecker, template, actionId);
088 }
089
090 }