diff --git a/src/auth/utils.js b/src/auth/utils.js index 169fb3f..ad5e6c6 100644 --- a/src/auth/utils.js +++ b/src/auth/utils.js @@ -9,8 +9,8 @@ import useJwt from 'auth/jwt/coreUseJwt'; export const hostname = 'localhost'; const hostPort = '8090'; export const hostPath = `http://${hostname}:${hostPort}`; -export const apiPath = window.location.href.match("localhost:3000")?`${hostPath}/api`:(window.location.href.match(":3000")? "http://"+window.location.hostname+":8090/api":`/api`); -export const paymentPath = window.location.href.match("localhost:3000")?`${hostPath}/payment`:`/payment`; +export const apiPath = window.location.href.match("localhost:3000") ? `${hostPath}/api` : (window.location.href.match(":3000") ? "http://" + window.location.hostname + ":8090/api" : `/api`); +export const paymentPath = window.location.href.match("localhost:3000") ? `${hostPath}/payment` : `/payment`; export const delBugMode = true; @@ -31,7 +31,7 @@ export const iAmSmartCallbackPath = () => { let hostname = window.location.hostname; if (hostname.match("pnspsuat")) { hostname = "pnspsuat.gld.gov.hk"; - }else{ + } else { hostname = "pnspsdev.gld.gov.hk"; } return hostname; @@ -85,6 +85,39 @@ export const isUserLoggedIn = () => { export const getUserData = () => JSON.parse(localStorage.getItem('userData')); +export const isGranted = (auth) => { + const abilities = getUserData() ? getUserData()["abilities"] : null; + if (abilities == null || abilities.length == 0) return false; + if (!Array.isArray(auth)) return _checkAuth(abilities, auth); + + if (auth.length > abilities.length) return false; + let haveAuth = true; + for (let i = 0; i < auth.length; i++) { + haveAuth = _checkAuth(abilities, auth[i]) + if (!haveAuth) return haveAuth; + } + return haveAuth; +}; + +const _checkAuth = (abilities, auth) => { + for (let i = 0; i < abilities.length; i++) { + if (auth == abilities[i].actionSubjectCombo) return true; + } + return false; +} + +export const isGrantedAny = (auth) => { + const abilities = getUserData() ? getUserData()["abilities"] : null; + if (abilities == null || abilities.length == 0) return false; + if (!Array.isArray(auth)) return _checkAuth(abilities, auth); + let haveAuth = false; + for (let i = 0; i < auth.length; i++) { + haveAuth = _checkAuth(abilities, auth[i]) + if (haveAuth) return haveAuth; + } + return haveAuth; +}; + /** * This function is used for demo purpose route navigation * In real app you won't need this function because your app will navigate to same route for each users regardless of ability @@ -101,5 +134,5 @@ export const getHomeRouteForLoggedInUser = (userRole) => { }; // open payment record -export const local = {en:"en-us", zh:"zh-hk", cn:"zh-cn"}; +export const local = { en: "en-us", zh: "zh-hk", cn: "zh-cn" }; export const preferpaymentmethods = ['visa', 'mastercard', 'pps', 'creditcard', 'fps']; diff --git a/src/components/FiDataGrid.js b/src/components/FiDataGrid.js index 8e86dbe..17150dd 100644 --- a/src/components/FiDataGrid.js +++ b/src/components/FiDataGrid.js @@ -1,5 +1,5 @@ // material-ui -import * as React from 'react'; +import {useState, useEffect} from 'react'; import { DataGrid, GridOverlay, } from "@mui/x-data-grid"; @@ -13,15 +13,19 @@ export function FiDataGrid({ rows, columns, sx, autoHeight, hideFooterSelectedRowCount, rowModesModel, editMode, pageSizeOptions, filterItems, customPageSize, doLoad, ...props }) { const intl = useIntl(); - const [_rows, set_rows] = React.useState([]); - const [_doLoad, set_doLoad] = React.useState({}); - const [_columns, set_columns] = React.useState([]); - const [_rowModesModel, set_rowModesModel] = React.useState({}); - const [_editMode, set_editMode] = React.useState("row"); - const [_pageSizeOptions, set_pageSizeOptions] = React.useState([10]); - const [_filterItems, set_filterItems] = React.useState([]); - const [_autoHeight, set_autoHeight] = React.useState(true); - const [_sx, set_sx] = React.useState({ + const [_rows, set_rows] = useState([]); + const [_doLoad, set_doLoad] = useState({}); + const [_columns, set_columns] = useState([]); + const [_rowModesModel, set_rowModesModel] = useState({}); + const [_editMode, set_editMode] = useState("row"); + const [_pageSizeOptions, set_pageSizeOptions] = useState([10]); + const [_filterItems, set_filterItems] = useState([]); + + const [page, setPage] = useState(0); + const [pageSize, setPageSize] = useState(10); + const [_autoHeight, set_autoHeight] = useState(true); + const [myHideFooterSelectedRowCount, setMyHideFooterSelectedRowCount] = useState(true); + const [_sx, set_sx] = useState({ padding: "4 2 4 2", '& .MuiDataGrid-cell': { borderTop: 1, @@ -34,22 +38,19 @@ export function FiDataGrid({ rows, columns, sx, autoHeight, }, }); - - const [page, setPage] = React.useState(0); - const [pageSize, setPageSize] = React.useState(10); - const [rowCount, setRowCount] = React.useState(0); - const [myHideFooterSelectedRowCount, setMyHideFooterSelectedRowCount] = React.useState(true); + const [rowCount, setRowCount] = useState(0); - React.useEffect(() => { + useEffect(() => { setPage(0); set_doLoad(doLoad); }, [doLoad]); - React.useEffect(()=>{ + useEffect(()=>{ getDataList(); },[_doLoad, page]); - React.useEffect(() => { + + useEffect(() => { if (sx) { set_sx(sx); } diff --git a/src/layout/MainLayout/Header/HeaderContent/index.js b/src/layout/MainLayout/Header/HeaderContent/index.js index ee5ad28..fd2f90b 100644 --- a/src/layout/MainLayout/Header/HeaderContent/index.js +++ b/src/layout/MainLayout/Header/HeaderContent/index.js @@ -9,7 +9,6 @@ import { Button ,Box } from '@mui/material'; import Profile from './Profile'; import LocaleSelector from "./LocaleSelector"; import {FormattedMessage} from "react-intl"; -import React from "react"; // import Notification from './Notification'; // import MobileSection from './MobileSection'; diff --git a/src/layout/MainLayout/Header/index.js b/src/layout/MainLayout/Header/index.js index 258b808..a85a0c2 100644 --- a/src/layout/MainLayout/Header/index.js +++ b/src/layout/MainLayout/Header/index.js @@ -41,16 +41,17 @@ import AdminLogo from 'components/AdminLogo'; import MobileLogo from 'components/MobileLogo'; //import Profile from './HeaderContent/Profile'; import "assets/style/navbarStyles.css"; -import { - isUserLoggedIn, - isGLDLoggedIn, - isPrimaryLoggedIn, +import { + isUserLoggedIn, + isGLDLoggedIn, + isPrimaryLoggedIn, isCreditorLoggedIn, isINDLoggedIn, // isORGLoggedIn, // getUserId } from "utils/Utils"; import { handleLogoutFunction } from 'auth/index'; +import { isGranted, isGrantedAny } from "auth/utils"; // assets // import { MenuFoldOutlined,MenuOutlined } from '@ant-design/icons'; @@ -93,80 +94,175 @@ function Header(props) {
  • Application
  • -
  • - Proof -
  • -
  • - Payment - -
  • -
  • - Client - -
  • Settings
  • - +
  • Logout
  • @@ -194,7 +290,7 @@ function Header(props) { <> - + @@ -254,46 +350,46 @@ function Header(props) { : - isINDLoggedIn()? - <> - - console.log(event)}> - - - - -
      -
    • - - - {/* */} - - - -
    • -
    - - : - <> - - console.log(event)}> - - - - -
      -
    • - - - - - -
    • -
    - + isINDLoggedIn() ? + <> + + console.log(event)}> + + + + +
      +
    • + + + {/* */} + + + +
    • +
    + + : + <> + + console.log(event)}> + + + + +
      +
    • + + + + + +
    • +
    + } - +
  • @@ -328,7 +424,7 @@ function Header(props) { {/* PNSPS */} - + PNSPS @@ -347,7 +443,7 @@ function Header(props) { : - + PNSPS @@ -395,7 +491,7 @@ function Header(props) { justifyContent="flex-start" alignItems="center" spacing={0} - sx={{width:{xs:'100%',md:'25%'}}} + sx={{ width: { xs: '100%', md: '25%' } }} > @@ -447,8 +543,8 @@ function Header(props) { - { @@ -493,7 +589,7 @@ function Header(props) { alignItems="center" spacing={0} // width="100%" - sx={{width:{xs:'100%',md:'25%'}}} + sx={{ width: { xs: '100%', md: '25%' } }} > @@ -542,7 +638,7 @@ function Header(props) { - {/**/} + {/**/} diff --git a/src/pages/Proof/Reply_GLD/ApplicationDetails.js b/src/pages/Proof/Reply_GLD/ApplicationDetails.js index 214cdbd..259e9ec 100644 --- a/src/pages/Proof/Reply_GLD/ApplicationDetails.js +++ b/src/pages/Proof/Reply_GLD/ApplicationDetails.js @@ -11,14 +11,15 @@ import { } from '@mui/material'; import { useFormik } from 'formik'; -import * as React from "react"; +import {isGranted} from "auth/utils"; +import {useState,useEffect,lazy} from "react"; import * as HttpUtils from "utils/HttpUtils" import * as UrlUtils from "utils/ApiPathConst" import * as DateUtils from "utils/DateUtils" import * as FormatUtils from "utils/FormatUtils" import { useParams } from "react-router-dom"; import Loadable from 'components/Loadable'; -const MainCard = Loadable(React.lazy(() => import('components/MainCard'))); +const MainCard = Loadable(lazy(() => import('components/MainCard'))); import * as StatusUtils from "utils/statusUtils/PublicNoteStatusUtils"; import FileList from "components/FileList" // ==============================|| DASHBOARD - DEFAULT ||============================== // @@ -31,14 +32,12 @@ const ApplicationDetailCard = ({ const params = useParams(); - const [data, setData] = React.useState({}); - const [cancelPopUp, setCancelPopUp] = React.useState(false); - //const [proofId, setProofId] = React.useState(); + const [data, setData] = useState({}); + const [cancelPopUp, setCancelPopUp] = useState(false); - React.useEffect(() => { + useEffect(() => { if (formData) { setData(formData); - //setProofId(formData.id); } }, [formData]); @@ -69,31 +68,26 @@ const ApplicationDetailCard = ({ />; } - const confirmCancel = () =>{ + const confirmCancel = () => { setCancelPopUp(false); HttpUtils.get({ - url: UrlUtils.CANCEL_PROOF+"/"+params.id, - onSuccess: function(){ + url: UrlUtils.CANCEL_PROOF + "/" + params.id, + onSuccess: function () { window.location.reload(false); } }); } - const doCancel = () =>{ + const doCancel = () => { setCancelPopUp(true); } - const genProof = () =>{ - // window.open(UrlUtils.GEN_GAZETTE_PROOF); + const genProof = () => { HttpUtils.fileDownload({ - url: UrlUtils.GEN_GAZETTE_PROOF+"/"+params.id + url: UrlUtils.GEN_GAZETTE_PROOF + "/" + params.id }); } - // React.useEffect(()=>{ - // if (document.getElementById("applicationDetailsMainCard")) setBackButtonPos(`${document.getElementById("applicationDetailsMainCard")?.getBoundingClientRect().left / 3}px`) - // },[document.getElementById("applicationDetailsMainCard")]) - return ( Proof Slip - + { + isGranted(["MAINTAIN_PROOF"]) ? : <> + } + diff --git a/src/pages/PublicNotice/Details_GLD/ApplicationDetailCard.js b/src/pages/PublicNotice/Details_GLD/ApplicationDetailCard.js index d2c32d0..9fadf14 100644 --- a/src/pages/PublicNotice/Details_GLD/ApplicationDetailCard.js +++ b/src/pages/PublicNotice/Details_GLD/ApplicationDetailCard.js @@ -8,7 +8,7 @@ import { Stack, Dialog, DialogTitle, DialogContent, DialogActions, InputAdornment, } from '@mui/material'; -import { delBugMode } from "auth/utils"; +import {isGranted, delBugMode } from "auth/utils"; const MainCard = Loadable(lazy(() => import('components/MainCard'))); import { useForm } from "react-hook-form"; import { @@ -168,7 +168,7 @@ const ApplicationDetailCard = ( spacing={2} mb={2} > - {currentApplicationDetailData.status === "reviewed" ? + {currentApplicationDetailData.status === "reviewed" && isGranted("MAINTAIN_PROOF") ?