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