From 2368d17bed1813b958b97f173426ed35acdf1afc Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 22 Nov 2018 22:39:27 +0100 Subject: Sheet: fix treatment file edit --- archaeological_finds/ishtar_menu.py | 16 +++--- archaeological_finds/models_treatments.py | 16 ++---- fixtures/initial_data-auth-fr.json | 65 ++++++---------------- .../0076_migrate_treatmentfile_permissions.py | 34 +++++++++++ 4 files changed, 63 insertions(+), 68 deletions(-) create mode 100644 ishtar_common/migrations/0076_migrate_treatmentfile_permissions.py diff --git a/archaeological_finds/ishtar_menu.py b/archaeological_finds/ishtar_menu.py index 2f37f4c4b..cf903e2f5 100644 --- a/archaeological_finds/ishtar_menu.py +++ b/archaeological_finds/ishtar_menu.py @@ -99,23 +99,23 @@ MENU_SECTIONS = [ MenuItem('treatmentfle_search', _(u"Search"), model=models.TreatmentFile, - access_controls=['view_filetreatment', - 'view_own_filetreatment']), + access_controls=['view_treatmentfile', + 'view_own_treatmentfile']), MenuItem('treatmentfle_creation', _(u"Creation"), model=models.TreatmentFile, - access_controls=['change_filetreatment', - 'change_own_filetreatment']), + access_controls=['change_treatmentfile', + 'change_own_treatmentfile']), MenuItem('treatmentfle_modification', _(u"Modification"), model=models.TreatmentFile, - access_controls=['change_filetreatment', - 'change_own_filetreatment']), + access_controls=['change_treatmentfile', + 'change_own_treatmentfile']), MenuItem('treatmentfle_deletion', _(u"Deletion"), model=models.TreatmentFile, - access_controls=['change_filetreatment', - 'change_own_filetreatment']), + access_controls=['change_treatmentfile', + 'change_own_treatmentfile']), SectionItem( 'admin_act_fletreatments', _(u"Administrative act"), childs=[ diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index bc5eace58..a902741a3 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -782,21 +782,15 @@ class TreatmentFile(DashboardFormItem, ClosedItem, BaseHistorizedItem, verbose_name_plural = _(u"Treatment requests") unique_together = ('year', 'index') permissions = ( - ("view_filetreatment", + ("view_treatmentfile", u"Can view all Treatment requests"), - ("add_filetreatment", - u"Can add Treatment request"), - ("change_filetreatment", - u"Can change Treatment request"), - ("delete_filetreatment", - u"Can delete Treatment request"), - ("view_own_filetreatment", + ("view_own_treatmentfile", u"Can view own Treatment request"), - ("add_own_filetreatment", + ("add_own_treatmentfile", u"Can add own Treatment request"), - ("change_own_filetreatment", + ("change_own_treatmentfile", u"Can change own Treatment request"), - ("delete_own_filetreatment", + ("delete_own_treatmentfile", u"Can delete own Treatment request"), ) ordering = ('cached_label',) diff --git a/fixtures/initial_data-auth-fr.json b/fixtures/initial_data-auth-fr.json index feecf1e8a..64fbd8051 100644 --- a/fixtures/initial_data-auth-fr.json +++ b/fixtures/initial_data-auth-fr.json @@ -3849,39 +3849,6 @@ "codename": "delete_historicaltreatmentfile" } }, -{ - "model": "auth.permission", - "fields": { - "name": "Can add Treatment file", - "content_type": [ - "archaeological_finds", - "treatmentfile" - ], - "codename": "add_treatmentfile" - } -}, -{ - "model": "auth.permission", - "fields": { - "name": "Can change Treatment file", - "content_type": [ - "archaeological_finds", - "treatmentfile" - ], - "codename": "change_treatmentfile" - } -}, -{ - "model": "auth.permission", - "fields": { - "name": "Can delete Treatment file", - "content_type": [ - "archaeological_finds", - "treatmentfile" - ], - "codename": "delete_treatmentfile" - } -}, { "model": "auth.permission", "fields": { @@ -4121,7 +4088,7 @@ "archaeological_finds", "treatmentfile" ], - "codename": "view_filetreatment" + "codename": "view_treatmentfile" } }, { @@ -4132,7 +4099,7 @@ "archaeological_finds", "treatmentfile" ], - "codename": "view_own_filetreatment" + "codename": "view_own_treatmentfile" } }, { @@ -4143,7 +4110,7 @@ "archaeological_finds", "treatmentfile" ], - "codename": "add_own_filetreatment" + "codename": "add_own_treatmentfile" } }, { @@ -4154,7 +4121,7 @@ "archaeological_finds", "treatmentfile" ], - "codename": "change_own_filetreatment" + "codename": "change_own_treatmentfile" } }, { @@ -4165,7 +4132,7 @@ "archaeological_finds", "treatmentfile" ], - "codename": "delete_own_filetreatment" + "codename": "delete_own_treatmentfile" } }, { @@ -4308,7 +4275,7 @@ "archaeological_finds", "treatmentfile" ], - "codename": "add_filetreatment" + "codename": "add_treatmentfile" } }, { @@ -4319,7 +4286,7 @@ "archaeological_finds", "treatmentfile" ], - "codename": "change_filetreatment" + "codename": "change_treatmentfile" } }, { @@ -4330,7 +4297,7 @@ "archaeological_finds", "treatmentfile" ], - "codename": "delete_filetreatment" + "codename": "delete_treatmentfile" } }, { @@ -5935,7 +5902,7 @@ "name": "Demandes de traitement : ajout", "permissions": [ [ - "add_filetreatment", + "add_treatmentfile", "archaeological_finds", "treatmentfile" ] @@ -5948,12 +5915,12 @@ "name": "Demandes de traitement : modification/suppression", "permissions": [ [ - "change_filetreatment", + "change_treatmentfile", "archaeological_finds", "treatmentfile" ], [ - "delete_filetreatment", + "delete_treatmentfile", "archaeological_finds", "treatmentfile" ] @@ -5966,7 +5933,7 @@ "name": "Demandes de traitement : lecture", "permissions": [ [ - "view_filetreatment", + "view_treatmentfile", "archaeological_finds", "treatmentfile" ] @@ -5979,7 +5946,7 @@ "name": "Demandes de traitement rattach\u00e9es : ajout", "permissions": [ [ - "add_own_filetreatment", + "add_own_treatmentfile", "archaeological_finds", "treatmentfile" ] @@ -5992,7 +5959,7 @@ "name": "Demandes de traitement rattach\u00e9es : lecture", "permissions": [ [ - "view_own_filetreatment", + "view_own_treatmentfile", "archaeological_finds", "treatmentfile" ] @@ -6005,12 +5972,12 @@ "name": "Demandes de traitement rattach\u00e9es : modification/suppression", "permissions": [ [ - "change_own_filetreatment", + "change_own_treatmentfile", "archaeological_finds", "treatmentfile" ], [ - "delete_own_filetreatment", + "delete_own_treatmentfile", "archaeological_finds", "treatmentfile" ] diff --git a/ishtar_common/migrations/0076_migrate_treatmentfile_permissions.py b/ishtar_common/migrations/0076_migrate_treatmentfile_permissions.py new file mode 100644 index 000000000..0defa4efe --- /dev/null +++ b/ishtar_common/migrations/0076_migrate_treatmentfile_permissions.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-11-22 22:17 +from __future__ import unicode_literals + +from django.db import migrations + + +def migrate_perm(apps, schema_editor): + Permission = apps.get_model('auth', 'Permission') + Group = apps.get_model('auth', 'Group') + for perm in Permission.objects.filter( + codename__icontains='filetreatment').exclude( + codename__icontains='source').all(): + new_codename = perm.codename.replace('filetreatment', 'treatmentfile') + q = Permission.objects.filter( + codename=new_codename).exclude(pk=perm.pk) + if q.count(): + for gp in Group.objects.filter(permissions=q.all()[0]): + gp.permissions.add(perm) + q.all()[0].delete() + print(new_codename) + perm.codename = new_codename + perm.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0075_auto_20181108_1908'), + ] + + operations = [ + migrations.RunPython(migrate_perm) + ] -- cgit v1.2.3