From 04d72c050f31e29c3b787b135d70594af7eeaa7a Mon Sep 17 00:00:00 2001 From: Mahender Reddy Jangari Date: Thu, 4 May 2023 21:28:41 +0530 Subject: [PATCH] Fixed issues reported on wiki and integrated middleware for the redirection --- config/saml.ts | 8 +- .../notifications/notifications.controller.ts | 30 ++++ kubernetes/k8-deployment.yaml | 20 +++ kubernetes/k8-secrets.yaml | 4 + next.config.js | 3 +- package.json | 5 +- src/components/elements/Navbar/SideNavbar.tsx | 16 +- .../elements/Notifications/Notifications.tsx | 134 ++++++++++------ src/middleware.ts | 116 ++++++++++++++ src/pages/_app.tsx | 150 ------------------ src/pages/api/db/admin/notifications/index.ts | 20 +++ src/pages/login/index.js | 69 -------- src/redux/actions/actions.js | 41 +++++ 13 files changed, 332 insertions(+), 284 deletions(-) create mode 100644 controllers/db/notifications/notifications.controller.ts create mode 100644 src/middleware.ts create mode 100644 src/pages/api/db/admin/notifications/index.ts diff --git a/config/saml.ts b/config/saml.ts index e9f23bb2..52ce0c3b 100644 --- a/config/saml.ts +++ b/config/saml.ts @@ -3,10 +3,10 @@ import fs from 'fs' export const reciterSamlConfig = { saml_options: { - entity_id: "https://reciter-dev.weill.cornell.edu", + entity_id: process.env.ENTITY_ID, private_key: fs.readFileSync(process.cwd() + "/config/certs/reciter-saml.key").toString(), certificate: fs.readFileSync(process.cwd() + "/config/certs/reciter-saml.crt").toString(), - assert_endpoint: "https://reciter-dev.weill.cornell.edu/api/auth/callback/saml", + assert_endpoint: process.env.ASSERT_ENDPOINT, force_authn: true, auth_context: { comparison: "exact", class_refs: ["urn:oasis:names:tc:SAML:1.0:am:password"] }, nameid_format: "urn:oasis:names:tc:SAML:2.0:nameid-format:transient", @@ -15,8 +15,8 @@ export const reciterSamlConfig = { }, saml_idp_options: { - sso_login_url: "https://login-proxy-test.weill.cornell.edu/idp/profile/SAML2/Redirect/SSO", - sso_logout_url: "https://login-proxy-test.weill.cornell.edu/idp/profile/SAML2/Redirect/SLO", + sso_login_url: process.env.SSO_LOGIN_URL, + sso_logout_url: process.env.SSO_LOGOUT_URL, certificates: [ fs.readFileSync(process.cwd() + "/config/certs/idp.crt").toString() ], diff --git a/controllers/db/notifications/notifications.controller.ts b/controllers/db/notifications/notifications.controller.ts new file mode 100644 index 00000000..3a8aa39c --- /dev/null +++ b/controllers/db/notifications/notifications.controller.ts @@ -0,0 +1,30 @@ +import { response } from "express"; +import type { NextApiRequest, NextApiResponse } from "next"; +//import { Op, Sequelize, where,Transaction } from "sequelize"; +import { Op, Sequelize } from "sequelize"; +import models from "../../../src/db/sequelize"; +import sequelize from "../../../src/db/db"; + +export const saveNotifications = async ( + req: NextApiRequest, + res: NextApiResponse +) => { + const { frequency, accepted, status, minimumThreshold, userId } = req.body; + try { + let createUserPayload = { + 'frequency': frequency, + 'accepted': accepted, + 'minimumThreshold1': minimumThreshold, + 'status': status, // Hardcoded 1 to make user active bydefault + 'userId': userId, + 'createTimestamp': new Date() + } + const result = await sequelize.transaction(async (t) => { + const saveNotificationResp = await models.AdminNotificationPreference.create(createUserPayload, { transaction: t }) + res.send(saveNotificationResp) + }); + } catch (e) { + console.log(e); + res.status(500).send(e); + } +} \ No newline at end of file diff --git a/kubernetes/k8-deployment.yaml b/kubernetes/k8-deployment.yaml index eb822d55..768c8fb5 100644 --- a/kubernetes/k8-deployment.yaml +++ b/kubernetes/k8-deployment.yaml @@ -117,6 +117,26 @@ spec: key: RECITER_SEARCH_COUNT_PUBMED - name: LOGIN_PROVIDER value: SAML + - name : ENTITY_ID + valueFrom: + secretKeyRef: + name: reciter-pm-dev-secrets + key: ENTITY_ID + - name: ASSERT_ENDPOINT + valueFrom: + secretKeyRef: + name: reciter-pm-dev-secrets + key: ASSERT_ENDPOINT + - name: SSO_LOGIN_URL + valueFrom: + secretKeyRef: + name: reciter-pm-dev-secrets + key : SSO_LOGIN_URL + - name: SSO_LOGOUT_URL + valueFrom: + secretKeyRef: + name: reciter-pm-dev-secrets + key : SSO_LOGOUT_URL ports: - containerPort: 3000 name: reciter-pm diff --git a/kubernetes/k8-secrets.yaml b/kubernetes/k8-secrets.yaml index a8dc02ed..dac47ccb 100644 --- a/kubernetes/k8-secrets.yaml +++ b/kubernetes/k8-secrets.yaml @@ -26,4 +26,8 @@ stringData: RECITER_FIND_USER_FEEDBACK: <> RECITER_SEARCH_PUBMED: <> RECITER_SEARCH_COUNT_PUBMED: <> + ENTITY_ID: <> + ASSERT_ENDPOINT: <> + SSO_LOGIN_URL : <> + SSO_LOGOUT_URL: <> type: Opaque \ No newline at end of file diff --git a/next.config.js b/next.config.js index 125c958c..a20c5d37 100644 --- a/next.config.js +++ b/next.config.js @@ -3,5 +3,6 @@ module.exports = { reactStrictMode: true, images: { domains: ['directory.weill.cornell.edu'], - } + }, + swcMinify: true, } diff --git a/package.json b/package.json index 2522e03a..a1b1ab30 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,8 @@ "next": "^12.2.5", "next-auth": "^3.29.10", "next-redux-wrapper": "^7.0.5", + "nodemailer": "^6.9.1", + "nodemailer-smtp-transport": "^2.7.4", "react": "^16.14.0", "react-bootstrap": "^2.0.3", "react-dates": "^21.8.0", @@ -48,8 +50,7 @@ "redux-thunk": "^2.3.0", "reflect-metadata": "^0.1.13", "saml2-js": "^3.0.1", - "sequelize": "^6.9.0", - "nodemailer": "^6.9.1" + "sequelize": "^6.9.0" }, "devDependencies": { "@types/express": "^4.17.13", diff --git a/src/components/elements/Navbar/SideNavbar.tsx b/src/components/elements/Navbar/SideNavbar.tsx index 98fcc16d..c042d386 100644 --- a/src/components/elements/Navbar/SideNavbar.tsx +++ b/src/components/elements/Navbar/SideNavbar.tsx @@ -173,14 +173,14 @@ const SideNavbar: React.FC = () => { disabled: false, allowedRoleNames: ["Superuser","Reporter_All" ], }, - // { - // title: 'Manage Notifications', - // to: '/notifications', - // imgUrl: chartIcon, - // imgUrlActive: chartIconActive, - // disabled: false, - // allowedRoleNames: ["Curator_Self" ], - // }, + { + title: 'Manage Notifications', + to: '/notifications', + imgUrl: chartIcon, + imgUrlActive: chartIconActive, + disabled: false, + allowedRoleNames: ["Department_user"], + }, {title: 'Manage Users', to: '/manageusers', imgUrl: facultyIcon, diff --git a/src/components/elements/Notifications/Notifications.tsx b/src/components/elements/Notifications/Notifications.tsx index 4c5590e6..5ec979fc 100644 --- a/src/components/elements/Notifications/Notifications.tsx +++ b/src/components/elements/Notifications/Notifications.tsx @@ -4,58 +4,92 @@ import appStyles from '../App/App.module.css'; import { useSelector, useDispatch, RootStateOrAny } from "react-redux"; import Loader from "../Common/Loader"; import { Form,Button } from "react-bootstrap"; -import { sendNotification } from "../../../redux/actions/actions"; +import { saveNotification, sendNotification } from "../../../redux/actions/actions"; +import { useSession } from "next-auth/client"; const Notifications = () => { - const dispatch = useDispatch() - - useEffect(() => { - - }, []) - - const onSave = ()=>{ - sendNotification(); - } - - return ( -
-

Manage Notifications

- - - - - Frequency - - - - - - - -
-

Reasons for sending a notification

- - - - - - -
- - - - - - - - - -
-

Emails will be sent to Email

-
- + const dispatch = useDispatch() + const [session, loading] = useSession(); + const [state, setState] = useState({ + frequency: 1, + minimumThreshold:8, +}) + +const identityData = useSelector((state: RootStateOrAny) => state.identityData); +const {frequency,minimumThreshold} = state +const [formErrorsInst, setformErrInst] = useState<{[key: string]: any}>({}); +const [accepted, setAccepted] = useState(false); +const [status, setStatus] = useState(false); +const [evidence, setEvidance] = useState(true) +const [userId, setUserId] = useState("") + +useEffect(()=>{ + setUserId( session.data.username) +},[]) + + const handleAccept = ()=>{ + setAccepted(!accepted) + } + const handleEvidence = ()=>{ + setEvidance(!evidence) + } + const onSave = ()=>{ + let payload = {frequency,accepted : accepted === true ? 1 : 0,status : status === true ? 1 : 0,minimumThreshold, userId} + dispatch(saveNotification(payload)) + } + const handleStatus= ()=>{ + setStatus(!status) + } + const handleValueChange = (field, value) => { + if(value != '') formErrorsInst[field] = ''; + setState(state => ({ ...state, [field]: value })) +} + return ( +
+

Manage Notifications

+ + handleStatus()}/> + + + Frequency + handleValueChange("frequency",e.target.value)} className={styles.selectFrequecy}> + + + + + + +
+

Reasons for sending a notification

+ + handleAccept()}/> + + + + +
+ + handleEvidence()}/> + + handleValueChange("minimumThreshold",e.target.value)} className={styles.selectCount}> + {/* */} + + + + + + + +
- ) +

