diff --git a/src/auth/utils.js b/src/auth/utils.js index 10c4acc..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,13 +85,37 @@ export const isUserLoggedIn = () => { export const getUserData = () => JSON.parse(localStorage.getItem('userData')); -export const checkAuth = (auth) => { - const abilities= getUserData()?getUserData()["abilities"]:null; - if(abilities == null || abilities.length==0) return false; - for(let i= 0; i { + 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; }; /** @@ -110,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/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 -
      -
    • - Online Payment Record -
    • + { + isGrantedAny(["VIEW_PROOF", "MAINTAIN_PROOF"]) ?
    • - GFMIS Generate XML -
    • -
    • - Recon Report -
    • -
    • - Create Demand Note -
    • -
    • - Demand Note -
    • -
    -
  • -
  • - Client -
      -
    • - Users (GLD) -
    • -
    • - Users (Individual) -
    • -
    • - Users (Organisation) + Proof
    • + : <> + } + + { + isGrantedAny(["MAINTAIN_PAYMENT", "MAINTAIN_RECON", "VIEW_DEMANDNOTE", "MAINTAIN_DEMANDNOTE"]) ?
    • - Organisation + Payment +
        + { + isGranted("MAINTAIN_PAYMENT") ? +
      • + Online Payment Record +
      • + : + <> + } + + { + isGranted("MAINTAIN_RECON") ? + <> +
      • + GFMIS Generate XML +
      • +
      • + Recon Report +
      • + + + : + <> + } + + { + isGranted("MAINTAIN_DEMANDNOTE") ? +
      • + Create Demand Note +
      • + : + <> + } + + { + isGrantedAny(["VIEW_DEMANDNOTE", "MAINTAIN_DEMANDNOTE"]) ? +
      • + Demand Note +
      • + : + <> + } + +
    • + : + <> + } + + { + isGrantedAny(["VIEW_USER", "MAINTAIN_USER", "VIEW_ORG", "MAINTAIN_ORG", "VIEW_GROUP", "MAINTAIN_GROUP"]) ?
    • - User Group + Client +
        + { + isGrantedAny(["VIEW_USER", "MAINTAIN_USER"]) ? + <> +
      • + Users (GLD) +
      • +
      • + Users (Individual) +
      • +
      • + Users (Organisation) +
      • + + : + <> + } + + { + isGrantedAny(["VIEW_ORG", "MAINTAIN_ORG"]) ? +
      • + Organisation +
      • + : + <> + } + + { + isGrantedAny(["VIEW_GROUP", "MAINTAIN_GROUP"]) ? +
      • + User Group +
      • + : + <> + } + +
    • + : + <> + } + -
    -
  • Settings
    • My Profile
    • -
    • - Holiday Settings -
    • -
    • - Gazette Issues -
    • -
    • - Announcement -
    • -
    • - Email Template -
    • -
    • - DR Import -
    • -
    • - System Settings -
    • + { + isGranted("MAINTAIN_GAZETTE_ISSUE") ? + <> +
    • + Holiday Settings +
    • +
    • + Gazette Issues +
    • + + : + <> + } + + { + isGranted("MAINTAIN_ANNOUNCEMENT") ? +
    • + Announcement +
    • + : + <> + } + + {isGranted("MAINTAIN_EMAIL") ? +
    • + Email Template +
    • + : + <> + } + + { + isGranted("MAINTAIN_DR") ? +
    • + DR Import +
    • + : + <> + } + + { + isGranted("MAINTAIN_SETTING") ? +
    • + System Settings +
    • + : + <> + } +
    • Audit Log
  • - +
  • 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") ?