From c7c854858394b2432cf67703a8a0d7ccb25d0866 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Mon, 1 Jan 2018 02:34:12 +0100 Subject: [PATCH] =?UTF-8?q?Valeurs=20par=20d=C3=A9fault=20aux=20permission?= =?UTF-8?q?s=20par=20groupes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- users/migrations/0066_grouppermissions.py | 207 ++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 users/migrations/0066_grouppermissions.py diff --git a/users/migrations/0066_grouppermissions.py b/users/migrations/0066_grouppermissions.py new file mode 100644 index 00000000..a4f4a058 --- /dev/null +++ b/users/migrations/0066_grouppermissions.py @@ -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), + ]