ldap: Minor styling fixes

This commit is contained in:
Sunil Mohan Adapa 2015-06-25 23:40:24 +05:30
parent bc8523d9a3
commit 82090af423
5 changed files with 15 additions and 6 deletions

View File

@ -148,6 +148,7 @@ def subcommand_enable_ldap(_):
"""Enable LDAP authentication""" """Enable LDAP authentication"""
with open(EJABBERD_CONFIG, 'r') as conffile: with open(EJABBERD_CONFIG, 'r') as conffile:
lines = conffile.readlines() lines = conffile.readlines()
with open(EJABBERD_CONFIG, 'w') as conffile: with open(EJABBERD_CONFIG, 'w') as conffile:
for line in lines: for line in lines:
if 'auth_method: internal' in line: if 'auth_method: internal' in line:
@ -161,6 +162,7 @@ def subcommand_enable_ldap(_):
conffile.write('ldap_base: "ou=users,dc=thisbox"\n') conffile.write('ldap_base: "ou=users,dc=thisbox"\n')
else: else:
conffile.write(line) conffile.write(line)
try: try:
subprocess.check_output(['ejabberdctl', 'restart']) subprocess.check_output(['ejabberdctl', 'restart'])
except subprocess.CalledProcessError as err: except subprocess.CalledProcessError as err:
@ -171,6 +173,7 @@ def subcommand_disable_ldap(_):
"""Disable LDAP authentication""" """Disable LDAP authentication"""
with open(EJABBERD_CONFIG, 'r') as conffile: with open(EJABBERD_CONFIG, 'r') as conffile:
lines = conffile.readlines() lines = conffile.readlines()
with open(EJABBERD_CONFIG, 'w') as conffile: with open(EJABBERD_CONFIG, 'w') as conffile:
for line in lines: for line in lines:
if '## auth_method: internal' in line: if '## auth_method: internal' in line:
@ -179,6 +182,7 @@ def subcommand_disable_ldap(_):
conffile.write('## auth_method: ldap\n') conffile.write('## auth_method: ldap\n')
else: else:
conffile.write(line) conffile.write(line)
try: try:
subprocess.check_output(['ejabberdctl', 'restart']) subprocess.check_output(['ejabberdctl', 'restart'])
except subprocess.CalledProcessError as err: except subprocess.CalledProcessError as err:
@ -196,12 +200,14 @@ def subcommand_enable_inband(_):
"""Enable inband registration""" """Enable inband registration"""
with open(EJABBERD_CONFIG, 'r') as conffile: with open(EJABBERD_CONFIG, 'r') as conffile:
lines = conffile.readlines() lines = conffile.readlines()
with open(EJABBERD_CONFIG, 'w') as conffile: with open(EJABBERD_CONFIG, 'w') as conffile:
for line in lines: for line in lines:
if 'ip_access' in line: if 'ip_access' in line:
conffile.write(line.replace('trusted_network', 'all')) conffile.write(line.replace('trusted_network', 'all'))
else: else:
conffile.write(line) conffile.write(line)
try: try:
subprocess.check_output(['ejabberdctl', 'restart']) subprocess.check_output(['ejabberdctl', 'restart'])
except subprocess.CalledProcessError as err: except subprocess.CalledProcessError as err:
@ -212,12 +218,14 @@ def subcommand_disable_inband(_):
"""Disable inband registration""" """Disable inband registration"""
with open(EJABBERD_CONFIG, 'r') as conffile: with open(EJABBERD_CONFIG, 'r') as conffile:
lines = conffile.readlines() lines = conffile.readlines()
with open(EJABBERD_CONFIG, 'w') as conffile: with open(EJABBERD_CONFIG, 'w') as conffile:
for line in lines: for line in lines:
if 'ip_access' in line: if 'ip_access' in line:
conffile.write(line.replace('all', 'trusted_network')) conffile.write(line.replace('all', 'trusted_network'))
else: else:
conffile.write(line) conffile.write(line)
try: try:
subprocess.check_output(['ejabberdctl', 'restart']) subprocess.check_output(['ejabberdctl', 'restart'])
except subprocess.CalledProcessError as err: except subprocess.CalledProcessError as err:

View File

@ -26,9 +26,9 @@ from plinth.errors import ActionError
class CreateUserForm(UserCreationForm): class CreateUserForm(UserCreationForm):
"""Custom user create form """Custom user create form.
Includes options to also create POSIX and LDAP user. Include options to also create POSIX and LDAP user.
""" """
add_posix_user = forms.BooleanField( add_posix_user = forms.BooleanField(
@ -62,6 +62,7 @@ class CreateUserForm(UserCreationForm):
except ActionError: except ActionError:
messages.error(self.request, messages.error(self.request,
_('Creating POSIX system user failed.')) _('Creating POSIX system user failed.'))
if self.cleaned_data['add_ldap_user']: if self.cleaned_data['add_ldap_user']:
try: try:
actions.superuser_run( actions.superuser_run(
@ -114,12 +115,14 @@ class UserUpdateForm(forms.ModelForm):
except ActionError: except ActionError:
messages.error(self.request, messages.error(self.request,
_('Renaming POSIX system user failed.')) _('Renaming POSIX system user failed.'))
try: try:
actions.superuser_run('rename-ldap-user', actions.superuser_run('rename-ldap-user',
[self.username, user.get_username()]) [self.username, user.get_username()])
except ActionError: except ActionError:
messages.error(self.request, messages.error(self.request,
_('Renaming LDAP user failed.')) _('Renaming LDAP user failed.'))
return user return user

View File

@ -31,7 +31,7 @@
{% endif %} {% endif %}
{% if is_ldap_user %} {% if is_ldap_user %}
<p>This user is also an LDAP user. LDAP user will also be deleted.</p> <p>This user is also an LDAP user. LDAP user will also be deleted.</p>
{% endif %} {% endif %}
<p>Delete user permanently?</p> <p>Delete user permanently?</p>

View File

@ -53,7 +53,7 @@
{% endif %} {% endif %}
{% if is_ldap_user %} {% if is_ldap_user %}
<p>This user is also an LDAP user.</p> <p>This user is also an LDAP user.</p>
{% endif %} {% endif %}
<input type="submit" class="btn btn-primary" value="Save Changes"/> <input type="submit" class="btn btn-primary" value="Save Changes"/>

View File

@ -146,7 +146,6 @@ def _apply_changes(request, old_status, new_status):
output) output)
else: else:
messages.success(request, _('LDAP authentication enabled')) messages.success(request, _('LDAP authentication enabled'))
elif old_status['ldap_enabled'] and not new_status['ldap_enabled']: elif old_status['ldap_enabled'] and not new_status['ldap_enabled']:
setting_changed = True setting_changed = True
output = actions.superuser_run('xmpp', ['disable-ldap']) output = actions.superuser_run('xmpp', ['disable-ldap'])
@ -166,7 +165,6 @@ def _apply_changes(request, old_status, new_status):
output) output)
else: else:
messages.success(request, _('Inband registration enabled')) messages.success(request, _('Inband registration enabled'))
elif old_status['inband_enabled'] and not new_status['inband_enabled']: elif old_status['inband_enabled'] and not new_status['inband_enabled']:
setting_changed = True setting_changed = True
output = actions.superuser_run('xmpp', ['disable-inband']) output = actions.superuser_run('xmpp', ['disable-inband'])