2018-03-31 00:32:46 +00:00
|
|
|
from functools import wraps
|
|
|
|
from flask import g, request, redirect, url_for
|
|
|
|
|
|
|
|
from app import app
|
2018-08-21 06:26:27 +00:00
|
|
|
from app.models import Role, Setting
|
2018-03-31 00:32:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def admin_role_required(f):
|
|
|
|
@wraps(f)
|
|
|
|
def decorated_function(*args, **kwargs):
|
|
|
|
if g.user.role.name != 'Administrator':
|
|
|
|
return redirect(url_for('error', code=401))
|
|
|
|
return f(*args, **kwargs)
|
|
|
|
return decorated_function
|
|
|
|
|
|
|
|
|
|
|
|
def can_access_domain(f):
|
|
|
|
@wraps(f)
|
|
|
|
def decorated_function(*args, **kwargs):
|
|
|
|
if g.user.role.name != 'Administrator':
|
|
|
|
domain_name = kwargs.get('domain_name')
|
|
|
|
user_domain = [d.name for d in g.user.get_domain()]
|
|
|
|
|
|
|
|
if domain_name not in user_domain:
|
|
|
|
return redirect(url_for('error', code=401))
|
|
|
|
|
|
|
|
return f(*args, **kwargs)
|
|
|
|
return decorated_function
|
2018-06-07 02:28:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def can_configure_dnssec(f):
|
|
|
|
@wraps(f)
|
|
|
|
def decorated_function(*args, **kwargs):
|
2018-08-21 06:26:27 +00:00
|
|
|
if g.user.role.name != 'Administrator' and Setting().get('dnssec_admins_only'):
|
2018-06-07 02:28:14 +00:00
|
|
|
return redirect(url_for('error', code=401))
|
|
|
|
|
|
|
|
return f(*args, **kwargs)
|
|
|
|
return decorated_function
|