Files
mayan-edms/mayan/apps/permissions/management/commands/purgepermissions.py
2015-07-11 01:48:34 -04:00

18 lines
544 B
Python

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()