fix: Reorders auto-join logic post-registration

Moves auto-join functionality for newly registered users to
occur after sending the registration approval email. Ensures
user feedback through email is handled before attempting room
joins, potentially improving user experience.
This commit is contained in:
Kumi 2024-11-16 20:23:20 +01:00
parent a43914de62
commit 5bb74d5389
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -28,6 +28,13 @@ def handle_status_change(sender, instance, created, **kwargs):
[settings.ADMIN_EMAIL], [settings.ADMIN_EMAIL],
) )
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}"},
)
send_mail( send_mail(
"Registration Approved", "Registration Approved",
f"Congratulations, {instance.username}! Your registration at {settings.MATRIX_DOMAIN} has been approved.", f"Congratulations, {instance.username}! Your registration at {settings.MATRIX_DOMAIN} has been approved.",
@ -49,13 +56,6 @@ 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",