Commit | Line | Data |
---|---|---|
3f5cbabe OL |
1 | |
2 | # -*- encoding: utf-8 -*- | |
3 | ||
4 | from django.db import models | |
5 | from django.db.models import Q | |
6 | from utils import get_employe_from_user | |
7 | from workflow import dae_groupes, \ | |
8 | grp_administrateurs, \ | |
9 | grp_directeurs_bureau, \ | |
10 | grp_drh, \ | |
11 | grp_drh2, \ | |
12 | grp_accior, \ | |
13 | grp_abf, \ | |
14 | grp_haute_direction, \ | |
15 | grp_service_utilisateurs, \ | |
16 | grp_correspondants_rh | |
17 | ||
18 | ||
19 | class SecurityManager(models.Manager): | |
20 | ||
21 | prefixe_service = None | |
22 | prefixe_implantation = None | |
23 | ||
24 | def ma_region_ou_service(self, user): | |
25 | """ | |
26 | Filtrage des postes en fonction du user connecté (region / service) | |
27 | On s'intéresse aussi au groupe auquel appartient le user car certains groupes | |
28 | peuvent tout voir. | |
29 | """ | |
30 | employe = get_employe_from_user(user) | |
31 | ||
32 | ############################################ | |
33 | # TRAITEMENT NORMAL | |
34 | ############################################ | |
35 | # REGION | |
36 | q = Q(**{ self.prefixe_implantation : employe.implantation.region }) | |
37 | ||
38 | # SERVICE | |
39 | if self.prefixe_service and grp_service_utilisateurs in user.groups.all(): | |
40 | q = q | Q(**{ self.prefixe_service : employe.service}) | |
41 | ||
42 | liste = self.get_query_set().filter(q) | |
43 | ||
44 | ############################################ | |
45 | # TRAITEMENT ACCIOR | |
46 | ############################################ | |
47 | if grp_accior in user.groups.all(): | |
48 | liste = self.get_query_set().all() | |
49 | ||
50 | ############################################ | |
51 | # TRAITEMENT ABF | |
52 | ############################################ | |
53 | if grp_abf in user.groups.all(): | |
54 | liste = self.get_query_set().all() | |
55 | ||
56 | ############################################ | |
57 | # TRAITEMENT HAUTE DIRECTION | |
58 | ############################################ | |
59 | if grp_haute_direction in user.groups.all(): | |
60 | liste = self.get_query_set().all() | |
61 | ||
62 | ############################################ | |
63 | # TRAITEMENT DRH | |
64 | ############################################ | |
65 | if grp_drh in user.groups.all() or grp_drh2 in user.groups.all(): | |
66 | liste = self.get_query_set().all() | |
67 | ||
9817fed5 OL |
68 | if user.is_superuser: |
69 | liste = self.get_query_set().all() | |
70 | ||
3f5cbabe OL |
71 | return liste |
72 | ||
73 | ||
74 | class PosteManager(SecurityManager): | |
75 | """ | |
76 | Chargement de tous les objets FK existants sur chaque QuerySet. | |
77 | """ | |
78 | prefixe_service = "service" | |
79 | prefixe_implantation = "implantation__region" | |
80 | ||
81 | def ma_region_ou_service(self, user): | |
82 | return super(PosteManager, self).ma_region_ou_service(user).filter(actif=True) | |
83 | ||
105dd778 OL |
84 | #def get_query_set(self): |
85 | # fkeys = ( | |
86 | # 'id_rh', | |
87 | # 'responsable', | |
88 | # 'implantation', | |
89 | # 'implantation.bureau_rattachement', | |
90 | # 'type_poste', | |
91 | # 'service', | |
92 | # 'classement_min', | |
93 | # 'classement_max', | |
94 | # 'valeur_point_min', | |
95 | # 'valeur_point_max', | |
96 | # ) | |
97 | # return super(PosteManager, self).get_query_set() \ | |
98 | # .select_related(*fkeys).all() | |
3f5cbabe OL |
99 | |
100 | ||
101 | class DossierManager(SecurityManager): | |
102 | prefixe_service = "poste__service" | |
103 | prefixe_implantation = "poste__implantation__region" | |
104 | ||
105 | def get_query_set(self): | |
106 | fkeys = ( | |
107 | 'poste', | |
108 | ) | |
109 | return super(DossierManager, self).get_query_set() \ | |
110 | .select_related(*fkeys).all() | |
111 | ||
112 | def ma_region_ou_service(self, user): | |
113 | return super(DossierManager, self).ma_region_ou_service(user).filter(poste__actif=True) | |
114 | ||
115 | ||
116 | class PosteComparaisonManager(SecurityManager): | |
117 | use_for_related_fields = True | |
118 | prefixe_implantation = "implantation__region" | |
119 | ||
120 | class DossierComparaisonManager(SecurityManager): | |
121 | use_for_related_fields = True | |
122 | prefixe_implantation = "implantation__region" |