Initial stuff for services.

This commit is contained in:
Víðir Valberg Guðmundsson 2024-01-13 20:42:31 +01:00
parent 43d5dcbd52
commit 2b50677114
13 changed files with 152 additions and 0 deletions

View file

@ -20,6 +20,7 @@ from .emails import InviteEmail
from .models import Member from .models import Member
from .models import Membership from .models import Membership
from .models import MembershipType from .models import MembershipType
from .models import ServiceAccess
from .models import SubscriptionPeriod from .models import SubscriptionPeriod
from .models import WaitingListEntry from .models import WaitingListEntry
@ -46,6 +47,12 @@ class SubscriptionPeriodAdmin(admin.ModelAdmin):
"""Admin for SubscriptionPeriod model.""" """Admin for SubscriptionPeriod model."""
@admin.register(ServiceAccess)
class ServiceAccessAdmin(admin.ModelAdmin):
"""Admin for ServiceAccess model."""
pass
class MembershipInlineAdmin(admin.TabularInline): class MembershipInlineAdmin(admin.TabularInline):
"""Inline admin.""" """Inline admin."""

View file

@ -0,0 +1,64 @@
# Generated by Django 5.0.1 on 2024-01-13 19:20
import django.db.models.deletion
import django_registries.registry
import services.registry
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("membership", "0005_member"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name="ServiceAccess",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"modified",
models.DateTimeField(auto_now=True, verbose_name="modified"),
),
(
"created",
models.DateTimeField(auto_now_add=True, verbose_name="created"),
),
(
"service",
django_registries.registry.ChoicesField(
choices=[],
registry=services.registry.ServiceRegistry,
verbose_name="service",
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"verbose_name": "service access",
"verbose_name_plural": "service accesses",
},
),
migrations.AddConstraint(
model_name="serviceaccess",
constraint=models.UniqueConstraint(
fields=("user", "service"), name="unique_user_service"
),
),
]

View file

@ -12,6 +12,8 @@ from django.contrib.postgres.fields import RangeOperators
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from services.registry import ServiceRegistry
from djmoney.money import Money from djmoney.money import Money
from utils.mixins import CreatedModifiedAbstract from utils.mixins import CreatedModifiedAbstract
@ -245,3 +247,22 @@ class WaitingListEntry(CreatedModifiedAbstract):
class Meta: class Meta:
verbose_name = _("waiting list entry") verbose_name = _("waiting list entry")
verbose_name_plural = _("waiting list entries") verbose_name_plural = _("waiting list entries")
class ServiceAccess(CreatedModifiedAbstract):
class Meta:
verbose_name = _("service access")
verbose_name_plural = _("service accesses")
constraints = [
models.UniqueConstraint(
fields=["user", "service"],
name="unique_user_service",
),
]
user = models.ForeignKey("auth.User", on_delete=models.PROTECT)
service = ServiceRegistry.choices_field(verbose_name=_("service"))
def __str__(self):
return f"{self.user} - {self.service}"

View file

@ -46,12 +46,14 @@ THIRD_PARTY_APPS = [
"allauth", "allauth",
"allauth.account", "allauth.account",
"django_view_decorator", "django_view_decorator",
"django_registries",
] ]
LOCAL_APPS = [ LOCAL_APPS = [
"utils", "utils",
"accounting", "accounting",
"membership", "membership",
"services",
] ]
INSTALLED_APPS = [ INSTALLED_APPS = [

0
src/services/__init__.py Normal file
View file

1
src/services/admin.py Normal file
View file

@ -0,0 +1 @@
# Register your models here.

6
src/services/apps.py Normal file
View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class ServicesConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "services"

View file

1
src/services/models.py Normal file
View file

@ -0,0 +1 @@
# Create your models here.

21
src/services/registry.py Normal file
View file

@ -0,0 +1,21 @@
from django_registries.registry import Interface
from django_registries.registry import Registry
class ServiceRegistry(Registry):
"""Registry for services"""
implementations_module = "services"
class ServiceInterface(Interface):
"""Interface for services"""
registry = ServiceRegistry
public: bool = False
# 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

27
src/services/services.py Normal file
View file

@ -0,0 +1,27 @@
from .registry import ServiceInterface
class MailService(ServiceInterface):
slug = "mail"
class MatrixService(ServiceInterface):
slug = "matrix"
class MastodonService(ServiceInterface):
slug = "mastodon"
class NextcloudService(ServiceInterface):
slug = "nextcloud"
class HedgeDocService(ServiceInterface):
slug = "hedgedoc"
public = True
class RalllyService(ServiceInterface):
slug = "rallly"
public = True

1
src/services/tests.py Normal file
View file

@ -0,0 +1 @@
# Create your tests here.

1
src/services/views.py Normal file
View file

@ -0,0 +1 @@
# Create your views here.