diff --git a/taccsite_cms/management/commands/README.md b/taccsite_cms/management/commands/README.md new file mode 100644 index 000000000..679f64f3c --- /dev/null +++ b/taccsite_cms/management/commands/README.md @@ -0,0 +1,220 @@ +# TACC CMS - Add Groups & Permissions + +- [Groups & Permissions](#groups--permissions) +- [Usage](#usage) +- [Development](#development) +- [Reference](#reference) + +## Groups & Permissions + +Every file in [`group_perms/`](./group_perms) represents a group. Each group's intended usage is described at the top of its file. Permissions are set via function calls in each file.[^1] + +## Usage + +- [Add a Permissions Group](#add-a-permissions-group) +- [Debug a Command](#debug-a-command) +- [Assign Permissions to a User](#assign-permissions-to-a-user) + +### Add a Permissions Group + +1. Open a shell into the CMS container e.g. + ```sh + docker exec -it core_cms /bin/bash + ``` +2. In the shell, run the group/permission command e.g. + ```sh + python manage.py set_group_perms news_writer_advanced grid_editor_basic + ``` +3. Open the CMS admin interface e.g. + [https://localhost:8000/admin/auth/group](https://localhost:8000/admin/auth/group) +4. Verify group permissions are as you intend. + +> **Note:** If group does not exist, this will **create** it. If group exists, this will **add** permissions to it, but will **not remove** permissions from it. + +### Debug a Command + +1. Open a shell into the CMS container e.g. + ```sh + docker exec -it core_cms /bin/bash + ``` +2. In the shell, open a Python shell i.e. + ```sh + python + ``` +3. In the Python shell, run the following commands. + ```py + import os + import django + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "taccsite_cms.settings") + django.setup() + ``` +4. Then run any additional debugging code or scripts you want to execute. + +### Assign Permissions to a User + +Add the User to one or more groups.[^1] + +> **Warning:** +> If [`CMS_PERMISSION = True`](https://docs.django-cms.org/en/3.11.8/topics/permissions.html#permission-modes) ([default for Core-CMS](https://github.com/TACC/Core-CMS/blob/v4.21.0/taccsite_cms/settings.py#L164)), then assigning one of these groups to a user is **not enough** to allow them to edit a page. You must also give that user [Global or per-page permissions](https://docs.django-cms.org/en/3.11.8/topics/permissions.html#global-and-per-page-permissions); do so [via a group](https://docs.django-cms.org/en/3.11.8/topics/permissions.html#use-permissions-on-groups-not-on-users). + +## Development + +- [Create a New Group](#create-a-new-group) +- [Create a New Permission Set](#create-a-new-permission-set) + - [via Existing Set in this Code](#via-existing-set-in-this-code) + - [via Existing Group in CMS Admin](#via-existing-group-in-cms-admin) +- [Update all CMS Instances](#update-all-cms-instances) + +### Create a New Group + +1. Duplicate an existing group. +2. Rename the file and gorup name. Rewrite file description. +3. Adjust permissions using existing sets. + +### Create a New Permission Set + +#### via Existing Set in this Code + +1. Duplicate an existing `let_*` function in [`util.py`](./util.py). +2. Rename the function. Rewrite its descritpion. +3. Assign the permission set to a relevant group. + +#### via Existing Group in CMS Admin + +##### 1. Get Permissions from HTML + +You may **either** download an appropriate `.html` from [Django CMS - Developer Guide - User Permissions / Groups / Roles](https://tacc-main.atlassian.net/wiki/x/egtv) **or**: + +1. Using the CMS admin interface, build out the permissions for a group. +2. Using the browser Developer Tools, copy the ` - ``` - -- Replace: - - ```text - - model_name = '$2'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='$1', model=model_name) - group.permissions.add( Permission.objects.get(name='$3', content_type=content_type) ) - ``` - -## Program Permissions - -1. Create a python script in this directory named after the group e.g. `news_writer_advanced.py`. -2. Add this starter code: - - ```py - from django.contrib.auth.models import Group, Permission - from django.contrib.contenttypes.models import ContentType - from django.core.management import BaseCommand - - def set_group_perms(): - group, was_created = Group.objects.get_or_create( - name='__GROUP_NAME__' - ) - ``` - -3. Change `__GROUP_NAME__` to the name of the group to add permissions for e.g. `News Writer (Advanced)`. -4. Within the `handle` method, add all the commands from the "Convert Permissions" step. - -## Set Permissions - -1. Login to the CMS admin. -2. Open a shell into the CMS container e.g. - `docker exec -it core_cms /bin/bash` -3. In the shell, run the group/permission command e.g. - `python manage.py set_group_perms news_writer_advanced` -4. Open the CMS admin interface e.g. - [https://localhost:8000/admin/auth/group](https://localhost:8000/admin/auth/group) -5. In the CMS admin, verify group permissions are as you intend. - -## Debug Command - -1. Open a shell into the CMS container e.g. `docker exec -it core_cms /bin/bash`. -2. In the shell, open a Python shell i.e. `python`. -3. In the Python shell, run the following commands. - -```py -import os -import django -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "taccsite_cms.settings") -django.setup() -# any additional debugging code or scripts you want to execute -``` - -## Reference - -- ["Next Steps" for this feature](https://github.com/TACC/Core-CMS/pull/598#issuecomment-1423258767) -- [Programmatically create a django group with permissions](https://stackoverflow.com/q/22250352/11817077) -- [Writing custom django-admin commands](https://docs.djangoproject.com/en/2.2/howto/custom-management-commands/) diff --git a/taccsite_cms/management/commands/group_perms/grid_editor_advanced.py b/taccsite_cms/management/commands/group_perms/grid_editor_advanced.py new file mode 100644 index 000000000..fd7d4bdf0 --- /dev/null +++ b/taccsite_cms/management/commands/group_perms/grid_editor_advanced.py @@ -0,0 +1,22 @@ +""" +To edit, move, add, and delete layout elements (Containers, Rows, Columns) +""" + +from django.contrib.auth.models import Group + +from ..util import ( + let_view_and_change_page_structure, + let_view_and_change_grid, + let_add_and_delete_grid +) + +GROUP_NAME = 'Grid Editor (Advanced)' + +def set_group_perms(): + group, was_created = Group.objects.get_or_create( + name=GROUP_NAME + ) + + let_view_and_change_page_structure(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 new file mode 100644 index 000000000..582167ff0 --- /dev/null +++ b/taccsite_cms/management/commands/group_perms/grid_editor_basic.py @@ -0,0 +1,20 @@ +""" +To edit and move layout elements (Containers, Rows, Columns) +""" + +from django.contrib.auth.models import Group + +from ..util import ( + let_view_and_change_page_structure, + let_view_and_change_grid +) + +GROUP_NAME = 'Grid Editor (Basic)' + +def set_group_perms(): + group, was_created = Group.objects.get_or_create( + name=GROUP_NAME + ) + + let_view_and_change_page_structure(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 3855270da..ad16e0132 100644 --- a/taccsite_cms/management/commands/group_perms/media_editor_advanced.py +++ b/taccsite_cms/management/commands/group_perms/media_editor_advanced.py @@ -1,126 +1,32 @@ -from django.contrib.auth.models import Group, Permission -from django.contrib.contenttypes.models import ContentType -from django.core.management import BaseCommand +""" +To edit, move, add, and delete images, videos, thumbnail sizes, and folders +""" -def set_group_perms(): - group, was_created = Group.objects.get_or_create( - name='Media Editor (Advanced)' - ) - - model_name = 'page'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='cms', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change page', content_type=content_type) ) - model_name = 'page'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='cms', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view page', content_type=content_type) ) - - model_name = 'placeholder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='cms', model=model_name) - group.permissions.add( Permission.objects.get(name='Can use Structure mode', content_type=content_type) ) - - model_name = 'bootstrap4 picture'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='bootstrap4_picture', model=model_name) - group.permissions.add( Permission.objects.get(name='Can add bootstrap4 picture', content_type=content_type) ) - model_name = 'bootstrap4 picture'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='bootstrap4_picture', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change bootstrap4 picture', content_type=content_type) ) - model_name = 'bootstrap4 picture'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='bootstrap4_picture', model=model_name) - group.permissions.add( Permission.objects.get(name='Can delete bootstrap4 picture', content_type=content_type) ) - model_name = 'bootstrap4 picture'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='bootstrap4_picture', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view bootstrap4 picture', content_type=content_type) ) +from django.contrib.auth.models import Group - model_name = 'picture'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_picture', model=model_name) - group.permissions.add( Permission.objects.get(name='Can add picture', content_type=content_type) ) - model_name = 'picture'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_picture', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change picture', content_type=content_type) ) - model_name = 'picture'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_picture', model=model_name) - group.permissions.add( Permission.objects.get(name='Can delete picture', content_type=content_type) ) - model_name = 'picture'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_picture', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view picture', content_type=content_type) ) +from ..util import ( + let_view_and_change_page_structure, + let_view_and_change_media_plugins, + let_add_and_delete_media_plugins, + let_view_and_change_adv_media_plugins, + let_add_and_delete_adv_media_plugins, + let_view_thumbnail_option, + let_view_and_change_folder, + let_view_and_change_image_file, +) - model_name = 'video player'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can add video player', content_type=content_type) ) - model_name = 'video player'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change video player', content_type=content_type) ) - model_name = 'video player'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can delete video player', content_type=content_type) ) - model_name = 'video player'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view video player', content_type=content_type) ) - model_name = 'video source'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can add video source', content_type=content_type) ) - model_name = 'video source'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change video source', content_type=content_type) ) - model_name = 'video source'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can delete video source', content_type=content_type) ) - model_name = 'video source'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view video source', content_type=content_type) ) - model_name = 'video track'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can add video track', content_type=content_type) ) - model_name = 'video track'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change video track', content_type=content_type) ) - model_name = 'video track'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can delete video track', content_type=content_type) ) - model_name = 'video track'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view video track', content_type=content_type) ) +GROUP_NAME = 'Media Editor (Advanced)' - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can add Folder', content_type=content_type) ) - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change Folder', content_type=content_type) ) - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view Folder', content_type=content_type) ) - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can delete Folder', content_type=content_type) ) - - model_name = 'file'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can add file', content_type=content_type) ) - model_name = 'file'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change file', content_type=content_type) ) - model_name = 'file'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view file', content_type=content_type) ) - model_name = 'file'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can delete file', content_type=content_type) ) - - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can use directory listing', content_type=content_type) ) - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view Folder', content_type=content_type) ) - - model_name = 'image'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change image', content_type=content_type) ) - model_name = 'image'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view image', content_type=content_type) ) +def set_group_perms(): + group, was_created = Group.objects.get_or_create( + name=GROUP_NAME + ) - model_name = 'thumbnail option'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view thumbnail option', content_type=content_type) ) + let_view_and_change_page_structure(group) + let_view_and_change_media_plugins(group) + let_add_and_delete_media_plugins(group) + let_view_and_change_adv_media_plugins(group) + let_add_and_delete_adv_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 470a18d06..175d27d49 100644 --- a/taccsite_cms/management/commands/group_perms/media_editor_basic.py +++ b/taccsite_cms/management/commands/group_perms/media_editor_basic.py @@ -1,74 +1,28 @@ -from django.contrib.auth.models import Group, Permission -from django.contrib.contenttypes.models import ContentType -from django.core.management import BaseCommand +""" +To edit and move images, videos, thumbnail sizes, and folders +""" -def set_group_perms(): - group, was_created = Group.objects.get_or_create( - name='Media Editor (Basic)' - ) - - model_name = 'page'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='cms', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change page', content_type=content_type) ) - - model_name = 'placeholder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='cms', model=model_name) - group.permissions.add( Permission.objects.get(name='Can use Structure mode', content_type=content_type) ) - - model_name = 'bootstrap4 picture'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='bootstrap4_picture', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change bootstrap4 picture', content_type=content_type) ) - model_name = 'bootstrap4 picture'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='bootstrap4_picture', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view bootstrap4 picture', content_type=content_type) ) +from django.contrib.auth.models import Group - model_name = 'picture'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_picture', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change picture', content_type=content_type) ) - model_name = 'picture'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_picture', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view picture', content_type=content_type) ) +from ..util import ( + let_view_and_change_page_structure, + let_view_and_change_media_plugins, + let_view_and_change_adv_media_plugins, + let_view_thumbnail_option, + let_view_folder, + let_view_and_change_image_file, +) - model_name = 'video player'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change video player', content_type=content_type) ) - model_name = 'video player'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view video player', content_type=content_type) ) - model_name = 'video source'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change video source', content_type=content_type) ) - model_name = 'video source'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view video source', content_type=content_type) ) - model_name = 'video track'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change video track', content_type=content_type) ) - model_name = 'video track'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_video', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view video track', content_type=content_type) ) +GROUP_NAME = 'Media Editor (Basic)' - model_name = 'file'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change file', content_type=content_type) ) - model_name = 'file'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view file', content_type=content_type) ) - - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can use directory listing', content_type=content_type) ) - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view Folder', content_type=content_type) ) - - model_name = 'image'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change image', content_type=content_type) ) - model_name = 'image'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view image', content_type=content_type) ) +def set_group_perms(): + group, was_created = Group.objects.get_or_create( + name=GROUP_NAME + ) - model_name = 'thumbnail option'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view thumbnail option', content_type=content_type) ) + let_view_and_change_page_structure(group) + let_view_and_change_media_plugins(group) + let_view_and_change_adv_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/news_writer_advanced.py b/taccsite_cms/management/commands/group_perms/news_writer_advanced.py index 931dc8f5d..2e0234a69 100644 --- a/taccsite_cms/management/commands/group_perms/news_writer_advanced.py +++ b/taccsite_cms/management/commands/group_perms/news_writer_advanced.py @@ -1,53 +1,63 @@ -from django.contrib.auth.models import Group, Permission -from django.core.management import BaseCommand +""" +To edit and add Blog articles +To edit, add, and delete Blockquotes +To edit, assign, add, and delete news Categories and Tags +""" + +from django.contrib.auth.models import Group + +from ..util import ( + add_perm, + let_view_and_change_page_structure, + let_view_and_change_plugin, + let_view_and_change_text, + let_add_and_delete_text, + let_view_and_change_media_plugins, + let_add_and_delete_media_plugins, + let_view_and_change_image_file, +) + +GROUP_NAME = 'News Writer (Advanced)' def set_group_perms(): group, was_created = Group.objects.get_or_create( - name='News Writer (Advanced)' + name=GROUP_NAME ) - group.permissions.add( Permission.objects.get(name='Can add bootstrap4 blockquote') ) - group.permissions.add( Permission.objects.get(name='Can change bootstrap4 blockquote') ) - group.permissions.add( Permission.objects.get(name='Can delete bootstrap4 blockquote') ) - group.permissions.add( Permission.objects.get(name='Can view bootstrap4 blockquote') ) - group.permissions.add( Permission.objects.get(name='Can add bootstrap4 picture') ) - group.permissions.add( Permission.objects.get(name='Can change bootstrap4 picture') ) - group.permissions.add( Permission.objects.get(name='Can delete bootstrap4 picture') ) - group.permissions.add( Permission.objects.get(name='Can view bootstrap4 picture') ) - group.permissions.add( Permission.objects.get(name='Can change cms plugin') ) - group.permissions.add( Permission.objects.get(name='Can view cms plugin') ) - group.permissions.add( Permission.objects.get(name='Can add cms plugin') ) - group.permissions.add( Permission.objects.get(name='Can delete cms plugin') ) - group.permissions.add( Permission.objects.get(name='Can change page') ) - group.permissions.add( Permission.objects.get(name='Can view page') ) - group.permissions.add( Permission.objects.get(name='Can use Structure mode') ) - group.permissions.add( Permission.objects.get(name='Can add blog category') ) - group.permissions.add( Permission.objects.get(name='Can change blog category') ) - group.permissions.add( Permission.objects.get(name='Can delete blog category') ) - group.permissions.add( Permission.objects.get(name='Can view blog category') ) - group.permissions.add( Permission.objects.get(name='Can add blog article') ) - group.permissions.add( Permission.objects.get(name='Can change blog article') ) - group.permissions.add( Permission.objects.get(name='Can view blog article') ) - group.permissions.add( Permission.objects.get(name='Can add link') ) - group.permissions.add( Permission.objects.get(name='Can change link') ) - group.permissions.add( Permission.objects.get(name='Can delete link') ) - group.permissions.add( Permission.objects.get(name='Can view link') ) - group.permissions.add( Permission.objects.get(name='Can add text') ) - group.permissions.add( Permission.objects.get(name='Can change text') ) - group.permissions.add( Permission.objects.get(name='Can delete text') ) - group.permissions.add( Permission.objects.get(name='Can view text') ) - group.permissions.add( Permission.objects.get(name='Can add video player') ) - group.permissions.add( Permission.objects.get(name='Can change video player') ) - group.permissions.add( Permission.objects.get(name='Can delete video player') ) - group.permissions.add( Permission.objects.get(name='Can view video player') ) - group.permissions.add( Permission.objects.get(name='Can add image') ) - group.permissions.add( Permission.objects.get(name='Can change image') ) - group.permissions.add( Permission.objects.get(name='Can view image') ) - group.permissions.add( Permission.objects.get(name='Can add tag') ) - group.permissions.add( Permission.objects.get(name='Can change tag') ) - group.permissions.add( Permission.objects.get(name='Can delete tag') ) - group.permissions.add( Permission.objects.get(name='Can view tag') ) - group.permissions.add( Permission.objects.get(name='Can add tagged item') ) - group.permissions.add( Permission.objects.get(name='Can change tagged item') ) - group.permissions.add( Permission.objects.get(name='Can delete tagged item') ) - group.permissions.add( Permission.objects.get(name='Can view tagged item') ) + let_view_and_change_page_structure(group) + let_view_and_change_plugin(group) + + let_view_and_change_text(group) + let_add_and_delete_text(group) + # NOTE: Consider adding these to `let…text` functions + add_perm(group, 'bootstrap4_content', 'bootstrap4 blockquote', 'Can add bootstrap4 blockquote') + add_perm(group, 'bootstrap4_content', 'bootstrap4 blockquote', 'Can change bootstrap4 blockquote') + add_perm(group, 'bootstrap4_content', 'bootstrap4 blockquote', 'Can delete bootstrap4 blockquote') + add_perm(group, 'bootstrap4_content', 'bootstrap4 blockquote', 'Can view bootstrap4 blockquote') + + let_view_and_change_media_plugins(group) + let_add_and_delete_media_plugins(group) + + let_view_and_change_image_file(group) + add_perm(group, 'filer', 'image', 'Can add image') + + # Add permissions to view & change & add articles + add_perm(group, None, None, 'Can view blog article') + add_perm(group, None, None, 'Can change blog article') + add_perm(group, None, None, 'Can add blog article') + + # Add permissions to manage categories + add_perm(group, None, None, 'Can add blog category') + add_perm(group, None, None, 'Can change blog category') + add_perm(group, None, None, 'Can delete blog category') + add_perm(group, None, None, 'Can view blog category') + + # Add permissions to manage tags & tagged items (e.g. articles) + add_perm(group, 'taggit', 'tag', 'Can add tag') + add_perm(group, 'taggit', 'tag', 'Can change tag') + add_perm(group, 'taggit', 'tag', 'Can delete tag') + add_perm(group, 'taggit', 'tag', 'Can view tag') + add_perm(group, 'taggit', 'tagged item', 'Can add tagged item') + add_perm(group, 'taggit', 'tagged item', 'Can change tagged item') + add_perm(group, 'taggit', 'tagged item', 'Can delete tagged item') + add_perm(group, 'taggit', 'tagged item', 'Can view tagged item') diff --git a/taccsite_cms/management/commands/group_perms/news_writer_basic.py b/taccsite_cms/management/commands/group_perms/news_writer_basic.py index b5924611d..fc91cbbf1 100644 --- a/taccsite_cms/management/commands/group_perms/news_writer_basic.py +++ b/taccsite_cms/management/commands/group_perms/news_writer_basic.py @@ -1,35 +1,40 @@ -from django.contrib.auth.models import Group, Permission -from django.core.management import BaseCommand +""" +To edit and add Blog articles +""" + +from django.contrib.auth.models import Group + +from ..util import ( + add_perm, + let_view_and_change_page_structure, + let_view_and_change_plugin, + let_view_and_change_text, + let_add_and_delete_text, + let_view_and_change_media_plugins, + let_add_and_delete_media_plugins, + let_view_and_change_image_file, +) + +GROUP_NAME = 'News Writer (Basic)' def set_group_perms(): group, was_created = Group.objects.get_or_create( - name='News Writer (Basic)' + name=GROUP_NAME ) - group.permissions.add( Permission.objects.get(name='Can add bootstrap4 picture') ) - group.permissions.add( Permission.objects.get(name='Can change bootstrap4 picture') ) - group.permissions.add( Permission.objects.get(name='Can delete bootstrap4 picture') ) - group.permissions.add( Permission.objects.get(name='Can view bootstrap4 picture') ) - group.permissions.add( Permission.objects.get(name='Can change cms plugin') ) - group.permissions.add( Permission.objects.get(name='Can view cms plugin') ) - group.permissions.add( Permission.objects.get(name='Can change page') ) - group.permissions.add( Permission.objects.get(name='Can view page') ) - group.permissions.add( Permission.objects.get(name='Can use Structure mode') ) - group.permissions.add( Permission.objects.get(name='Can add blog article') ) - group.permissions.add( Permission.objects.get(name='Can change blog article') ) - group.permissions.add( Permission.objects.get(name='Can view blog article') ) - group.permissions.add( Permission.objects.get(name='Can add link') ) - group.permissions.add( Permission.objects.get(name='Can change link') ) - group.permissions.add( Permission.objects.get(name='Can delete link') ) - group.permissions.add( Permission.objects.get(name='Can view link') ) - group.permissions.add( Permission.objects.get(name='Can add text') ) - group.permissions.add( Permission.objects.get(name='Can change text') ) - group.permissions.add( Permission.objects.get(name='Can delete text') ) - group.permissions.add( Permission.objects.get(name='Can view text') ) - group.permissions.add( Permission.objects.get(name='Can add video player') ) - group.permissions.add( Permission.objects.get(name='Can change video player') ) - group.permissions.add( Permission.objects.get(name='Can delete video player') ) - group.permissions.add( Permission.objects.get(name='Can view video player') ) - group.permissions.add( Permission.objects.get(name='Can add image') ) - group.permissions.add( Permission.objects.get(name='Can change image') ) - group.permissions.add( Permission.objects.get(name='Can view image') ) + let_view_and_change_page_structure(group) + let_view_and_change_plugin(group) + + let_view_and_change_text(group) + let_add_and_delete_text(group) + + let_view_and_change_media_plugins(group) + let_add_and_delete_media_plugins(group) + + let_view_and_change_image_file(group) + add_perm(group, 'filer', 'image', 'Can add image') + + # Add permissions to view & change & add articles + add_perm(group, None, None, 'Can view blog article') + add_perm(group, None, None, 'Can change blog article') + add_perm(group, None, None, 'Can add blog article') 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 59103cec8..3b1f21d31 100644 --- a/taccsite_cms/management/commands/group_perms/text_editor_advanced.py +++ b/taccsite_cms/management/commands/group_perms/text_editor_advanced.py @@ -1,74 +1,30 @@ -from django.contrib.auth.models import Group, Permission -from django.contrib.contenttypes.models import ContentType -from django.core.management import BaseCommand +""" +To edit, move, add, and delete textual elements, folders, and files +""" -def set_group_perms(): - group, was_created = Group.objects.get_or_create( - name='Text Editor (Advanced)' - ) - - model_name = 'page'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='cms', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change page', content_type=content_type) ) - model_name = 'page'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='cms', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view page', content_type=content_type) ) +from django.contrib.auth.models import Group - model_name = 'placeholder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='cms', model=model_name) - group.permissions.add( Permission.objects.get(name='Can use Structure mode', content_type=content_type) ) +from ..util import ( + let_view_and_change_page_structure, + 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, +) - model_name = 'link'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_link', model=model_name) - group.permissions.add( Permission.objects.get(name='Can add link', content_type=content_type) ) - model_name = 'link'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_link', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change link', content_type=content_type) ) - model_name = 'link'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_link', model=model_name) - group.permissions.add( Permission.objects.get(name='Can delete link', content_type=content_type) ) - model_name = 'link'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_link', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view link', content_type=content_type) ) +GROUP_NAME = 'Text Editor (Advanced)' - model_name = 'text'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_text_ckeditor', model=model_name) - group.permissions.add( Permission.objects.get(name='Can add text', content_type=content_type) ) - model_name = 'text'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_text_ckeditor', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change text', content_type=content_type) ) - model_name = 'text'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_text_ckeditor', model=model_name) - group.permissions.add( Permission.objects.get(name='Can delete text', content_type=content_type) ) - model_name = 'text'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_text_ckeditor', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view text', content_type=content_type) ) - - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can use directory listing', content_type=content_type) ) - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can add Folder', content_type=content_type) ) - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change Folder', content_type=content_type) ) - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view Folder', content_type=content_type) ) - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can delete Folder', content_type=content_type) ) +def set_group_perms(): + group, was_created = Group.objects.get_or_create( + name=GROUP_NAME + ) - model_name = 'file'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can add file', content_type=content_type) ) - model_name = 'file'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change file', content_type=content_type) ) - model_name = 'file'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can delete file', content_type=content_type) ) - model_name = 'file'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view file', content_type=content_type) ) + let_view_and_change_page_structure(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 576b98566..33e551ccc 100644 --- a/taccsite_cms/management/commands/group_perms/text_editor_basic.py +++ b/taccsite_cms/management/commands/group_perms/text_editor_basic.py @@ -1,47 +1,24 @@ -from django.contrib.auth.models import Group, Permission -from django.contrib.contenttypes.models import ContentType -from django.core.management import BaseCommand +""" +To edit and move textual elements blocks, folders, and files +""" -def set_group_perms(): - group, was_created = Group.objects.get_or_create( - name='Text Editor (Basic)' - ) - - model_name = 'page'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='cms', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change page', content_type=content_type) ) +from django.contrib.auth.models import Group - model_name = 'placeholder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='cms', model=model_name) - group.permissions.add( Permission.objects.get(name='Can use Structure mode', content_type=content_type) ) +from ..util import ( + let_view_and_change_page_structure, + let_view_and_change_text, + let_view_and_change_folder, + let_view_and_change_file, +) - model_name = 'link'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_link', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change link', content_type=content_type) ) - model_name = 'link'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_link', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view link', content_type=content_type) ) +GROUP_NAME = 'Text Editor (Basic)' - model_name = 'text'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_text_ckeditor', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change text', content_type=content_type) ) - model_name = 'text'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='djangocms_text_ckeditor', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view text', content_type=content_type) ) - - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can use directory listing', content_type=content_type) ) - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change Folder', content_type=content_type) ) - model_name = 'Folder'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view Folder', content_type=content_type) ) +def set_group_perms(): + group, was_created = Group.objects.get_or_create( + name=GROUP_NAME + ) - model_name = 'file'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can change file', content_type=content_type) ) - model_name = 'file'.lower().replace(' ', '') - content_type = ContentType.objects.get(app_label='filer', model=model_name) - group.permissions.add( Permission.objects.get(name='Can view file', content_type=content_type) ) + let_view_and_change_page_structure(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/set_group_perms.py b/taccsite_cms/management/commands/set_group_perms.py index c767db0a3..28fe4097f 100644 --- a/taccsite_cms/management/commands/set_group_perms.py +++ b/taccsite_cms/management/commands/set_group_perms.py @@ -2,7 +2,6 @@ import logging import importlib -from django.contrib.auth.models import Group, Permission from django.core.management import BaseCommand logger = logging.getLogger(__name__) diff --git a/taccsite_cms/management/commands/util.py b/taccsite_cms/management/commands/util.py new file mode 100644 index 000000000..f5bb831b7 --- /dev/null +++ b/taccsite_cms/management/commands/util.py @@ -0,0 +1,240 @@ +import logging + +from django.core.management import BaseCommand +from django.contrib.auth.models import Permission +from django.contrib.contenttypes.models import ContentType + +logger = logging.getLogger(__name__) + +def add_perm(group, app_label, model_name, perm_name): + """ + Add specific permission to a given group + + This can often be done with just the permission name e.g. — + `group.permissions.add( Permission.objects.get( name='…' ) )` + — but providing app and model ensure no conflict. + """ + logger.debug(f'Adding permission ({app_label}.{model_name}) "{perm_name}"') + + if app_label and model_name: + model = model_name.lower().replace(' ', '') + content_type = ContentType.objects.get( + app_label=app_label, + model=model + ) + group.permissions.add( + Permission.objects.get( + name=perm_name, + content_type=content_type + ) + ) + else: + group.permissions.add( Permission.objects.get( name=perm_name )) + + + +# Page +def let_view_and_change_page_structure(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') + # HELP: Not necessary on TACC (as of Core-CMS v4.17.1) + # Is necessary on WTCS (as of Core-CMS v4.20.2) + add_perm(group, 'cms', 'static placeholder', 'Can change static placeholder') + + + +# Plugin +# HELP: What does this do? Does plugin-specific permission make this moot? +def let_view_and_change_plugin(group): + """ + Add permissions to view & change ??? plugins + """ + add_perm(group, 'cms', 'cms plugin', 'Can view cms plugin') + add_perm(group, 'cms', 'cms plugin', 'Can change cms plugin') + + + +# Grid +def let_view_and_change_grid(group): + """ + Add permissions to view & change 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') + + + +# Text +def let_view_and_change_text(group): + """ + Add permissions to view & change 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') + + + +# Media +def let_view_and_change_media_plugins(group): + """ + Add permissions to view & change 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') + +def let_view_and_change_adv_media_plugins(group): + """ + Add permissions to view & change advanced media plugins + """ + 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') + +def let_add_and_delete_adv_media_plugins(group): + """ + Add permissions to add & delete advanced media plugins + """ + 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') + + + +# Files +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') + + + +# Folders +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') + + + +# Miscellaneous +def let_view_thumbnail_option(group): + """ + Add permissions to view thumbnail options + """ + + add_perm(group, 'filer', 'thumbnail option', 'Can view thumbnail option') diff --git a/taccsite_cms/migrations/0001_add_groups.py b/taccsite_cms/migrations/0001_add_groups.py new file mode 100644 index 000000000..94ef39471 --- /dev/null +++ b/taccsite_cms/migrations/0001_add_groups.py @@ -0,0 +1,42 @@ +from django.db import migrations + +def add_groups(apps, schema_editor): + from taccsite_cms.management.commands.group_perms.text_editor_basic import set_group_perms as add_text_editor_basic + from taccsite_cms.management.commands.group_perms.text_editor_advanced import set_group_perms as add_text_editor_advanced + from taccsite_cms.management.commands.group_perms.media_editor_basic import set_group_perms as add_media_editor_basic + from taccsite_cms.management.commands.group_perms.media_editor_advanced import set_group_perms as add_media_editor_advanced + from taccsite_cms.management.commands.group_perms.grid_editor_basic import set_group_perms as add_grid_editor_basic + from taccsite_cms.management.commands.group_perms.grid_editor_advanced import set_group_perms as add_grid_editor_advanced + + add_text_editor_basic() + add_text_editor_advanced() + add_media_editor_basic() + add_media_editor_advanced() + add_grid_editor_basic() + add_grid_editor_advanced() + +def remove_groups(apps, schema_editor): + from taccsite_cms.management.commands.group_perms.text_editor_basic import GROUP_NAME as text_editor_basic_name + from taccsite_cms.management.commands.group_perms.text_editor_advanced import GROUP_NAME as text_editor_advanced_name + from taccsite_cms.management.commands.group_perms.media_editor_basic import GROUP_NAME as media_editor_basic_name + from taccsite_cms.management.commands.group_perms.media_editor_advanced import GROUP_NAME as media_editor_advanced_name + from taccsite_cms.management.commands.group_perms.grid_editor_basic import GROUP_NAME as grid_editor_basic_name + from taccsite_cms.management.commands.group_perms.grid_editor_advanced import GROUP_NAME as grid_editor_advanced_name + + Group = apps.get_model('auth', 'Group') + + group_names = [ + text_editor_basic_name, + text_editor_advanced_name, + media_editor_basic_name, + media_editor_advanced_name, + grid_editor_basic_name, + grid_editor_advanced_name, + ] + + Group.objects.filter(name__in=group_names).delete() + +class Migration(migrations.Migration): + operations = [ + migrations.RunPython(add_groups, reverse_code=remove_groups), + ] diff --git a/taccsite_cms/migrations/README.md b/taccsite_cms/migrations/README.md new file mode 100644 index 000000000..de13c8599 --- /dev/null +++ b/taccsite_cms/migrations/README.md @@ -0,0 +1,7 @@ +# TACC CMS - Migrations + +These allow us to perform programmatic actions, and successive adjustments, in sequence, for all instances of a Core-CMS. + +## Reference + +- [Mastering Django Migrations: A Comprehensive Guide for Efficient Database Management](https://medium.com/django-unleashed/mastering-django-migrations-a-comprehensive-guide-for-efficient-database-management-f2fc219f9a20) diff --git a/taccsite_cms/migrations/__init__.py b/taccsite_cms/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb