diff --git a/src/app/api/project-tasks/route.js b/src/app/api/project-tasks/route.js index 9429832..d954d4f 100644 --- a/src/app/api/project-tasks/route.js +++ b/src/app/api/project-tasks/route.js @@ -47,10 +47,19 @@ async function createProjectTaskHandler(req) { const taskData = { ...data, created_by: req.user?.id || null, - // If no assigned_to is specified, default to the creator - assigned_to: data.assigned_to || req.user?.id || null, }; + // Set assigned_to: if specified, use it; otherwise default to creator only if they're not admin + if (data.assigned_to) { + taskData.assigned_to = data.assigned_to; + } else if (req.user?.id) { + // Check if the creator is an admin - if so, don't assign to them + const userRole = db.prepare('SELECT role FROM users WHERE id = ?').get(req.user.id); + taskData.assigned_to = userRole?.role === 'admin' ? null : req.user.id; + } else { + taskData.assigned_to = null; + } + const result = createProjectTask(taskData); return NextResponse.json({ success: true, id: result.lastInsertRowid }); } catch (error) { diff --git a/src/app/projects/page.js b/src/app/projects/page.js index b63d5a6..60811fb 100644 --- a/src/app/projects/page.js +++ b/src/app/projects/page.js @@ -449,15 +449,15 @@ export default function ProjectListPage() {