фаил видит только исполнитель

This commit is contained in:
2026-02-05 20:46:36 +05:00
parent 699bdf6961
commit dc1471b4fb

View File

@@ -660,25 +660,68 @@ function closeAddFileModal() {
async function loadTaskFiles(taskId) { async function loadTaskFiles(taskId) {
try { try {
const response = await fetch(`/api/tasks/${taskId}/files`); 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); const taskIndex = tasks.findIndex(t => t.id === taskId);
if (taskIndex !== -1) { if (taskIndex === -1) {
tasks[taskIndex].files = files; 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}`); const fileContainer = document.getElementById(`files-${taskId}`);
if (fileContainer) { if (fileContainer) {
const fileList = fileContainer.querySelector('.file-icons-container'); const fileList = fileContainer.querySelector('.file-icons-container');
if (fileList) { if (fileList) {
fileList.innerHTML = files.map(file => renderFileIcon(file)).join(''); fileList.innerHTML = filteredFiles.map(file => renderFileIcon(file)).join('');
} else { } else {
fileContainer.innerHTML = ` fileContainer.innerHTML = `
<strong>Файлы:</strong> <strong>Файлы:</strong>
${files.length > 0 ? ${filteredFiles.length > 0 ?
`<div class="file-icons-container">${files.map(file => renderFileIcon(file)).join('')}</div>` : `<div class="file-icons-container">${filteredFiles.map(file => renderFileIcon(file)).join('')}</div>` :
'<span class="no-files">нет файлов</span>' '<span class="no-files">нет файлов</span>'
} }
`; `;