001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
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    /**
030     * @author Brian Wing Shun Chan
031     */
032    public class MBBanServiceImpl extends MBBanServiceBaseImpl {
033    
034            public MBBan addBan(long banUserId, ServiceContext serviceContext)
035                    throws PortalException, SystemException {
036    
037                    PermissionChecker permissionChecker = getPermissionChecker();
038    
039                    MBPermission.check(
040                            permissionChecker, serviceContext.getScopeGroupId(),
041                            ActionKeys.BAN_USER);
042    
043                    User banUser = userLocalService.getUser(banUserId);
044    
045                    boolean communityAdmin = false;
046    
047                    try {
048                            communityAdmin = PortalUtil.isCommunityAdmin(
049                                    banUser, serviceContext.getScopeGroupId());
050                    }
051                    catch (Exception e) {
052                            throw new SystemException(e);
053                    }
054    
055                    if (communityAdmin) {
056                            throw new PrincipalException();
057                    }
058    
059                    return mbBanLocalService.addBan(getUserId(), banUserId, serviceContext);
060            }
061    
062            public void deleteBan(long banUserId, ServiceContext serviceContext)
063                    throws PortalException, SystemException {
064    
065                    MBPermission.check(
066                            getPermissionChecker(), serviceContext.getScopeGroupId(),
067                            ActionKeys.BAN_USER);
068    
069                    mbBanLocalService.deleteBan(banUserId, serviceContext);
070            }
071    
072    }