Merge branch 'feature/role_middleware' into 'develop'
role_middleware See merge request witel3/loan-facilities-expert!56
This commit is contained in:
@@ -24,10 +24,10 @@
|
|||||||
},
|
},
|
||||||
"sidebar": {
|
"sidebar": {
|
||||||
"dashboard": "داشبورد",
|
"dashboard": "داشبورد",
|
||||||
"passenger-office": "اداره مسافر",
|
"passenger-office-chief": "اداره مسافر",
|
||||||
"machinary-office": "ماشین آلات",
|
"machinary-expert": "ماشین آلات",
|
||||||
"passenger-boss": "رئیس مسافر ",
|
"passenger-boss": "رئیس مسافر ",
|
||||||
"transportation-assistance": "معاونت حمل و نقل",
|
"transportation-assistant": "معاونت حمل و نقل",
|
||||||
"province-manager": "مدیر کل استانی",
|
"province-manager": "مدیر کل استانی",
|
||||||
"change-password": "تغییر رمز عبور",
|
"change-password": "تغییر رمز عبور",
|
||||||
"edit-profile": "ویرایش پروفایل"
|
"edit-profile": "ویرایش پروفایل"
|
||||||
@@ -43,6 +43,10 @@
|
|||||||
"typography_routing_previuos_page": "صفحه قبل...",
|
"typography_routing_previuos_page": "صفحه قبل...",
|
||||||
"typography_routing_dashbaord_page": "داشبورد..."
|
"typography_routing_dashbaord_page": "داشبورد..."
|
||||||
},
|
},
|
||||||
|
"Permission": {
|
||||||
|
"typography_you_dont_have_access": "شما دسترسی لازم برای مشاهده این صفحه را ندارید!",
|
||||||
|
"button_back_dashboard": "بازگشت به صفحه اصلی"
|
||||||
|
},
|
||||||
"LoginPage": {
|
"LoginPage": {
|
||||||
"text_field_user_name": "نام کاربری",
|
"text_field_user_name": "نام کاربری",
|
||||||
"text_field_enter_your_username": "نام کاربری خود را وارد کنید",
|
"text_field_enter_your_username": "نام کاربری خود را وارد کنید",
|
||||||
|
|||||||
@@ -16,18 +16,18 @@ const sidebarMenu = [
|
|||||||
role: "all",
|
role: "all",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.passenger-office",
|
key: "sidebar.passenger-office-chief",
|
||||||
secondary: "secondary.passenger-office",
|
secondary: "secondary.passenger-office",
|
||||||
type: "page",
|
type: "page",
|
||||||
route: "/dashboard/passenger-office",
|
route: "/dashboard/passenger-office-chief",
|
||||||
icon: <AirlineSeatReclineNormalIcon />,
|
icon: <AirlineSeatReclineNormalIcon />,
|
||||||
selected: false,
|
selected: false,
|
||||||
role: "passenger_office_chief",
|
role: "passenger_office_chief",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.machinary-office",
|
key: "sidebar.machinary-expert",
|
||||||
type: "page",
|
type: "page",
|
||||||
route: "/dashboard/machinary-office",
|
route: "/dashboard/machinary-expert",
|
||||||
icon: <DirectionsCarFilledIcon />,
|
icon: <DirectionsCarFilledIcon />,
|
||||||
selected: false,
|
selected: false,
|
||||||
role: "machinery_expert",
|
role: "machinery_expert",
|
||||||
@@ -42,9 +42,9 @@ const sidebarMenu = [
|
|||||||
role: "passenger_office_chief",
|
role: "passenger_office_chief",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.transportation-assistance",
|
key: "sidebar.transportation-assistant",
|
||||||
type: "page",
|
type: "page",
|
||||||
route: "/dashboard/transportation-assistance",
|
route: "/dashboard/transportation-assistant",
|
||||||
icon: <DirectionsRailwayIcon />,
|
icon: <DirectionsRailwayIcon />,
|
||||||
selected: false,
|
selected: false,
|
||||||
role: "transportation_assistant",
|
role: "transportation_assistant",
|
||||||
|
|||||||
43
src/middlewares/RolePermission.jsx
Normal file
43
src/middlewares/RolePermission.jsx
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { NextLinkComposed } from "@/core/components/LinkRouting";
|
||||||
|
import Message from "@/core/components/Messages";
|
||||||
|
import useUser from "@/lib/app/hooks/useUser";
|
||||||
|
import { Button, Typography } from "@mui/material";
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
|
||||||
|
const RolePermission = ({ children, requiredPermissions }) => {
|
||||||
|
const { user } = useUser();
|
||||||
|
const t = useTranslations();
|
||||||
|
|
||||||
|
const hasPermission = requiredPermissions.some((permission) =>
|
||||||
|
user?.role?.includes(permission)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!hasPermission) {
|
||||||
|
return (
|
||||||
|
<Message
|
||||||
|
text={
|
||||||
|
<Typography sx={{ textAlign: "center" }}>
|
||||||
|
{t("Permission.typography_you_dont_have_access")}
|
||||||
|
</Typography>
|
||||||
|
}
|
||||||
|
actions={
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
component={NextLinkComposed}
|
||||||
|
to={{
|
||||||
|
pathname: "/dashboard",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("Permission.button_back_dashboard")}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <>{children}</>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RolePermission;
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
import DashboardMachinaryOfficeComponent from "@/components/dashboard/machinary-office";
|
import DashboardMachinaryOfficeComponent from "@/components/dashboard/machinary-office";
|
||||||
import TitlePage from "@/core/components/TitlePage";
|
import TitlePage from "@/core/components/TitlePage";
|
||||||
|
import RolePermission from "@/middlewares/RolePermission";
|
||||||
import WithAuthMiddleware from "@/middlewares/WithAuth";
|
import WithAuthMiddleware from "@/middlewares/WithAuth";
|
||||||
import { parse } from "next-useragent";
|
import { parse } from "next-useragent";
|
||||||
|
const requiredPermissions = ["machinery_expert"];
|
||||||
export default function PassengerOffice() {
|
export default function PassengerOffice() {
|
||||||
return (
|
return (
|
||||||
<WithAuthMiddleware>
|
<WithAuthMiddleware>
|
||||||
<TitlePage text="Dashboard.machinary_office_page" />
|
<RolePermission requiredPermissions={requiredPermissions}>
|
||||||
<DashboardMachinaryOfficeComponent />
|
<TitlePage text="Dashboard.machinary_office_page" />
|
||||||
|
<DashboardMachinaryOfficeComponent />
|
||||||
|
</RolePermission>
|
||||||
</WithAuthMiddleware>
|
</WithAuthMiddleware>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
import DashboardPassengerBossComponent from "@/components/dashboard/passenger-boss";
|
import DashboardPassengerBossComponent from "@/components/dashboard/passenger-boss";
|
||||||
import TitlePage from "@/core/components/TitlePage";
|
import TitlePage from "@/core/components/TitlePage";
|
||||||
|
import RolePermission from "@/middlewares/RolePermission";
|
||||||
import WithAuthMiddleware from "@/middlewares/WithAuth";
|
import WithAuthMiddleware from "@/middlewares/WithAuth";
|
||||||
import { parse } from "next-useragent";
|
import { parse } from "next-useragent";
|
||||||
|
const requiredPermissions = ["passenger_office_chief"];
|
||||||
export default function PassengerBoss() {
|
export default function PassengerBoss() {
|
||||||
return (
|
return (
|
||||||
<WithAuthMiddleware>
|
<WithAuthMiddleware>
|
||||||
<TitlePage text="Dashboard.passenger_boss_page" />
|
<RolePermission requiredPermissions={requiredPermissions}>
|
||||||
<DashboardPassengerBossComponent />
|
<TitlePage text="Dashboard.passenger_boss_page" />
|
||||||
|
<DashboardPassengerBossComponent />
|
||||||
|
</RolePermission>
|
||||||
</WithAuthMiddleware>
|
</WithAuthMiddleware>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
import DashboardPassengerOfficeComponent from "@/components/dashboard/passenger-office";
|
import DashboardPassengerOfficeComponent from "@/components/dashboard/passenger-office";
|
||||||
import TitlePage from "@/core/components/TitlePage";
|
import TitlePage from "@/core/components/TitlePage";
|
||||||
|
import RolePermission from "@/middlewares/RolePermission";
|
||||||
import WithAuthMiddleware from "@/middlewares/WithAuth";
|
import WithAuthMiddleware from "@/middlewares/WithAuth";
|
||||||
import { parse } from "next-useragent";
|
import { parse } from "next-useragent";
|
||||||
|
const requiredPermissions = ["passenger_office_chief"];
|
||||||
export default function PassengerOffice() {
|
export default function PassengerOffice() {
|
||||||
return (
|
return (
|
||||||
<WithAuthMiddleware>
|
<WithAuthMiddleware>
|
||||||
<TitlePage text="Dashboard.passenger_office_page" />
|
<RolePermission requiredPermissions={requiredPermissions}>
|
||||||
<DashboardPassengerOfficeComponent />
|
<TitlePage text="Dashboard.passenger_office_page" />
|
||||||
|
<DashboardPassengerOfficeComponent />
|
||||||
|
</RolePermission>
|
||||||
</WithAuthMiddleware>
|
</WithAuthMiddleware>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
import DashboardProvinceManagerComponent from "@/components/dashboard/province-manager";
|
import DashboardProvinceManagerComponent from "@/components/dashboard/province-manager";
|
||||||
import TitlePage from "@/core/components/TitlePage";
|
import TitlePage from "@/core/components/TitlePage";
|
||||||
|
import RolePermission from "@/middlewares/RolePermission";
|
||||||
import WithAuthMiddleware from "@/middlewares/WithAuth";
|
import WithAuthMiddleware from "@/middlewares/WithAuth";
|
||||||
import { parse } from "next-useragent";
|
import { parse } from "next-useragent";
|
||||||
|
const requiredPermissions = ["province_manager"];
|
||||||
export default function PassengerOffice() {
|
export default function PassengerOffice() {
|
||||||
return (
|
return (
|
||||||
<WithAuthMiddleware>
|
<WithAuthMiddleware>
|
||||||
<TitlePage text="Dashboard.province_manager_page" />
|
<RolePermission requiredPermissions={requiredPermissions}>
|
||||||
<DashboardProvinceManagerComponent />
|
<TitlePage text="Dashboard.province_manager_page" />
|
||||||
|
<DashboardProvinceManagerComponent />
|
||||||
|
</RolePermission>
|
||||||
</WithAuthMiddleware>
|
</WithAuthMiddleware>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
import DashboardTransportationAssistanceComponent from "@/components/dashboard/transportation-assistance";
|
import DashboardTransportationAssistanceComponent from "@/components/dashboard/transportation-assistance";
|
||||||
import TitlePage from "@/core/components/TitlePage";
|
import TitlePage from "@/core/components/TitlePage";
|
||||||
|
import RolePermission from "@/middlewares/RolePermission";
|
||||||
import WithAuthMiddleware from "@/middlewares/WithAuth";
|
import WithAuthMiddleware from "@/middlewares/WithAuth";
|
||||||
import { parse } from "next-useragent";
|
import { parse } from "next-useragent";
|
||||||
|
const requiredPermissions = ["transportation_assistant"];
|
||||||
export default function TransportationAssistance() {
|
export default function TransportationAssistance() {
|
||||||
return (
|
return (
|
||||||
<WithAuthMiddleware>
|
<WithAuthMiddleware>
|
||||||
<TitlePage text="Dashboard.transportation_assistance" />
|
<RolePermission requiredPermissions={requiredPermissions}>
|
||||||
<DashboardTransportationAssistanceComponent />
|
<TitlePage text="Dashboard.transportation_assistance" />
|
||||||
|
<DashboardTransportationAssistanceComponent />
|
||||||
|
</RolePermission>
|
||||||
</WithAuthMiddleware>
|
</WithAuthMiddleware>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user