Commit 17a2d9a1 authored by Charlie Jacomme's avatar Charlie Jacomme

[login.py] Gestion des droits customs

Permet de choisir de mettre dans les groupes canoniques
des droits custom pour des apps précises
parent 64948596
......@@ -38,6 +38,17 @@ GROUPES_SPECIAUX = { # Dictionnaire de groupe spéciaux à attribuer selon le te
"crans_adherent": lambda u: 'aid' in u,
"crans_club": lambda u: 'cid' in u,
}
USER_TYPE = ContentType.objects.get(app_label="auth", model="user")
CRANS_MULTIMACHINES,created = Permission.objects.get_or_create(codename=u"crans_multimachines",
name=u"crans_multimachines",
content_type=USER_TYPE)
DROITS_SPECIAUX = { # Dictionnaire de groupe devant contenir les droits correspondant
"crans_cableur": [CRANS_MULTIMACHINES],
"crans_imprimeur": [CRANS_MULTIMACHINES],
"crans_apprenti": [CRANS_MULTIMACHINES],
"crans_bureau": [CRANS_MULTIMACHINES],
}
def get_or_create_cransgroup(name):
......@@ -45,11 +56,12 @@ def get_or_create_cransgroup(name):
"""
group, created = Group.objects.get_or_create(name=name)
if created:
user_type = ContentType.objects.get(app_label="auth", model="user")
permission,created = Permission.objects.get_or_create(codename=name,
name=name,
content_type=user_type)
content_type=USER_TYPE)
group.permissions.add(permission)
if name in DROITS_SPECIAUX:
group.permissions.add(*DROITS_SPECIAUX[name])
group.save()
return group
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment