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>
This commit is contained in:
2025-12-01 21:24:27 +03:00
parent 9f48ae0a35
commit 14cc73722f
11 changed files with 479 additions and 2 deletions

View File

@@ -0,0 +1,63 @@
{% extends "base.html" %}
{% block title %}Изменить роль пользователя{% endblock %}
{% block content %}
<div class="container mt-4">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h4 class="mb-0">Изменить роль пользователя</h4>
</div>
<div class="card-body">
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
{% endfor %}
{% endif %}
<div class="mb-3">
<label class="form-label">Пользователь:</label>
<p class="form-control-plaintext">{{ user_role.user.email }} ({{ user_role.user.name }})</p>
</div>
<form method="post">
{% csrf_token %}
<div class="mb-3">
<label for="role" class="form-label">Роль *</label>
<select class="form-select" id="role" name="role" required>
{% for role in roles %}
<option value="{{ role.code }}" {% if role.code == user_role.role.code %}selected{% endif %}>
{{ role.name }} - {{ role.description }}
</option>
{% endfor %}
</select>
</div>
<div class="mb-3">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="is_active" name="is_active"
{% if user_role.is_active %}checked{% endif %}>
<label class="form-check-label" for="is_active">
Активен
</label>
</div>
<div class="form-text">Снимите галочку, чтобы временно отключить доступ</div>
</div>
<div class="d-flex justify-content-between">
<a href="{% url 'user_roles:list' %}" class="btn btn-secondary">Отмена</a>
<button type="submit" class="btn btn-primary">Сохранить изменения</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}