1 /*******************************************************************************
3 * Copyright � Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
4 * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
5 * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
7 * This file is part of the work and learning management system Pentila Nero.
9 * Pentila Nero is free software. You can redistribute it and/or modify since
10 * you respect the terms of either (at least one of the both license) :
11 * - under the terms of the GNU Affero General Public License as
12 * published by the Free Software Foundation, either version 3 of the
13 * License, or (at your option) any later version.
14 * - the CeCILL-C as published by CeCILL-C; either version 1 of the
15 * License, or any later version
16 * - the GNU Lesser General Public License as published by the
17 * Free Software Foundation, either version 3 of the license,
18 * or (at your option) any later version.
20 * There are special exceptions to the terms and conditions of the
21 * licenses as they are applied to this software. View the full text of
22 * the exception in file LICENSE-PROJECT.txt in the directory of this software
25 * Pentila Nero is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * Licenses for more details.
30 * You should have received a copy of the GNU Affero General Public License
31 * and the CeCILL-C and the GNU Lesser General Public License along with
32 * Pentila Nero. If not, see :
33 * <http://www.gnu.org/licenses/> and
34 * <http://www.cecill.info/licences.fr.html>.
35 ******************************************************************************/
36 package com.pentila.entSavoie;
38 import com.liferay.portal.kernel.exception.PortalException;
39 import com.liferay.portal.kernel.exception.SystemException;
40 import com.liferay.portal.model.Role;
41 import com.liferay.portal.model.RoleConstants;
42 import com.liferay.portal.model.User;
43 import com.liferay.portal.service.RoleLocalServiceUtil;
44 import com.pentila.entSavoie.utils.ENTMainUtilsLocalServiceUtil;
46 public class ENTRolesConstants {
48 // Role administrateur local
49 public static final String GROUP_ADMIN = "Group_admin";
51 // Role administrateur du forum
52 public static final String FORUM_ADMIN = "Forum_admin";
53 // Role membre du forum
54 public static final String FORUM_MEMBER = "Forum_member";
56 // Role des plans sports
57 public static final String ADMIN_PLAN_SPORT = "Admin_plan_sport";
58 public static final String MEMBER_PLAN_SPORT = "Member_plan_sport";
60 // Role des cuisiniers
61 public static final String ADMIN_CANTINE = "Admin_cantine";
62 public static final String MEMBER_CANTINE = "Member_cantine";
64 // Role pour la gestion des wordpress
65 public static final String ADMIN_WORDPRESS = "Admin_wordpress";
67 public static final String COMMUNITY_VISITOR = "Community Visitor";
69 public static final String ORGANIZATION_USER = "Organization User";
71 // Roles pour les profs principaux
72 public static final String PROF_PRINCIPAL = "Prof_principal";
73 public static final String ORGANIZATION_PROF_PRINCIPAL = "Organization Prof_principal";
75 // School manager role
76 public static final String SCHOOL_MANAGER = "Chef Etablissement";
78 // Role pour les personnes exterieurs a la plateforme
79 public static final String EXTERNAL = "External";
81 // Role nationnaux SCONET
85 public static final String NATIONAL_1 = "National_1";
90 public static final String NATIONAL_2 = "National_2";
95 public static final String NATIONAL_3 = "National_3";
98 * Roles "personnel de direction"
100 public static final String NATIONAL_4 = "National_4";
103 * Roles "Personnel de vie scolaire travaillant dans lՎtablissement"
105 public static final String NATIONAL_5 = "National_5";
108 * Roles "Personnel administratif, technique ou d�encadrement"
110 public static final String NATIONAL_6 = "National_6";
113 * Roles "Personnel de rectorat, de DRAF, de collectivit� territoriale, d�inspection acad�mique"
115 public static final String NATIONAL_7 = "National_7";
118 * Roles "personnel administratif"
120 public static final String NATIONAL_20 = "National_20";
123 * Roles "assistant d'éducation"
125 public static final String NATIONAL_21 = "National_21";
128 * Role "Assistant étranger"
130 public static final String NATIONAL_22 = "National_22";
135 public static final String NATIONAL_23 = "National_23";
138 * Role "Documentation"
140 public static final String NATIONAL_24 = "National_24";
145 public static final String NATIONAL_25 = "National_25";
148 * Role "Enseignement"
150 public static final String NATIONAL_26 = "National_26";
153 * Role "Personnels de laboratoire"
155 public static final String NATIONAL_27 = "National_27";
158 * Role "Personnel médicaux sociaux"
160 public static final String NATIONAL_28 = "National_28";
165 public static final String NATIONAL_29 = "National_29";
167 /*Noms de role explicites*/
168 public static final String ELEVE = NATIONAL_1;
169 public static final String PARENT = NATIONAL_2;
170 public static final String ENSEIGNANT = NATIONAL_3;
172 public static final String CODES_NATIONAUX[] = {
173 NATIONAL_1, NATIONAL_2, NATIONAL_3, NATIONAL_4, NATIONAL_5, NATIONAL_6,
178 * In case of administration we manage National_5 the same as all other NAtional (6 to 29)
179 * It's consider as "Education Employees"
181 public static final String CODES_NATIONAUX_ADMINISTRATION[] = {
182 NATIONAL_1, NATIONAL_2, NATIONAL_3, NATIONAL_4, NATIONAL_7
185 public static final String CODES_ADITIONNELS[] = {
186 NATIONAL_20, NATIONAL_21, NATIONAL_22, NATIONAL_23, NATIONAL_24,
187 NATIONAL_25, NATIONAL_26, NATIONAL_27, NATIONAL_28, NATIONAL_29
190 public static final String CODES_FILTERED[] = {
191 NATIONAL_1, NATIONAL_2, NATIONAL_3, PROF_PRINCIPAL, NATIONAL_4, NATIONAL_5, NATIONAL_6,
192 NATIONAL_7, NATIONAL_20, NATIONAL_21, NATIONAL_22, NATIONAL_24,
193 NATIONAL_25, NATIONAL_27, NATIONAL_28, NATIONAL_29
196 public static final String CODES_FILTERED_SUPANN[] = {
197 NATIONAL_3, NATIONAL_4
200 public static final String CODES_FILTERED_ENABLED[] = ENTMainUtilsLocalServiceUtil.getEntListRolesEnabled();
201 public static final String CODES_NATIONAUX_FILTERED_ENABLED[] = ENTMainUtilsLocalServiceUtil.getEntListRolesNationauxEnabled();
203 public static String[] getCodesFiltered(long companyId){
204 if (ENTMainUtilsLocalServiceUtil.isSchemaSupann(companyId)){
205 return CODES_FILTERED_SUPANN;
206 } else if(CODES_FILTERED_ENABLED != null){
207 return CODES_FILTERED_ENABLED;
209 return CODES_FILTERED;
213 public static String[] getCodesNationaux(long companyId){
214 if(CODES_NATIONAUX_FILTERED_ENABLED != null){
215 return CODES_NATIONAUX_FILTERED_ENABLED;
217 return CODES_NATIONAUX;
221 public static boolean isNationalCode(String pCode){
222 for(int i = 0; i < CODES_NATIONAUX.length; i++){
223 if(CODES_NATIONAUX[i].equals(pCode)){
231 * Role lists concerns per panel
235 * Role list for student panel
237 public static final String[] LIST_ROLES_STUDENT = {ENTRolesConstants.NATIONAL_1};
240 * Role list for parent panel
242 public static final String[] LIST_ROLES_PARENT = {ENTRolesConstants.NATIONAL_2};
245 * Role list for teacher panel
247 public static final String[] LIST_ROLES_TEACHER = {ENTRolesConstants.NATIONAL_3,
248 ENTRolesConstants.NATIONAL_26};
251 * Role list for school employez panel
253 public static final String[] LIST_ROLES_PERSONNAL = {ENTRolesConstants.NATIONAL_4,
254 ENTRolesConstants.NATIONAL_5,
255 ENTRolesConstants.NATIONAL_6,
256 ENTRolesConstants.NATIONAL_20,
257 ENTRolesConstants.NATIONAL_21,
258 ENTRolesConstants.NATIONAL_22,
259 ENTRolesConstants.NATIONAL_23,
260 ENTRolesConstants.NATIONAL_24,
261 ENTRolesConstants.NATIONAL_25,
262 ENTRolesConstants.NATIONAL_27,
263 ENTRolesConstants.NATIONAL_28,
264 ENTRolesConstants.NATIONAL_29};
268 * Role list for school directo panel
270 public static final String[] LIST_ROLES_DIRECTOR = {ENTRolesConstants.NATIONAL_4,
271 ENTRolesConstants.NATIONAL_23};
274 * Role list for academic employees panel
276 public static final String[] LIST_ROLES_ACADEMIC = {ENTRolesConstants.NATIONAL_7};
279 * List of role list which can acces to all class of etab
281 public static final String[][] ROLES_ACCESS_TO_ALL_CLASS = {ENTRolesConstants.LIST_ROLES_PERSONNAL};
284 * 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)
286 public static final String[] LIST_ROLES_NEWS_DELEGATION = {ENTRolesConstants.NATIONAL_3,
287 ENTRolesConstants.NATIONAL_4,
288 ENTRolesConstants.NATIONAL_5,
289 ENTRolesConstants.NATIONAL_6,
290 ENTRolesConstants.NATIONAL_7,
291 ENTRolesConstants.NATIONAL_21,
292 ENTRolesConstants.NATIONAL_22,
293 ENTRolesConstants.NATIONAL_24,
294 ENTRolesConstants.NATIONAL_27,
295 ENTRolesConstants.NATIONAL_28,
296 ENTRolesConstants.NATIONAL_29};
299 * This method return true if the user is a student, a parent or an external
300 * @param aUser User object which represent a user
301 * @return true if the user have the role student, parent or external
302 * @throws PortalException
303 * @throws SystemException
305 public static boolean isParentEleveOrExt(User aUser) throws PortalException, SystemException{
306 Role external = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), ENTRolesConstants.EXTERNAL);
308 return ENTRolesConstants.isParentOrEleve(aUser)
309 || RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), external.getRoleId());
313 * This method return true if the user is a student
314 * @param aUser User object which represent a user
315 * @return true if the user have the role student
317 public static boolean isStudent(User aUser) throws PortalException, SystemException{
318 Role studentRole = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), ENTRolesConstants.NATIONAL_1);
319 return RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), studentRole.getRoleId());
323 * This method return true if the user is a parent
324 * @param aUser User object which represent a user
325 * @return true if the user have the role parent
327 public static boolean isParent(User aUser) throws PortalException, SystemException{
328 Role parentRole = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), ENTRolesConstants.NATIONAL_2);
329 return RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), parentRole.getRoleId());
333 * This method return true if the user is a student or a parent
334 * @param aUser User object which represent a user
335 * @return true if the user have the role student, parent
336 * @throws PortalException
337 * @throws SystemException
339 public static boolean isParentOrEleve(User aUser) throws PortalException, SystemException{
340 Role eleve = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), ENTRolesConstants.NATIONAL_1);
341 Role parent = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), ENTRolesConstants.NATIONAL_2);
343 return RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), eleve.getRoleId())
344 || RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), parent.getRoleId());
348 * This method return true if the user is a teacher
349 * @param aUser User object which represent a user
350 * @return true if the user have the role teacher
351 * @throws PortalException
352 * @throws SystemException
354 public static boolean isTeacher(User aUser) throws PortalException, SystemException{
355 Role teacherRole = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), ENTRolesConstants.NATIONAL_3);
356 Role teachingRole = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), ENTRolesConstants.NATIONAL_26);
358 return RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), teacherRole.getRoleId())
359 || RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), teachingRole.getRoleId());
363 * This method return true if the user is a personal
364 * @param aUser User object which represent a user
365 * @return true if the user have the role student, parent
366 * @throws PortalException
367 * @throws SystemException
369 public static boolean isPersonal(User aUser) throws PortalException, SystemException{
370 boolean isPersonnal = false;
372 for(String rolePersonal:LIST_ROLES_PERSONNAL){
373 Role role = RoleLocalServiceUtil.getRole(aUser.getCompanyId(), rolePersonal);
374 isPersonnal |= RoleLocalServiceUtil.hasUserRole(aUser.getUserId(), role.getRoleId());
380 * Test if user has permission to see org root
381 * @param pUser User to verify the permission
382 * @return true if the user can see org root
383 * @throws SystemException database error
384 * @throws PortalException database error
386 public static boolean hasVisibilityOnOrgRoot(User pUser) throws PortalException, SystemException{
387 return RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), RoleConstants.ADMINISTRATOR, false);
392 * For the groups service we don't want to give visibility for National 5 and 6
393 * @param pUser User to verify the permission
394 * @return true if the user can see all group in their school
395 * @throws SystemException database error
396 * @throws PortalException database error
398 public static boolean hasGlobalVisibilityOnGroupClassOnItsSchool(User pUser) throws PortalException, SystemException{
399 return RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_21, false)
400 || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_23, false)
401 || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_24, false)
402 || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_25, false)
403 || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_4, false)
404 || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.GROUP_ADMIN, false);
408 * All services except groups
409 * @param pUser User to verify the permission
410 * @return true if the user can see all group in their school
411 * @throws SystemException database error
412 * @throws PortalException database error
414 public static boolean hasGlobalVisibilityOnGroupOnItsSchool(User pUser) throws PortalException, SystemException{
415 return RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_21, false)
416 || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_23, false)
417 || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_24, false)
418 || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_25, false)
419 || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_4, false)
420 || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_5, false)
421 || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.NATIONAL_6, false)
422 || RoleLocalServiceUtil.hasUserRole(pUser.getUserId(), pUser.getCompanyId(), ENTRolesConstants.GROUP_ADMIN, false);
426 * VErify if the name verified role is contains in string array
427 * @param roleToVerify
429 * @return true if role name is contains in String array
431 public static final boolean isRoleContainsInRoleNameArray(Role roleToVerify, String[] rolesArray ){
432 for(String aRoleName : rolesArray){
433 if(roleToVerify.getName().equals(aRoleName)){