Add exception, check and message when an invalid permission namespace is requested.
This commit is contained in:
@@ -5,6 +5,7 @@ import logging
|
|||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from .exceptions import InvalidNamespace
|
||||||
from .models import StoredPermission
|
from .models import StoredPermission
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -19,7 +20,10 @@ class PermissionNamespace(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get(cls, name):
|
def get(cls, name):
|
||||||
return cls._registry[name]
|
try:
|
||||||
|
return cls._registry[name]
|
||||||
|
except KeyError:
|
||||||
|
raise InvalidNamespace('Invalid namespace name. This is probably an obsolete permission namespace, execute the management command "purge_permissions" and try again.')
|
||||||
|
|
||||||
def __init__(self, name, label):
|
def __init__(self, name, label):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|||||||
9
mayan/apps/permissions/exceptions.py
Normal file
9
mayan/apps/permissions/exceptions.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
|
||||||
|
class PermissionError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidNamespace(PermissionError):
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user