--- /dev/null
+/*******************************************************************************
+
+ * Copyright � Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
+ *
+ * This file is part of the work and learning management system Pentila Nero.
+ *
+ * Pentila Nero is free software. You can redistribute it and/or modify since
+ * you respect the terms of either (at least one of the both license) :
+ * - under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ * - the CeCILL-C as published by CeCILL-C; either version 1 of the
+ * License, or any later version
+ * - the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the license,
+ * or (at your option) any later version.
+ *
+ * There are special exceptions to the terms and conditions of the
+ * licenses as they are applied to this software. View the full text of
+ * the exception in file LICENSE-PROJECT.txt in the directory of this software
+ * distribution.
+ *
+ * Pentila Nero is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Licenses for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * and the CeCILL-C and the GNU Lesser General Public License along with
+ * Pentila Nero. If not, see :
+ * <http://www.gnu.org/licenses/> and
+ * <http://www.cecill.info/licences.fr.html>.
+ ******************************************************************************/
+package com.pentila.entSavoie;
+
+import com.liferay.portal.kernel.exception.PortalException;
+import com.liferay.portal.kernel.exception.SystemException;
+import com.liferay.portal.model.Role;
+import com.liferay.portal.model.RoleConstants;
+import com.liferay.portal.model.User;
+import com.liferay.portal.service.RoleLocalServiceUtil;
+import com.pentila.entSavoie.utils.ENTMainUtilsLocalServiceUtil;
+
+public class ENTRolesConstants {
+
+ // Role administrateur local
+ public static final String GROUP_ADMIN = "Group_admin";
+
+ // Role administrateur du forum
+ public static final String FORUM_ADMIN = "Forum_admin";
+ // Role membre du forum
+ public static final String FORUM_MEMBER = "Forum_member";
+
+ // Role des plans sports
+ public static final String ADMIN_PLAN_SPORT = "Admin_plan_sport";
+ public static final String MEMBER_PLAN_SPORT = "Member_plan_sport";
+
+ // Role des cuisiniers
+ public static final String ADMIN_CANTINE = "Admin_cantine";
+ public static final String MEMBER_CANTINE = "Member_cantine";
+
+ // Role pour la gestion des wordpress
+ public static final String ADMIN_WORDPRESS = "Admin_wordpress";
+
+ public static final String COMMUNITY_VISITOR = "Community Visitor";
+
+ public static final String ORGANIZATION_USER = "Organization User";
+
+ // Roles pour les profs principaux
+ public static final String PROF_PRINCIPAL = "Prof_principal";
+ public static final String ORGANIZATION_PROF_PRINCIPAL = "Organization Prof_principal";
+
+ // School manager role
+ public static final String SCHOOL_MANAGER = "Chef Etablissement";
+
+ // Role pour les personnes exterieurs a la plateforme
+ public static final String EXTERNAL = "External";
+
+ // Role nationnaux SCONET
+ /**
+ * Roles "eleve"
+ */
+ public static final String NATIONAL_1 = "National_1";
+
+ /**
+ * Roles "parent"
+ */
+ public static final String NATIONAL_2 = "National_2";
+
+ /**
+ * Roles "professeur"
+ */
+ public static final String NATIONAL_3 = "National_3";
+
+ /**
+ * Roles "personnel de direction"
+ */
+ public static final String NATIONAL_4 = "National_4";
+
+ /**
+ * Roles "Personnel de vie scolaire travaillant dans lՎtablissement"
+ */
+ public static final String NATIONAL_5 = "National_5";
+
+ /**
+ * Roles "Personnel administratif, technique ou d�encadrement"
+ */
+ public static final String NATIONAL_6 = "National_6";
+
+ /**
+ * Roles "Personnel de rectorat, de DRAF, de collectivit� territoriale, d�inspection acad�mique"
+ */
+ public static final String NATIONAL_7 = "National_7";
+
+ /**
+ * Roles "personnel administratif"
+ */
+ public static final String NATIONAL_20 = "National_20";
+
+ /**
+ * Roles "assistant d'éducation"
+ */
+ public static final String NATIONAL_21 = "National_21";
+
+ /**
+ * Role "Assistant étranger"
+ */
+ public static final String NATIONAL_22 = "National_22";
+
+ /**
+ * Role "Direction"
+ */
+ public static final String NATIONAL_23 = "National_23";
+
+ /**
+ * Role "Documentation"
+ */
+ public static final String NATIONAL_24 = "National_24";
+
+ /**
+ * Role "Education"
+ */
+ public static final String NATIONAL_25 = "National_25";
+
+ /**
+ * Role "Enseignement"
+ */
+ public static final String NATIONAL_26 = "National_26";
+
+ /**
+ * Role "Personnels de laboratoire"
+ */
+ public static final String NATIONAL_27 = "National_27";
+
+ /**
+ * Role "Personnel médicaux sociaux"
+ */
+ public static final String NATIONAL_28 = "National_28";
+
+ /**
+ * Role "Orientation"
+ */
+ public static final String NATIONAL_29 = "National_29";
+
+ /*Noms de role explicites*/
+ public static final String ELEVE = NATIONAL_1;
+ public static final String PARENT = NATIONAL_2;
+ public static final String ENSEIGNANT = NATIONAL_3;
+
+ public static final String CODES_NATIONAUX[] = {
+ NATIONAL_1, NATIONAL_2, NATIONAL_3, NATIONAL_4, NATIONAL_5, NATIONAL_6,
+ NATIONAL_7
+ };
+
+ /**
+ * In case of administration we manage National_5 the same as all other NAtional (6 to 29)
+ * It's consider as "Education Employees"
+ */
+ public static final String CODES_NATIONAUX_ADMINISTRATION[] = {
+ NATIONAL_1, NATIONAL_2, NATIONAL_3, NATIONAL_4, NATIONAL_7
+ };
+
+ public static final String CODES_ADITIONNELS[] = {
+ NATIONAL_20, NATIONAL_21, NATIONAL_22, NATIONAL_23, NATIONAL_24,
+ NATIONAL_25, NATIONAL_26, NATIONAL_27, NATIONAL_28, NATIONAL_29
+ };
+
+ public static final String CODES_FILTERED[] = {
+ NATIONAL_1, NATIONAL_2, NATIONAL_3, PROF_PRINCIPAL, NATIONAL_4, NATIONAL_5, NATIONAL_6,
+ NATIONAL_7, NATIONAL_20, NATIONAL_21, NATIONAL_22, NATIONAL_24,
+ NATIONAL_25, NATIONAL_27, NATIONAL_28, NATIONAL_29
+ };
+
+ public static final String CODES_FILTERED_SUPANN[] = {
+ NATIONAL_3, NATIONAL_4
+ };
+
+ public static final String CODES_FILTERED_ENABLED[] = ENTMainUtilsLocalServiceUtil.getEntListRolesEnabled();
+ public static final String CODES_NATIONAUX_FILTERED_ENABLED[] = ENTMainUtilsLocalServiceUtil.getEntListRolesNationauxEnabled();
+
+ public static String[] getCodesFiltered(long companyId){
+ if (ENTMainUtilsLocalServiceUtil.isSchemaSupann(companyId)){
+ return CODES_FILTERED_SUPANN;
+ } else if(CODES_FILTERED_ENABLED != null){
+ return CODES_FILTERED_ENABLED;
+ } else {
+ return CODES_FILTERED;
+ }
+ }
+
+ public static String[] getCodesNationaux(long companyId){
+ if(CODES_NATIONAUX_FILTERED_ENABLED != null){
+ return CODES_NATIONAUX_FILTERED_ENABLED;
+ } else {
+ return CODES_NATIONAUX;
+ }
+ }
+
+ public static boolean isNationalCode(String pCode){
+ for(int i = 0; i < CODES_NATIONAUX.length; i++){
+ if(CODES_NATIONAUX[i].equals(pCode)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Role lists concerns per panel
+ */
+
+ /**
+ * Role list for student panel
+ */
+ public static final String[] LIST_ROLES_STUDENT = {ENTRolesConstants.NATIONAL_1};
+
+ /**
+ * Role list for parent panel
+ */
+ public static final String[] LIST_ROLES_PARENT = {ENTRolesConstants.NATIONAL_2};
+
+ /**
+ * Role list for teacher panel
+ */
+ public static final String[] LIST_ROLES_TEACHER = {ENTRolesConstants.NATIONAL_3,
+ ENTRolesConstants.NATIONAL_26};
+
+ /**
+ * Role list for school employez panel
+ */
+ public static final String[] LIST_ROLES_PERSONNAL = {ENTRolesConstants.NATIONAL_4,
+ ENTRolesConstants.NATIONAL_5,
+ ENTRolesConstants.NATIONAL_6,
+ ENTRolesConstants.NATIONAL_20,
+ ENTRolesConstants.NATIONAL_21,
+ ENTRolesConstants.NATIONAL_22,
+ ENTRolesConstants.NATIONAL_23,
+ ENTRolesConstants.NATIONAL_24,
+ ENTRolesConstants.NATIONAL_25,
+ ENTRolesConstants.NATIONAL_27,
+ ENTRolesConstants.NATIONAL_28,
+ ENTRolesConstants.NATIONAL_29};
+
+
+ /**
+ * Role list for school directo panel
+ */
+ public static final String[] LIST_ROLES_DIRECTOR = {ENTRolesConstants.NATIONAL_4,
+ ENTRolesConstants.NATIONAL_23};
+
+ /**
+ * Role list for academic employees panel
+ */
+ public static final String[] LIST_ROLES_ACADEMIC = {ENTRolesConstants.NATIONAL_7};
+
+ /**
+ * List of role list which can acces to all class of etab
+ */
+ public static final String[][] ROLES_ACCESS_TO_ALL_CLASS = {ENTRolesConstants.LIST_ROLES_PERSONNAL};
+
+ /**
+ * Role list for HM new delegation, dont select N20,N23,N25,,N26 cause of role are very similar from other in list (with same people affected)
+ */
+ public static final String[] LIST_ROLES_NEWS_DELEGATION = {ENTRolesConstants.NATIONAL_3,
+ ENTRolesConstants.NATIONAL_4,
+ ENTRolesConstants.NATIONAL_5,
+ ENTRolesConstants.NATIONAL_6,
+ ENTRolesConstants.NATIONAL_7,
+ ENTRolesConstants.NATIONAL_21,
+ ENTRolesConstants.NATIONAL_22,
+ ENTRolesConstants.NATIONAL_24,
+ ENTRolesConstants.NATIONAL_27,
+ ENTRolesConstants.NATIONAL_28,
+ ENTRolesConstants.NATIONAL_29};
+
+ /**
+ * This method return true if the user is a student, a parent or an external
+ * @param aUser User object which represent a user
+ * @return true if the user have the role student, parent or external
+ * @throws PortalException
+ * @throws SystemException
+ */
+ public static boolean isParentEleveOrExt(User aUser) throws PortalException, SystemException{
+ Role external = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), ENTRolesConstants.EXTERNAL);
+
+ return ENTRolesConstants.isParentOrEleve(aUser)
+ || RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), external.getRoleId());
+ }
+
+ /**
+ * This method return true if the user is a student
+ * @param aUser User object which represent a user
+ * @return true if the user have the role student
+ */
+ public static boolean isStudent(User aUser) throws PortalException, SystemException{
+ Role studentRole = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), ENTRolesConstants.NATIONAL_1);
+ return RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), studentRole.getRoleId());
+ }
+
+ /**
+ * This method return true if the user is a parent
+ * @param aUser User object which represent a user
+ * @return true if the user have the role parent
+ */
+ public static boolean isParent(User aUser) throws PortalException, SystemException{
+ Role parentRole = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), ENTRolesConstants.NATIONAL_2);
+ return RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), parentRole.getRoleId());
+ }
+
+ /**
+ * This method return true if the user is a student or a parent
+ * @param aUser User object which represent a user
+ * @return true if the user have the role student, parent
+ * @throws PortalException
+ * @throws SystemException
+ */
+ public static boolean isParentOrEleve(User aUser) throws PortalException, SystemException{
+ Role eleve = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), ENTRolesConstants.NATIONAL_1);
+ Role parent = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), ENTRolesConstants.NATIONAL_2);
+
+ return RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), eleve.getRoleId())
+ || RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), parent.getRoleId());
+ }
+
+ /**
+ * This method return true if the user is a teacher
+ * @param aUser User object which represent a user
+ * @return true if the user have the role teacher
+ * @throws PortalException
+ * @throws SystemException
+ */
+ public static boolean isTeacher(User aUser) throws PortalException, SystemException{
+ Role teacherRole = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), ENTRolesConstants.NATIONAL_3);
+ Role teachingRole = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), ENTRolesConstants.NATIONAL_26);
+
+ return RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), teacherRole.getRoleId())
+ || RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), teachingRole.getRoleId());
+ }
+
+ /**
+ * This method return true if the user is a personal
+ * @param aUser User object which represent a user
+ * @return true if the user have the role student, parent
+ * @throws PortalException
+ * @throws SystemException
+ */
+ public static boolean isPersonal(User aUser) throws PortalException, SystemException{
+ boolean isPersonnal = false;
+
+ for(String rolePersonal:LIST_ROLES_PERSONNAL){
+ Role role = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), rolePersonal);
+ isPersonnal |= RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), role.getRoleId());
+ }
+ return isPersonnal;
+ }
+
+ /**
+ * Test if user has permission to see org root
+ * @param pUser User to verify the permission
+ * @return true if the user can see org root
+ * @throws SystemException database error
+ * @throws PortalException database error
+ */
+ public static boolean hasVisibilityOnOrgRoot(User pUser) throws PortalException, SystemException{
+ return RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), RoleConstants.ADMINISTRATOR, false);
+ }
+
+
+ /**
+ * For the groups service we don't want to give visibility for National 5 and 6
+ * @param pUser User to verify the permission
+ * @return true if the user can see all group in their school
+ * @throws SystemException database error
+ * @throws PortalException database error
+ */
+ public static boolean hasGlobalVisibilityOnGroupClassOnItsSchool(User pUser) throws PortalException, SystemException{
+ return RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_21, false)
+ || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_23, false)
+ || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_24, false)
+ || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_25, false)
+ || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_4, false)
+ || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.GROUP_ADMIN, false);
+ }
+
+ /**
+ * All services except groups
+ * @param pUser User to verify the permission
+ * @return true if the user can see all group in their school
+ * @throws SystemException database error
+ * @throws PortalException database error
+ */
+ public static boolean hasGlobalVisibilityOnGroupOnItsSchool(User pUser) throws PortalException, SystemException{
+ return RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_21, false)
+ || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_23, false)
+ || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_24, false)
+ || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_25, false)
+ || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_4, false)
+ || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_5, false)
+ || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_6, false)
+ || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.GROUP_ADMIN, false);
+ }
+
+ /**
+ * VErify if the name verified role is contains in string array
+ * @param roleToVerify
+ * @param rolesArray
+ * @return true if role name is contains in String array
+ */
+ public static final boolean isRoleContainsInRoleNameArray(Role roleToVerify, String[] rolesArray ){
+ for(String aRoleName : rolesArray){
+ if(roleToVerify.getName().equals(aRoleName)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+}