Files
ACORE/apps/hiring/migrations/0005_seed_intern_accounts.py
T
lokses 70e5a77b04 Harden portal access and hiring, add RRO portal CRUD.
Remove the is_staff permission bridge, tighten intern credential handling with one-time PDFs and random seed passwords, and let staff manage cash registers from the portal.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-10 08:54:41 +03:00

42 lines
1.1 KiB
Python

"""Seed pool of 5 shared intern accounts for hiring trial period.
Passwords are random per environment — set/rotate real ones in admin after migrate.
"""
import secrets
from django.db import migrations
def seed_intern_accounts(apps, schema_editor):
# Concrete model — EncryptedCharField must encrypt on save.
from apps.hiring.models import InternAccount
for i in range(1, 6):
InternAccount.objects.get_or_create(
label=f'Intern-{i}',
defaults={
'username': f'intern{i}',
'password': secrets.token_urlsafe(12),
'is_active': True,
},
)
def unseed_intern_accounts(apps, schema_editor):
InternAccount = apps.get_model('hiring', 'InternAccount')
InternAccount.objects.filter(
label__in=[f'Intern-{i}' for i in range(1, 6)],
assigned_to__isnull=True,
).delete()
class Migration(migrations.Migration):
dependencies = [
('hiring', '0004_intern_account_and_user_location'),
]
operations = [
migrations.RunPython(seed_intern_accounts, unseed_intern_accounts),
]