Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: better group perms mgmt #895

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions taccsite_cms/management/commands/group_perms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,22 @@ Use regex to convert the `<option>`s from HTML to Python Django CMS instructions

- Replace:

```text
```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) )
```
add_perm(group, '$1', '$2', '$3')
```

## 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
from django.contrib.auth.models import Group

def set_group_perms():
group, was_created = Group.objects.get_or_create(
name='__GROUP_NAME__'
name='__GROUP_NAME__'
)
```

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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
)

def set_group_perms():
group, was_created = Group.objects.get_or_create(
name='Grid Editor (Advanced)'
)

let_view_and_change_page_structure(group)
let_view_and_change_grid(group)
let_add_and_delete_grid(group)
14 changes: 14 additions & 0 deletions taccsite_cms/management/commands/group_perms/grid_editor_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.contrib.auth.models import Group

from .util import (
let_view_and_change_page_structure,
let_view_and_change_grid
)

def set_group_perms():
group, was_created = Group.objects.get_or_create(
name='Grid Editor (Basic)'
)

let_view_and_change_page_structure(group)
let_view_and_change_grid(group)
140 changes: 20 additions & 120 deletions taccsite_cms/management/commands/group_perms/media_editor_advanced.py
Original file line number Diff line number Diff line change
@@ -1,126 +1,26 @@
from django.contrib.auth.models import Group, Permission
from django.contrib.contenttypes.models import ContentType
from django.core.management import BaseCommand
from django.contrib.auth.models import Group

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,
)

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) )

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) )

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) )

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) )

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)
84 changes: 16 additions & 68 deletions taccsite_cms/management/commands/group_perms/media_editor_basic.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,22 @@
from django.contrib.auth.models import Group, Permission
from django.contrib.contenttypes.models import ContentType
from django.core.management import BaseCommand
from django.contrib.auth.models import Group

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,
)

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) )

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) )

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) )

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) )

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)
Loading