001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }