diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-03-25 17:59:58 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-03-26 10:08:14 +0100 |
commit | b3fe436d1bd499da970fbaf80ec3dc151dc80f79 (patch) | |
tree | 065ec3c572393933aaab854f206eabdbb4358bf4 | |
parent | 60843f670447b8359c633e05f0ebff3018db17bf (diff) | |
download | Ishtar-b3fe436d1bd499da970fbaf80ec3dc151dc80f79.tar.bz2 Ishtar-b3fe436d1bd499da970fbaf80ec3dc151dc80f79.zip |
🔧 default permissions for BiographicalNote
-rw-r--r-- | fixtures/initial_data-auth-fr.json | 194 | ||||
-rw-r--r-- | ishtar_common/migrations/0243_default_biographicalnote_permissions.json | 201 | ||||
-rw-r--r-- | ishtar_common/migrations/0243_default_biographicalnote_permissions.py | 32 | ||||
-rw-r--r-- | ishtar_common/utils.py | 7 |
4 files changed, 433 insertions, 1 deletions
diff --git a/fixtures/initial_data-auth-fr.json b/fixtures/initial_data-auth-fr.json index 9ef5e728a..6ae64f829 100644 --- a/fixtures/initial_data-auth-fr.json +++ b/fixtures/initial_data-auth-fr.json @@ -6388,5 +6388,197 @@ ] ] } -} +}, + { + "model": "auth.permission", + "fields": { + "name": "Can add biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "add_biographicalnote" + } + }, + { + "model": "auth.permission", + "fields": { + "name": "Can change biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "change_biographicalnote" + } + }, + { + "model": "auth.permission", + "fields": { + "name": "Can delete biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "delete_biographicalnote" + } + }, + { + "model": "auth.permission", + "fields": { + "name": "Can view biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "view_biographicalnote" + } + }, + { + "model": "auth.permission", + "fields": { + "name": "Can view own Biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "view_own_biographicalnote" + } + }, + { + "model": "auth.permission", + "fields": { + "name": "Can add own Biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "add_own_biographicalnote" + } + }, + { + "model": "auth.permission", + "fields": { + "name": "Can change own Biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "change_own_biographicalnote" + } + }, + { + "model": "auth.permission", + "fields": { + "name": "Can delete own Biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "delete_own_biographicalnote" + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques : ajout", + "permissions": [ + [ + "add_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques : lecture", + "permissions": [ + [ + "view_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques : modification", + "permissions": [ + [ + "change_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques : suppression", + "permissions": [ + [ + "delete_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques rattach\u00e9es : ajout", + "permissions": [ + [ + "add_own_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques rattach\u00e9es : lecture", + "permissions": [ + [ + "view_own_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques rattach\u00e9es : modification", + "permissions": [ + [ + "change_own_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques rattach\u00e9es : suppression", + "permissions": [ + [ + "delete_own_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + } ] diff --git a/ishtar_common/migrations/0243_default_biographicalnote_permissions.json b/ishtar_common/migrations/0243_default_biographicalnote_permissions.json new file mode 100644 index 000000000..c2144a855 --- /dev/null +++ b/ishtar_common/migrations/0243_default_biographicalnote_permissions.json @@ -0,0 +1,201 @@ +[ + { + "model": "contenttypes.contenttype", + "fields": { + "app_label": "ishtar_common", + "model": "biographicalnote" + } + }, + { + "model": "auth.permission", + "fields": { + "name": "Can add Biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "add_biographicalnote" + } + }, + { + "model": "auth.permission", + "fields": { + "name": "Can change Biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "change_biographicalnote" + } + }, + { + "model": "auth.permission", + "fields": { + "name": "Can delete Biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "delete_biographicalnote" + } + }, + { + "model": "auth.permission", + "fields": { + "name": "Can view Biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "view_biographicalnote" + } + }, + { + "model": "auth.permission", + "fields": { + "name": "Can view own Biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "view_own_biographicalnote" + } + }, + { + "model": "auth.permission", + "fields": { + "name": "Can add own Biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "add_own_biographicalnote" + } + }, + { + "model": "auth.permission", + "fields": { + "name": "Can change own Biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "change_own_biographicalnote" + } + }, + { + "model": "auth.permission", + "fields": { + "name": "Can delete own Biographical note", + "content_type": [ + "ishtar_common", + "biographicalnote" + ], + "codename": "delete_own_biographicalnote" + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques : ajout", + "permissions": [ + [ + "add_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques : lecture", + "permissions": [ + [ + "view_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques : modification", + "permissions": [ + [ + "change_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques : suppression", + "permissions": [ + [ + "delete_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques rattach\u00e9es : ajout", + "permissions": [ + [ + "add_own_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques rattach\u00e9es : lecture", + "permissions": [ + [ + "view_own_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques rattach\u00e9es : modification", + "permissions": [ + [ + "change_own_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + }, + { + "model": "auth.group", + "fields": { + "name": "Notices biographiques rattach\u00e9es : suppression", + "permissions": [ + [ + "delete_own_biographicalnote", + "ishtar_common", + "biographicalnote" + ] + ] + } + } +] diff --git a/ishtar_common/migrations/0243_default_biographicalnote_permissions.py b/ishtar_common/migrations/0243_default_biographicalnote_permissions.py new file mode 100644 index 000000000..a5399d9a8 --- /dev/null +++ b/ishtar_common/migrations/0243_default_biographicalnote_permissions.py @@ -0,0 +1,32 @@ +# Generated by Django 2.2.24 on 2024-03-25 17:24 + +from django.db import migrations +from ishtar_common.utils import migrations_load_data + +COLOR_WARNING = "\033[93m" +COLOR_ENDC = "\033[0m" + + +def load_data(apps, _): + migrations_load_data("ishtar_common", "0243_default_biographicalnote_permissions.json") + Group = apps.get_model("auth", "group") + ProfileType = apps.get_model("ishtar_common", "profiletype") + q = ProfileType.objects.filter(txt_idx="administrator") + if q.count(): + admin = q.all()[0] + for group in Group.objects.filter(name__icontains="biographique").all(): + admin.groups.add(group) + else: + print(COLOR_WARNING + "** No administrator profile found **" + COLOR_ENDC) + print(COLOR_WARNING + "** Verify biographical notes permissions in profile **" + COLOR_ENDC) + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0242_import_debug_field'), + ] + + operations = [ + migrations.RunPython(load_data) + ]
\ No newline at end of file diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 1ebb87565..d24944f8d 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -62,6 +62,7 @@ from django.core.exceptions import SuspiciousOperation, ObjectDoesNotExist, \ ValidationError from django.core.files import File from django.core.files.storage import FileSystemStorage +from django.core.management import call_command from django.core.validators import EMPTY_VALUES, MaxValueValidator from django.db import models from django.db.models import Q @@ -1485,6 +1486,12 @@ def get_columns_from_class(cls, table_cols_attr="TABLE_COLS", dict_col_labels=Tr return table_cols, table_cols_label +def migrations_load_data(module_name, migration_filename): + json_path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-2] + [ + module_name, "migrations", migration_filename]) + call_command("loaddata", json_path) + + def create_default_areas(models=None, verbose=False): # can be used on migrations if models are provided if not models: |