-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccess.py
35 lines (27 loc) · 1007 Bytes
/
access.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from functools import wraps
from flask import session, render_template, request, current_app
def login_required(func):
@wraps(func)
def wrapper(*argc, **kwargs):
if 'user_id' in session:
return func(*argc, **kwargs)
return render_template('access_refused.html')
return wrapper
def group_validation(config: dict) -> bool:
endpoint_func = request.endpoint
endpoint_app = request.endpoint.split('.')[0]
if 'user_group' in session:
user_group = session['user_group']
if user_group in config and endpoint_app in config[user_group]:
return True
elif user_group in config and endpoint_func in config[user_group]:
return True
return False
def group_required(f):
@wraps(f)
def wrapper(*argc, **kwargs):
config = current_app.config['access_config']
if group_validation(config):
return f(*argc, **kwargs)
return render_template('refuse.html')
return wrapper