diff --git a/src/components/ProjectSearch/ProjectSearchWrapper.tsx b/src/components/ProjectSearch/ProjectSearchWrapper.tsx index 2d7db12..4cba478 100644 --- a/src/components/ProjectSearch/ProjectSearchWrapper.tsx +++ b/src/components/ProjectSearch/ProjectSearchWrapper.tsx @@ -5,6 +5,7 @@ import ProjectSearchLoading from "./ProjectSearchLoading"; import { fetchUserAbilities, fetchUserStaff } from "@/app/utils/fetchUtil"; import { authOptions } from "@/config/authConfig"; import { getServerSession } from "next-auth"; +import { VIEW_ALL_PROJECTS } from "@/middleware"; interface SubComponents { Loading: typeof ProjectSearchLoading; @@ -15,11 +16,15 @@ const ProjectSearchWrapper: React.FC & SubComponents = async () => { const userStaff = await fetchUserStaff() const teamId = userStaff?.teamId const projects = await fetchProjects(); + + const abilities = await fetchUserAbilities() + const isViewAllProjectRight = [VIEW_ALL_PROJECTS].some((ability) => abilities.includes(ability)) + + let filteredProjects = projects - if (teamId) { + if (!isViewAllProjectRight) { filteredProjects = projects.filter(project => project.teamId === teamId) } - const abilities = await fetchUserAbilities() return ; }; diff --git a/src/middleware.ts b/src/middleware.ts index 50b2db9..2277652 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -70,7 +70,8 @@ export const [ GENERATE_FINANCIAL_STATUS_REPORT, GENERATE_PROJECT_CASH_FLOW_REPORT, GENERATE_STAFF_MONTHLY_WORK_HOURS_ANALYSIS_REPORT, - GENERATE_CROSS_TEAM_CHARGE_REPORT + GENERATE_CROSS_TEAM_CHARGE_REPORT, + VIEW_ALL_PROJECTS ] = [ 'MAINTAIN_USER', 'MAINTAIN_TIMESHEET', @@ -122,7 +123,8 @@ export const [ 'G_FINANCIAL_STATUS_REPORT', 'G_PROJECT_CASH_FLOW_REPORT', 'G_STAFF_MONTHLY_WORK_HOURS_ANALYSIS_REPORT', - 'G_CROSS_TEAM_CHARGE_REPORT' + 'G_CROSS_TEAM_CHARGE_REPORT', + 'VIEW_ALL_PROJECTS' ] const PRIVATE_ROUTES = [