8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-09 03:16:25 +00:00

Valeurs par défault aux permissions par groupes

This commit is contained in:
Gabriel Detraz 2018-01-01 02:34:12 +01:00 committed by root
parent 3722eea29a
commit c7c8548583

View file

@ -0,0 +1,207 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-12-31 19:53
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('users', '0065_auto_20171231_2053'),
]
def transfer_permissions(apps, schema_editor):
permission_groups = {'bofh': ['add_ban',
'change_ban',
'delete_ban',
'view_ban',
'add_club',
'change_club',
'delete_club',
'add_user',
'change_user',
'change_user_force',
'change_user_password',
'change_user_shell',
'view_user',
'add_whitelist',
'change_whitelist',
'delete_whitelist',
'view_whitelist'],
'bureau': ['add_logentry',
'change_logentry',
'delete_logentry',
'add_group',
'change_group',
'delete_group',
'add_permission',
'change_permission',
'delete_permission',
'add_adherent',
'change_adherent',
'delete_adherent',
'add_ban',
'change_ban',
'delete_ban',
'view_ban',
'add_club',
'change_club',
'delete_club',
'add_listright',
'change_listright',
'delete_listright',
'view_listright',
'add_school',
'change_school',
'delete_school',
'view_school',
'add_user',
'change_user',
'change_user_force',
'change_user_groups',
'change_user_password',
'change_user_shell',
'change_user_state',
'delete_user',
'view_user',
'add_whitelist',
'change_whitelist',
'delete_whitelist',
'view_whitelist'],
'cableur': ['view_article',
'add_banque',
'change_banque',
'delete_banque',
'view_banque',
'add_cotisation',
'change_cotisation',
'delete_cotisation',
'view_cotisation',
'add_facture',
'can_create',
'can_delete',
'can_edit',
'can_view',
'can_view_all',
'change_facture',
'delete_facture',
'view_facture',
'view_paiement',
'add_vente',
'change_vente',
'delete_vente',
'view_vente',
'add_domain',
'change_domain',
'delete_domain',
'view_domain',
'use_all_extension',
'view_extension',
'add_interface',
'change_interface',
'delete_interface',
'view_interface',
'view_iplist',
'view_iptype',
'add_machine',
'change_machine',
'view_machine',
'view_machinetype',
'view_mx',
'view_nas',
'view_ns',
'view_ouvertureportlist',
'view_service',
'view_soa',
'view_soa',
'view_txt',
'view_vlan',
'view_assooption',
'view_generaloption',
'view_mailmessageoption',
'view_optionalmachine',
'view_optionaltopologie',
'view_optionaluser',
'view_service',
'view_constructorswitch',
'view_modelswitch',
'view_port',
'view_room',
'view_stack',
'view_switch',
'add_adherent',
'change_adherent',
'view_ban',
'add_club',
'change_club',
'view_listright',
'add_school',
'change_school',
'delete_school',
'view_school',
'view_serviceuser',
'add_user',
'change_user',
'change_user_force',
'change_user_password',
'view_user',
'add_whitelist',
'change_whitelist',
'delete_whitelist',
'view_whitelist'],
'tresorier': ['add_article',
'change_article',
'delete_article',
'view_article',
'add_banque',
'change_banque',
'delete_banque',
'view_banque',
'add_cotisation',
'change_all_cotisation',
'change_cotisation',
'delete_cotisation',
'view_cotisation',
'add_facture',
'can_change_control',
'can_change_pdf',
'can_create',
'can_delete',
'can_edit',
'can_view',
'can_view_all',
'change_all_facture',
'change_facture',
'change_facture_control',
'change_facture_pdf',
'delete_facture',
'view_facture',
'add_paiement',
'change_paiement',
'delete_paiement',
'view_paiement',
'add_vente',
'change_all_vente',
'change_vente',
'delete_vente',
'view_vente']}
rights = apps.get_model("users", "ListRight")
permissions = apps.get_model("auth", "Permission")
db_alias = schema_editor.connection.alias
for group in permission_groups:
group_object = rights.objects.using(db_alias).filter(unix_name=group).first()
if group_object:
group_object = group_object.group_ptr
for permission in permission_groups[group]:
perm = permissions.objects.using(db_alias).filter(codename=permission).first()
if perm:
group_object.permissions.add(perm)
group_object.save()
def untransfer_permissions(apps, schema_editor):
return
operations = [
migrations.RunPython(transfer_permissions, untransfer_permissions),
]