* [x] Adds a ServiceRequest model for all service types
* [x] Pre-define simple service requests to begin with
* [x] Django admin for admins to handle requests
* [x] Notifications for Matrix
* [x] Moved Service Access to `services` app
* [x] Auto-create default service requests for new memberships
* [x] Most simple kinds of tests added
* [x] Fix issue in generating service requests (check for service access firstly)
* [ ] Channel and bot account
## Deployment
1. Create a bot account. Get an access token with:
```
curl -XPOST \
-d '{"type":"m.login.password", "user":"<userid>", "password":"<password>"}' \
"https://data.coop/_matrix/client/r0/login"
```
2. Create an admin room for admins. Add admins + bot. Copy the room ID.
3. Add new environment variables for the setup `MATRIX_ACCESS_TOKEN` and `MATRIX_SERVICE_REQUEST_ADMIN_ROOM`
Reviewed-on: https://git.data.coop/data.coop/membersystem/pulls/59
Co-authored-by: bbb <benjamin@overtag.dk>
Co-committed-by: bbb <benjamin@overtag.dk>
25 lines
729 B
Python
25 lines
729 B
Python
from urllib.parse import urljoin
|
|
|
|
import httpx
|
|
from django.conf import settings
|
|
|
|
|
|
def notify_admins(message: str) -> None:
|
|
"""Notify admins on their own Matrix channel."""
|
|
return notify_matrix_channel(settings.MATRIX_SERVICE_REQUEST_ADMIN_ROOM, message)
|
|
|
|
|
|
def notify_matrix_channel(channel_url: str, message: str) -> None:
|
|
"""Send a message to a matrix channel."""
|
|
result = httpx.post(
|
|
urljoin(channel_url, "send/m.room.message"),
|
|
json={
|
|
"msgtype": "m.text",
|
|
"body": message,
|
|
},
|
|
params={
|
|
"access_token": settings.MATRIX_ACCESS_TOKEN,
|
|
},
|
|
)
|
|
if settings.MATRIX_ACCESS_TOKEN and not settings.DEBUG:
|
|
result.raise_for_status()
|