From e3762f6ce58917c5984182c78a2723eaa9548b8d Mon Sep 17 00:00:00 2001 From: Wesley B <62723358+wesleyboar@users.noreply.github.com> Date: Fri, 15 Nov 2024 17:44:47 -0600 Subject: [PATCH] =?UTF-8?q?refactor:=20consolidate=20add=5Fperm=20calls=20?= =?UTF-8?q?(=E2=9A=A0=EF=B8=8F=20untested)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../group_perms/grid_editor_advanced.py | 28 +-- .../commands/group_perms/grid_editor_basic.py | 20 +-- .../group_perms/media_editor_advanced.py | 60 ++----- .../group_perms/media_editor_basic.py | 40 ++--- .../group_perms/text_editor_advanced.py | 42 ++--- .../commands/group_perms/text_editor_basic.py | 27 ++- .../management/commands/group_perms/util.py | 165 ++++++++++++++++++ 7 files changed, 231 insertions(+), 151 deletions(-) diff --git a/taccsite_cms/management/commands/group_perms/grid_editor_advanced.py b/taccsite_cms/management/commands/group_perms/grid_editor_advanced.py index 5b3715355..a00f96e78 100644 --- a/taccsite_cms/management/commands/group_perms/grid_editor_advanced.py +++ b/taccsite_cms/management/commands/group_perms/grid_editor_advanced.py @@ -1,28 +1,16 @@ from django.contrib.auth.models import Group -from .util import add_perm +from .util import ( + let_edit_page_content, + let_view_and_change_grid, + let_add_and_delete_grid +) def set_group_perms(): group, was_created = Group.objects.get_or_create( name='Grid Editor (Advanced)' ) - add_perm(group, 'cms', 'page', 'Can change page') - add_perm(group, 'cms', 'page', 'Can view page') - - add_perm(group, 'cms', 'placeholder', 'Can use Structure mode') - - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid container', 'Can add bootstrap4 grid container') - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid container', 'Can change bootstrap4 grid container') - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid container', 'Can delete bootstrap4 grid container') - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid container', 'Can view bootstrap4 grid container') - - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid column', 'Can add bootstrap4 grid column') - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid column', 'Can change bootstrap4 grid column') - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid column', 'Can delete bootstrap4 grid column') - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid column', 'Can view bootstrap4 grid column') - - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid row', 'Can add bootstrap4 grid row') - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid row', 'Can change bootstrap4 grid row') - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid row', 'Can delete bootstrap4 grid row') - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid row', 'Can view bootstrap4 grid row') + let_edit_page_content(group) + let_view_and_change_grid(group) + let_add_and_delete_grid(group) diff --git a/taccsite_cms/management/commands/group_perms/grid_editor_basic.py b/taccsite_cms/management/commands/group_perms/grid_editor_basic.py index e27e69c0b..8eeb66380 100644 --- a/taccsite_cms/management/commands/group_perms/grid_editor_basic.py +++ b/taccsite_cms/management/commands/group_perms/grid_editor_basic.py @@ -1,22 +1,14 @@ from django.contrib.auth.models import Group -from .util import add_perm +from .util import ( + let_edit_page_content, + let_view_and_change_grid +) def set_group_perms(): group, was_created = Group.objects.get_or_create( name='Grid Editor (Basic)' ) - add_perm(group, 'cms', 'page', 'Can change page') - add_perm(group, 'cms', 'page', 'Can view page') - - add_perm(group, 'cms', 'placeholder', 'Can use Structure mode') - - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid container', 'Can change bootstrap4 grid container') - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid container', 'Can view bootstrap4 grid container') - - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid column', 'Can change bootstrap4 grid column') - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid column', 'Can view bootstrap4 grid column') - - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid row', 'Can change bootstrap4 grid row') - add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid row', 'Can view bootstrap4 grid row') + let_edit_page_content(group) + let_view_and_change_grid(group) diff --git a/taccsite_cms/management/commands/group_perms/media_editor_advanced.py b/taccsite_cms/management/commands/group_perms/media_editor_advanced.py index 77bec06dc..2f5164d84 100644 --- a/taccsite_cms/management/commands/group_perms/media_editor_advanced.py +++ b/taccsite_cms/management/commands/group_perms/media_editor_advanced.py @@ -1,54 +1,22 @@ from django.contrib.auth.models import Group -from .util import add_perm +from .util import ( + let_edit_page_content, + let_view_and_change_media_plugins, + let_add_and_delete_media_plugins, + let_view_thumbnail_option, + let_view_and_change_folder, + let_view_and_change_image_file, +) def set_group_perms(): group, was_created = Group.objects.get_or_create( name='Media Editor (Advanced)' ) - add_perm(group, 'cms', 'page', 'Can change page') - add_perm(group, 'cms', 'page', 'Can view page') - - add_perm(group, 'cms', 'placeholder', 'Can use Structure mode') - - add_perm(group, 'bootstrap4_picture', 'bootstrap4 picture', 'Can add bootstrap4 picture') - add_perm(group, 'bootstrap4_picture', 'bootstrap4 picture', 'Can change bootstrap4 picture') - add_perm(group, 'bootstrap4_picture', 'bootstrap4 picture', 'Can delete bootstrap4 picture') - add_perm(group, 'bootstrap4_picture', 'bootstrap4 picture', 'Can view bootstrap4 picture') - - add_perm(group, 'djangocms_picture', 'picture', 'Can add picture') - add_perm(group, 'djangocms_picture', 'picture', 'Can change picture') - add_perm(group, 'djangocms_picture', 'picture', 'Can delete picture') - add_perm(group, 'djangocms_picture', 'picture', 'Can view picture') - - add_perm(group, 'djangocms_video', 'video player', 'Can add video player') - add_perm(group, 'djangocms_video', 'video player', 'Can change video player') - add_perm(group, 'djangocms_video', 'video player', 'Can delete video player') - add_perm(group, 'djangocms_video', 'video player', 'Can view video player') - add_perm(group, 'djangocms_video', 'video source', 'Can add video source') - add_perm(group, 'djangocms_video', 'video source', 'Can change video source') - add_perm(group, 'djangocms_video', 'video source', 'Can delete video source') - add_perm(group, 'djangocms_video', 'video source', 'Can view video source') - add_perm(group, 'djangocms_video', 'video track', 'Can add video track') - add_perm(group, 'djangocms_video', 'video track', 'Can change video track') - add_perm(group, 'djangocms_video', 'video track', 'Can delete video track') - add_perm(group, 'djangocms_video', 'video track', 'Can view video track') - - add_perm(group, 'filer', 'Folder', 'Can add Folder') - add_perm(group, 'filer', 'Folder', 'Can change Folder') - add_perm(group, 'filer', 'Folder', 'Can view Folder') - add_perm(group, 'filer', 'Folder', 'Can delete Folder') - - add_perm(group, 'filer', 'file', 'Can add file') - add_perm(group, 'filer', 'file', 'Can change file') - add_perm(group, 'filer', 'file', 'Can view file') - add_perm(group, 'filer', 'file', 'Can delete file') - - add_perm(group, 'filer', 'Folder', 'Can use directory listing') - add_perm(group, 'filer', 'Folder', 'Can view Folder') - - add_perm(group, 'filer', 'image', 'Can change image') - add_perm(group, 'filer', 'image', 'Can view image') - - add_perm(group, 'filer', 'thumbnail option', 'Can view thumbnail option') + let_edit_page_content(group) + let_view_and_change_media_plugins(group) + let_add_and_delete_media_plugins(group) + let_view_thumbnail_option(group) + let_view_and_change_folder(group) + let_view_and_change_image_file(group) diff --git a/taccsite_cms/management/commands/group_perms/media_editor_basic.py b/taccsite_cms/management/commands/group_perms/media_editor_basic.py index 4f4239af6..47c7fa24b 100644 --- a/taccsite_cms/management/commands/group_perms/media_editor_basic.py +++ b/taccsite_cms/management/commands/group_perms/media_editor_basic.py @@ -1,36 +1,20 @@ from django.contrib.auth.models import Group -from .util import add_perm +from .util import ( + let_edit_page_content, + let_view_and_change_media_plugins, + let_view_thumbnail_option, + let_view_folder, + let_view_and_change_image_file, +) def set_group_perms(): group, was_created = Group.objects.get_or_create( name='Media Editor (Basic)' ) - add_perm(group, 'cms', 'page', 'Can change page') - - add_perm(group, 'cms', 'placeholder', 'Can use Structure mode') - - add_perm(group, 'bootstrap4_picture', 'bootstrap4 picture', 'Can change bootstrap4 picture') - add_perm(group, 'bootstrap4_picture', 'bootstrap4 picture', 'Can view bootstrap4 picture') - - add_perm(group, 'djangocms_picture', 'picture', 'Can change picture') - add_perm(group, 'djangocms_picture', 'picture', 'Can view picture') - - add_perm(group, 'djangocms_video', 'video player', 'Can change video player') - add_perm(group, 'djangocms_video', 'video player', 'Can view video player') - add_perm(group, 'djangocms_video', 'video source', 'Can change video source') - add_perm(group, 'djangocms_video', 'video source', 'Can view video source') - add_perm(group, 'djangocms_video', 'video track', 'Can change video track') - add_perm(group, 'djangocms_video', 'video track', 'Can view video track') - - add_perm(group, 'filer', 'file', 'Can change file') - add_perm(group, 'filer', 'file', 'Can view file') - - add_perm(group, 'filer', 'Folder', 'Can use directory listing') - add_perm(group, 'filer', 'Folder', 'Can view Folder') - - add_perm(group, 'filer', 'image', 'Can change image') - add_perm(group, 'filer', 'image', 'Can view image') - - add_perm(group, 'filer', 'thumbnail option', 'Can view thumbnail option') + let_edit_page_content(group) + let_view_and_change_media_plugins(group) + let_view_folder(group) + let_view_and_change_image_file(group) + let_view_thumbnail_option(group) diff --git a/taccsite_cms/management/commands/group_perms/text_editor_advanced.py b/taccsite_cms/management/commands/group_perms/text_editor_advanced.py index c12638a5b..3cc7492f6 100644 --- a/taccsite_cms/management/commands/group_perms/text_editor_advanced.py +++ b/taccsite_cms/management/commands/group_perms/text_editor_advanced.py @@ -1,34 +1,24 @@ from django.contrib.auth.models import Group -from .util import add_perm +from .util import ( + let_edit_page_content, + let_view_and_change_text, + let_add_and_delete_text, + let_view_and_change_folder, + let_add_and_delete_folder, + let_view_and_change_file, + let_add_and_delete_file, +) def set_group_perms(): group, was_created = Group.objects.get_or_create( name='Text Editor (Advanced)' ) - add_perm(group, 'cms', 'page', 'Can change page') - add_perm(group, 'cms', 'page', 'Can view page') - - add_perm(group, 'cms', 'placeholder', 'Can use Structure mode') - - add_perm(group, 'djangocms_link', 'link', 'Can add link') - add_perm(group, 'djangocms_link', 'link', 'Can change link') - add_perm(group, 'djangocms_link', 'link', 'Can delete link') - add_perm(group, 'djangocms_link', 'link', 'Can view link') - - add_perm(group, 'djangocms_text_ckeditor', 'text', 'Can add text') - add_perm(group, 'djangocms_text_ckeditor', 'text', 'Can change text') - add_perm(group, 'djangocms_text_ckeditor', 'text', 'Can delete text') - add_perm(group, 'djangocms_text_ckeditor', 'text', 'Can view text') - - add_perm(group, 'filer', 'Folder', 'Can use directory listing') - add_perm(group, 'filer', 'Folder', 'Can add Folder') - add_perm(group, 'filer', 'Folder', 'Can change Folder') - add_perm(group, 'filer', 'Folder', 'Can view Folder') - add_perm(group, 'filer', 'Folder', 'Can delete Folder') - - add_perm(group, 'filer', 'file', 'Can add file') - add_perm(group, 'filer', 'file', 'Can change file') - add_perm(group, 'filer', 'file', 'Can delete file') - add_perm(group, 'filer', 'file', 'Can view file') + let_edit_page_content(group) + let_view_and_change_text(group) + let_add_and_delete_text(group) + let_view_and_change_folder(group) + let_add_and_delete_folder(group) + let_view_and_change_file(group) + let_add_and_delete_file(group) diff --git a/taccsite_cms/management/commands/group_perms/text_editor_basic.py b/taccsite_cms/management/commands/group_perms/text_editor_basic.py index 8881c0367..89bd96d50 100644 --- a/taccsite_cms/management/commands/group_perms/text_editor_basic.py +++ b/taccsite_cms/management/commands/group_perms/text_editor_basic.py @@ -1,25 +1,18 @@ from django.contrib.auth.models import Group -from .util import add_perm +from .util import ( + let_edit_page_content, + let_view_and_change_text, + let_view_folder, + let_view_and_change_file, +) def set_group_perms(): group, was_created = Group.objects.get_or_create( name='Text Editor (Basic)' ) - add_perm(group, 'cms', 'page', 'Can change page') - - add_perm(group, 'cms', 'placeholder', 'Can use Structure mode') - - add_perm(group, 'djangocms_link', 'link', 'Can change link') - add_perm(group, 'djangocms_link', 'link', 'Can view link') - - add_perm(group, 'djangocms_text_ckeditor', 'text', 'Can change text') - add_perm(group, 'djangocms_text_ckeditor', 'text', 'Can view text') - - add_perm(group, 'filer', 'Folder', 'Can use directory listing') - add_perm(group, 'filer', 'Folder', 'Can change Folder') - add_perm(group, 'filer', 'Folder', 'Can view Folder') - - add_perm(group, 'filer', 'file', 'Can change file') - add_perm(group, 'filer', 'file', 'Can view file') + let_edit_page_content(group) + let_view_and_change_text(group) + let_view_and_change_folder(group) + let_view_and_change_file(group) diff --git a/taccsite_cms/management/commands/group_perms/util.py b/taccsite_cms/management/commands/group_perms/util.py index a3c0097cf..cb1928c43 100644 --- a/taccsite_cms/management/commands/group_perms/util.py +++ b/taccsite_cms/management/commands/group_perms/util.py @@ -21,3 +21,168 @@ def add_perm(group, app_label, model_name, perm_name): content_type=content_type ) ) + +def let_edit_page_content(group): + """ + Add permissions to edit a page + """ + add_perm(group, 'cms', 'page', 'Can view page') + add_perm(group, 'cms', 'page', 'Can change page') + + add_perm(group, 'cms', 'placeholder', 'Can use Structure mode') + +def let_view_and_change_grid(group): + """ + Add permissions to view & edit Grid plugins + """ + add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid container', 'Can view bootstrap4 grid container') + add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid container', 'Can change bootstrap4 grid container') + + add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid column', 'Can view bootstrap4 grid column') + add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid column', 'Can change bootstrap4 grid column') + + add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid row', 'Can view bootstrap4 grid row') + add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid row', 'Can change bootstrap4 grid row') + +def let_add_and_delete_grid(group): + """ + Add permissions to add & delete Grid plugins + """ + add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid container', 'Can add bootstrap4 grid container') + add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid container', 'Can delete bootstrap4 grid container') + + add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid column', 'Can add bootstrap4 grid column') + add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid column', 'Can delete bootstrap4 grid column') + + add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid row', 'Can add bootstrap4 grid row') + add_perm(group, 'bootstrap4_grid', 'bootstrap4 grid row', 'Can delete bootstrap4 grid row') + +def let_view_and_change_text(group): + """ + Add permissions to view & edit text-based plugins + """ + add_perm(group, 'djangocms_link', 'link', 'Can change link') + add_perm(group, 'djangocms_link', 'link', 'Can view link') + + add_perm(group, 'djangocms_text_ckeditor', 'text', 'Can change text') + add_perm(group, 'djangocms_text_ckeditor', 'text', 'Can view text') + +def let_add_and_delete_text(group): + """ + Add permissions to add & delete text-based plugins + """ + add_perm(group, 'djangocms_link', 'link', 'Can add link') + add_perm(group, 'djangocms_link', 'link', 'Can delete link') + + add_perm(group, 'djangocms_text_ckeditor', 'text', 'Can add text') + add_perm(group, 'djangocms_text_ckeditor', 'text', 'Can delete text') + +def let_view_and_change_media_plugins(group): + """ + Add permissions to view & edit media plugins + """ + add_perm(group, 'bootstrap4_picture', 'bootstrap4 picture', 'Can view bootstrap4 picture') + add_perm(group, 'bootstrap4_picture', 'bootstrap4 picture', 'Can change bootstrap4 picture') + + add_perm(group, 'djangocms_picture', 'picture', 'Can view picture') + add_perm(group, 'djangocms_picture', 'picture', 'Can change picture') + + add_perm(group, 'djangocms_video', 'video player', 'Can view video player') + add_perm(group, 'djangocms_video', 'video player', 'Can change video player') + + add_perm(group, 'djangocms_video', 'video source', 'Can view video source') + add_perm(group, 'djangocms_video', 'video source', 'Can change video source') + + add_perm(group, 'djangocms_video', 'video track', 'Can view video track') + add_perm(group, 'djangocms_video', 'video track', 'Can change video track') + +def let_add_and_delete_media_plugins(group): + """ + Add permissions to add & delete media plugins + """ + add_perm(group, 'bootstrap4_picture', 'bootstrap4 picture', 'Can add bootstrap4 picture') + add_perm(group, 'bootstrap4_picture', 'bootstrap4 picture', 'Can delete bootstrap4 picture') + + add_perm(group, 'djangocms_picture', 'picture', 'Can add picture') + add_perm(group, 'djangocms_picture', 'picture', 'Can delete picture') + + add_perm(group, 'djangocms_video', 'video player', 'Can add video player') + add_perm(group, 'djangocms_video', 'video player', 'Can delete video player') + + add_perm(group, 'djangocms_video', 'video source', 'Can add video source') + add_perm(group, 'djangocms_video', 'video source', 'Can delete video source') + + add_perm(group, 'djangocms_video', 'video track', 'Can add video track') + add_perm(group, 'djangocms_video', 'video track', 'Can delete video track') + +def let_view_and_change_file(group): + """ + Add permissions to view & change files and file plugins + """ + # (actual files) + add_perm(group, 'filer', 'file', 'Can change file') + add_perm(group, 'filer', 'file', 'Can view file') + # (file plugin instances) + add_perm(group, 'djangocms_file', 'file', 'Can change file') + add_perm(group, 'djangocms_file', 'file', 'Can view file') + +def let_add_and_delete_file(group): + """ + Add permissions to add & delete files + """ + # (actual files) + add_perm(group, 'filer', 'file', 'Can add file') + add_perm(group, 'filer', 'file', 'Can delete file') + # (file plugin instances) + add_perm(group, 'djangocms_file', 'file', 'Can add file') + add_perm(group, 'djangocms_file', 'file', 'Can delete file') + +def let_view_and_change_image_file(group): + """ + Add permissions to view & change image files + """ + add_perm(group, 'filer', 'image', 'Can change image') + add_perm(group, 'filer', 'image', 'Can view image') + +def let_add_and_delete_image_file(group): + """ + Add permissions to add & delete image files + """ + add_perm(group, 'filer', 'image', 'Can add image') + add_perm(group, 'filer', 'image', 'Can delete image') + # HELP: An image is a fileā€¦ Is this overkill? + add_perm(group, 'filer', 'file', 'Can add file') + add_perm(group, 'filer', 'file', 'Can delete file') + +def let_view_folder(group): + """ + Add permissions to view folders + """ + + add_perm(group, 'filer', 'Folder', 'Can use directory listing') + add_perm(group, 'filer', 'Folder', 'Can view Folder') + + add_perm(group, 'djangocms_file', 'folder', 'Can view folder') + +def let_view_and_change_folder(group): + """ + Add permissions to view & change folders + """ + + let_view_folder(group) + add_perm(group, 'filer', 'Folder', 'Can change Folder') + +def let_add_and_delete_folder(group): + """ + Add permissions to add & delete folders + """ + + add_perm(group, 'filer', 'Folder', 'Can add Folder') + add_perm(group, 'filer', 'Folder', 'Can delete Folder') + +def let_view_thumbnail_option(group): + """ + Add permissions to view thumbnail options + """ + + add_perm(group, 'filer', 'thumbnail option', 'Can view thumbnail option')