Files
octopus/assign_owner_role.py
Andrey Smakotin 14cc73722f feat: add user roles management UI with owner access control
- Added role management views (list, create, edit, delete)
- Created user_roles URL routing
- Added role management templates with Bootstrap styling
- Updated navbar with Roles link for owners and superusers
- Enhanced decorators and mixins with superuser bypass
- Added assign_owner_role.py utility script

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-01 21:24:27 +03:00

49 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import sys
import django
# Добавляем путь к проекту
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'myproject'))
# Настраиваем Django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
django.setup()
from django.contrib.auth import get_user_model
from django_tenants.utils import schema_context
from user_roles.services import RoleService
User = get_user_model()
# Схема тенанта
schema_name = 'buba'
# Email пользователя
user_email = 'admin@localhost'
print(f"Назначение роли Owner для пользователя {user_email} в тенанте {schema_name}...")
# Переключаемся на схему тенанта
with schema_context(schema_name):
try:
# Находим пользователя
user = User.objects.get(email=user_email)
print(f"Пользователь найден: {user.email} (ID: {user.id})")
# Назначаем роль Owner
user_role = RoleService.assign_role_to_user(user, 'owner')
print(f"✓ Роль '{user_role.role.name}' успешно назначена!")
print(f" - Email: {user_role.user.email}")
print(f" - Имя: {user_role.user.name}")
print(f" - Роль: {user_role.role.name} ({user_role.role.code})")
print(f" - Активен: {user_role.is_active}")
except User.DoesNotExist:
print(f"✗ Ошибка: Пользователь с email '{user_email}' не найден")
except Exception as e:
print(f"✗ Ошибка при назначении роли: {e}")
import traceback
traceback.print_exc()
print("\nГотово!")