mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
matrixsnapse: Minor refactor in getting/setting public registrations
- Consistency with rest of the apps, more robustness and extensibility. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
bb544b0a6d
commit
89a404fb7d
@ -134,13 +134,12 @@ class MatrixSynapseTurnConsumer(TurnConsumer):
|
|||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
"""Upgrade matrix-synapse configuration to avoid conffile prompt."""
|
"""Upgrade matrix-synapse configuration to avoid conffile prompt."""
|
||||||
public_registration_status = privileged.public_registration('status')
|
config = privileged.get_config()
|
||||||
privileged.move_old_conf()
|
privileged.move_old_conf()
|
||||||
install(['matrix-synapse'], force_configuration='new', reinstall=True,
|
install(['matrix-synapse'], force_configuration='new', reinstall=True,
|
||||||
force_missing_configuration=True)
|
force_missing_configuration=True)
|
||||||
privileged.post_install()
|
privileged.post_install()
|
||||||
if public_registration_status:
|
privileged.set_config(**config)
|
||||||
privileged.public_registration('enable')
|
|
||||||
|
|
||||||
|
|
||||||
def setup_domain(domain_name):
|
def setup_domain(domain_name):
|
||||||
|
|||||||
@ -69,36 +69,29 @@ def setup(domain_name: str):
|
|||||||
{'server-name': domain_name})
|
{'server-name': domain_name})
|
||||||
|
|
||||||
|
|
||||||
@privileged
|
def get_config():
|
||||||
def public_registration(command: str) -> Optional[bool]:
|
"""Return the current configuration of matrix-synapse."""
|
||||||
"""Enable/Disable/Status public user registration."""
|
|
||||||
if command not in ('enable', 'disable', 'status'):
|
|
||||||
raise ValueError('Invalid command')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(REGISTRATION_CONF_PATH, encoding='utf-8') as reg_conf_file:
|
with open(REGISTRATION_CONF_PATH, encoding='utf-8') as reg_conf_file:
|
||||||
config = yaml.safe_load(reg_conf_file)
|
config = yaml.safe_load(reg_conf_file)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
# Check if its set in original conffile.
|
# Check if its set in original conffile.
|
||||||
with open(ORIG_CONF_PATH, encoding='utf-8') as orig_conf_file:
|
with open(ORIG_CONF_PATH, encoding='utf-8') as orig_conf_file:
|
||||||
orig_config = yaml.safe_load(orig_conf_file)
|
config = yaml.safe_load(orig_conf_file)
|
||||||
config = {
|
|
||||||
'enable_registration':
|
|
||||||
orig_config.get('enable_registration', False)
|
|
||||||
}
|
|
||||||
|
|
||||||
if command == 'status':
|
return {
|
||||||
return bool(config['enable_registration'])
|
'public_registration': bool(config.get('enable_registration', False)),
|
||||||
elif command == 'enable':
|
}
|
||||||
config['enable_registration'] = True
|
|
||||||
elif command == 'disable':
|
|
||||||
config['enable_registration'] = False
|
|
||||||
|
|
||||||
|
|
||||||
|
@privileged
|
||||||
|
def set_config(public_registration: bool):
|
||||||
|
"""Enable/disable public user registration."""
|
||||||
|
config = {'enable_registration': public_registration}
|
||||||
with open(REGISTRATION_CONF_PATH, 'w', encoding='utf-8') as reg_conf_file:
|
with open(REGISTRATION_CONF_PATH, 'w', encoding='utf-8') as reg_conf_file:
|
||||||
yaml.dump(config, reg_conf_file)
|
yaml.dump(config, reg_conf_file)
|
||||||
|
|
||||||
action_utils.service_try_restart('matrix-synapse')
|
action_utils.service_try_restart('matrix-synapse')
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@privileged
|
@privileged
|
||||||
|
|||||||
@ -69,7 +69,7 @@ class MatrixSynapseAppView(AppView):
|
|||||||
config, managed = get_turn_configuration()
|
config, managed = get_turn_configuration()
|
||||||
initial.update({
|
initial.update({
|
||||||
'enable_public_registration':
|
'enable_public_registration':
|
||||||
privileged.public_registration('status'),
|
privileged.get_config()['public_registration'],
|
||||||
'enable_managed_turn':
|
'enable_managed_turn':
|
||||||
managed,
|
managed,
|
||||||
'turn_uris':
|
'turn_uris':
|
||||||
@ -79,14 +79,6 @@ class MatrixSynapseAppView(AppView):
|
|||||||
})
|
})
|
||||||
return initial
|
return initial
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _handle_public_registrations(new_config):
|
|
||||||
|
|
||||||
if new_config['enable_public_registration']:
|
|
||||||
privileged.public_registration('enable')
|
|
||||||
else:
|
|
||||||
privileged.public_registration('disable')
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _handle_turn_configuration(old_config, new_config):
|
def _handle_turn_configuration(old_config, new_config):
|
||||||
if not new_config['enable_managed_turn']:
|
if not new_config['enable_managed_turn']:
|
||||||
@ -116,7 +108,8 @@ class MatrixSynapseAppView(AppView):
|
|||||||
|
|
||||||
is_changed = False
|
is_changed = False
|
||||||
if changed('enable_public_registration'):
|
if changed('enable_public_registration'):
|
||||||
self._handle_public_registrations(new_config)
|
privileged.set_config(
|
||||||
|
public_registration=new_config['enable_public_registration'])
|
||||||
is_changed = True
|
is_changed = True
|
||||||
|
|
||||||
if changed('enable_managed_turn') or changed('turn_uris') or \
|
if changed('enable_managed_turn') or changed('turn_uris') or \
|
||||||
|
|||||||
@ -28,7 +28,7 @@ class MediaWikiAppView(views.AppView):
|
|||||||
initial = super().get_initial()
|
initial = super().get_initial()
|
||||||
initial.update({
|
initial.update({
|
||||||
'enable_public_registrations':
|
'enable_public_registrations':
|
||||||
privileged.public_registrations('status'),
|
privileged.get_config()['public_registration'],
|
||||||
'enable_private_mode':
|
'enable_private_mode':
|
||||||
privileged.private_mode('status'),
|
privileged.private_mode('status'),
|
||||||
'default_skin':
|
'default_skin':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user