From a43914de625f7f88cef30c985d0efebc484905b6 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 16 Nov 2024 20:19:48 +0100 Subject: [PATCH] feat: Add automatic room joining for new users Introduces automatic room joining upon user registration. Updates configuration to include a list of rooms for auto-join. Enhances user onboarding experience by simplifying setup. Addresses onboarding workflow. --- config.dist.yaml | 4 +++- src/synapse_registration/registration/signals.py | 7 +++++++ src/synapse_registration/registration/views.py | 2 ++ src/synapse_registration/synapse_registration/settings.py | 5 +++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/config.dist.yaml b/config.dist.yaml index 28079d3..f6f5fc6 100644 --- a/config.dist.yaml +++ b/config.dist.yaml @@ -12,4 +12,6 @@ email: tls: true admin: email: admin@your.server -trust_proxy: false \ No newline at end of file +trust_proxy: false +auto_join: + - "!your_room_id:your.server" diff --git a/src/synapse_registration/registration/signals.py b/src/synapse_registration/registration/signals.py index 8b396ac..c90ffe3 100644 --- a/src/synapse_registration/registration/signals.py +++ b/src/synapse_registration/registration/signals.py @@ -49,6 +49,13 @@ def handle_status_change(sender, instance, created, **kwargs): headers={"Authorization": f"Bearer {settings.SYNAPSE_ADMIN_TOKEN}"}, ) + for room in settings.AUTO_JOIN: + response = requests.post( + f"{settings.SYNAPSE_SERVER}/_synapse/admin/v1/join/{room}", + json={"user_id": f"@{instance.username}:{settings.MATRIX_DOMAIN}"}, + headers={"Authorization": f"Bearer {settings.SYNAPSE_ADMIN_TOKEN}"}, + ) + if response.status_code != 200: send_mail( "Deactivation Failed", diff --git a/src/synapse_registration/registration/views.py b/src/synapse_registration/registration/views.py index bd6d3e5..0aa755f 100644 --- a/src/synapse_registration/registration/views.py +++ b/src/synapse_registration/registration/views.py @@ -144,12 +144,14 @@ class CompleteRegistrationView(FormView): registration.status = UserRegistration.STATUS_REQUESTED registration.registration_reason = registration_reason registration.save() + send_mail( "New Registration Request", f"Approve the new user {username}", settings.DEFAULT_FROM_EMAIL, [settings.ADMIN_EMAIL], ) + return render(self.request, "registration/registration_pending.html") form.add_error(None, "Registration failed.") diff --git a/src/synapse_registration/synapse_registration/settings.py b/src/synapse_registration/synapse_registration/settings.py index 856f71a..4ae0ee6 100644 --- a/src/synapse_registration/synapse_registration/settings.py +++ b/src/synapse_registration/synapse_registration/settings.py @@ -69,6 +69,11 @@ SYNAPSE_SERVER = config["synapse"]["server"] SYNAPSE_ADMIN_TOKEN = config["synapse"]["admin_token"] MATRIX_DOMAIN = config["synapse"]["domain"] +if "auto_join" in config: + AUTO_JOIN = config["auto_join"] +else: + AUTO_JOIN = [] + response = requests.get( f"{SYNAPSE_SERVER}/_matrix/client/r0/account/whoami", headers={"Authorization": f"Bearer {SYNAPSE_ADMIN_TOKEN}"},