1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.shopping.service.permission;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.security.auth.PrincipalException;
20  import com.liferay.portal.security.permission.ActionKeys;
21  import com.liferay.portal.security.permission.PermissionChecker;
22  import com.liferay.portlet.shopping.model.ShoppingOrder;
23  import com.liferay.portlet.shopping.service.ShoppingOrderLocalServiceUtil;
24  
25  /**
26   * <a href="ShoppingOrderPermission.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class ShoppingOrderPermission {
31  
32      public static void check(
33              PermissionChecker permissionChecker, long groupId, long orderId,
34              String actionId)
35          throws PortalException, SystemException {
36  
37          if (!contains(permissionChecker, groupId, orderId, actionId)) {
38              throw new PrincipalException();
39          }
40      }
41  
42      public static void check(
43              PermissionChecker permissionChecker, long groupId,
44              ShoppingOrder order, String actionId)
45          throws PortalException {
46  
47          if (!contains(permissionChecker, groupId, order, actionId)) {
48              throw new PrincipalException();
49          }
50      }
51  
52      public static boolean contains(
53              PermissionChecker permissionChecker, long groupId, long orderId,
54              String actionId)
55          throws PortalException, SystemException {
56  
57          ShoppingOrder order =
58              ShoppingOrderLocalServiceUtil.getOrder(orderId);
59  
60          return contains(permissionChecker, groupId, order, actionId);
61      }
62  
63      public static boolean contains(
64          PermissionChecker permissionChecker, long groupId, ShoppingOrder order,
65          String actionId) {
66  
67          if (ShoppingPermission.contains(
68                  permissionChecker, groupId, ActionKeys.MANAGE_ORDERS)) {
69  
70              return true;
71          }
72          else {
73              if (permissionChecker.hasOwnerPermission(
74                      order.getCompanyId(), ShoppingOrder.class.getName(),
75                      order.getOrderId(), order.getUserId(), actionId)) {
76  
77                  return true;
78              }
79  
80              return permissionChecker.hasPermission(
81                  order.getGroupId(), ShoppingOrder.class.getName(),
82                  order.getOrderId(), actionId);
83          }
84      }
85  
86  }