feat(dgsi): Add a Service model
This will allow to list our services, whith links directly in the app and perform ToS verification
This commit is contained in:
parent
cfa14a6aae
commit
9b7f4f17e8
5 changed files with 62 additions and 4 deletions
|
@ -1,9 +1,15 @@
|
|||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
||||
|
||||
from dgsi.models import User
|
||||
from unfold.admin import ModelAdmin
|
||||
|
||||
from dgsi.models import Service, User
|
||||
|
||||
|
||||
@admin.register(User)
|
||||
class UserAdmin(BaseUserAdmin, ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
@admin.register(Service)
|
||||
class AdminClass(ModelAdmin):
|
||||
compressed_fields = True
|
||||
|
|
33
src/dgsi/migrations/0002_service.py
Normal file
33
src/dgsi/migrations/0002_service.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
# Generated by Django 4.2.12 on 2024-09-23 15:03
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("dgsi", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Service",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
(
|
||||
"name",
|
||||
models.CharField(
|
||||
max_length=255, verbose_name="Nom du service proposé"
|
||||
),
|
||||
),
|
||||
("url", models.URLField(verbose_name="Adresse du service")),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -4,6 +4,8 @@ from typing import Optional
|
|||
|
||||
from asgiref.sync import async_to_sync
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from kanidm.exceptions import NoMatchingEntries
|
||||
from kanidm.models.person import Person
|
||||
|
||||
|
@ -12,6 +14,14 @@ from shared.kanidm import client
|
|||
ADMIN_GROUP = "idm_admins@sso.dgnum.eu"
|
||||
|
||||
|
||||
class Service(models.Model):
|
||||
name = models.CharField(_("Nom du service proposé"), max_length=255)
|
||||
url = models.URLField(_("Adresse du service"))
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.name} [{self.url}]"
|
||||
|
||||
|
||||
@dataclass
|
||||
class KanidmProfile:
|
||||
person: Person
|
||||
|
|
|
@ -16,4 +16,5 @@ urlpatterns = [
|
|||
views.TemplateView.as_view(template_name="account/forbidden_category.html"),
|
||||
name="dgn-forbidden_account",
|
||||
),
|
||||
path("services/", views.ServiceListView.as_view(), name="dgn-services"),
|
||||
]
|
||||
|
|
|
@ -5,11 +5,11 @@ from django.core.mail import EmailMessage
|
|||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import FormView, TemplateView
|
||||
from django.views.generic import FormView, ListView, TemplateView
|
||||
|
||||
from dgsi.forms import CreateKanidmAccountForm
|
||||
from dgsi.mixins import StaffRequiredMixin
|
||||
from dgsi.models import User
|
||||
from dgsi.models import Service, User
|
||||
from shared.kanidm import client
|
||||
|
||||
|
||||
|
@ -26,6 +26,14 @@ class ProfileView(LoginRequiredMixin, TemplateView):
|
|||
)
|
||||
|
||||
|
||||
class ServiceListView(LoginRequiredMixin, ListView):
|
||||
model = Service
|
||||
|
||||
|
||||
##
|
||||
# INFO: Below are views related to the administration of DGSI
|
||||
|
||||
|
||||
class CreateKanidmAccountView(StaffRequiredMixin, SuccessMessageMixin, FormView):
|
||||
form_class = CreateKanidmAccountForm
|
||||
template_name = "account/create_kanidm.html"
|
||||
|
|
Loading…
Reference in a new issue