Add management command to purge obsolete permissions from the database

This commit is contained in:
Roberto Rosario
2015-06-29 17:12:18 -04:00
parent a68be31e52
commit 29447f16f4
4 changed files with 18 additions and 0 deletions

View File

@@ -85,6 +85,7 @@ Common steps
Migrate existing database schema with::
$ mayan-edms.py purge_permissions
$ mayan-edms.py migrate
During the migration several messages of stale content types can occur:

View File

@@ -0,0 +1,17 @@
from __future__ import unicode_literals
from django.core.management.base import BaseCommand
from ...classes import Permission
from ...models import StoredPermission
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': '%s.%s' % (permission.namespace, permission.name)}, proxy_only=True)
except KeyError:
permission.delete()