aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-04-01 13:23:40 +0100
committerGravatar Gareth Coles <[email protected]>2018-04-01 13:23:40 +0100
commit4bd97cb6f245e4c9ce07752d4d041461b6ed0244 (patch)
tree4a5e4079099904d28fae2ec1b14468397972e59c
parentFix logging, restrict staff index route (diff)
Role requirement decorator should return json on an API error
-rw-r--r--pysite/decorators.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/pysite/decorators.py b/pysite/decorators.py
index 93e015e4..8abde932 100644
--- a/pysite/decorators.py
+++ b/pysite/decorators.py
@@ -23,6 +23,9 @@ def require_roles(*roles: int):
if role in data["roles"]:
return f(self, *args, **kwargs)
+ if isinstance(self, APIView):
+ return self.error(ErrorCodes.unauthorized)
+
raise Forbidden()
return redirect(url_for("discord.login"))
return inner