Большое обновление
1. Создание личных проектов 2. Управление командой 3. Приглашение участников 4. Уведомления и многое другое...
This commit is contained in:
85
backend/api/projectAccess.php
Normal file
85
backend/api/projectAccess.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
if ($method === 'POST') {
|
||||
$data = RestApi::getInput();
|
||||
$action = $data['action'] ?? null;
|
||||
$current_user_id = RestApi::getCurrentUserId();
|
||||
|
||||
// Приглашение участника в проект (только админ)
|
||||
if ($action === 'add_member') {
|
||||
$project_id = (int)($data['project_id'] ?? 0);
|
||||
$user_id = (int)($data['user_id'] ?? 0);
|
||||
$is_admin = (bool)($data['is_admin'] ?? false);
|
||||
$permissions = $data['permissions'] ?? null;
|
||||
|
||||
if (!$project_id || !$user_id) {
|
||||
RestApi::response(['success' => false, 'errors' => ['data' => 'Укажите project_id и user_id']], 400);
|
||||
}
|
||||
|
||||
// Приглашать участников могут только админы
|
||||
ProjectAccess::requireAdmin($project_id, $current_user_id);
|
||||
|
||||
$result = ProjectAccess::addMember($project_id, $user_id, $current_user_id, $is_admin, $permissions);
|
||||
RestApi::response($result, $result['success'] ? 200 : 400);
|
||||
}
|
||||
|
||||
// Обновление прав участника (только админ)
|
||||
if ($action === 'update_member') {
|
||||
$project_id = (int)($data['project_id'] ?? 0);
|
||||
$user_id = (int)($data['user_id'] ?? 0);
|
||||
$is_admin = isset($data['is_admin']) ? (bool)$data['is_admin'] : null;
|
||||
$permissions = $data['permissions'] ?? null;
|
||||
|
||||
if (!$project_id || !$user_id) {
|
||||
RestApi::response(['success' => false, 'errors' => ['data' => 'Укажите project_id и user_id']], 400);
|
||||
}
|
||||
|
||||
// Редактировать права могут только админы
|
||||
ProjectAccess::requireAdmin($project_id, $current_user_id);
|
||||
|
||||
// Обновляем is_admin если передан
|
||||
if ($is_admin !== null) {
|
||||
$result = ProjectAccess::setAdmin($project_id, $user_id, $is_admin, $current_user_id);
|
||||
if (!$result['success']) {
|
||||
RestApi::response($result, 400);
|
||||
}
|
||||
}
|
||||
|
||||
// Обновляем права если переданы
|
||||
if ($permissions !== null) {
|
||||
$result = ProjectAccess::setPermissions($project_id, $user_id, $permissions, $current_user_id);
|
||||
if (!$result['success']) {
|
||||
RestApi::response($result, 400);
|
||||
}
|
||||
}
|
||||
|
||||
RestApi::response(['success' => true]);
|
||||
}
|
||||
|
||||
// Удаление участника из проекта (право remove_members или админ, или сам себя)
|
||||
if ($action === 'remove_member') {
|
||||
$project_id = (int)($data['project_id'] ?? 0);
|
||||
$user_id = (int)($data['user_id'] ?? 0);
|
||||
|
||||
if (!$project_id || !$user_id) {
|
||||
RestApi::response(['success' => false, 'errors' => ['data' => 'Укажите project_id и user_id']], 400);
|
||||
}
|
||||
|
||||
// Пользователь может удалить сам себя, иначе нужно право remove_members
|
||||
if ((int)$user_id !== (int)$current_user_id) {
|
||||
ProjectAccess::requirePermission($project_id, $current_user_id, 'remove_members');
|
||||
}
|
||||
|
||||
$result = ProjectAccess::removeMember($project_id, $user_id, $current_user_id);
|
||||
RestApi::response($result, $result['success'] ? 200 : 400);
|
||||
}
|
||||
|
||||
// Метод не указан
|
||||
if (!$action) {
|
||||
RestApi::response(['success' => false, 'error' => 'Укажите метод'], 400);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user