From dc1471b4fb67fcdc175549276b1ba7e0ab170013 Mon Sep 17 00:00:00 2001 From: kalugin66 Date: Thu, 5 Feb 2026 20:46:36 +0500 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B0=D0=B8=D0=BB=20=D0=B2=D0=B8=D0=B4?= =?UTF-8?q?=D0=B8=D1=82=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D0=B5=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/ui.js | 57 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/public/ui.js b/public/ui.js index 31cac93..e9ff1c2 100644 --- a/public/ui.js +++ b/public/ui.js @@ -660,25 +660,68 @@ function closeAddFileModal() { async function loadTaskFiles(taskId) { try { const response = await fetch(`/api/tasks/${taskId}/files`); - const files = await response.json(); + const allFiles = await response.json(); - // Обновляем файлы в задаче + // Получаем задачу для определения создателя const taskIndex = tasks.findIndex(t => t.id === taskId); - if (taskIndex !== -1) { - tasks[taskIndex].files = files; + if (taskIndex === -1) { + console.error('Задача не найдена:', taskId); + return; } + const task = tasks[taskIndex]; + const creatorId = parseInt(task.created_by); + + // Фильтруем файлы по тем же правилам, что и в HTML + const filteredFiles = allFiles.filter(file => { + // Определяем, может ли пользователь видеть этот файл + let canSeeFile = false; + + // 1. Администратор видит все файлы + if (currentUser.role === 'admin') { + canSeeFile = true; + } + // 2. Создатель задачи видит все файлы + else if (creatorId === currentUser.id) { + canSeeFile = true; + } + // 3. Исполнитель видит: + // - Файлы, загруженные создателем + // - Свои файлы + else { + const fileUserId = parseInt(file.user_id); + + // Файл загружен создателем + if (fileUserId === creatorId) { + canSeeFile = true; + } + // Файл загружен текущим пользователем (исполнителем) + else if (fileUserId === currentUser.id) { + canSeeFile = true; + } + // Если файл загружен другим исполнителем - не показываем + else { + canSeeFile = false; + } + } + + return canSeeFile; + }); + + // Обновляем отфильтрованные файлы в задаче + tasks[taskIndex].files = filteredFiles; + // Обновляем отображение файлов const fileContainer = document.getElementById(`files-${taskId}`); if (fileContainer) { const fileList = fileContainer.querySelector('.file-icons-container'); if (fileList) { - fileList.innerHTML = files.map(file => renderFileIcon(file)).join(''); + fileList.innerHTML = filteredFiles.map(file => renderFileIcon(file)).join(''); } else { fileContainer.innerHTML = ` Файлы: - ${files.length > 0 ? - `
${files.map(file => renderFileIcon(file)).join('')}
` : + ${filteredFiles.length > 0 ? + `
${filteredFiles.map(file => renderFileIcon(file)).join('')}
` : 'нет файлов' } `;