Convert web service from FastAPI to Django 6.1

Replace the FastAPI/SQLAlchemy/Alembic web service with a Django project
laid out like cumorah-build: manage.py at the root, settings in the
privatestudio.settings package (base/dev/production), and a
privatestudio.studio app.

- Studio model owns a unique bucket_name; access is granted through
  membership in the studio's auth Group. Assets, profiles and jobs are
  scoped to a studio; API keys and S3 credentials stay per user.
- JSON API via Django Ninja under /api/ (profiles and transcode jobs now
  live under /api/studios/{bucket}/).
- S3-compatible interface as plain class-based views under /s3/,
  supporting bearer tokens and AWS v4 signatures.
- create_studio and create_key management commands replace ps-serve.
- Fresh Django initial migration; tests ported to Django TestCase.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shaun Kruger
2026-11-29 21:54:16 -07:00
co-authored by Claude Opus 5.5
parent 46adddd50a
commit b3b51f6cc5
60 changed files with 1776 additions and 3002 deletions
@@ -0,0 +1,42 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.core.management.base import BaseCommand, CommandError
from django.utils.text import slugify
from privatestudio.studio.models import Studio
class Command(BaseCommand):
help = "Create a studio (S3 bucket) whose access is granted by membership in a group."
def add_arguments(self, parser):
parser.add_argument("bucket_name", help="Unique bucket name for the studio")
parser.add_argument("--name", help="Display name (defaults to the bucket name)")
parser.add_argument("--group", required=True, help="Group granting access (created if missing)")
parser.add_argument("--add-user", action="append", default=[], metavar="USERNAME",
help="Add a user to the group (may be repeated)")
def handle(self, *args, **options):
bucket_name = options["bucket_name"]
if slugify(bucket_name) != bucket_name:
raise CommandError(f"Invalid bucket name '{bucket_name}': use lowercase letters, digits and hyphens")
if Studio.objects.filter(bucket_name=bucket_name).exists():
raise CommandError(f"Studio with bucket '{bucket_name}' already exists")
User = get_user_model()
users = []
for username in options["add_user"]:
try:
users.append(User.objects.get_by_natural_key(username))
except User.DoesNotExist:
raise CommandError(f"User '{username}' not found")
group, created = Group.objects.get_or_create(name=options["group"])
if created:
self.stdout.write(f"Created group '{group.name}'")
for user in users:
user.groups.add(group)
self.stdout.write(f"Added {user.get_username()} to group '{group.name}'")
studio = Studio.objects.create(name=options["name"] or bucket_name, bucket_name=bucket_name, group=group)
self.stdout.write(self.style.SUCCESS(f"Studio created: {studio}"))