From 3481af149b8a56e21bcfaec1c139f0adfaa0d89c Mon Sep 17 00:00:00 2001 From: Khanh Ngo Date: Sat, 1 Sep 2018 17:53:05 +0700 Subject: [PATCH] Add option to allow user to create domain --- app/decorators.py | 15 +++++++++++++++ app/models.py | 1 + app/templates/admin_setting_basic.html | 2 +- app/templates/base.html | 4 +++- app/views.py | 10 ++++++++-- .../versions/4a666113c7bb_add_operator_role.py | 8 +++++--- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/app/decorators.py b/app/decorators.py index f0e990c..a1cfacf 100644 --- a/app/decorators.py +++ b/app/decorators.py @@ -61,3 +61,18 @@ def can_configure_dnssec(f): return f(*args, **kwargs) return decorated_function + + +def can_create_domain(f): + """ + Grant access if: + - user is in Operator role or higher, or + - allow_user_create_domain is on + """ + @wraps(f) + def decorated_function(*args, **kwargs): + if g.user.role.name not in ['Administrator', 'Operator'] and not Setting().get('allow_user_create_domain'): + return redirect(url_for('error', code=401)) + + return f(*args, **kwargs) + return decorated_function diff --git a/app/models.py b/app/models.py index 816e226..82fabf9 100644 --- a/app/models.py +++ b/app/models.py @@ -1799,6 +1799,7 @@ class Setting(db.Model): 'allow_quick_edit': True, 'pretty_ipv6_ptr': False, 'dnssec_admins_only': False, + 'allow_user_create_domain': False, 'bg_domain_updates': False, 'site_name': 'PowerDNS-Admin', 'pdns_api_url': '', diff --git a/app/templates/admin_setting_basic.html b/app/templates/admin_setting_basic.html index b289f75..d5bdb84 100644 --- a/app/templates/admin_setting_basic.html +++ b/app/templates/admin_setting_basic.html @@ -69,7 +69,7 @@