from django.db.models import Q
-from project.groups import \
- get_employe_from_user, is_user_dans_services_centraux
+from project import groups
from project.rh import models as rh
-from project.dae.workflow import grp_drh
-
class Responsable(object):
q = ""
class Dossier(object):
def get_query(self, q, request):
- employe = get_employe_from_user(request.user)
+ employe = groups.get_employe_from_user(request.user)
prefixe_implantation = 'poste__implantation'
q_recherche = Q(poste__nom__icontains=q) | \
Q(employe__nom__icontains=q) | \
Q(employe__prenom__icontains=q)
- if is_user_dans_services_centraux(request.user):
+ if groups.is_user_dans_services_centraux(request.user):
q_place = Q(**{prefixe_implantation: employe.implantation})
else:
q_place = Q(**{
prefixe_implantation + '__region': employe.implantation.region
})
- if grp_drh in request.user.groups.all():
+ user_groupes = [g.name for g in request.user.groups.all()]
+ if groups.DRH_NIVEAU_1 in user_groupes:
q_filtre = q_recherche
else:
q_filtre = q_place & q_recherche
class Poste(object):
def get_query(self, q, request):
- employe = get_employe_from_user(request.user)
+ employe = groups.get_employe_from_user(request.user)
prefixe_implantation = 'poste__implantation'
q_recherche = \
Q(poste__nom__icontains=q) | \
Q(poste__type_poste__nom__icontains=q)
- if is_user_dans_services_centraux(request.user):
+ if groups.is_user_dans_services_centraux(request.user):
q_place = Q(**{prefixe_implantation: employe.implantation})
else:
q_place = Q(**{
prefixe_implantation + '__region': employe.implantation.region
})
- if grp_drh in request.user.groups.all():
+ user_groupes = [g.name for g in request.user.groups.all()]
+ if groups.DRH_NIVEAU_1 in user_groupes:
q_filtre = q_recherche
else:
q_filtre = q_place & q_recherche
# -*- encoding: utf-8 -*-
-from django.contrib import messages
-from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
+from project import groups
from project.decorators import redirect_interdiction
from project.rh import models as rh
from project.dae import models as dae
-from project.dae.groups import dae_groupes, grp_drh, grp_drh2
+from project.dae.groups import dae_groupes
from project.dae.workflow import ETATS_EDITABLE, ETATS_VALIDE
"""
Teste si un user Django fait parti des groupes prédéfinis de DAE.
"""
- for g in user.groups.all():
+ for g in [g.name for g in user.groups.all()]:
if g in dae_groupes:
return True
return False
def dossier_est_modifiable(fn):
def inner(request, *args, **kwargs):
dossier_id = kwargs.get('dossier_id', None)
- user_groupes = request.user.groups.all()
+ user_groupes = [g.name for g in request.user.groups.all()]
if dossier_id is not None:
dossier = dae.Dossier.objects.get(id=dossier_id)
if not (dossier.etat in ETATS_EDITABLE and
- (grp_drh in user_groupes or grp_drh2 in user_groupes or
+ (groups.DRH_NIVEAU_1 in user_groupes or groups.DRH_NIVEAU_2 in user_groupes or
dossier in dae.Dossier.objects \
.mes_choses_a_faire(request.user).all())):
msg = u"Ce dossier d'embauche ne peut plus être modifié."
if key is not None and key.split('-')[0] == 'dae':
poste_id = key.split('-')[1]
poste = dae.Poste.objects.get(id=poste_id)
- if grp_drh not in request.user.groups.all() and \
+ user_groupes = [g.name for g in request.user.groups.all()]
+ if groups.DRH_NIVEAU_1 not in user_groupes and \
+ groups.DRH_NIVEAU_2 not in user_groupes and \
(poste.etat not in ETATS_EDITABLE \
or poste not in dae.Poste.objects \
.mes_choses_a_faire(request.user).all()):
def inner(request, contrat_id, *args, **kwargs):
contrat = get_object_or_404(dae.Contrat, pk=contrat_id)
dossier = contrat.dossier
- user_groupes = request.user.groups.all()
+ user_groupes = [g.name for g in request.user.groups.all()]
if not (dossier.etat in ETATS_VALIDE and
- (grp_drh in user_groupes or grp_drh2 in user_groupes or
+ (groups.DRH_NIVEAU_1 in user_groupes or groups.DRH_NIVEAU_2 in user_groupes or
dossier in dae.Dossier.objects \
.mes_choses_a_faire(request.user).all())):
return redirect_interdiction(request)
# -*- encoding: utf-8 -*-
-import datetime
-
from django import forms
from django.forms.models import BaseInlineFormSet
from django.contrib.admin import widgets as admin_widgets
from auf.django.references import models as ref
from auf.django.workflow.forms import WorkflowFormMixin
+from project import groups
from project.rh import models as rh
-from project.groups import \
- get_employe_from_user, is_user_dans_services_centraux
-
from project.dae import models as dae
-from project.dae.workflow import grp_drh, POSTE_ETATS_BOUTONS
+from project.dae.workflow import POSTE_ETATS_BOUTONS
class BaseInlineFormSetWithInitial(BaseInlineFormSet):
def _implantation_choices(obj, request):
# TRAITEMENT NORMAL
- employe = get_employe_from_user(request.user)
+ employe = groups.get_employe_from_user(request.user)
# SERVICE
- if is_user_dans_services_centraux(request.user):
+ if groups.is_user_dans_services_centraux(request.user):
q = Q(**{'id': employe.implantation_id})
# REGION
else:
q = Q(**{'region': employe.implantation.region})
# TRAITEMENT DRH
- if grp_drh in request.user.groups.all():
+ user_groupes = [g.name for g in request.user.groups.all()]
+ if groups.DRH_NIVEAU_1 in user_groupes:
q = Q()
return [('', '----------')] + \
[(i.id, unicode(i), )for i in ref.Implantation.objects.filter(q)]
def _employe_choices(obj, request):
# TRAITEMENT NORMAL
- employe = get_employe_from_user(request.user)
+ employe = groups.get_employe_from_user(request.user)
# SERVICE
- if is_user_dans_services_centraux(request.user):
+ if groups.is_user_dans_services_centraux(request.user):
q_dae_region_service = Q(poste__implantation=employe.implantation)
q_rh_region_service = Q(poste__implantation=employe.implantation)
# REGION
poste__implantation__region=employe.implantation.region
)
# TRAITEMENT DRH
- if grp_drh in request.user.groups.all():
+ user_groupes = [g.name for g in request.user.groups.all()]
+ if groups.DRH_NIVEAU_1 in user_groupes:
q_dae_region_service = Q()
q_rh_region_service = Q()
# -*- encoding: utf-8 -*-
-from project.groups import \
- grp_drh, grp_drh2, grp_administrateurs, grp_service_utilisateurs, \
- grp_correspondants_rh, grp_directeurs_bureau, grp_accior, grp_abf, \
- grp_haute_direction
+from project import groups
dae_groupes = (
- grp_correspondants_rh,
- grp_administrateurs,
- grp_directeurs_bureau,
- grp_drh,
- grp_drh2,
- grp_accior,
- grp_abf,
- grp_haute_direction,
- grp_service_utilisateurs,
+ groups.CORRESPONDANT_RH,
+ groups.DRH_NIVEAU_1,
+ groups.DRH_NIVEAU_2,
+ groups.DIRECTEUR_DE_BUREAU,
+ groups.ADMINISTRATEURS,
+ groups.HAUTE_DIRECTION,
+ groups.ACCIOR,
+ groups.ABF,
+ groups.SERVICE_UTILISATEURS,
)
from django.conf import settings
from django.core.mail import send_mail
from django.core.urlresolvers import reverse
-
-from project.dae.workflow import grp_drh
+from django.contrib.auth.models import Group
+from project import groups
def send_drh_finalisation_mail(request, dossier):
'',
dossier_url
])
+ grp_drh = Group.objects.get(name=groups.DRH_NIVEAU_1)
recipients = [u.email for u in grp_drh.user_set.filter(is_active=True)]
send_mail(subject, message, settings.SERVER_EMAIL, recipients)
from django.db.models import Q
-from project.groups import get_employe_from_user
+from project import groups
from project.rh.managers import \
DossierManager as RHDossierManager, \
PosteManager as RHPosteManager, \
PosteComparaisonManager as RHPosteComparaisonManager, \
DossierComparaisonManager as RHDossierComparaisonManager
-
from project.dae.workflow import MAP_GROUPE_ETATS_A_FAIRE
-from project.dae.workflow import \
- grp_drh, grp_drh2, grp_accior, \
- grp_abf, grp_haute_direction, grp_service_utilisateurs
class TodoManagerMixin(object):
def mes_choses_a_faire(self, user):
q = Q()
- employe = get_employe_from_user(user)
+ employe = groups.get_employe_from_user(user)
rien_a_faire = True
- for g in user.groups.all():
+ for g in [g.name for g in user.groups.all()]:
etats = MAP_GROUPE_ETATS_A_FAIRE.get(g, ())
for etat in etats:
rien_a_faire = False
q2 = Q(etat=etat)
- if g == grp_service_utilisateurs:
+ if g == groups.SERVICE_UTILISATEURS:
q2 &= Q(**{self.prefixe_service: employe.service})
elif g not in (
- grp_accior, grp_abf, grp_haute_direction, grp_drh, grp_drh2
+ groups.ACCIOR,
+ groups.ABF,
+ groups.HAUTE_DIRECTION,
+ groups.DRH_NIVEAU_1,
+ groups.DRH_NIVEAU_2,
):
q2 &= Q(**{
self.prefixe_implantation: employe.implantation.region
from auf.django.permissions import allow
+from project import groups
from project.dae import models as dae
from project.dae.decorators import user_in_dae_groupes
-from project.dae.groups import grp_drh, grp_drh2, grp_haute_direction
def user_in_group(*groups):
allow(
'modifier_dae_numerisee',
dae.Dossier,
- user_in_group(grp_drh, grp_drh2, grp_haute_direction)
+ user_in_group(groups.DRH_NIVEAU_1, groups.DRH_NIVEAU_2,
+ groups.HAUTE_DIRECTION)
)
allow(
from django import template
-from project.groups import grp_correspondants_rh, grp_administrateurs, \
- grp_drh, grp_drh2
+from project import groups
from project.dae.workflow import ETATS_EDITABLE
@register.filter
def test_membre_drh(user):
- grps = user.groups.all()
- if grp_drh in grps or grp_drh2 in grps:
+ grps = [g.name for g in user.groups.all()]
+ if groups.DRH_NIVEAU_1 in grps or groups.DRH_NIVEAU_2 in grps:
return True
else:
return False
@register.filter
def peut_ajouter(user):
- for g in user.groups.all():
- if g in (grp_administrateurs, grp_correspondants_rh, grp_drh):
+ for g in [g.name for g in user.groups.all()]:
+ if g in (groups.ADMINISTRATEURS,
+ groups.CORRESPONDANT_RH,
+ groups.DRH_NIVEAU_1,
+ groups.DRH_NIVEAU_2):
return True
return False
@register.filter
def peut_importer(user):
- return grp_drh in user.groups.all()
+ return groups.DRH_NIVEAU_1 in [g.name for g in user.groups.all()]
@register.filter
def est_editable(obj, user):
klass = obj.__class__
- groupes_users = user.groups.all()
+ groupes_users = [g.name for g in user.groups.all()]
if obj.etat in ETATS_EDITABLE and \
- (obj in klass.objects.mes_choses_a_faire(user).all() or grp_drh in groupes_users):
+ (obj in klass.objects.mes_choses_a_faire(user).all() or \
+ groups.DRH_NIVEAU_1 in groupes_users or \
+ groups.DRH_NIVEAU_2 in groupes_users):
return True
else:
return False
from auf.django.workflow.models import WorkflowMixin
-from project.groups import \
- grp_drh, grp_drh2, grp_administrateurs, grp_service_utilisateurs, \
- grp_correspondants_rh, grp_directeurs_bureau, grp_accior, grp_abf, \
- grp_haute_direction
-from project.groups import \
- is_user_dans_services_centraux, is_user_dans_region
+from project import groups
dae_groupes = (
- grp_correspondants_rh,
- grp_administrateurs,
- grp_directeurs_bureau,
- grp_drh,
- grp_drh2,
- grp_accior,
- grp_abf,
- grp_haute_direction,
- grp_service_utilisateurs,
+ groups.CORRESPONDANT_RH,
+ groups.ADMINISTRATEURS,
+ groups.DIRECTEUR_DE_BUREAU,
+ groups.DRH_NIVEAU_1,
+ groups.DRH_NIVEAU_2,
+ groups.ACCIOR,
+ groups.ABF,
+ groups.HAUTE_DIRECTION,
+ groups.SERVICE_UTILISATEURS,
)
# codes états
abstract = True
def acces_directeur_bureau(self, action, request):
- user_groups = request.user.groups.all()
- return grp_drh in user_groups or grp_drh2 in user_groups or \
- (is_user_dans_services_centraux(request.user) and
- grp_administrateurs in user_groups)
+ user_groups = [g.name for g in request.user.groups.all()]
+ return groups.DRH_NIVEAU_1 in user_groups or groups.DRH_NIVEAU_2 in user_groups or \
+ (groups.is_user_dans_services_centraux(request.user) and
+ groups.ADMINISTRATEURS in user_groups)
def acces_administrateur(self, action, request):
- user_groups = request.user.groups.all()
- return grp_correspondants_rh in user_groups or grp_drh in user_groups \
- or grp_drh2 in user_groups
+ user_groups = [g.name for g in request.user.groups.all()]
+ return groups.CORRESPONDANT_RH in user_groups or groups.DRH_NIVEAU_1 in user_groups \
+ or groups.DRH_NIVEAU_2 in user_groups
def acces_drh_controle(self, action, request):
- user_groups = request.user.groups.all()
- return grp_directeurs_bureau in user_groups or \
- grp_service_utilisateurs in user_groups or \
- grp_drh in user_groups or grp_drh2 in user_groups or \
- (grp_administrateurs in user_groups and
+ user_groups = [g.name for g in request.user.groups.all()]
+ return groups.DIRECTEUR_DE_BUREAU in user_groups or \
+ groups.SERVICE_UTILISATEURS in user_groups or \
+ groups.DRH_NIVEAU_1 in user_groups or groups.DRH_NIVEAU_2 in user_groups or \
+ (groups.ADMINISTRATEURS in user_groups and
(action == POSTE_ACTION_RETOUR_DEMANDE_MODIF or
- is_user_dans_region(request.user)))
+ groups.is_user_dans_region(request.user)))
def acces_drh_2(self, action, request):
- user_groups = request.user.groups.all()
- return grp_drh in user_groups
+ user_groups = [g.name for g in request.user.groups.all()]
+ return groups.DRH_NIVEAU_1 in user_groups
def acces_demande_modif(self, action, request):
- user_groups = request.user.groups.all()
- return grp_drh in user_groups or grp_drh2 in user_groups
+ user_groups = [g.name for g in request.user.groups.all()]
+ return groups.DRH_NIVEAU_1 in user_groups or groups.DRH_NIVEAU_2 in user_groups
def acces_srv_utilisateurs(self, action, request):
- if not is_user_dans_services_centraux(request.user):
+ if not groups.is_user_dans_services_centraux(request.user):
return False
- user_groups = request.user.groups.all()
- return grp_administrateurs in user_groups or grp_drh in user_groups \
- or grp_drh2 in user_groups
+ user_groups = [g.name for g in request.user.groups.all()]
+ return groups.ADMINISTRATEURS in user_groups or groups.DRH_NIVEAU_1 in user_groups \
+ or groups.DRH_NIVEAU_2 in user_groups
def acces_accior(self, action, request):
- user_groups = request.user.groups.all()
- return grp_drh in user_groups or grp_drh2 in user_groups
+ user_groups = [g.name for g in request.user.groups.all()]
+ return groups.DRH_NIVEAU_1 in user_groups or groups.DRH_NIVEAU_2 in user_groups
def acces_abf(self, action, request):
- user_groups = request.user.groups.all()
- return grp_accior in user_groups or grp_drh in user_groups \
- or grp_drh2 in user_groups
+ user_groups = [g.name for g in request.user.groups.all()]
+ return groups.ACCIOR in user_groups or groups.DRH_NIVEAU_1 in user_groups \
+ or groups.DRH_NIVEAU_2 in user_groups
def acces_haute_direction(self, action, request):
- user_groups = request.user.groups.all()
- return grp_abf in user_groups or grp_drh in user_groups \
- or grp_drh2 in user_groups
+ user_groups = [g.name for g in request.user.groups.all()]
+ return groups.ABF in user_groups or groups.DRH_NIVEAU_1 in user_groups \
+ or groups.DRH_NIVEAU_2 in user_groups
def acces_region_finalisation(self, action, request):
- user_groups = request.user.groups.all()
- return grp_haute_direction in user_groups or grp_drh in user_groups \
- or grp_drh2 in user_groups
+ user_groups = [g.name for g in request.user.groups.all()]
+ return groups.HAUTE_DIRECTION in user_groups or groups.DRH_NIVEAU_1 in user_groups \
+ or groups.DRH_NIVEAU_2 in user_groups
def acces_drh_finalisation(self, action, request):
- user_groups = request.user.groups.all()
- return grp_administrateurs in user_groups or \
- grp_correspondants_rh in user_groups or \
- grp_drh in user_groups or \
- grp_drh2 in user_groups
+ user_groups = [g.name for g in request.user.groups.all()]
+ return groups.ADMINISTRATEURS in user_groups or \
+ groups.CORRESPONDANT_RH in user_groups or \
+ groups.DRH_NIVEAU_1 in user_groups or \
+ groups.DRH_NIVEAU_2 in user_groups
def acces_demande_justif(self, action, request):
- user_groups = request.user.groups.all()
- return grp_haute_direction in user_groups or grp_drh in user_groups \
- or grp_drh2 in user_groups
+ user_groups = [g.name for g in request.user.groups.all()]
+ return groups.HAUTE_DIRECTION in user_groups or groups.DRH_NIVEAU_1 in user_groups \
+ or groups.DRH_NIVEAU_2 in user_groups
def acces_retour_demande_modif(self, action, request):
- user_groups = request.user.groups.all()
- return grp_administrateurs in user_groups or grp_drh in user_groups \
- or grp_drh2 in user_groups
+ user_groups = [g.name for g in request.user.groups.all()]
+ return groups.ADMINISTRATEURS in user_groups or groups.DRH_NIVEAU_1 in user_groups \
+ or groups.DRH_NIVEAU_2 in user_groups
def acces_retour_demande_justif(self, action, request):
- user_groups = request.user.groups.all()
- return grp_drh in user_groups or grp_drh2 in user_groups
+ user_groups = [g.name for g in request.user.groups.all()]
+ return groups.DRH_NIVEAU_1 in user_groups or groups.DRH_NIVEAU_2 in user_groups
def acces_finaliser(self, action, request):
- user_groups = request.user.groups.all()
- return grp_drh in user_groups or grp_drh2 in user_groups
+ user_groups = [g.name for g in request.user.groups.all()]
+ return groups.DRH_NIVEAU_1 in user_groups or groups.DRH_NIVEAU_2 in user_groups
#codes actions
MAP_GROUPE_ETATS_A_FAIRE = {
- grp_correspondants_rh: (
+ groups.CORRESPONDANT_RH: (
POSTE_ETAT_BROUILLON, DOSSIER_ETAT_BROUILLON,
POSTE_ETAT_REGION_FINALISATION, DOSSIER_ETAT_REGION_FINALISATION
),
- grp_service_utilisateurs: (
+ groups.SERVICE_UTILISATEURS: (
POSTE_ETAT_SERVICE_UTILISATEURS,
DOSSIER_ETAT_SERVICE_UTILISATEURS
),
- grp_administrateurs: (
+ groups.ADMINISTRATEURS: (
POSTE_ETAT_ADMINISTRATEUR, DOSSIER_ETAT_ADMINISTRATEUR,
POSTE_ETAT_DEMANDE_MODIF, DOSSIER_ETAT_DEMANDE_MODIF,
POSTE_ETAT_REGION_FINALISATION, DOSSIER_ETAT_REGION_FINALISATION,
),
- grp_directeurs_bureau: (
+ groups.DIRECTEUR_DE_BUREAU: (
POSTE_ETAT_DIRECTEUR_BUREAU, DOSSIER_ETAT_DIRECTEUR_BUREAU
),
- grp_drh: (
+ groups.DRH_NIVEAU_1: (
POSTE_ETAT_DRH_CONTROLE, POSTE_ETAT_DRH_FINALISATION,
DOSSIER_ETAT_DRH_CONTROLE, DOSSIER_ETAT_DRH_FINALISATION,
POSTE_ETAT_DEMANDE_JUSTIF, DOSSIER_ETAT_DEMANDE_JUSTIF
),
- grp_drh2: (POSTE_ETAT_DRH_2, DOSSIER_ETAT_DRH_2),
- grp_accior: (POSTE_ETAT_ACCIOR, DOSSIER_ETAT_ACCIOR),
- grp_abf: (POSTE_ETAT_ABF, DOSSIER_ETAT_ABF),
- grp_haute_direction: (
+ groups.DRH_NIVEAU_2: (POSTE_ETAT_DRH_2, DOSSIER_ETAT_DRH_2),
+ groups.ACCIOR: (POSTE_ETAT_ACCIOR, DOSSIER_ETAT_ACCIOR),
+ groups.ABF: (POSTE_ETAT_ABF, DOSSIER_ETAT_ABF),
+ groups.HAUTE_DIRECTION: (
POSTE_ETAT_HAUTE_DIRECTION, DOSSIER_ETAT_HAUTE_DIRECTION
),
}
from django.utils.http import urlquote
from project import groups
-from project.groups import get_employe_from_user
def redirect_interdiction(request, msg=u"Vous n'avez pas accès à cette page"):
"""
Teste si un user Django fait parti du groupe DRH, DRH2 ou s'il est admin
"""
- user_groups = user.groups.all()
+ user_groups = [g.name for g in user.groups.all()]
if user.is_superuser or \
- groups.grp_drh in user_groups or \
- groups.grp_drh2 in user_groups:
+ groups.DRH_NIVEAU_1 in user_groups or \
+ groups.DRH_NIVEAU_2 in user_groups:
return True
else:
return False
def wrapped(request, id):
if request.user.is_superuser:
return func(request, id)
- user_groups = request.user.groups.all()
- if groups.grp_drh in user_groups or \
- groups.grp_drh2 in user_groups:
+ user_groups = [g.name for g in request.user.groups.all()]
+ if groups.DRH_NIVEAU_1 in user_groups or \
+ groups.DRH_NIVEAU_2 in user_groups:
return func(request, id)
- if groups.grp_correspondants_rh in user_groups or \
- groups.grp_administrateurs in user_groups or \
- groups.grp_directeurs_bureau in user_groups:
- employe = get_employe_from_user(request.user)
+ if groups.CORRESPONDANT_RH in user_groups or \
+ groups.ADMINISTRATEURS in user_groups or \
+ groups.DIRECTEUR_DE_BUREAU in user_groups:
+ employe = groups.get_employe_from_user(request.user)
q = Q(**{
model.prefix_implantation: employe.implantation.region
})
"""
def wrapper(fn):
def wrapped(request, *args, **kwargs):
- user_groups = request.user.groups.all()
+ user_groups = [g.name for g in request.user.groups.all()]
for g in user_groups:
if g in groups:
return fn(request, *args, **kwargs)
# -*- encoding: utf-8 -*-
-from django.contrib.auth.models import Group
import auf.django.references.models as ref
-def safe_create_groupe(name):
- """
- Création d'un groupe prédéfini. Retourne None, quand la création
- ne peut se faire. (C'est le cas au syncdb, quand la table de groupe
- n'a pas été crée encore).
- """
- try:
- grp, created = Group.objects.get_or_create(name=name)
- except Exception, e:
- return None
- return grp
-
CORRESPONDANT_RH = 'Correspondants RH'
ADMINISTRATEURS ='Administrateurs'
DIRECTEUR_DE_BUREAU = 'Directeurs de bureau'
SERVICE_UTILISATEURS = 'Service utilisateurs'
# Groupes impliqués dans le Worflow
-grp_correspondants_rh = safe_create_groupe(name=CORRESPONDANT_RH)
-grp_administrateurs = safe_create_groupe(name=ADMINISTRATEURS)
-grp_directeurs_bureau = safe_create_groupe(name=DIRECTEUR_DE_BUREAU)
-grp_drh = safe_create_groupe(name=DRH_NIVEAU_1)
-grp_drh2 = safe_create_groupe(name=DRH_NIVEAU_2)
-grp_accior = safe_create_groupe(name=ACCIOR)
-grp_abf = safe_create_groupe(name=ABF)
-grp_haute_direction = safe_create_groupe(name=HAUTE_DIRECTION)
-grp_service_utilisateurs = safe_create_groupe(name=SERVICE_UTILISATEURS)
+#grp_correspondants_rh = safe_create_groupe(name=CORRESPONDANT_RH)
+#grp_administrateurs = safe_create_groupe(name=ADMINISTRATEURS)
+#grp_directeurs_bureau = safe_create_groupe(name=DIRECTEUR_DE_BUREAU)
+#grp_drh = safe_create_groupe(name=DRH_NIVEAU_1)
+#grp_drh2 = safe_create_groupe(name=DRH_NIVEAU_2)
+#grp_accior = safe_create_groupe(name=ACCIOR)
+#grp_abf = safe_create_groupe(name=ABF)
+#grp_haute_direction = safe_create_groupe(name=HAUTE_DIRECTION)
+#grp_service_utilisateurs = safe_create_groupe(name=SERVICE_UTILISATEURS)
def get_employe_from_user(user):
"""
return employe.implantation_id in (15, 19)
def is_user_dans_region(user):
- employe = get_employe_from_user(user)
return not is_user_dans_services_centraux(user)
kwargs={'app_label': 'dae'})),
]
- user_groups = request.user.groups.all()
+ user_groups = [g.name for g in request.user.groups.all()]
if in_drh_or_admin(request.user) or\
- groups.grp_correspondants_rh in user_groups or\
- groups.grp_administrateurs in user_groups or\
- groups.grp_directeurs_bureau in user_groups:
+ groups.CORRESPONDANT_RH in user_groups or\
+ groups.ADMINISTRATEURS in user_groups or\
+ groups.DIRECTEUR_DE_BUREAU in user_groups:
self.children += [
items.MenuItem('Rapports',
children=[
--- /dev/null
+#encoding UTF-8
+# -*- encoding: utf-8 -*-
+
+"""
+Configuration du site pour faire fonctionner les tests unitaires avec
+MySQL en RAM.
+"""
+
+from production import *
+
+DATABASES['default']['HOST'] = '/var/run/mysqld/mysqld-ram.sock'
+
+host = "mysql --socket=%s -uroot -e" % DATABASES['default']['HOST']
+db = "unittests_%s" % DATABASES['default']['NAME']
+DATABASES['default']['NAME'] = db
+DATABASES['default']['TEST_NAME'] = db
+user = DATABASES['default']['USER']
+pwd = DATABASES['default']['PASSWORD']
+
+cmd_creer_bd = "%(host)s \
+ 'CREATE DATABASE %(db)s;'" % {
+ 'host': host,
+ 'db': db,
+ }
+
+cmd_creer_user = """%(host)s \
+ "GRANT USAGE ON *.* TO %(user)s@localhost \
+ IDENTIFIED BY '%(pwd)s';" """ % {
+ 'host': host,
+ 'user': user,
+ 'pwd': pwd,
+ }
+
+cmd_creer_privileges = "%(host)s \
+ 'GRANT ALL PRIVILEGES ON *.* TO %(user)s@localhost ;'" % {
+ 'host': host,
+ 'user': user,
+ }
+
+
+# La bd non préfixée par "test_" a besoin d'exister pour lancer les tests.
+# Cette commande ne modifie rien, si la table existe déjà.
+os.system(cmd_creer_bd)
+
+# Création de l'accès à la base "test_xxx" en fonction de conf.py
+os.system(cmd_creer_user)
+os.system(cmd_creer_privileges)
from rh import models as rh
def user_gere_obj_de_sa_region(user):
- user_groups = user.groups.all()
- if groups.grp_correspondants_rh in user_groups or \
- groups.grp_administrateurs in user_groups or \
- groups.grp_directeurs_bureau in user_groups:
+ user_groups = [g.name for g in user.groups.all()]
+ if groups.CORRESPONDANT_RH in user_groups or \
+ groups.ADMINISTRATEURS in user_groups or \
+ groups.DIRECTEUR_DE_BUREAU in user_groups:
return True
return False
from django.shortcuts import redirect
from reversion.admin import VersionAdmin
-from project.groups import get_employe_from_user as get_emp
+from project import groups
from project.rh import models as rh
from project.recrutement.forms import OffreEmploiForm
-from project.recrutement.groups import \
- grp_drh, grp_drh2, \
- grp_directeurs_bureau, \
- grp_administrateurs, \
- grp_correspondants_rh, \
- grp_haute_direction
from project.recrutement.models import \
Evaluateur, CandidatEvaluation, \
ProxyOffreEmploi, ProxyCandidat, MesCandidatEvaluation, \
### Formulaire
def get_form(self, request, obj=None, **kwargs):
form = super(OffreEmploiAdmin, self).get_form(request, obj, **kwargs)
- employe = get_emp(request.user)
- user_groupes = request.user.groups.all()
+ employe = groups.get_employe_from_user(request.user)
+ user_groupes = [g.name for g in request.user.groups.all()]
# Region
if 'region' in form.declared_fields:
else:
region_field = form.base_fields['region']
- if grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_haute_direction in user_groupes:
+ if groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
region_field.queryset = Region.objects.all()
else:
region_field.queryset = Region.objects.\
else:
poste_field = form.base_fields['poste']
- if grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_haute_direction in user_groupes:
+ if groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
poste_field.queryset = rh.Poste.objects.all()
else:
poste_field.queryset = rh.Poste.objects.\
else:
bureau_field = form.base_fields['bureau']
- if grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_haute_direction in user_groupes:
+ if groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
bureau_field.queryset = Bureau.objects.all()
else:
bureau_field.queryset = \
qs = self.model._default_manager.get_query_set() \
.select_related('offre_emploi')
user_groupes = request.user.groups.all()
- if grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_haute_direction in user_groupes:
+ if groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
return qs
- if grp_directeurs_bureau in user_groupes or \
- grp_correspondants_rh in user_groupes or \
- grp_administrateurs in user_groupes:
- employe = get_emp(request.user)
+ if groups.DIRECTEUR_DE_BUREAU in user_groupes or \
+ groups.CORRESPONDANT_RH in user_groupes or \
+ groups.ADMINISTRATEURS in user_groupes:
+ employe = groups.get_employe_from_user(request.user)
return qs.filter(region=employe.implantation.region)
if Evaluateur.objects.filter(user=request.user).exists():
### Permission add, delete, change
def has_add_permission(self, request):
- user_groupes = request.user.groups.all()
+ user_groupes = [g.name for g in request.user.groups.all()]
if request.user.is_superuser is True or \
- grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_directeurs_bureau in user_groupes or \
- grp_administrateurs in user_groupes or \
- grp_haute_direction in user_groupes:
+ groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.DIRECTEUR_DE_BUREAU in user_groupes or \
+ groups.ADMINISTRATEURS in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
return True
return False
def has_delete_permission(self, request, obj=None):
- user_groupes = request.user.groups.all()
+ user_groupes = [g.name for g in request.user.groups.all()]
if request.user.is_superuser is True or \
- grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_directeurs_bureau in user_groupes or \
- grp_administrateurs in user_groupes or \
- grp_haute_direction in user_groupes:
+ groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.DIRECTEUR_DE_BUREAU in user_groupes or \
+ groups.ADMINISTRATEURS in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
return True
return False
def has_change_permission(self, request, obj=None):
- user_groupes = request.user.groups.all()
+ user_groupes = [g.name for g in request.user.groups.all()]
if request.user.is_superuser is True or \
- grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_directeurs_bureau in user_groupes or \
- grp_administrateurs in user_groupes or \
- grp_haute_direction in user_groupes:
+ groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.DIRECTEUR_DE_BUREAU in user_groupes or \
+ groups.ADMINISTRATEURS in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
return True
return False
return False
def has_change_permission(self, request, obj=None):
- user_groupes = request.user.groups.all()
+ user_groupes = [g.name for g in request.user.groups.all()]
if request.user.is_superuser is True or \
- grp_correspondants_rh in user_groupes or \
- grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_directeurs_bureau in user_groupes or \
- grp_administrateurs in user_groupes or \
- grp_haute_direction in user_groupes:
+ groups.CORRESPONDANT_RH in user_groupes or \
+ groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.DIRECTEUR_DE_BUREAU in user_groupes or \
+ groups.ADMINISTRATEURS in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
return True
if obj is not None:
### Permissions add, delete, change
def has_add_permission(self, request):
- user_groupes = request.user.groups.all()
+ user_groupes = [g.name for g in request.user.groups.all()]
if request.user.is_superuser is True or \
- grp_correspondants_rh in user_groupes or \
- grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_directeurs_bureau in user_groupes or \
- grp_administrateurs in user_groupes or \
- grp_haute_direction in user_groupes:
+ groups.CORRESPONDANT_RH in user_groupes or \
+ groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.DIRECTEUR_DE_BUREAU in user_groupes or \
+ groups.ADMINISTRATEURS in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
return True
return False
def has_delete_permission(self, request, obj=None):
- user_groupes = request.user.groups.all()
+ user_groupes = [g.name for g in request.user.groups.all()]
if request.user.is_superuser is True or \
- grp_correspondants_rh in user_groupes or \
- grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_directeurs_bureau in user_groupes or \
- grp_administrateurs in user_groupes or \
- grp_haute_direction in user_groupes:
+ groups.CORRESPONDANT_RH in user_groupes or \
+ groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.DIRECTEUR_DE_BUREAU in user_groupes or \
+ groups.ADMINISTRATEURS in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
return True
return False
def has_change_permission(self, request, obj=None):
- user_groupes = request.user.groups.all()
+ user_groupes = [g.name for g in request.user.groups.all()]
if request.user.is_superuser is True or \
- grp_correspondants_rh in user_groupes or \
- grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_directeurs_bureau in user_groupes or \
- grp_administrateurs in user_groupes or \
- grp_haute_direction in user_groupes:
+ groups.CORRESPONDANT_RH in user_groupes or \
+ groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.DIRECTEUR_DE_BUREAU in user_groupes or \
+ groups.ADMINISTRATEURS in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
return True
return False
.select_related('offre_emploi') \
.annotate(moyenne=Avg('evaluations__note'))
- user_groupes = request.user.groups.all()
- if grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_haute_direction in user_groupes:
+ user_groupes = [g.name for g in request.user.groups.all()]
+ if groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
return qs
- if grp_directeurs_bureau in user_groupes or \
- grp_correspondants_rh in user_groupes or \
- grp_administrateurs in user_groupes:
- employe = get_emp(request.user)
+ if groups.DIRECTEUR_DE_BUREAU in user_groupes or \
+ groups.CORRESPONDANT_RH in user_groupes or \
+ groups.ADMINISTRATEURS in user_groupes:
+ employe = groups.get_employe_from_user(request.user)
return qs.filter(offre_emploi__region=employe.implantation.region)
if Evaluateur.objects.filter(user=request.user).exists():
return False
def has_change_permission(self, request, obj=None):
- user_groupes = request.user.groups.all()
+ user_groupes = [g.name for g in request.user.groups.all()]
if request.user.is_superuser is True or \
- grp_correspondants_rh in user_groupes or \
- grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_directeurs_bureau in user_groupes or \
- grp_administrateurs in user_groupes or \
- grp_haute_direction in user_groupes:
+ groups.CORRESPONDANT_RH in user_groupes or \
+ groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.DIRECTEUR_DE_BUREAU in user_groupes or \
+ groups.ADMINISTRATEURS in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
return True
if obj is not None:
### Permissions add, delete, change
def has_add_permission(self, request):
- user_groupes = request.user.groups.all()
+ user_groupes = [g.name for g in request.user.groups.all()]
if request.user.is_superuser is True or \
- grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_haute_direction in user_groupes:
+ groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
return True
return False
def has_delete_permission(self, request, obj=None):
- user_groupes = request.user.groups.all()
+ user_groupes = [g.name for g in request.user.groups.all()]
if request.user.is_superuser is True or \
- grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_haute_direction in user_groupes:
+ groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
return True
return False
def has_change_permission(self, request, obj=None):
- user_groupes = request.user.groups.all()
+ user_groupes = [g.name for g in request.user.groups.all()]
if request.user.is_superuser is True or \
- grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_haute_direction in user_groupes:
+ groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
return True
return False
mais interdire l'accès à modifier l'objet si l'évaluateur n'est pas
le request.user
"""
- user_groupes = request.user.groups.all()
+ user_groupes = [g.name for g in request.user.groups.all()]
if request.user.is_superuser or \
- grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_correspondants_rh in user_groupes or \
- grp_directeurs_bureau in user_groupes or \
- grp_administrateurs in user_groupes or \
- grp_haute_direction in user_groupes:
+ groups.CORRESPONDANT_RH in user_groupes or \
+ groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.DIRECTEUR_DE_BUREAU in user_groupes or \
+ groups.ADMINISTRATEURS in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
is_recrutement = True
else:
is_recrutement = False
qs = self.model._default_manager.get_query_set() \
.select_related('offre_emploi')
user_groupes = request.user.groups.all()
+ user_groupes = [g.name for g in request.user.groups.all()]
- if grp_drh in user_groupes or \
- grp_drh2 in user_groupes or \
- grp_correspondants_rh in user_groupes or \
- grp_directeurs_bureau in user_groupes or \
- grp_administrateurs in user_groupes or \
- grp_haute_direction in user_groupes:
+ if request.user.is_superuser or \
+ groups.CORRESPONDANT_RH in user_groupes or \
+ groups.DRH_NIVEAU_1 in user_groupes or \
+ groups.DRH_NIVEAU_2 in user_groupes or \
+ groups.DIRECTEUR_DE_BUREAU in user_groupes or \
+ groups.ADMINISTRATEURS in user_groupes or \
+ groups.HAUTE_DIRECTION in user_groupes:
return qs
evaluateur = Evaluateur.objects.get(user=request.user)
# -*- encoding: utf-8 -*-
-from project.groups import safe_create_groupe
-from project.groups import grp_correspondants_rh, \
- grp_drh, \
- grp_drh2, \
- grp_directeurs_bureau, \
- grp_administrateurs, \
- grp_haute_direction
+from project import groups
EVALUATEURS = 'Évaluateurs'
-grp_evaluateurs = safe_create_groupe(name=EVALUATEURS)
recrutement_groupes = (
- grp_evaluateurs,
- grp_correspondants_rh,
- grp_drh,
- grp_drh2,
- grp_directeurs_bureau,
- grp_administrateurs,
- grp_haute_direction,
+ EVALUATEURS,
+ groups.CORRESPONDANT_RH,
+ groups.DRH_NIVEAU_1,
+ groups.DRH_NIVEAU_2,
+ groups.DIRECTEUR_DE_BUREAU,
+ groups.ADMINISTRATEURS,
+ groups.HAUTE_DIRECTION,
)
# -=- encoding: utf-8 -=-
from auf.django.emploi import models as emploi
-from django.contrib.auth.models import User
+from django.contrib.auth.models import User, Group
from django.db import models
from django.db.models.signals import pre_save, pre_delete
from django.dispatch import receiver
from south.modelsinspector import add_introspection_rules
from tinymce import models as tinymce_models
-from project.recrutement.groups import grp_evaluateurs
+from project.recrutement import groups as recrutement_groups
### CONSTANTES
@receiver(pre_save, sender=Evaluateur)
def sync_add_groupe_evaluateur(sender, **kwargs):
instance = kwargs['instance']
- if grp_evaluateurs not in instance.user.groups.all():
+ user_groups = [g.name for g in instance.user.groups.all()]
+ if recrutement_groups.EVALUATEURS not in user_groups:
+ grp_evaluateurs = Group.objects.get(name=recrutement_groups.EVALUATEURS)
instance.user.groups.add(grp_evaluateurs)
instance.user.save()
@receiver(pre_delete, sender=Evaluateur)
def sync_delete_groupe_evaluateur(sender, **kwargs):
instance = kwargs['instance']
+ grp_evaluateurs = Group.objects.get(name=recrutement_groups.EVALUATEURS)
instance.user.groups.remove(grp_evaluateurs)
instance.user.save()
from project import groups
from project.decorators import in_drh_or_admin
-from project.groups import grp_correspondants_rh
-from project.groups import get_employe_from_user
from project.rh import models as rh
from project.permissions import get_region_user, \
user_gere_obj_de_sa_region, \
return False
def has_change_permission(self, request, obj=None):
- user_groups = request.user.groups.all()
- if groups.grp_correspondants_rh in user_groups or \
- groups.grp_administrateurs in user_groups or \
- groups.grp_directeurs_bureau in user_groups or \
+ user_groups = [g.name for g in request.user.groups.all()]
+ if groups.CORRESPONDANT_RH in user_groups or \
+ groups.ADMINISTRATEURS in user_groups or \
+ groups.DIRECTEUR_DE_BUREAU in user_groups or \
in_drh_or_admin(request.user):
return True
return False
return False
def has_change_permission(self, request, obj=None):
- user_groups = request.user.groups.all()
- if groups.grp_correspondants_rh in user_groups or \
- groups.grp_administrateurs in user_groups or \
- groups.grp_directeurs_bureau in user_groups or \
+ user_groups = [g.name for g in request.user.groups.all()]
+ if groups.CORRESPONDANT_RH in user_groups or \
+ groups.ADMINISTRATEURS in user_groups or \
+ groups.DIRECTEUR_DE_BUREAU in user_groups or \
in_drh_or_admin(request.user):
return True
return False
return False
def has_change_permission(self, request, obj=None):
- user_groups = request.user.groups.all()
- if groups.grp_correspondants_rh in user_groups or \
- groups.grp_administrateurs in user_groups or \
- groups.grp_directeurs_bureau in user_groups or \
+ user_groups = [g.name for g in request.user.groups.all()]
+ if groups.CORRESPONDANT_RH in user_groups or \
+ groups.ADMINISTRATEURS in user_groups or \
+ groups.DIRECTEUR_DE_BUREAU in user_groups or \
in_drh_or_admin(request.user):
return True
return False
return False
def has_change_permission(self, request, obj=None):
- user_groups = request.user.groups.all()
- if groups.grp_correspondants_rh in user_groups or \
- groups.grp_administrateurs in user_groups or \
- groups.grp_directeurs_bureau in user_groups or \
+ user_groups = [g.name for g in request.user.groups.all()]
+ if groups.CORRESPONDANT_RH in user_groups or \
+ groups.ADMINISTRATEURS in user_groups or \
+ groups.DIRECTEUR_DE_BUREAU in user_groups or \
in_drh_or_admin(request.user):
return True
return False
from django.db.models import Q
from django.db.models.query import QuerySet
-from project.groups import get_employe_from_user
-from project.groups import \
- grp_drh, grp_drh2, grp_accior, grp_abf, grp_haute_direction, \
- grp_service_utilisateurs
+from project import groups
class SecurityManager(models.Manager):
On s'intéresse aussi au groupe auquel appartient le user car
certains groupes peuvent tout voir.
"""
- employe = get_employe_from_user(user)
+ employe = groups.get_employe_from_user(user)
+ groupes = [g.name for g in user.groups.all()]
############################################
# TRAITEMENT NORMAL
# SERVICE
if self.prefixe_service \
- and grp_service_utilisateurs in user.groups.all():
+ and groups.SERVICE_UTILISATEURS in groupes:
q = q | Q(**{self.prefixe_service: employe.service})
liste = self.get_query_set().filter(q)
############################################
# TRAITEMENT ACCIOR
############################################
- if grp_accior in user.groups.all():
+ if groups.ACCIOR in groupes:
liste = self.get_query_set().all()
############################################
# TRAITEMENT ABF
############################################
- if grp_abf in user.groups.all():
+ if groups.ABF in groupes:
liste = self.get_query_set().all()
############################################
# TRAITEMENT HAUTE DIRECTION
############################################
- if grp_haute_direction in user.groups.all():
+ if groups.HAUTE_DIRECTION in groupes:
liste = self.get_query_set().all()
############################################
# TRAITEMENT DRH
############################################
- if grp_drh in user.groups.all() or grp_drh2 in user.groups.all():
+ if groups.DRH_NIVEAU_1 in groupes or groups.DRH_NIVEAU_2 in groupes:
liste = self.get_query_set().all()
if user.is_superuser:
from auf.django.references.models import Implantation, Region
from project import groups
-from project.groups import get_employe_from_user
from project.rh.models import TypeContrat
@register.inclusion_tag('admin/filter.html', takes_context=True)
def filter_region_contrat(context):
request = context['request']
- user_groups = request.user.groups.all()
- if groups.grp_correspondants_rh in user_groups or\
- groups.grp_administrateurs in user_groups or\
- groups.grp_directeurs_bureau in user_groups:
- employe = get_employe_from_user(request.user)
+ user_groups = [g.name for g in request.user.groups.all()]
+ if groups.CORRESPONDANT_RH in user_groups or\
+ groups.ADMINISTRATEURS in user_groups or\
+ groups.DIRECTEUR_DE_BUREAU in user_groups:
+ employe = groups.get_employe_from_user(request.user)
regions = Region.objects.filter(id=employe.implantation.region.id)
else:
regions = Region.objects.all()
@register.inclusion_tag('admin/filter.html', takes_context=True)
def filter_implantation_contrat(context):
request = context['request']
- user_groups = request.user.groups.all()
- if groups.grp_correspondants_rh in user_groups or\
- groups.grp_administrateurs in user_groups or\
- groups.grp_directeurs_bureau in user_groups:
- employe = get_employe_from_user(request.user)
+ user_groups = [g.name for g in request.user.groups.all()]
+ if groups.CORRESPONDANT_RH in user_groups or\
+ groups.ADMINISTRATEURS in user_groups or\
+ groups.DIRECTEUR_DE_BUREAU in user_groups:
+ employe = groups.get_employe_from_user(request.user)
implantations = Implantation.objects.filter(region=employe.implantation.region)
else:
implantations = Implantation.objects.all()
# -*- coding: utf-8 -*-
import datetime
-from django.contrib.auth.models import User
+from django.contrib.auth.models import User, Group
from project import groups
from auf.django.references import models as ref
from django.test import TestCase
from project.rh import models as rh
-
class RhTest(TestCase):
def setUp(self):
"""
+ GROUPES
+ =======
+ self.grp_correspondants_rh
+ self.grp_administrateurs
+ self.grp_directeurs_bureau
+ self.grp_drh
+ self.grp_drh2
+ self.grp_accior
+ self.grp_abf
+ self.grp_haute_direction
+ self.grp_service_utilisateurs
+
POSTES
======
self.poste_cnf_ngaoundere
"""
+ self.grp_correspondants_rh = Group(name=groups.CORRESPONDANT_RH)
+ self.grp_correspondants_rh.save()
+
+ self.grp_administrateurs = Group(name=groups.ADMINISTRATEURS)
+ self.grp_administrateurs.save()
+
+ self.grp_directeurs_bureau = Group(name=groups.DIRECTEUR_DE_BUREAU)
+ self.grp_directeurs_bureau.save()
+
+ self.grp_drh = Group(name=groups.DRH_NIVEAU_1)
+ self.grp_drh.save()
+
+ self.grp_drh2 = Group(name=groups.DRH_NIVEAU_2)
+ self.grp_drh2.save()
+
+ self.grp_accior = Group(name=groups.ACCIOR)
+ self.grp_accior.save()
+
+ self.grp_abf = Group(name=groups.ABF)
+ self.grp_abf.save()
+
+ self.grp_haute_direction = Group(name=groups.HAUTE_DIRECTION)
+ self.grp_haute_direction.save()
+
+ self.grp_service_utilisateurs = Group(name=groups.SERVICE_UTILISATEURS)
+ self.grp_service_utilisateurs.save()
+
self.password = "0000"
self.today = datetime.datetime.now()
#########################
def _test_correspondant_rh(self, email="0@test.auf"):
u = User.objects.get(email=email)
- groups.grp_correspondants_rh.user_set.add(u)
- groups.grp_correspondants_rh.save()
+ self.grp_correspondants_rh.user_set.add(u)
+ self.grp_correspondants_rh.save()
credentials = {'username': email, 'password': self.password}
self.assertTrue(self.client.login(**credentials), "login failed")
def _test_administrateur_regional(self, email="0@test.auf"):
u = User.objects.get(email=email)
- groups.grp_administrateurs.user_set.add(u)
- groups.grp_administrateurs.save()
+ self.grp_administrateurs.user_set.add(u)
+ self.grp_administrateurs.save()
credentials = {'username': email, 'password': self.password}
self.assertTrue(self.client.login(**credentials), "login failed")
def _test_directeur_bureau(self, email="0@test.auf"):
u = User.objects.get(email=email)
- groups.grp_directeurs_bureau.user_set.add(u)
- groups.grp_directeurs_bureau.save()
+ self.grp_directeurs_bureau.user_set.add(u)
+ self.grp_directeurs_bureau.save()
credentials = {'username': email, 'password': self.password}
self.assertTrue(self.client.login(**credentials), "login failed")
email = "0@test.auf"
u = User.objects.get(email=email)
- groups.grp_drh.user_set.add(u)
- groups.grp_drh.save()
+ self.grp_drh.user_set.add(u)
+ self.grp_drh.save()
credentials = {'username': email, 'password': self.password}
self.assertTrue(self.client.login(**credentials), "login failed")
email = "0@test.auf"
u = User.objects.get(email=email)
- groups.grp_drh2.user_set.add(u)
- groups.grp_drh2.save()
+ self.grp_drh2.user_set.add(u)
+ self.grp_drh2.save()
credentials = {'username': email, 'password': self.password}
self.assertTrue(self.client.login(**credentials), "login failed")
email = "0@test.auf"
u = User.objects.get(email=email)
- groups.grp_accior.user_set.add(u)
- groups.grp_accior.save()
+ self.grp_accior.user_set.add(u)
+ self.grp_accior.save()
credentials = {'username': email, 'password': self.password}
self.assertTrue(self.client.login(**credentials), "login failed")
email = "0@test.auf"
u = User.objects.get(email=email)
- groups.grp_abf.user_set.add(u)
- groups.grp_abf.save()
+ self.grp_abf.user_set.add(u)
+ self.grp_abf.save()
credentials = {'username': email, 'password': self.password}
self.assertTrue(self.client.login(**credentials), "login failed")
email = "0@test.auf"
u = User.objects.get(email=email)
- groups.grp_haute_direction.user_set.add(u)
- groups.grp_haute_direction.save()
+ self.grp_haute_direction.user_set.add(u)
+ self.grp_haute_direction.save()
credentials = {'username': email, 'password': self.password}
self.assertTrue(self.client.login(**credentials), "login failed")
email = "0@test.auf"
u = User.objects.get(email=email)
- groups.grp_service_utilisateurs.user_set.add(u)
- groups.grp_service_utilisateurs.save()
+ self.grp_service_utilisateurs.user_set.add(u)
+ self.grp_service_utilisateurs.save()
credentials = {'username': email, 'password': self.password}
self.assertTrue(self.client.login(**credentials), "login failed")
-
from project.rh.test.employe import *
from project.rh.test.dossier import *
from project.rh.test.poste import *
@login_required
-@in_one_of_group((groups.grp_correspondants_rh,
- groups.grp_administrateurs,
- groups.grp_directeurs_bureau,
- groups.grp_drh,
- groups.grp_drh2))
+@in_one_of_group((groups.CORRESPONDANT_RH,
+ groups.ADMINISTRATEURS,
+ groups.DIRECTEUR_DE_BUREAU,
+ groups.DRH_NIVEAU_1,
+ groups.DRH_NIVEAU_2))
def rapports_contrat(request):
# statut default = actif?
if 'HTTP_REFERER' in request.META.keys():
q_temporel = cl.get_q_temporel(contrats)
q = Q(**lookup_params) & q_temporel
contrats = contrats.filter(q)
- user_groups = request.user.groups.all()
- if groups.grp_correspondants_rh in user_groups or\
- groups.grp_administrateurs in user_groups or\
- groups.grp_directeurs_bureau in user_groups:
+ user_groups = [g.name for g in request.user.groups.all()]
+ if groups.CORRESPONDANT_RH in user_groups or\
+ groups.ADMINISTRATEURS in user_groups or\
+ groups.DIRECTEUR_DE_BUREAU in user_groups:
employe = get_employe_from_user(request.user)
q = q & Q(dossier__poste__implantation__region=employe.implantation.region)
@login_required
-@in_one_of_group((groups.grp_correspondants_rh,
- groups.grp_administrateurs,
- groups.grp_directeurs_bureau,
- groups.grp_drh,
- groups.grp_drh2))
+@in_one_of_group((groups.CORRESPONDANT_RH,
+ groups.ADMINISTRATEURS,
+ groups.DIRECTEUR_DE_BUREAU,
+ groups.DRH_NIVEAU_1,
+ groups.DRH_NIVEAU_2))
def rapports_employes_sans_contrat(request):
"""
Employé sans contrat = a un Dossier qui n'a pas de Contrat associé
lookup_params = get_lookup_params(request)
# régionalisation
- user_groups = request.user.groups.all()
+ user_groups = [g.name for g in request.user.groups.all()]
q_region = Q()
- if groups.grp_correspondants_rh in user_groups or\
- groups.grp_administrateurs in user_groups or\
- groups.grp_directeurs_bureau in user_groups:
+ if groups.CORRESPONDANT_RH in user_groups or\
+ groups.ADMINISTRATEURS in user_groups or\
+ groups.DIRECTEUR_DE_BUREAU in user_groups:
employe = get_employe_from_user(request.user)
q_region = Q(poste__implantation__region=employe.implantation.region)
@login_required
-@in_one_of_group((groups.grp_correspondants_rh,
- groups.grp_administrateurs,
- groups.grp_directeurs_bureau,
- groups.grp_drh,
- groups.grp_drh2))
+@in_one_of_group((groups.CORRESPONDANT_RH,
+ groups.ADMINISTRATEURS,
+ groups.DIRECTEUR_DE_BUREAU,
+ groups.DRH_NIVEAU_1,
+ groups.DRH_NIVEAU_2))
def rapports_masse_salariale(request):
form = MasseSalarialeForm(request.user, request.GET)
if 'annee' in request.GET and form.is_valid():
}
return render(request, 'admin/rh/poste/apercu.html', c)
-@in_one_of_group((groups.grp_correspondants_rh,
- groups.grp_administrateurs,
- groups.grp_directeurs_bureau,
- groups.grp_drh,
- groups.grp_drh2))
+@login_required
+@in_one_of_group((groups.CORRESPONDANT_RH,
+ groups.ADMINISTRATEURS,
+ groups.DIRECTEUR_DE_BUREAU,
+ groups.DRH_NIVEAU_1,
+ groups.DRH_NIVEAU_2))
def employe_apercu(request, employe_id):
employe = get_object_or_404(rh.Employe, pk=employe_id)
- user_groups = request.user.groups.all()
+ user_groups = [g.name for g in request.user.groups.all()]
dossiers = None
if in_drh_or_admin(request.user):
q = Q(employe=employe)
- if groups.grp_correspondants_rh in user_groups or\
- groups.grp_administrateurs in user_groups or\
- groups.grp_directeurs_bureau in user_groups:
+ if groups.CORRESPONDANT_RH in user_groups or\
+ groups.ADMINISTRATEURS in user_groups or\
+ groups.DIRECTEUR_DE_BUREAU in user_groups:
employe_connecte = get_employe_from_user(request.user)
q = Q(employe=employe) & Q(poste__implantation__region=employe_connecte.implantation.region)
@login_required
-@in_one_of_group((groups.grp_correspondants_rh,
- groups.grp_administrateurs,
- groups.grp_directeurs_bureau,
- groups.grp_drh,
- groups.grp_drh2))
+@in_one_of_group((groups.CORRESPONDANT_RH,
+ groups.ADMINISTRATEURS,
+ groups.DIRECTEUR_DE_BUREAU,
+ groups.DRH_NIVEAU_1,
+ groups.DRH_NIVEAU_2))
def organigrammes_employe(request, id, level="all"):
poste = get_object_or_404(rh.Poste, pk=id)
dossiers_by_poste = dict(
@login_required
-@in_one_of_group((groups.grp_correspondants_rh,
- groups.grp_administrateurs,
- groups.grp_directeurs_bureau,
- groups.grp_drh,
- groups.grp_drh2))
+@in_one_of_group((groups.CORRESPONDANT_RH,
+ groups.ADMINISTRATEURS,
+ groups.DIRECTEUR_DE_BUREAU,
+ groups.DRH_NIVEAU_1,
+ groups.DRH_NIVEAU_2))
def organigrammes_service(request, id):
service = get_object_or_404(rh.Service, pk=id)
svg = rh_graph.organigramme_postes_cluster( \
@login_required
-@in_one_of_group((groups.grp_correspondants_rh,
- groups.grp_administrateurs,
- groups.grp_directeurs_bureau,
- groups.grp_drh,
- groups.grp_drh2))
+@in_one_of_group((groups.CORRESPONDANT_RH,
+ groups.ADMINISTRATEURS,
+ groups.DIRECTEUR_DE_BUREAU,
+ groups.DRH_NIVEAU_1,
+ groups.DRH_NIVEAU_2))
def organigrammes_implantation(request, id):
implantation = get_object_or_404(ref.Implantation, pk=id)
svg = rh_graph.organigramme_postes_cluster( \
@login_required
-@in_one_of_group((groups.grp_correspondants_rh,
- groups.grp_administrateurs,
- groups.grp_directeurs_bureau,
- groups.grp_drh,
- groups.grp_drh2))
+@in_one_of_group((groups.CORRESPONDANT_RH,
+ groups.ADMINISTRATEURS,
+ groups.DIRECTEUR_DE_BUREAU,
+ groups.DRH_NIVEAU_1,
+ groups.DRH_NIVEAU_2))
def organigrammes_region(request, id):
region = get_object_or_404(ref.Region, pk=id)
svg = rh_graph.organigramme_postes_cluster( \