From 3b547d2cf9ca4f9bdb7df9a880e2ca776c9d4647 Mon Sep 17 00:00:00 2001 From: Alex Barcelo Date: Fri, 18 Dec 2015 14:35:50 +0100 Subject: [PATCH] creation of Permission-per-Queue is done always --- .../commands/create_queue_permissions.py | 9 ++++++--- .../migrations/0009_migrate_queuemembership.py | 10 +--------- helpdesk/models.py | 15 +++++++-------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/helpdesk/management/commands/create_queue_permissions.py b/helpdesk/management/commands/create_queue_permissions.py index ca42375d..66118e75 100644 --- a/helpdesk/management/commands/create_queue_permissions.py +++ b/helpdesk/management/commands/create_queue_permissions.py @@ -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 diff --git a/helpdesk/migrations/0009_migrate_queuemembership.py b/helpdesk/migrations/0009_migrate_queuemembership.py index 3ba6ae62..10d27cd0 100644 --- a/helpdesk/migrations/0009_migrate_queuemembership.py +++ b/helpdesk/migrations/0009_migrate_queuemembership.py @@ -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 diff --git a/helpdesk/models.py b/helpdesk/models.py index 1d533e52..a67f989f 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -274,16 +274,15 @@ 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"), - codename=basename, - ) + Permission.objects.create( + name=_("Permission for queue: ") + self.title, + content_type=ContentType.objects.get(model="queue"), + codename=basename, + ) super(Queue, self).save(*args, **kwargs)