Commit | Line | Data |
---|---|---|
f258e4e7 OL |
1 | # -*- encoding: utf-8 -*- |
2 | ||
3 | from django.db import models | |
4 | from django.db.models import Q | |
5 | from utils import is_user_dans_service, get_employe_from_user | |
6 | from workflow import POSTE_ETAT_HAUTE_DIRECTION, POSTE_ETAT_POLE_FINANCIER | |
7 | from workflow import dae_groupes, \ | |
8 | grp_administrateurs, \ | |
9 | grp_gestionnaires, \ | |
10 | grp_directeurs_bureau, \ | |
11 | grp_drh, \ | |
12 | grp_pole_financier, \ | |
13 | grp_haute_direction, \ | |
14 | grp_service_utilisateurs, \ | |
15 | grp_directeurs_service, \ | |
16 | grp_correspondants_rh | |
17 | ||
18 | class SecurityManager(models.Manager): | |
19 | ||
20 | prefixe_implantation = None | |
21 | ||
22 | def ma_region_ou_service(self, user): | |
23 | """ | |
24 | Filtrage des postes en fonction du user connecté (region / service) | |
25 | On s'intéresse aussi au groupe auquel appartient le user car certains groupes | |
26 | peuvent tout voir. | |
27 | """ | |
28 | ||
29 | employe = get_employe_from_user(user) | |
30 | ||
31 | ############################################ | |
32 | # TRAITEMENT NORMAL | |
33 | ############################################ | |
34 | ||
35 | # SERVICE | |
36 | if is_user_dans_service(user): | |
37 | q = Q(**{ '%s' % self.prefixe_implantation : employe.implantation }) | |
38 | # REGION | |
39 | else: | |
40 | q = Q(**{ '%s__region' % self.prefixe_implantation : employe.implantation.region }) | |
41 | liste = self.get_query_set().filter(q) | |
42 | ||
43 | ############################################ | |
44 | # TRAITEMENT POLE FINANCIER | |
45 | ############################################ | |
46 | if grp_pole_financier in user.groups.all(): | |
47 | liste = self.get_query_set().filter(etat=POSTE_ETAT_FINANCE) | |
48 | ||
49 | ############################################ | |
50 | # TRAITEMENT HAUTE DIRECTION | |
51 | ############################################ | |
52 | if grp_haute_direction in user.groups.all(): | |
53 | liste = self.get_query_set().filter(etat=POSTE_ETAT_HAUTE_DIRECTION) | |
54 | ||
55 | ############################################ | |
56 | # TRAITEMENT DRH | |
57 | ############################################ | |
58 | if grp_drh in user.groups.all(): | |
59 | liste = self.get_query_set() | |
60 | ||
61 | return liste | |
62 | ||
63 | ||
64 | class PosteManager(SecurityManager): | |
65 | """ | |
66 | Chargement de tous les objets FK existants sur chaque QuerySet. | |
67 | """ | |
68 | prefixe_implantation = "implantation" | |
69 | ||
70 | def get_query_set(self): | |
71 | fkeys = ( | |
72 | 'id_rh', | |
73 | 'responsable', | |
74 | 'implantation', | |
75 | 'type_poste', | |
76 | 'service', | |
77 | 'classement_min', | |
78 | 'classement_max', | |
79 | 'valeur_point_min', | |
80 | 'valeur_point_max', | |
81 | ) | |
82 | return super(PosteManager, self).get_query_set() \ | |
83 | .select_related(*fkeys).all() | |
84 | ||
85 | ||
86 | class DossierManager(SecurityManager): | |
87 | prefixe_implantation = "poste__implantation" | |
88 |