001    /**
002     * Copyright (c) 2000-2013 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            @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    }