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.
This commit is contained in:
Kumi 2024-11-16 20:19:48 +01:00
parent 044f18b822
commit a43914de62
Signed by: kumi
GPG key ID: ECBCC9082395383F
4 changed files with 17 additions and 1 deletions

View file

@ -13,3 +13,5 @@ email:
admin: admin:
email: admin@your.server email: admin@your.server
trust_proxy: false trust_proxy: false
auto_join:
- "!your_room_id:your.server"

View file

@ -49,6 +49,13 @@ def handle_status_change(sender, instance, created, **kwargs):
headers={"Authorization": f"Bearer {settings.SYNAPSE_ADMIN_TOKEN}"}, 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: if response.status_code != 200:
send_mail( send_mail(
"Deactivation Failed", "Deactivation Failed",

View file

@ -144,12 +144,14 @@ class CompleteRegistrationView(FormView):
registration.status = UserRegistration.STATUS_REQUESTED registration.status = UserRegistration.STATUS_REQUESTED
registration.registration_reason = registration_reason registration.registration_reason = registration_reason
registration.save() registration.save()
send_mail( send_mail(
"New Registration Request", "New Registration Request",
f"Approve the new user {username}", f"Approve the new user {username}",
settings.DEFAULT_FROM_EMAIL, settings.DEFAULT_FROM_EMAIL,
[settings.ADMIN_EMAIL], [settings.ADMIN_EMAIL],
) )
return render(self.request, "registration/registration_pending.html") return render(self.request, "registration/registration_pending.html")
form.add_error(None, "Registration failed.") form.add_error(None, "Registration failed.")

View file

@ -69,6 +69,11 @@ SYNAPSE_SERVER = config["synapse"]["server"]
SYNAPSE_ADMIN_TOKEN = config["synapse"]["admin_token"] SYNAPSE_ADMIN_TOKEN = config["synapse"]["admin_token"]
MATRIX_DOMAIN = config["synapse"]["domain"] MATRIX_DOMAIN = config["synapse"]["domain"]
if "auto_join" in config:
AUTO_JOIN = config["auto_join"]
else:
AUTO_JOIN = []
response = requests.get( response = requests.get(
f"{SYNAPSE_SERVER}/_matrix/client/r0/account/whoami", f"{SYNAPSE_SERVER}/_matrix/client/r0/account/whoami",
headers={"Authorization": f"Bearer {SYNAPSE_ADMIN_TOKEN}"}, headers={"Authorization": f"Bearer {SYNAPSE_ADMIN_TOKEN}"},