ФУНКЦИИ - МЕЖПРОЕКТНАЯ КОММУНИКАЦИЯ: администрирование воркспейсов и feature-gates в God Mode

This commit is contained in:
DCCONSTRUCTIONS
2026-04-29 00:38:11 +03:00
parent 7f47b85c36
commit 7bf416ec1f
15 changed files with 923 additions and 40 deletions
@@ -0,0 +1,93 @@
# Generated by Codex on 2026-04-28
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("db", "0134_voice_tasker_retention"),
]
operations = [
migrations.CreateModel(
name="WorkspaceFeatureEntitlement",
fields=[
(
"created_at",
models.DateTimeField(auto_now_add=True, verbose_name="Created At"),
),
(
"updated_at",
models.DateTimeField(auto_now=True, verbose_name="Last Modified At"),
),
("deleted_at", models.DateTimeField(blank=True, editable=False, null=True)),
(
"id",
models.UUIDField(
db_index=True,
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
unique=True,
),
),
(
"feature_key",
models.CharField(
choices=[("voice_tasker", "AI / Voice Tasker")],
max_length=80,
),
),
("is_enabled", models.BooleanField(default=False)),
("metadata", models.JSONField(blank=True, default=dict)),
(
"created_by",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="%(class)s_created_by",
to=settings.AUTH_USER_MODEL,
verbose_name="Created By",
),
),
(
"updated_by",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="%(class)s_updated_by",
to=settings.AUTH_USER_MODEL,
verbose_name="Last Modified By",
),
),
(
"workspace",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="feature_entitlements",
to="db.workspace",
),
),
],
options={
"verbose_name": "Workspace Feature Entitlement",
"verbose_name_plural": "Workspace Feature Entitlements",
"db_table": "workspace_feature_entitlements",
"ordering": ("-created_at",),
},
),
migrations.AddConstraint(
model_name="workspacefeatureentitlement",
constraint=models.UniqueConstraint(
condition=models.Q(("deleted_at__isnull", True)),
fields=("workspace", "feature_key"),
name="workspace_feature_entitlement_unique_active_feature",
),
),
]
@@ -69,6 +69,7 @@ from .voice_tasker import VoiceTaskSession, WorkspaceAICredential, WorkspaceAISe
from .workspace import (
Workspace,
WorkspaceBaseModel,
WorkspaceFeatureEntitlement,
WorkspaceMember,
WorkspaceMemberInvite,
WorkspaceTheme,
@@ -260,6 +260,36 @@ class WorkspaceMemberInvite(BaseModel):
return f"{self.workspace.name} {self.email} {self.accepted}"
class WorkspaceFeatureEntitlement(BaseModel):
class FeatureKey(models.TextChoices):
VOICE_TASKER = "voice_tasker", "AI / Voice Tasker"
workspace = models.ForeignKey(
"db.Workspace",
on_delete=models.CASCADE,
related_name="feature_entitlements",
)
feature_key = models.CharField(max_length=80, choices=FeatureKey.choices)
is_enabled = models.BooleanField(default=False)
metadata = models.JSONField(default=dict, blank=True)
class Meta:
constraints = [
models.UniqueConstraint(
fields=["workspace", "feature_key"],
condition=models.Q(deleted_at__isnull=True),
name="workspace_feature_entitlement_unique_active_feature",
)
]
verbose_name = "Workspace Feature Entitlement"
verbose_name_plural = "Workspace Feature Entitlements"
db_table = "workspace_feature_entitlements"
ordering = ("-created_at",)
def __str__(self):
return f"{self.workspace.slug} <{self.feature_key}>"
class Team(BaseModel):
name = models.CharField(max_length=255, verbose_name="Team Name")
description = models.TextField(verbose_name="Team Description", blank=True)