001    /**
002     * Copyright (c) 2000-2010 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.enterpriseadmin;
016    
017    import com.liferay.portal.model.Organization;
018    import com.liferay.portal.model.Portlet;
019    import com.liferay.portal.security.permission.ActionKeys;
020    import com.liferay.portal.security.permission.PermissionChecker;
021    import com.liferay.portal.service.OrganizationLocalServiceUtil;
022    import com.liferay.portal.service.permission.OrganizationPermissionUtil;
023    import com.liferay.portlet.BaseControlPanelEntry;
024    
025    import java.util.List;
026    
027    /**
028     * @author Jorge Ferrer
029     */
030    public class UsersControlPanelEntry extends BaseControlPanelEntry {
031    
032            public boolean isVisible(
033                            PermissionChecker permissionChecker, Portlet portlet)
034                    throws Exception {
035    
036                    List<Organization> organizations =
037                            OrganizationLocalServiceUtil.getUserOrganizations(
038                                    permissionChecker.getUserId());
039    
040                    for (Organization organization : organizations) {
041                            if (OrganizationPermissionUtil.contains(
042                                            permissionChecker, organization.getOrganizationId(),
043                                            ActionKeys.MANAGE_USERS)) {
044    
045                                    return true;
046                            }
047    
048                            if (OrganizationPermissionUtil.contains(
049                                            permissionChecker, organization.getOrganizationId(),
050                                            ActionKeys.MANAGE_SUBORGANIZATIONS)) {
051    
052                                    return true;
053                            }
054    
055                            if (OrganizationPermissionUtil.contains(
056                                            permissionChecker, organization.getOrganizationId(),
057                                            ActionKeys.VIEW)) {
058    
059                                    return true;
060                            }
061                    }
062    
063                    return false;
064            }
065    
066    }