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:
parent
044f18b822
commit
a43914de62
4 changed files with 17 additions and 1 deletions
|
@ -12,4 +12,6 @@ email:
|
||||||
tls: true
|
tls: true
|
||||||
admin:
|
admin:
|
||||||
email: admin@your.server
|
email: admin@your.server
|
||||||
trust_proxy: false
|
trust_proxy: false
|
||||||
|
auto_join:
|
||||||
|
- "!your_room_id:your.server"
|
||||||
|
|
|
@ -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",
|
||||||
|
|
|
@ -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.")
|
||||||
|
|
|
@ -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}"},
|
||||||
|
|
Loading…
Reference in a new issue