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