fix(tasks): allow self-referencing userId filter for non-privileged users
Advocates could not filter their own task list by client because the /api/tasks endpoint treated any userId query param as a request to view another user's tasks, rejecting non-Admin/Manager callers with 403 even when userId matched their own session id.
This commit is contained in:
parent
b1b0dfa64d
commit
db37313631
1 changed files with 2 additions and 1 deletions
|
|
@ -81,7 +81,8 @@ export async function GET(request: NextRequest) {
|
||||||
}
|
}
|
||||||
if (viewUserId) {
|
if (viewUserId) {
|
||||||
const userRoles = (session.user as any).roles || []
|
const userRoles = (session.user as any).roles || []
|
||||||
if (!userRoles.includes('Admin') && !userRoles.includes('Manager')) {
|
const isSelf = viewUserId === (session.user as any).id
|
||||||
|
if (!isSelf && !userRoles.includes('Admin') && !userRoles.includes('Manager')) {
|
||||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
|
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
|
||||||
}
|
}
|
||||||
where.assignments = { some: { userId: viewUserId } }
|
where.assignments = { some: { userId: viewUserId } }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue