Skip to content

Commit

Permalink
Merge branch 'release/0.1.20' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
benzkji committed Jun 26, 2021
2 parents 53aa9bf + daa49d8 commit 954f1c0
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.txt
Expand Up @@ -3,6 +3,11 @@
- more tests: autopublisher, for example!


==== 0.1.20 (2021-06-27) ===

- management commands for easy cms/plugin auth group creation


==== 0.1.19 (2021-06-05) ===

- switched to github actions
Expand Down
2 changes: 1 addition & 1 deletion djangocms_misc/__init__.py
@@ -1,2 +1,2 @@
__version__ = '0.1.19'
__version__ = '0.1.20'
__author__ = 'benzkji'
@@ -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)
@@ -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)
2 changes: 2 additions & 0 deletions djangocms_misc/tests/settings.py
Expand Up @@ -117,6 +117,8 @@
('base.html', 'Default'),
)

CMS_PERMISSION = True

COVERAGE_REPORT_HTML_OUTPUT_DIR = os.path.join(
os.path.join(APP_ROOT, 'tests/coverage'))
COVERAGE_MODULE_EXCLUDES = [
Expand Down
2 changes: 2 additions & 0 deletions release.txt
Expand Up @@ -6,6 +6,8 @@ CHANGELOG.txt
git flow release finish 0.xxx
git push --all; git push --tags
git push upstream --all; git push upstream --tags

# no more, is in github action
python setup.py sdist && python setup.py bdist_wheel --universal
twine upload dist/* -r pypitest
twine upload dist/*
Expand Down

0 comments on commit 954f1c0

Please sign in to comment.