
* [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>
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
"""Registry for services."""
|
|
|
|
from django import forms
|
|
from django.db.models import TextChoices
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django_registries.registry import Interface
|
|
from django_registries.registry import Registry
|
|
|
|
|
|
class ServiceRegistry(Registry):
|
|
"""Registry for services."""
|
|
|
|
implementations_module = "services"
|
|
|
|
|
|
class ServiceRequests(TextChoices):
|
|
CREATION = "CREATION", _("Creation")
|
|
PASSWORD_RESET = "PASSWORD_RESET", _("Password reset")
|
|
DELETION = "DELETION", _("Deletion")
|
|
|
|
|
|
DEFAULT_SERVICE_REQUEST_TYPES = [ServiceRequests.CREATION, ServiceRequests.PASSWORD_RESET, ServiceRequests.DELETION]
|
|
|
|
|
|
class ServiceInterface(Interface):
|
|
"""Interface for services."""
|
|
|
|
registry = ServiceRegistry
|
|
|
|
name: str
|
|
description: str
|
|
url: str
|
|
|
|
public: bool = False
|
|
|
|
# An auto-created service is added for all new members.
|
|
# This is a way of saying that the service is "mandatory" to have.
|
|
auto_create: bool = False
|
|
|
|
request_types: list[str, str] = DEFAULT_SERVICE_REQUEST_TYPES
|
|
|
|
# TODO: add a way to add a something which defines the required fields for a service
|
|
# - maybe a list of tuples with the field name and the type of the field
|
|
# this could be used to generate a form for the service, and also to validate
|
|
# the data saved in a JSONField on the ServiceAccess model
|
|
|
|
subscribe_fields: tuple[tuple[str, forms.Field]] = []
|
|
|
|
def get_form_class(self) -> type:
|
|
"""Get the form class for the service."""
|
|
return type(
|
|
"ServiceForm",
|
|
(forms.Form,),
|
|
dict(self.subscribe_fields),
|
|
)
|
|
|
|
def __str__(self) -> str:
|
|
return self.name
|