feat: Add the extra chars as an option

This commit is contained in:
Jérôme BECOT 2021-12-01 14:35:05 +01:00
parent e33822fa45
commit 30a2925fae
5 changed files with 24 additions and 12 deletions

View file

@ -34,8 +34,12 @@ class Account(db.Model):
self.API_EXTENDED_URL = utils.pdns_api_extended_uri(self.PDNS_VERSION)
if self.name is not None:
if Setting().get('account_name_extra_chars'):
char_list = "abcdefghijklmnopqrstuvwxyz0123456789_-."
else:
char_list = "abcdefghijklmnopqrstuvwxyz0123456789"
self.name = ''.join(c for c in self.name.lower()
if c in "abcdefghijklmnopqrstuvwxyz0123456789_-")
if c in char_list)
def __repr__(self):
return '<Account {0}r>'.format(self.name)

View file

@ -190,7 +190,8 @@ class Setting(db.Model):
'otp_field_enabled': True,
'custom_css': '',
'otp_force': False,
'max_history_records': 1000
'max_history_records': 1000,
'account_name_extra_chars': False
}
def __init__(self, id=None, name=None, value=None):
@ -271,15 +272,15 @@ class Setting(db.Model):
def get(self, setting):
if setting in self.defaults:
if setting.upper() in current_app.config:
result = current_app.config[setting.upper()]
else:
result = self.query.filter(Setting.name == setting).first()
if result is not None:
if hasattr(result,'value'):
result = result.value
result = result.value
return strtobool(result) if result in [
'True', 'False'
] else result
@ -287,7 +288,7 @@ class Setting(db.Model):
return self.defaults[setting]
else:
current_app.logger.error('Unknown setting queried: {0}'.format(setting))
def get_records_allow_to_edit(self):
return list(
set(self.get_forward_records_allow_to_edit() +

View file

@ -1260,7 +1260,9 @@ def setting_basic():
'allow_user_create_domain', 'allow_user_remove_domain', 'allow_user_view_history', 'bg_domain_updates', 'site_name',
'session_timeout', 'warn_session_timeout', 'ttl_options',
'pdns_api_timeout', 'verify_ssl_connections', 'verify_user_email',
'delete_sso_accounts', 'otp_field_enabled', 'custom_css', 'enable_api_rr_history', 'max_history_records', 'otp_force'
'delete_sso_accounts', 'otp_field_enabled', 'custom_css', 'enable_api_rr_history', 'max_history_records', 'otp_force',
'account_name_extra_chars'
]
return render_template('admin_setting_basic.html', settings=settings)

View file

@ -403,7 +403,7 @@ def login():
if name_prop in me and desc_prop in me:
accounts_name_prop = [me[name_prop]] if type(me[name_prop]) is not list else me[name_prop]
accounts_desc_prop = [me[desc_prop]] if type(me[desc_prop]) is not list else me[desc_prop]
#Run on all groups the user is in by the index num.
for i in range(len(accounts_name_prop)):
description = ''
@ -413,7 +413,7 @@ def login():
account_to_add.append(account)
user_accounts = user.get_accounts()
# Add accounts
for account in account_to_add:
if account not in user_accounts:
@ -1088,8 +1088,12 @@ def create_group_to_account_mapping():
def handle_account(account_name, account_description=""):
if Setting().get('account_name_extra_chars'):
char_list = "abcdefghijklmnopqrstuvwxyz0123456789_-."
else:
char_list = "abcdefghijklmnopqrstuvwxyz0123456789"
clean_name = ''.join(c for c in account_name.lower()
if c in "abcdefghijklmnopqrstuvwxyz0123456789_-")
if c in char_list)
if len(clean_name) > Account.name.type.length:
current_app.logger.error(
"Account name {0} too long. Truncated.".format(clean_name))

View file

@ -49,7 +49,7 @@
<span class="fa fa-cog form-control-feedback"></span>
{% if invalid_accountname %}
<span class="help-block">Cannot be blank and must only contain alphanumeric
characters, hyphens or underscores.</span>
characters{% if SETTING.get('account_name_extra_chars') %}, dots, hyphens or underscores{% endif %}.</span>
{% elif duplicate_accountname %}
<span class="help-block">Account name already in use.</span>
{% endif %}
@ -113,7 +113,8 @@
<p>Fill in all the fields to the in the form to the left.</p>
<p>
<strong>Name</strong> is an account identifier. It will be lowercased and can contain alphanumeric
characters, hyphens and underscores (no space or other special character is allowed).<br />
characters{% if SETTING.get('account_name_extra_chars') %}, dots, hyphens and underscores (no space or other special character is allowed)
{% else %} (no extra character is allowed){% endif %}.<br />
<strong>Description</strong> is a user friendly name for this account.<br />
<strong>Contact person</strong> is the name of a contact person at the account.<br />
<strong>Mail Address</strong> is an e-mail address for the contact person.