fix for 500 error
[auf_rh_dae.git] / project / dae / permissions.py
CommitLineData
c3f0b49f
EMS
1from auf.django.permissions import allow
2
3383b2d1 3from project import groups
ede47b04 4from project.dae import models as dae
75f0e87b 5from project.dae.decorators import user_in_dae_groupes
86e4bb65 6
c3f0b49f
EMS
7
8def user_in_group(*groups):
9 def test(user, obj):
a30f55e7 10 user_groups = set([g.name for g in user.groups.all()])
c3f0b49f
EMS
11 return any(g in user_groups for g in groups)
12 return test
13
c3f0b49f 14
ede47b04
EMS
15allow(
16 'modifier_dae_numerisee',
17 dae.Dossier,
3383b2d1
OL
18 user_in_group(groups.DRH_NIVEAU_1, groups.DRH_NIVEAU_2,
19 groups.HAUTE_DIRECTION)
ede47b04
EMS
20)
21
22allow(
23 'consulter',
24 dae.Dossier,
25 lambda user, obj: (
26 user_in_dae_groupes(user) or
27 dae.Dossier.objects.ma_region_ou_service(user)
28 .filter(id=obj.id).exists()
29 )
30)