Files

26 lines
1.2 KiB
Python
Raw Permalink Normal View History

2026-11-14 20:23:59 +01:00
from django.conf import settings
from django.db import models
APPLICATIONS = (
"auto-care", "autonomous-dev-studio", "codex-commander", "knowledge-graph",
"loutre-brain", "loutre-finance", "loutre-home", "loutre-os",
"nasflix-ai-media-curator", "nasflix-media-health", "network-guardian",
"pi-doctor", "print-pilot", "pwa-factory", "reverse-proxy-manager",
"smart-inventory", "trip-organizer",
)
ROLES = ("reader", "operator", "admin")
class ApplicationGrant(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
application = models.CharField(max_length=64, choices=[(name, name) for name in APPLICATIONS])
role = models.CharField(max_length=16, choices=[(name, name) for name in ROLES])
updated_at = models.DateTimeField(auto_now=True)
class Meta:
constraints = [
models.UniqueConstraint(fields=("user", "application"), name="identity_user_application"),
models.CheckConstraint(condition=models.Q(application__in=APPLICATIONS), name="identity_known_application"),
models.CheckConstraint(condition=models.Q(role__in=ROLES), name="identity_known_role"),
]