mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +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():
|
||||
"""Upgrade matrix-synapse configuration to avoid conffile prompt."""
|
||||
public_registration_status = privileged.public_registration('status')
|
||||
config = privileged.get_config()
|
||||
privileged.move_old_conf()
|
||||
install(['matrix-synapse'], force_configuration='new', reinstall=True,
|
||||
force_missing_configuration=True)
|
||||
privileged.post_install()
|
||||
if public_registration_status:
|
||||
privileged.public_registration('enable')
|
||||
privileged.set_config(**config)
|
||||
|
||||
|
||||
def setup_domain(domain_name):
|
||||
|
||||
@ -69,36 +69,29 @@ def setup(domain_name: str):
|
||||
{'server-name': domain_name})
|
||||
|
||||
|
||||
@privileged
|
||||
def public_registration(command: str) -> Optional[bool]:
|
||||
"""Enable/Disable/Status public user registration."""
|
||||
if command not in ('enable', 'disable', 'status'):
|
||||
raise ValueError('Invalid command')
|
||||
|
||||
def get_config():
|
||||
"""Return the current configuration of matrix-synapse."""
|
||||
try:
|
||||
with open(REGISTRATION_CONF_PATH, encoding='utf-8') as reg_conf_file:
|
||||
config = yaml.safe_load(reg_conf_file)
|
||||
except FileNotFoundError:
|
||||
# Check if its set in original conffile.
|
||||
with open(ORIG_CONF_PATH, encoding='utf-8') as orig_conf_file:
|
||||
orig_config = yaml.safe_load(orig_conf_file)
|
||||
config = {
|
||||
'enable_registration':
|
||||
orig_config.get('enable_registration', False)
|
||||
}
|
||||
config = yaml.safe_load(orig_conf_file)
|
||||
|
||||
if command == 'status':
|
||||
return bool(config['enable_registration'])
|
||||
elif command == 'enable':
|
||||
config['enable_registration'] = True
|
||||
elif command == 'disable':
|
||||
config['enable_registration'] = False
|
||||
return {
|
||||
'public_registration': bool(config.get('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:
|
||||
yaml.dump(config, reg_conf_file)
|
||||
|
||||
action_utils.service_try_restart('matrix-synapse')
|
||||
return None
|
||||
|
||||
|
||||
@privileged
|
||||
|
||||
@ -69,7 +69,7 @@ class MatrixSynapseAppView(AppView):
|
||||
config, managed = get_turn_configuration()
|
||||
initial.update({
|
||||
'enable_public_registration':
|
||||
privileged.public_registration('status'),
|
||||
privileged.get_config()['public_registration'],
|
||||
'enable_managed_turn':
|
||||
managed,
|
||||
'turn_uris':
|
||||
@ -79,14 +79,6 @@ class MatrixSynapseAppView(AppView):
|
||||
})
|
||||
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
|
||||
def _handle_turn_configuration(old_config, new_config):
|
||||
if not new_config['enable_managed_turn']:
|
||||
@ -116,7 +108,8 @@ class MatrixSynapseAppView(AppView):
|
||||
|
||||
is_changed = False
|
||||
if changed('enable_public_registration'):
|
||||
self._handle_public_registrations(new_config)
|
||||
privileged.set_config(
|
||||
public_registration=new_config['enable_public_registration'])
|
||||
is_changed = True
|
||||
|
||||
if changed('enable_managed_turn') or changed('turn_uris') or \
|
||||
|
||||
@ -28,7 +28,7 @@ class MediaWikiAppView(views.AppView):
|
||||
initial = super().get_initial()
|
||||
initial.update({
|
||||
'enable_public_registrations':
|
||||
privileged.public_registrations('status'),
|
||||
privileged.get_config()['public_registration'],
|
||||
'enable_private_mode':
|
||||
privileged.private_mode('status'),
|
||||
'default_skin':
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user