001    /**
002     * Copyright (c) 2000-present 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.portal.kernel.comment;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.security.auth.PrincipalException;
019    import com.liferay.portal.security.permission.ActionKeys;
020    
021    /**
022     * @author Adolfo P??rez
023     * @author Sergio Gonz??lez
024     */
025    public abstract class BaseDiscussionPermission implements DiscussionPermission {
026    
027            @Override
028            public void checkAddPermission(
029                            long companyId, long groupId, String className, long classPK)
030                    throws PortalException {
031    
032                    if (!hasAddPermission(companyId, groupId, className, classPK)) {
033                            throw new PrincipalException.MustHavePermission(
034                                    0, className, classPK, ActionKeys.ADD_DISCUSSION);
035                    }
036            }
037    
038            @Override
039            public void checkDeletePermission(long commentId) throws PortalException {
040                    if (!hasDeletePermission(commentId)) {
041                            throw new PrincipalException.MustHavePermission(
042                                    0, ActionKeys.DELETE_DISCUSSION);
043                    }
044            }
045    
046            @Override
047            public void checkSubscribePermission(
048                            long companyId, long groupId, String className, long classPK)
049                    throws PortalException {
050    
051                    if (!hasSubscribePermission(companyId, groupId, className, classPK)) {
052                            throw new PrincipalException();
053                    }
054            }
055    
056            @Override
057            public void checkUpdatePermission(long commentId) throws PortalException {
058                    if (!hasUpdatePermission(commentId)) {
059                            throw new PrincipalException.MustHavePermission(
060                                    0, ActionKeys.UPDATE_DISCUSSION);
061                    }
062            }
063    
064            @Override
065            public void checkViewPermission(
066                            long companyId, long groupId, String className, long classPK)
067                    throws PortalException {
068    
069                    if (!hasViewPermission(companyId, groupId, className, classPK)) {
070                            throw new PrincipalException.MustHavePermission(
071                                    0, className, classPK, ActionKeys.VIEW);
072                    }
073            }
074    
075            @Override
076            public boolean hasDeletePermission(long commentId) throws PortalException {
077                    return hasPermission(commentId, ActionKeys.DELETE_DISCUSSION);
078            }
079    
080            @Override
081            public boolean hasUpdatePermission(long commentId) throws PortalException {
082                    return hasPermission(commentId, ActionKeys.UPDATE_DISCUSSION);
083            }
084    
085    }