Move the purge permission logic to the manager

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-04-17 16:06:56 -04:00
parent 54020a8813
commit 33d073e7a0
4 changed files with 12 additions and 9 deletions

View File

@@ -92,6 +92,8 @@
* Expose Django's LOGOUT_REDIRECT_URL setting.
* Move current user views from the common app to the user
management app.
* Move the purge permission logic to the StorePermission
manager.
3.1.11 (2019-04-XX)
===================

View File

@@ -124,6 +124,8 @@ Other changes
* Expose Django's LOGOUT_REDIRECT_URL setting.
* Move current user views from the common app to the user
management app.
* Move the purge permission logic to the StorePermission
manager.
Removals
--------

View File

@@ -2,7 +2,6 @@ from __future__ import unicode_literals
from django.core.management.base import BaseCommand
from ...classes import Permission
from ...models import StoredPermission
@@ -10,11 +9,4 @@ class Command(BaseCommand):
help = 'Remove obsolete permissions from the database'
def handle(self, *args, **options):
for permission in StoredPermission.objects.all():
try:
Permission.get(
pk='{}.{}'.format(permission.namespace, permission.name),
proxy_only=True
)
except KeyError:
permission.delete()
StoredPermission.objects.purge_obsolete()

View File

@@ -15,3 +15,10 @@ class RoleManager(models.Manager):
class StoredPermissionManager(models.Manager):
def get_by_natural_key(self, namespace, name):
return self.get(namespace=namespace, name=name)
def purge_obsolete(self):
for permission in self.all():
try:
permission.volatile_permission
except KeyError:
permission.delete()