xmpp: Merge actions into single file.

This commit is contained in:
James Valleroy authored and Sunil Mohan Adapa committed 2015-06-12 15:49:41 +05:30
1 parent 27e19b4373
commit 73a03c3b39
3 files changed
+161 -131

No files matched your search

+50 -38
View File
@@ -91,7 +91,7 @@ class ConfigureForm(forms.Form): # pylint: disable-msg=W0232
ldap_enabled = forms.BooleanField(
label=_('Use LDAP for authentication'), required=False,
help_text=_('When enabled, only LDAP users will be able to login to \
the server'))
the XMPP service'))
inband_enabled = forms.BooleanField(
label=_('Allow In-Band Registration'), required=False,
help_text=_('When enabled, anyone who can reach this server will be \
@@ -123,50 +123,62 @@ def configure(request):
def get_status():
"""Return the current status"""
output = actions.run('xmpp-setup', ['status'])
return {'inband_enabled': 'inband_enable' in output.split(),
'ldap_enabled': 'ldap_enable' in output.split()}
output = actions.run('xmpp', ['is-ldap-enabled'])
ldap_enabled = 'True' in output.split()
output = actions.run('xmpp', ['is-inband-enabled'])
inband_enabled = 'True' in output.split()
return {'ldap_enabled': ldap_enabled,
'inband_enabled': inband_enabled}
def _apply_changes(request, old_status, new_status):
"""Apply the form changes"""
logger.info('Status - %s, %s', old_status, new_status)
if old_status['inband_enabled'] == new_status['inband_enabled'] \
and old_status['ldap_enabled'] == new_status['ldap_enabled']:
setting_changed = False
if not old_status['ldap_enabled'] and new_status['ldap_enabled']:
setting_changed = True
output = actions.superuser_run('xmpp', ['enable-ldap'])
if 'Failed' in output:
messages.error(request,
_('Error when configuring XMPP server: %s') %
output)
else:
messages.success(request, _('LDAP authentication enabled'))
elif old_status['ldap_enabled'] and not new_status['ldap_enabled']:
setting_changed = True
output = actions.superuser_run('xmpp', ['disable-ldap'])
if 'Failed' in output:
messages.error(request,
_('Error when configuring XMPP server: %s') %
output)
else:
messages.success(request, _('LDAP authentication disabled'))
if not old_status['inband_enabled'] and new_status['inband_enabled']:
setting_changed = True
output = actions.superuser_run('xmpp', ['enable-inband'])
if 'Failed' in output:
messages.error(request,
_('Error when configuring XMPP server: %s') %
output)
else:
messages.success(request, _('Inband registration enabled'))
elif old_status['inband_enabled'] and not new_status['inband_enabled']:
setting_changed = True
output = actions.superuser_run('xmpp', ['disable-inband'])
if 'Failed' in output:
messages.error(request,
_('Error when configuring XMPP server: %s') %
output)
else:
messages.success(request, _('Inband registration disabled'))
if not setting_changed:
messages.info(request, _('Setting unchanged'))
return
options = []
if new_status['inband_enabled']:
options.append('inband_enable')
else:
options.append('noinband_enable')
if new_status['ldap_enabled']:
options.append('ldap_enable')
else:
options.append('noldap_enable')
logger.info('Option - %s', options)
output = actions.superuser_run('xmpp-setup', options)
if 'Failed' in output:
messages.error(request,
_('Error when configuring XMPP server: %s') %
output)
return
if 'inband_enable' in options:
messages.success(request, _('Inband registration enabled'))
else:
messages.success(request, _('Inband registration disabled'))
if 'ldap_enable' in options:
messages.success(request, _('LDAP authentication enabled'))
else:
messages.success(request, _('LDAP authentication disabled'))
class RegisterForm(forms.Form): # pylint: disable-msg=W0232