Add management command to purge obsolete permissions from the database
This commit is contained in:
@@ -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:
|
||||
|
||||
0
mayan/apps/permissions/management/__init__.py
Normal file
0
mayan/apps/permissions/management/__init__.py
Normal 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()
|
||||
Reference in New Issue
Block a user