Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/0.1.20' into main
- Loading branch information
Showing
6 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
__version__ = '0.1.19' | ||
__version__ = '0.1.20' | ||
__author__ = 'benzkji' |
114 changes: 114 additions & 0 deletions
114
djangocms_misc/basic/management/commands/djangocms_misc_add_cms_group.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import logging | ||
import os | ||
import shutil | ||
|
||
from django.contrib.auth.models import Group, Permission | ||
from django.core.management.base import BaseCommand | ||
from django.db.models import Q | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
""" | ||
help = ( | ||
"Add an auth.Group that gives basic CMS Permissions. User --plugin or --cms to add additional perms." | ||
"") | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
'--cms-base', | ||
required=False, | ||
action='store_const', | ||
const=True, | ||
default=False, | ||
help="Basic CMS permissions (edit and publish pages, etc).") | ||
parser.add_argument( | ||
'--cms-publish', | ||
required=False, | ||
action='store_const', | ||
const=True, | ||
default=False, | ||
help="adds exactly 'can publish page' permission)." | ||
"") | ||
parser.add_argument( | ||
'--cms-superuser', | ||
required=False, | ||
action='store_const', | ||
const=True, | ||
default=False, | ||
help="Superuser CMS permissions (add own users, page permissions, etc, etc)." | ||
"") | ||
parser.add_argument( | ||
'--plugin', | ||
required=False, | ||
action='store_const', | ||
const=True, | ||
default=False, | ||
help=""" | ||
Searches for permissions with 'plugin' in their content type's app_label (ex.: cmsplugin_googlemaps), adds to group.""") | ||
parser.add_argument( | ||
'--cms', | ||
action='store_const', | ||
const=True, | ||
default=False, | ||
required=False, | ||
help=""" | ||
Searches for permissions with 'cms' in their content type's app_label (ex.:djangocms_text_ckeditor), adds to group.""") | ||
parser.add_argument( | ||
'--name', | ||
required=False, | ||
default='cms_base', | ||
help=""" | ||
Name of group. Defaults to cms_base.""") | ||
parser.add_argument( | ||
'--force', | ||
action='store_const', | ||
const=True, | ||
required=False, | ||
help=""" | ||
Force overwrite of existing group and it's permissions.""") | ||
|
||
def handle(self, *args, **options): | ||
group_name = options.get('name') | ||
# copy | ||
groups = Group.objects.filter(name=group_name) | ||
if groups.count(): | ||
if not options.get('force', None): | ||
exit("use --force to overwrite existing groups!") | ||
if groups.count() > 1: | ||
exit("more than one group with name that name ({}) found! exiting.".format(group_name)) | ||
group = groups.first() | ||
else: | ||
group = Group.objects.create(name=group_name) | ||
|
||
group.permissions.clear() | ||
if options.get('cms_base'): | ||
q_filter = Q(content_type__app_label='cms') | ||
q_exclude = Q(name__icontains='user') | ||
q_exclude |= Q(name__icontains='permission') | ||
q_exclude |= Q(name__icontains='publish') | ||
self.add_permission(group, q_filter, q_exclude) | ||
if options.get('cms_publish'): | ||
q_filter = Q(content_type__app_label='cms') | ||
q_filter &= Q(name__icontains='publish') | ||
self.add_permission(group, q_filter) | ||
if options.get('cms_superuser'): | ||
q_filter = Q(content_type__app_label='cms') | ||
self.add_permission(group, q_filter) | ||
if options.get('cms'): | ||
q_filter = Q(content_type__app_label__icontains='cms') | ||
q_exclude = Q(content_type__app_label='cms') | ||
self.add_permission(group, q_filter, q_exclude) | ||
if options.get('plugin'): | ||
q_filter = Q(content_type__app_label__icontains='plugin') | ||
q_exclude = Q(content_type__app_label='cms') | ||
self.add_permission(group, q_filter, q_exclude) | ||
|
||
print(logging.INFO, 'Group created! ({})'.format(group_name)) | ||
print(logging.INFO, 'Following permissions were granted:') | ||
for perm in group.permissions.all(): | ||
print(logging.INFO, '{}'.format(perm)) | ||
|
||
def add_permission(self, group, q_filter=Q(), q_exclude=Q()): | ||
perms = Permission.objects.filter(q_filter).exclude(q_exclude) | ||
group.permissions.add(*perms) |
34 changes: 34 additions & 0 deletions
34
djangocms_misc/basic/management/commands/djangocms_misc_add_groups.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import logging | ||
import os | ||
import shutil | ||
|
||
from django.contrib.auth.models import Group, Permission | ||
from django.core.management import call_command | ||
from django.core.management.base import BaseCommand | ||
from django.db.models import Q | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
""" | ||
help = ( | ||
"Add an basic set of auth.Groups for cms usage (cms-base, cms-publisher, cms-superuser, plugin-permissions) that gives basic CMS Permissions. User --plugin or --cms to add additional perms." | ||
"") | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
'--force', | ||
action='store_const', | ||
const=True, | ||
required=False, | ||
help=""" | ||
Force overwrite of existing group and it's permissions.""") | ||
|
||
def handle(self, *args, **options): | ||
args = [] | ||
if options.get('force'): | ||
args = ['--force', ] | ||
call_command('djangocms_misc_add_cms_group', '--cms-base', *args) | ||
call_command('djangocms_misc_add_cms_group', '--cms-publish', '--name=cms_publisher', *args) | ||
call_command('djangocms_misc_add_cms_group', '--cms-superuser', '--name=cms_superuser', *args) | ||
call_command('djangocms_misc_add_cms_group', '--cms', '--plugin', '--name=cms_plugin_permissions', *args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters