forked from extern/django-helpdesk
creation of Permission-per-Queue is done always
This commit is contained in:
parent
b2ae5e764f
commit
3b547d2cf9
@ -3,11 +3,14 @@
|
||||
scripts/create_queue_permissions.py -
|
||||
Create automatically permissions for all Queues.
|
||||
|
||||
This is typically used when some queues are created before using the flag
|
||||
HELPDESK_ENABLE_PER_QUEUE_PERMISSION, and then Permissions must be added.
|
||||
This is rarely needed. However, one use case is the scenario where the
|
||||
slugs of the Queues have been changed, and thus the Permission should be
|
||||
recreated according to the new slugs.
|
||||
|
||||
No cleanup of permissions is performed.
|
||||
|
||||
It should be safe to call this script multiple times or with partial
|
||||
permissions.
|
||||
existing permissions.
|
||||
"""
|
||||
|
||||
from optparse import make_option
|
||||
|
@ -3,22 +3,14 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db import migrations
|
||||
from django.conf import settings
|
||||
from django.db.utils import IntegrityError
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
def create_and_assign_permissions(apps, schema_editor):
|
||||
# If neither Permission nor Membership mechanism are enabled, ignore the migration
|
||||
if not ((hasattr(settings, 'HELPDESK_ENABLE_PER_QUEUE_STAFF_PERMISSION') and
|
||||
settings.HELPDESK_ENABLE_PER_QUEUE_STAFF_PERMISSION) or
|
||||
(hasattr(settings, 'HELPDESK_ENABLE_PER_QUEUE_STAFF_MEMBERSHIP') and
|
||||
settings.HELPDESK_ENABLE_PER_QUEUE_STAFF_MEMBERSHIP)):
|
||||
return
|
||||
|
||||
Permission = apps.get_model('auth', 'Permission')
|
||||
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||
# Otherwise, two steps:
|
||||
# Two steps:
|
||||
# 1. Create the permission for existing Queues
|
||||
# 2. Assign the permission to user according to QueueMembership objects
|
||||
|
||||
|
@ -274,11 +274,10 @@ class Queue(models.Model):
|
||||
self.email_box_port = 110
|
||||
|
||||
if not self.id:
|
||||
# Always prepare the permission codename
|
||||
# Prepare the permission codename and the permission
|
||||
# (even if they are not needed with the current configuration)
|
||||
basename = self.prepare_permission_name()
|
||||
|
||||
# Create the permission only if the flag is active
|
||||
if helpdesk_settings.HELPDESK_ENABLE_PER_QUEUE_STAFF_PERMISSION:
|
||||
Permission.objects.create(
|
||||
name=_("Permission for queue: ") + self.title,
|
||||
content_type=ContentType.objects.get(model="queue"),
|
||||
|
Loading…
Reference in New Issue
Block a user