Skip to content

Commit

Permalink
permissions translations
Browse files Browse the repository at this point in the history
  • Loading branch information
twd2 committed Jul 25, 2017
1 parent 26e5136 commit a4d4dab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 8 additions & 4 deletions vj4/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,18 @@ def message(self):


class PermissionError(ForbiddenError):
@property
def message(self):
def __init__(self, *args):
super().__init__(*args)
if any((p | builtin.PERM_VIEW) == builtin.PERM_VIEW for p in self.args):
return 'You cannot visit this domain.'
self.__message = 'You cannot visit this domain.'
else:
self.__message = "You don't have the required permission ({0}) in this domain."
if len(self.args) > 0 and self.args[0] in builtin.PERMS_BY_KEY:
self.args = (builtin.PERMS_BY_KEY[self.args[0]].desc, self.args[0], *self.args[1:])
return "You don't have the required permission ({0}) in this domain."

@property
def message(self):
return self.__message


class PrivilegeError(ForbiddenError):
Expand Down
2 changes: 2 additions & 0 deletions vj4/handler/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def __iter__(self):
raise
except error.UserFacingError as e:
self.response.set_status(e.http_status, None)
if isinstance(e, error.PermissionError):
e.args = (self.translate(e.args[0]), *e.args[1:])
if self.prefer_json:
self.response.content_type = 'application/json'
message = self.translate(e.message).format(*e.args)
Expand Down

0 comments on commit a4d4dab

Please sign in to comment.