Emails will be sent to Email

+
+ +
+ ) } -export default Notifications; + + + +export default Notifications; \ No newline at end of file diff --git a/src/middleware.ts b/src/middleware.ts new file mode 100644 index 00000000..ec5d380d --- /dev/null +++ b/src/middleware.ts @@ -0,0 +1,116 @@ +import {NextRequest, NextResponse } from 'next/server' +import { allowedPermissions } from './utils/constants' + + +//middleware should run for these router paths +export const config = { + matcher: ['/manageusers/:path*', '/curate/:path*','/report','/search','/configuration','/notifications/:path*'], +} + +export async function middleware(request: NextRequest) { + const res = NextResponse.next(); + const pathName = request.nextUrl.pathname; + + if(request && request.cookies && request.cookies.has('next-auth.session-token')) + { + let decodedTokenJson = decodeJwt(request.cookies.get('next-auth.session-token')?.toString); + let allUserRoles =''; + if(decodedTokenJson && decodedTokenJson.userRoles) + allUserRoles = decodedTokenJson.userRoles; + if (allUserRoles && allUserRoles.length > 0) { + let userRoles = allUserRoles && allUserRoles?.length > 0 && JSON.parse(allUserRoles) + if (userRoles && userRoles.length > 0) { + + let loggedInUserInfo = userRoles[0].personIdentifier; //should be reverted after testing + let isCuratorSelf = userRoles.some((role) => role.roleLabel === allowedPermissions.Curator_Self) + let isSuperUser = userRoles.some((role) => role.roleLabel === allowedPermissions.Superuser) + let isCuratorAll = userRoles.some((role) => role.roleLabel === allowedPermissions.Curator_All) + let isReporterAll = userRoles.some((role) => role.roleLabel === allowedPermissions.Reporter_All) + + + if (pathName && pathName.startsWith('/curate') && !isCuratorAll && !isSuperUser) + { + if (userRoles.length == 1 && isReporterAll && !isCuratorSelf) { + return redirectToLandingPage(request,'/search'); + } + else if (userRoles.length == 1 && (pathName !== '/curate/'+loggedInUserInfo || pathName.endsWith('curate'))&& isCuratorSelf && !isReporterAll ) { + return redirectToLandingPage(request,'/curate/'+loggedInUserInfo); + } + else if (userRoles.length == 2 && (pathName !== '/curate/'+loggedInUserInfo || pathName.endsWith('curate')) && isCuratorSelf && isReporterAll ) { + return redirectToLandingPage(request,'/curate/'+loggedInUserInfo); + } + + } + else if (pathName && pathName.startsWith('/search') && !isReporterAll && !isSuperUser && !isCuratorAll) + { + if (userRoles.length == 1 && isCuratorSelf ) + return redirectToLandingPage(request,'/curate/'+loggedInUserInfo); + } + else if (pathName && pathName.startsWith('/report') && !isReporterAll && !isSuperUser) + { + if (userRoles.length == 1 && isCuratorSelf && !isCuratorAll) + return redirectToLandingPage(request,'/curate/'+loggedInUserInfo); + else if (userRoles.length == 1 && !isCuratorSelf && isCuratorAll) + return redirectToLandingPage(request,'/search'); + else if (userRoles.length == 2 && isCuratorSelf && isCuratorAll) + return redirectToLandingPage(request,'/curate/'+loggedInUserInfo); + } + else if (pathName && pathName.startsWith('/notifications')) + { + //correct role restrictions will be implemented once notification functionality is ready. It is just a placeholder for now. + + if(isCuratorSelf) + return redirectToLandingPage(request,'/curate/'+loggedInUserInfo); + else if (isReporterAll || isCuratorAll || isSuperUser) + return redirectToLandingPage(request,'/search'); + } + else if (pathName && pathName.startsWith('/manageusers') && !isSuperUser) + { + if (userRoles.length == 1 && (isReporterAll || isCuratorAll) && !isCuratorSelf) + return redirectToLandingPage(request,'/search'); + else if (userRoles.length == 1 && isCuratorSelf && !isReporterAll && !isCuratorAll) + return redirectToLandingPage(request,'/curate/'+loggedInUserInfo); + else if (userRoles.length == 2 && isCuratorSelf && isReporterAll && !isCuratorAll) + return redirectToLandingPage(request,'/curate/'+loggedInUserInfo); + else if (userRoles.length == 2 && isCuratorSelf && !isReporterAll && isCuratorAll) + return redirectToLandingPage(request,'/curate/'+loggedInUserInfo); + else if (userRoles.length == 2 && !isCuratorSelf && isReporterAll && isCuratorAll) + return redirectToLandingPage(request,'/search'); + else if (userRoles.length == 3 && isCuratorSelf && isReporterAll && isCuratorAll) + return redirectToLandingPage(request,'/curate/'+loggedInUserInfo); + + } + else if (pathName && pathName.startsWith('/configuration') && !isSuperUser) + { + if (userRoles.length == 1 && (isReporterAll || isCuratorAll) && !isCuratorSelf) + return redirectToLandingPage(request,'/search'); + else if (userRoles.length == 1 && isCuratorSelf && !isReporterAll && !isCuratorAll) + return redirectToLandingPage(request,'/curate/'+loggedInUserInfo); + else if (userRoles.length == 2 && isCuratorSelf && isReporterAll && !isCuratorAll) + return redirectToLandingPage(request,'/curate/'+loggedInUserInfo); + else if (userRoles.length == 2 && !isCuratorSelf && isReporterAll && isCuratorAll) + return redirectToLandingPage(request,'/search'); + else if (userRoles.length == 2 && isCuratorSelf && !isReporterAll && isCuratorAll) + return redirectToLandingPage(request,'/curate/'+loggedInUserInfo); + else if (userRoles.length == 3 && isCuratorSelf && isReporterAll && isCuratorAll) + return redirectToLandingPage(request,'/curate/'+loggedInUserInfo); + } + } + } + else // redirects to error page when no roles found in access token + { + redirectToLandingPage(request,'/error'); + } + } + return res; +} +function decodeJwt(token:any) { + var base64Payload = token.split(".")[1]; + var payloadBuffer = Buffer.from(base64Payload, "base64"); + return JSON.parse(payloadBuffer.toString()); +} +function redirectToLandingPage(request:NextRequest,pathName:any){ + const redirectedUrl = request.nextUrl.clone() + redirectedUrl.pathname =pathName; + return NextResponse.redirect(redirectedUrl); +} \ No newline at end of file diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 95b1eade..ef695eb4 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -35,14 +35,10 @@ import "bootstrap/dist/css/bootstrap.min.css" import { Provider as ReduxProvider } from 'react-redux' import { useStore } from '../redux/store/store' import type { Page } from '../../types/pages' -import { Fragment, useEffect } from 'react' import type { AppProps } from 'next/app' import { Provider } from "next-auth/client" import type { NextPage } from 'next' import type { ReactElement, ReactNode } from 'react' -import { useRouter } from "next/router"; -import { allowedPermissions } from '../utils/constants' -import {useHistory} from "react-router-dom" // this should give a better typing @@ -60,156 +56,10 @@ type AppPropsWithLayout = AppProps & { export default function App({ Component, pageProps: { session, ...pageProps } }: AppPropsWithLayout) { const store = useStore(pageProps.initialReduxState) - const router = useRouter() - let history = useHistory() // Use the layout defined at the page level, if available const getLayout = Component.getLayout ?? ((page) => page) - useEffect(() => { - if(router.isReady) - { - rbaController(); - } - }, [router.isReady,router.pathname]) - - - - const rbaController = async () => { - let allUserRoles = sessionStorage.getItem("userRoles"); - - const personIdentifierInQueryParam=''; - - if(router && router.query && router.query.id) - { - personIdentifierInQueryParam = router.query.id; - } - if (allUserRoles && allUserRoles.length > 0) { - let userRoles = allUserRoles && allUserRoles?.length > 0 && JSON.parse(allUserRoles) - if (userRoles && userRoles.length > 0) { - let loggedInUserInfo = userRoles[0].personIdentifier; - let isCuratorSelf = userRoles.some((role) => role.roleLabel === allowedPermissions.Curator_Self) - let isSuperUser = userRoles.some((role) => role.roleLabel === allowedPermissions.Superuser) - let isCuratorAll = userRoles.some((role) => role.roleLabel === allowedPermissions.Curator_All) - let isReporterAll = userRoles.some((role) => role.roleLabel === allowedPermissions.Reporter_All) - if (router?.pathname === "/curate/[id]" && !isCuratorAll && !isSuperUser) - { - console.log('coming to /curate/id'); - if (userRoles.length == 1 && isReporterAll && !isCuratorSelf) { - router.push('/search'); - } - else if (userRoles.length == 1 && loggedInUserInfo !== personIdentifierInQueryParam && isCuratorSelf && !isReporterAll ) { - router.push('/curate/'+loggedInUserInfo); - } - else if (userRoles.length == 2 && loggedInUserInfo !== personIdentifierInQueryParam && isCuratorSelf && isReporterAll ) { - router.push('/curate/'+loggedInUserInfo); - } - - } - else if (router?.pathname === "/curate" && !isSuperUser && !isCuratorAll) - { - if (userRoles.length == 1 && isReporterAll && !isCuratorSelf) { - router.push("/search"); - } - else if (userRoles.length == 1 && isCuratorSelf && !isReporterAll ) { - router.push('/curate/'+loggedInUserInfo); - } - else if (userRoles.length == 2 && isCuratorSelf && isReporterAll) { - router.push('/curate/'+loggedInUserInfo); - } - - } - else if (router?.pathname === "/search" && !isReporterAll && !isSuperUser && !isCuratorAll) - { - if (userRoles.length == 1 && isCuratorSelf ) { - router.push('/curate/'+loggedInUserInfo); - } - } - else if (router?.pathname === "/report" && !isReporterAll && !isSuperUser) - { - if (userRoles.length == 1 && isCuratorSelf && !isCuratorAll) { - router.push('/curate/'+loggedInUserInfo); - } - else if (userRoles.length == 1 && !isCuratorSelf && isCuratorAll) { - router.push('/search') - } - else if (userRoles.length == 2 && isCuratorSelf && isCuratorAll) { - router.push('/curate/'+loggedInUserInfo); - } - } - else if (router?.pathname === "/notifications" && !isSuperUser && !isCuratorSelf && !isCuratorAll) - { - if (isReporterAll) { - router.push("/search"); - } - - } - else if (router?.pathname === "/manageusers" && !isSuperUser && !isCuratorAll) - { - if (userRoles.length == 1 && isReporterAll && !isCuratorSelf ) - { - router.push('/search'); - } - else if (userRoles.length == 1 && isCuratorSelf && !isReporterAll) - { - router.push('/curate/'+loggedInUserInfo); - } - else if (userRoles.length == 2 && isCuratorSelf && isReporterAll) - { - router.push('/curate/'+loggedInUserInfo); - } - //will be removed after implementing notifications functionality -mahender - else if (userRoles.length == 3 && isCuratorSelf && isReporterAll && isCuratorAll) { - router.push('/curate/'+loggedInUserInfo); - } - } - else if ((router?.pathname === "/manageusers/add" ||router?.pathname === "/manageusers/[id]") && !isSuperUser ) - { - if (userRoles.length == 1 && (isReporterAll || isCuratorAll) && !isCuratorSelf ) - { - router.push('/search'); - } - else if (userRoles.length == 1 && isCuratorSelf && !isReporterAll && !isCuratorAll) - { - router.push('/curate/'+loggedInUserInfo); - } - else if (userRoles.length == 2 && ((isCuratorSelf && isReporterAll) || (isCuratorSelf && isCuratorAll))) { - router.push('/curate/'+loggedInUserInfo); - } - else if (userRoles.length == 2 && isCuratorAll && isReporterAll) { - router.push('/search'); - } - else if (userRoles.length == 3 && isCuratorSelf && isReporterAll && isCuratorAll) { - router.push('/curate/'+loggedInUserInfo); - } - - } - - else if (router?.pathname === "/configuration" && !isSuperUser) - { - if (userRoles.length == 1 && isReporterAll && !isCuratorSelf && !isCuratorAll) { - router.push('/search'); - } - else if (userRoles.length == 1 && isCuratorSelf && !isReporterAll && !isCuratorAll) { - router.push('/curate/'+loggedInUserInfo); - } - else if (userRoles.length == 1 && !isCuratorSelf && !isReporterAll && isCuratorAll) { - router.push('/search'); - } - else if (userRoles.length == 2 && isCuratorSelf && isReporterAll && !isCuratorAll) { - router.push('/curate/'+loggedInUserInfo); - } - else if (userRoles.length == 2 && !isCuratorSelf && isReporterAll && isCuratorAll) { - router.push('/search'); - } - else if (userRoles.length == 3 && isCuratorSelf && isReporterAll && !isSuperUser && isCuratorAll) { - router.push('/curate/'+loggedInUserInfo); - } - } - } - } - } - return ( diff --git a/src/pages/api/db/admin/notifications/index.ts b/src/pages/api/db/admin/notifications/index.ts new file mode 100644 index 00000000..a32a5a98 --- /dev/null +++ b/src/pages/api/db/admin/notifications/index.ts @@ -0,0 +1,20 @@ +import type { NextApiRequest, NextApiResponse } from 'next' +import { reciterConfig } from '../../../../../../config/local' +import { saveNotifications } from '../../../../../../controllers/db/notifications/notifications.controller' +import { AdminUser } from '../../../../../db/models/AdminUser' + +export default async function handler(req: NextApiRequest, + res: NextApiResponse) { + if (req.method === "POST") { + if(req.headers.authorization !== undefined && req.headers.authorization === reciterConfig.backendApiKey) { + await saveNotifications (req, res) + } else if(req.headers.authorization === undefined) { + res.status(400).send("Authorization header is needed") + } else { + res.status(401).send("Authorization header is incorrect") + } + } else { + // Default this to a bad request for now + res.status(400).send('HTTP Supported method is GET') + } +} \ No newline at end of file diff --git a/src/pages/login/index.js b/src/pages/login/index.js index 15da9bee..99c75a58 100644 --- a/src/pages/login/index.js +++ b/src/pages/login/index.js @@ -1,73 +1,4 @@ import Login from '../../components/elements/Login/Login' -import { getSession } from "next-auth/client" -import { allowedPermissions, dropdownItemsReport } from "../../utils/constants"; - -export async function getServerSideProps(ctx) { - const session = await getSession(ctx); - let userPermissions = null; - let personIdentifier =null; - let userName =null; - if (session && session.data) { - userPermissions = JSON.parse(session.data.userRoles); - userName = session.data.username; - personIdentifier = userPermissions && userPermissions.length > 0 ? userPermissions[0].personIdentifier : "" - - if(session.data.databaseUser && session.data.databaseUser.status == 0) { - return { - redirect: { - destination: "/noaccess", - permanent: false, - }, - }; - } - else if((userPermissions && userPermissions.some(role => role.roleLabel === allowedPermissions.Curator_Self)) && userName) - { - return { - redirect: { - destination: `/api/saml/assert?callbackUrl=/curate/${personIdentifier}`, - permanent: false, - }, - }; - } - else - { - return { - redirect: { - destination: "/search", - permanent: false, - }, - }; - } - } - - if(process.env.LOGIN_PROVIDER == "SAML") { - if((userPermissions && userPermissions.some(role => role.roleLabel === allowedPermissions.Curator_Self)) && userName) - { - return { - redirect: { - destination: `/api/saml/assert?callbackUrl=/curate/${personIdentifier}`, - permanent: false, - }, - }; - } - else - { - return { - redirect: { - destination: "/api/saml/assert?callbackUrl=/search", - permanent: false, - }, - }; - } - - } - - return { - props: { - session: session, - }, - }; -} const LoginPage = () => { return ( diff --git a/src/redux/actions/actions.js b/src/redux/actions/actions.js index fc3befdf..19224781 100644 --- a/src/redux/actions/actions.js +++ b/src/redux/actions/actions.js @@ -2261,6 +2261,47 @@ export const adminSettingsListAction = (adminSettingsList) => dispatch => { }) } +export const saveNotification = (payload) => dispatch => { + fetch(`/api/db/admin/notifications`, { + credentials: "same-origin", + method: 'POST', + headers: { + Accept: 'application/json', + "Content-Type": "application/json", + 'Authorization': reciterConfig.backendApiKey + }, + body: JSON.stringify(payload) + }).then(response => { + if (response.status === 200) { + return response.json() + } else { + throw { + type: response.type, + title: response.statusText, + status: response.status, + detail: "Error occurred with api " + response.url + ". Please, try again later " + } + } + }).then(data => { + // dispatch({ + // type: methods.REPORTS_RESULTS_IDS_UPDATE, + // payload: data + // }) + // dispatch({ + // type: methods.REPORTS_RESULTS_IDS_CANCEL_LOADING + // }) + }).catch(error => { + console.log(error) + toast.error("Save notification Api failed - " + error.title, { + position: "top-right", + autoClose: 2000, + theme: 'colored' + }); + dispatch( + addError(error) + ) + }) + } export const sendNotification = (toEmail, body, subject) =>{ return fetch(`/api/notification`, { credentials: "same-origin",