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.sitesadmin;
016    
017    import com.liferay.portal.model.Group;
018    import com.liferay.portal.model.Portlet;
019    import com.liferay.portal.security.permission.PermissionChecker;
020    import com.liferay.portal.service.GroupLocalServiceUtil;
021    import com.liferay.portal.util.PropsValues;
022    import com.liferay.portlet.BaseControlPanelEntry;
023    
024    import java.util.LinkedHashMap;
025    
026    /**
027     * @author Jorge Ferrer
028     * @author Sergio Gonz??lez
029     * @author Miguel Pastor
030     */
031    public class SitesControlPanelEntry extends BaseControlPanelEntry {
032    
033            @Override
034            protected boolean hasPermissionImplicitlyGranted(
035                            PermissionChecker permissionChecker, Group group, Portlet portlet)
036                    throws Exception {
037    
038                    if (PropsValues.SITES_CONTROL_PANEL_MEMBERS_VISIBLE) {
039                            LinkedHashMap<String, Object> groupParams =
040                                    new LinkedHashMap<String, Object>();
041    
042                            groupParams.put("site", Boolean.TRUE);
043                            groupParams.put("usersGroups", permissionChecker.getUserId());
044    
045                            int count = GroupLocalServiceUtil.searchCount(
046                                    permissionChecker.getCompanyId(), null, null, groupParams);
047    
048                            if (count > 0) {
049                                    return true;
050                            }
051                    }
052    
053                    return false;
054            }
055    
056    }