38 lines
1.7 KiB
Python
38 lines
1.7 KiB
Python
|
|
from django.conf import settings
|
||
|
|
from django.db import migrations, models
|
||
|
|
import django.db.models.deletion
|
||
|
|
|
||
|
|
|
||
|
|
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 Migration(migrations.Migration):
|
||
|
|
initial = True
|
||
|
|
dependencies = [migrations.swappable_dependency(settings.AUTH_USER_MODEL)]
|
||
|
|
operations = [
|
||
|
|
migrations.CreateModel(
|
||
|
|
name="ApplicationGrant",
|
||
|
|
fields=[
|
||
|
|
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
|
||
|
|
("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)),
|
||
|
|
("user", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||
|
|
],
|
||
|
|
options={
|
||
|
|
"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"),
|
||
|
|
]
|
||
|
|
},
|
||
|
|
)
|
||
|
|
]
|