Skip to content

Commit 18b0c22

Browse files
author
Maximilian Siling
committed
Add @require_teacher() helper decorator
1 parent 6801924 commit 18b0c22

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

ennead/utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any, Callable
44
from functools import wraps
55

6-
from flask import g, redirect, url_for
6+
from flask import g, abort, redirect, url_for
77
from werkzeug.wrappers import Response
88

99

@@ -29,3 +29,16 @@ def wrapped(*args: Any, **kwargs: Any) -> Response:
2929
return func(*args, **kwargs)
3030

3131
return wrapped
32+
33+
34+
def require_teacher(func: Callable) -> Callable:
35+
"""Make endpoint require logged in teacher"""
36+
37+
# pylint: disable=inconsistent-return-statements
38+
@wraps(func)
39+
def wrapped(*args: Any, **kwargs: Any) -> Response:
40+
if g.user and g.user.is_teacher:
41+
return func(*args, **kwargs)
42+
abort(403)
43+
44+
return wrapped

0 commit comments

Comments
 (0)