Change drone.yml
This commit is contained in:
@@ -445,9 +445,11 @@ async def delete_user(username: str, user: dict = Depends(get_current_user)):
|
||||
if username not in users:
|
||||
raise HTTPException(404, "Пользователь не найден")
|
||||
|
||||
# Нельзя удалить другого владельца
|
||||
# Проверяем, что не удаляем последнего владельца
|
||||
if users[username]["role"] == "owner":
|
||||
raise HTTPException(400, "Нельзя удалить владельца")
|
||||
owners_count = sum(1 for u in users.values() if u.get("role") == "owner")
|
||||
if owners_count <= 1:
|
||||
raise HTTPException(400, "Нельзя удалить последнего владельца")
|
||||
|
||||
del users[username]
|
||||
save_users(users)
|
||||
@@ -1672,11 +1674,8 @@ async def change_user_role(username: str, role_data: RoleChange, current_user: d
|
||||
if role_data.role not in valid_roles:
|
||||
raise HTTPException(status_code=400, detail=f"Неверная роль")
|
||||
|
||||
# Если назначается новый owner, текущий owner становится admin
|
||||
if role_data.role == "owner":
|
||||
for user in users.values():
|
||||
if user.get("role") == "owner":
|
||||
user["role"] = "admin"
|
||||
# Разрешаем несколько владельцев (убрано ограничение на одного)
|
||||
# Теперь можно назначить несколько пользователей с ролью owner
|
||||
|
||||
old_role = users[username].get("role", "user")
|
||||
users[username]["role"] = role_data.role
|
||||
@@ -1733,8 +1732,11 @@ async def ban_user(username: str, ban_data: BanRequest, current_user: dict = Dep
|
||||
if username == current_user.get("username"):
|
||||
raise HTTPException(status_code=400, detail="Нельзя заблокировать самого себя")
|
||||
|
||||
# Проверяем, что не блокируем последнего владельца
|
||||
if users[username].get("role") == "owner":
|
||||
raise HTTPException(status_code=400, detail="Нельзя заблокировать владельца")
|
||||
owners_count = sum(1 for u in users.values() if u.get("role") == "owner")
|
||||
if owners_count <= 1:
|
||||
raise HTTPException(status_code=400, detail="Нельзя заблокировать последнего владельца. Должен остаться хотя бы один владелец.")
|
||||
|
||||
users[username]["role"] = "banned"
|
||||
users[username]["permissions"] = {
|
||||
@@ -1786,8 +1788,11 @@ async def delete_user(username: str, current_user: dict = Depends(get_current_us
|
||||
if username == current_user.get("username"):
|
||||
raise HTTPException(status_code=400, detail="Нельзя удалить самого себя")
|
||||
|
||||
# Проверяем, что не удаляем последнего владельца
|
||||
if users[username].get("role") == "owner":
|
||||
raise HTTPException(status_code=400, detail="Нельзя удалить владельца")
|
||||
owners_count = sum(1 for u in users.values() if u.get("role") == "owner")
|
||||
if owners_count <= 1:
|
||||
raise HTTPException(status_code=400, detail="Нельзя удалить последнего владельца. Должен остаться хотя бы один владелец.")
|
||||
|
||||
del users[username]
|
||||
save_users_dict(users)
|
||||
|
||||
Reference in New Issue
Block a user