001
014
015 package com.liferay.portlet.messageboards.service.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.model.User;
020 import com.liferay.portal.security.auth.PrincipalException;
021 import com.liferay.portal.security.permission.ActionKeys;
022 import com.liferay.portal.security.permission.PermissionChecker;
023 import com.liferay.portal.service.ServiceContext;
024 import com.liferay.portal.util.PortalUtil;
025 import com.liferay.portlet.messageboards.model.MBBan;
026 import com.liferay.portlet.messageboards.service.base.MBBanServiceBaseImpl;
027 import com.liferay.portlet.messageboards.service.permission.MBPermission;
028
029
032 public class MBBanServiceImpl extends MBBanServiceBaseImpl {
033
034 @Override
035 public MBBan addBan(long banUserId, ServiceContext serviceContext)
036 throws PortalException, SystemException {
037
038 PermissionChecker permissionChecker = getPermissionChecker();
039
040 MBPermission.check(
041 permissionChecker, serviceContext.getScopeGroupId(),
042 ActionKeys.BAN_USER);
043
044 User banUser = userPersistence.findByPrimaryKey(banUserId);
045
046 boolean groupAdmin = false;
047
048 try {
049 groupAdmin = PortalUtil.isGroupAdmin(
050 banUser, serviceContext.getScopeGroupId());
051 }
052 catch (Exception e) {
053 throw new SystemException(e);
054 }
055
056 if (groupAdmin) {
057 throw new PrincipalException();
058 }
059
060 return mbBanLocalService.addBan(getUserId(), banUserId, serviceContext);
061 }
062
063 @Override
064 public void deleteBan(long banUserId, ServiceContext serviceContext)
065 throws PortalException, SystemException {
066
067 MBPermission.check(
068 getPermissionChecker(), serviceContext.getScopeGroupId(),
069 ActionKeys.BAN_USER);
070
071 mbBanLocalService.deleteBan(banUserId, serviceContext);
072 }
073
074 }