Add exception, check and message when an invalid permission namespace is requested.

This commit is contained in:
Roberto Rosario
2015-06-30 16:48:27 -04:00
parent 060033b41c
commit 0bb8fa2ba9
2 changed files with 14 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import logging
from django.core.exceptions import PermissionDenied
from django.utils.translation import ugettext_lazy as _
from .exceptions import InvalidNamespace
from .models import StoredPermission
logger = logging.getLogger(__name__)
@@ -19,7 +20,10 @@ class PermissionNamespace(object):
@classmethod
def get(cls, 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):
self.name = name

View File

@@ -0,0 +1,9 @@
from __future__ import unicode_literals
class PermissionError(Exception):
pass
class InvalidNamespace(PermissionError):
pass