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.messageboards.service.impl;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.model.User;
20  import com.liferay.portal.security.auth.PrincipalException;
21  import com.liferay.portal.security.permission.ActionKeys;
22  import com.liferay.portal.security.permission.PermissionChecker;
23  import com.liferay.portal.service.ServiceContext;
24  import com.liferay.portal.util.PortalUtil;
25  import com.liferay.portlet.messageboards.model.MBBan;
26  import com.liferay.portlet.messageboards.service.base.MBBanServiceBaseImpl;
27  import com.liferay.portlet.messageboards.service.permission.MBPermission;
28  
29  /**
30   * <a href="MBBanServiceImpl.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   */
34  public class MBBanServiceImpl extends MBBanServiceBaseImpl {
35  
36      public MBBan addBan(long banUserId, ServiceContext serviceContext)
37          throws PortalException, SystemException {
38  
39          PermissionChecker permissionChecker = getPermissionChecker();
40  
41          MBPermission.check(
42              permissionChecker, serviceContext.getScopeGroupId(),
43              ActionKeys.BAN_USER);
44  
45          User banUser = userLocalService.getUser(banUserId);
46  
47          boolean communityAdmin = false;
48  
49          try {
50              communityAdmin = PortalUtil.isCommunityAdmin(
51                  banUser, serviceContext.getScopeGroupId());
52          }
53          catch (Exception e) {
54              throw new SystemException(e);
55          }
56  
57          if (communityAdmin) {
58              throw new PrincipalException();
59          }
60  
61          return mbBanLocalService.addBan(getUserId(), banUserId, serviceContext);
62      }
63  
64      public void deleteBan(long banUserId, ServiceContext serviceContext)
65          throws PortalException, SystemException {
66  
67          MBPermission.check(
68              getPermissionChecker(), serviceContext.getScopeGroupId(),
69              ActionKeys.BAN_USER);
70  
71          mbBanLocalService.deleteBan(banUserId, serviceContext);
72      }
73  
74  }