mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Fix task creation error by assigning default group
Correctly assigns a default `groupId` when creating tasks and improves group access validation logic. Replit-Commit-Author: Agent Replit-Commit-Session-Id: f2b9c241-9fdd-4abd-9041-720afc8b27d6 Replit-Commit-Checkpoint-Type: full_checkpoint
This commit is contained in:
1 parent
f2013cd616
commit
54aa499edd
2 files changed
+18
-2
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
+18
-2
@@ -1671,10 +1671,26 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
dueDateValue: data.dueDate
|
||||
});
|
||||
|
||||
// Assign a default groupId if not provided
|
||||
if (!data.groupId) {
|
||||
if (user.role === 'admin') {
|
||||
data.groupId = 1; // Default for admin
|
||||
} else {
|
||||
const userGroupIds = user.userGroups?.map(ug => ug.groupId) || [];
|
||||
data.groupId = userGroupIds.length > 0 ? userGroupIds[0] : 1;
|
||||
}
|
||||
console.log('📝 POST /api/tasks - Assigned default groupId:', data.groupId);
|
||||
}
|
||||
|
||||
// Check if user has access to the group
|
||||
if (user.role !== 'admin') {
|
||||
const userGroupIds = user.userGroups.map(ug => ug.groupId);
|
||||
if (!userGroupIds.includes(data.groupId)) {
|
||||
const userGroupIds = user.userGroups?.map(ug => ug.groupId) || [];
|
||||
console.log('📝 POST /api/tasks - User group access check:', {
|
||||
userGroupIds,
|
||||
requestedGroupId: data.groupId,
|
||||
hasUserGroups: !!user.userGroups
|
||||
});
|
||||
if (userGroupIds.length > 0 && !userGroupIds.includes(data.groupId)) {
|
||||
return res.status(403).json({ message: "Access denied to this group" });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user