Backend (Django 4.2 + DRF): - accounts: phone OTP login, JWT, profile, addresses - catalog: categories, products, images, filters, search, hits/new/related - orders: creation with Idempotency-Key, stock reservation, status history, cancel - loyalty: bonus accounts, promo codes, gift certificates - payments: payment records and YooKassa webhook handling - content: static pages, banners, site settings - integration: 1C exchange (catalog sync, order push via outbox, statuses, bonuses) - common: error envelope, pagination, request-id, integration auth, admin dashboard Infrastructure: Dockerfile, docker-compose (Postgres, Redis, Celery worker/beat, Nginx), requirements split by environment, OpenAPI contracts for site and 1C, architecture doc. Tests: 22 pytest cases covering catalog, orders, idempotency, OTP, integration.
28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
from django.contrib.auth.models import Group, Permission
|
|
from django.core.management.base import BaseCommand
|
|
|
|
ROLES = {
|
|
"Контент-менеджер": ["content", "catalog"],
|
|
"Менеджер заказов": ["orders", "payments"],
|
|
"Менеджер лояльности": ["loyalty"],
|
|
"Технический администратор": ["integration"],
|
|
}
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Creates the default admin roles (groups) and assigns app permissions."
|
|
|
|
def handle(self, *args, **options):
|
|
for role, app_labels in ROLES.items():
|
|
group, created = Group.objects.get_or_create(name=role)
|
|
permissions = Permission.objects.filter(
|
|
content_type__app_label__in=app_labels
|
|
)
|
|
group.permissions.set(permissions)
|
|
state = "создана" if created else "обновлена"
|
|
self.stdout.write(
|
|
self.style.SUCCESS(
|
|
f"Роль «{role}» {state}: {permissions.count()} прав"
|
|
)
|
|
)
|