Большое обновление
1. Создание личных проектов 2. Управление командой 3. Приглашение участников 4. Уведомления и многое другое...
This commit is contained in:
134
backend/api/projectInvite.php
Normal file
134
backend/api/projectInvite.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
// GET — получить свои pending-приглашения
|
||||
if ($method === 'GET') {
|
||||
$current_user_id = RestApi::getCurrentUserId();
|
||||
|
||||
if (!$current_user_id) {
|
||||
RestApi::response(['success' => false, 'errors' => ['auth' => 'Требуется авторизация']], 401);
|
||||
}
|
||||
|
||||
$invites = ProjectInvite::getMyPending($current_user_id);
|
||||
$count = count($invites);
|
||||
|
||||
RestApi::response([
|
||||
'success' => true,
|
||||
'data' => $invites,
|
||||
'count' => $count
|
||||
]);
|
||||
}
|
||||
|
||||
// POST — действия с приглашениями
|
||||
if ($method === 'POST') {
|
||||
$data = RestApi::getInput();
|
||||
$action = $data['action'] ?? null;
|
||||
$current_user_id = RestApi::getCurrentUserId();
|
||||
|
||||
if (!$current_user_id) {
|
||||
RestApi::response(['success' => false, 'errors' => ['auth' => 'Требуется авторизация']], 401);
|
||||
}
|
||||
|
||||
// Отправить приглашение (только админ проекта)
|
||||
if ($action === 'send') {
|
||||
$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 = ProjectInvite::create($project_id, $user_id, $current_user_id, $is_admin, $permissions);
|
||||
RestApi::response($result, $result['success'] ? 200 : 400);
|
||||
}
|
||||
|
||||
// Проверить, есть ли pending-приглашение для пользователя в проект
|
||||
if ($action === 'check_pending') {
|
||||
$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);
|
||||
}
|
||||
|
||||
// Проверяем доступ к проекту
|
||||
ProjectAccess::requireAccess($project_id, $current_user_id);
|
||||
|
||||
$hasPending = ProjectInvite::hasPending($project_id, $user_id);
|
||||
RestApi::response(['success' => true, 'has_pending' => $hasPending]);
|
||||
}
|
||||
|
||||
// Получить pending-приглашения проекта (для админа)
|
||||
if ($action === 'get_project_pending') {
|
||||
$project_id = (int)($data['project_id'] ?? 0);
|
||||
|
||||
if (!$project_id) {
|
||||
RestApi::response(['success' => false, 'errors' => ['data' => 'Укажите project_id']], 400);
|
||||
}
|
||||
|
||||
// Только админ может видеть
|
||||
ProjectAccess::requireAdmin($project_id, $current_user_id);
|
||||
|
||||
$invites = ProjectInvite::getProjectPending($project_id);
|
||||
RestApi::response(['success' => true, 'data' => $invites]);
|
||||
}
|
||||
|
||||
// Получить количество pending-приглашений для текущего пользователя
|
||||
if ($action === 'get_count') {
|
||||
$count = ProjectInvite::getPendingCount($current_user_id);
|
||||
RestApi::response(['success' => true, 'count' => $count]);
|
||||
}
|
||||
|
||||
// Принять приглашение
|
||||
if ($action === 'accept') {
|
||||
$invite_id = (int)($data['invite_id'] ?? 0);
|
||||
|
||||
if (!$invite_id) {
|
||||
RestApi::response(['success' => false, 'errors' => ['data' => 'Укажите invite_id']], 400);
|
||||
}
|
||||
|
||||
$result = ProjectInvite::accept($invite_id, $current_user_id);
|
||||
RestApi::response($result, $result['success'] ? 200 : 400);
|
||||
}
|
||||
|
||||
// Отклонить приглашение
|
||||
if ($action === 'decline') {
|
||||
$invite_id = (int)($data['invite_id'] ?? 0);
|
||||
|
||||
if (!$invite_id) {
|
||||
RestApi::response(['success' => false, 'errors' => ['data' => 'Укажите invite_id']], 400);
|
||||
}
|
||||
|
||||
$result = ProjectInvite::decline($invite_id, $current_user_id);
|
||||
RestApi::response($result, $result['success'] ? 200 : 400);
|
||||
}
|
||||
|
||||
// Отменить приглашение (только админ)
|
||||
if ($action === 'cancel') {
|
||||
$invite_id = (int)($data['invite_id'] ?? 0);
|
||||
$project_id = (int)($data['project_id'] ?? 0);
|
||||
|
||||
if (!$invite_id || !$project_id) {
|
||||
RestApi::response(['success' => false, 'errors' => ['data' => 'Укажите invite_id и project_id']], 400);
|
||||
}
|
||||
|
||||
// Только админ может отменять
|
||||
ProjectAccess::requireAdmin($project_id, $current_user_id);
|
||||
|
||||
$result = ProjectInvite::cancel($invite_id, $project_id);
|
||||
RestApi::response($result, $result['success'] ? 200 : 400);
|
||||
}
|
||||
|
||||
// Метод не указан
|
||||
if (!$action) {
|
||||
RestApi::response(['success' => false, 'error' => 'Укажите action'], 400);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user