aboutsummaryrefslogtreecommitdiffstats
path: root/pysite/decorators.py
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-05-20 23:29:17 +0100
committerGravatar GitHub <[email protected]>2018-05-20 23:29:17 +0100
commit449d52caf4010ed112f1928bf6b5234bcfb9a339 (patch)
tree3ce59258a68fcb4174610b157f3a3ae9c50be02a /pysite/decorators.py
parentTests directory (#73) (diff)
Privacy/Usability updates (#75)
* Use less intrusive oauth scopes, add login redirect method * Remove debugging prints, add missing __init__ * Work towards new privacy policy * Fix judging state icons on code jam management page * Jammer profile retraction and punishments based on jam status * Linting * [Jams] Deny profile saving for users < 13 years, and finish removal page * Fix tests * Clean up and address Volcyy's review * Add proper login redirection to require_roles decorator * Fix template is_staff() and add staff link to navigation * Address lemon's review * Linting * Privacy page formatting * Privacy page formatting
Diffstat (limited to 'pysite/decorators.py')
-rw-r--r--pysite/decorators.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/pysite/decorators.py b/pysite/decorators.py
index 16d555f0..705c519e 100644
--- a/pysite/decorators.py
+++ b/pysite/decorators.py
@@ -1,11 +1,11 @@
from functools import wraps
from json import JSONDecodeError
-from flask import redirect, request, url_for
+from flask import request
from schema import Schema, SchemaError
from werkzeug.exceptions import Forbidden
-from pysite.base_route import APIView, BaseView
+from pysite.base_route import APIView, RouteView
from pysite.constants import BOT_API_KEY, CSRF, DEBUG_MODE, ErrorCodes, ValidationTypes
@@ -27,21 +27,22 @@ def require_roles(*roles: int):
def inner_decorator(f):
@wraps(f)
- def inner(self: BaseView, *args, **kwargs):
+ def inner(self: RouteView, *args, **kwargs):
data = self.user_data
+ print(kwargs)
if DEBUG_MODE:
return f(self, *args, **kwargs)
elif data:
for role in roles:
- if DEBUG_MODE or role in data.get("roles", []):
+ if role in data.get("roles", []):
return f(self, *args, **kwargs)
if isinstance(self, APIView):
return self.error(ErrorCodes.unauthorized)
raise Forbidden()
- return redirect(url_for("discord.login"))
+ return self.redirect_login(**kwargs)
return inner
@@ -78,7 +79,7 @@ def api_params(schema: Schema, validation_type: ValidationTypes = ValidationType
def inner_decorator(f):
@wraps(f)
- def inner(self: BaseView, *args, **kwargs):
+ def inner(self: APIView, *args, **kwargs):
if validation_type == ValidationTypes.json:
try:
if not request.is_json: