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.portlet.social.service.permission;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.portlet.PortletProvider;
019    import com.liferay.portal.kernel.portlet.PortletProviderUtil;
020    import com.liferay.portal.kernel.security.auth.PrincipalException;
021    import com.liferay.portal.kernel.security.permission.PermissionChecker;
022    import com.liferay.social.kernel.model.SocialActivitySetting;
023    import com.liferay.social.kernel.service.permission.SocialActivityPermission;
024    
025    /**
026     * @author Zsolt Berentey
027     */
028    public class SocialActivityPermissionImpl implements SocialActivityPermission {
029    
030            @Override
031            public void check(
032                            PermissionChecker permissionChecker, long groupId, String actionId)
033                    throws PortalException {
034    
035                    if (!contains(permissionChecker, groupId, actionId)) {
036                            throw new PrincipalException.MustHavePermission(
037                                    permissionChecker, getPortletId(), groupId, actionId);
038                    }
039            }
040    
041            @Override
042            public boolean contains(
043                    PermissionChecker permissionChecker, long groupId, String actionId) {
044    
045                    if (permissionChecker.isGroupAdmin(groupId) ||
046                            permissionChecker.isGroupOwner(groupId)) {
047    
048                            return true;
049                    }
050    
051                    if (permissionChecker.hasPermission(
052                                    groupId, getPortletId(), 0, actionId)) {
053    
054                            return true;
055                    }
056    
057                    return false;
058            }
059    
060            protected String getPortletId() {
061                    return PortletProviderUtil.getPortletId(
062                            SocialActivitySetting.class.getName(), PortletProvider.Action.EDIT);
063            }
064    
065    }