diff options
author | lonkaars <l.leblansch@gmail.com> | 2021-04-15 15:14:44 +0200 |
---|---|---|
committer | lonkaars <l.leblansch@gmail.com> | 2021-04-15 15:14:44 +0200 |
commit | cc53f217f6122151bcae131a42da8f8887f8560d (patch) | |
tree | 2d09b9fd3758cecc00626c8aac31510dee7a37af /api/hierarchy.py | |
parent | c5f71bc38772dedb033258416e0cd722f7b9e7af (diff) |
new valid and util module, more function decorators
Diffstat (limited to 'api/hierarchy.py')
-rw-r--r-- | api/hierarchy.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/api/hierarchy.py b/api/hierarchy.py index 20dcc45..2f85225 100644 --- a/api/hierarchy.py +++ b/api/hierarchy.py @@ -1,7 +1,8 @@ from flask import request from auth.login_token import token_login -from user.info import valid_user_id from db import cursor +from util import all_def, all_notdef +import valid ranks = ["none", "user", "moderator", "admin", "bot"] @@ -19,7 +20,7 @@ def util_two_person(func): data = request.get_json() if data: explicit_id = data.get("id") - if explicit_id and not valid_user_id(explicit_id): explicit_id = None + if explicit_id and not valid.user_id(explicit_id): explicit_id = None return func(token_id, explicit_id) @@ -32,8 +33,7 @@ def util_two_person(func): def two_person(func): @util_two_person def wrapper(token_id, explicit_id): - if not token_id or \ - not explicit_id: + if not all_def([token_id, explicit_id]): return "", 400 return func(token_id, explicit_id) @@ -42,6 +42,21 @@ def two_person(func): return wrapper +# uses json data id with token_login id as fallback +# doesn't check for authentication +# expects that func takes these arguments: (user_id, viewer?) +def one_person(func): + @util_two_person + def wrapper(token_id, explicit_id): + if all_notdef([token_id, explicit_id]): + return "", 400 + + return func(explicit_id or token_id, token_id) + + wrapper.__name__ = func.__name__ + return wrapper + + # @auth_required function decorator (use after @flask.Blueprint.route() decorator) # This decorator only runs endpoint() if token_id from # @util_two_person is not None and passes hierarchy constraints |