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