Skip to content

Commit

Permalink
Merge pull request #326 from wcmc-its/dev_v2_mrj4001
Browse files Browse the repository at this point in the history
Fixed issues reported on wiki and integrated middleware for the redir…
  • Loading branch information
mrj4001 authored May 4, 2023
2 parents fa94f53 + 04d72c0 commit 20a1370
Show file tree
Hide file tree
Showing 13 changed files with 332 additions and 284 deletions.
8 changes: 4 additions & 4 deletions config/saml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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()
],
Expand Down
30 changes: 30 additions & 0 deletions controllers/db/notifications/notifications.controller.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
20 changes: 20 additions & 0 deletions kubernetes/k8-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions kubernetes/k8-secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ stringData:
RECITER_FIND_USER_FEEDBACK: <<RECITER_FIND_USER_FEEDBACK>>
RECITER_SEARCH_PUBMED: <<RECITER_SEARCH_PUBMED>>
RECITER_SEARCH_COUNT_PUBMED: <<RECITER_SEARCH_COUNT_PUBMED>>
ENTITY_ID: <<ENTITY_ID>>
ASSERT_ENDPOINT: <<ASSERT_ENDPOINT>>
SSO_LOGIN_URL : <<SSO_LOGIN_URL>>
SSO_LOGOUT_URL: <<SSO_LOGOUT_URL>>
type: Opaque
3 changes: 2 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ module.exports = {
reactStrictMode: true,
images: {
domains: ['directory.weill.cornell.edu'],
}
},
swcMinify: true,
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions src/components/elements/Navbar/SideNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ const SideNavbar: React.FC<SideNavBarProps> = () => {
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,
Expand Down
134 changes: 84 additions & 50 deletions src/components/elements/Notifications/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className={appStyles.mainContainer}>
<h1 className={styles.header}>Manage Notifications</h1>
<Form.Group className="mb-3" controlId="formBasicCheckbox">
<Form.Check type="checkbox" label="Disable all notifications" />
</Form.Group>

<Form.Label className="fw-bold">Frequency</Form.Label>
<Form.Select aria-label="Default select example" className={styles.selectFrequecy}>
<option>Daily</option>
<option value="1">Every 7 days</option>
<option value="2">Every 14 days</option>
<option value="3">Every 28 days</option>
</Form.Select>

<div className="mt-5">
<p className="fw-bold">Reasons for sending a notification</p>
<Form.Group className="mb-3" controlId="formBasicCheckbox">
<Form.Check type="checkbox" label="A new publication has been accepted on your behalf" />
</Form.Group>
<Form.Group className="mb-3" controlId="formBasicCheckbox">
<Form.Check type="checkbox" label="A new publication has been suggested" />
</Form.Group>
<div className={styles.nestedMenu}>
<Form.Group className="mb-3" controlId="formBasicCheckbox">
<Form.Check type="checkbox" label="Minimum evidence score for triggering a notification(higher scores indicate greater confidence)" />
</Form.Group>
<Form.Select aria-label="Default select example" className={styles.selectCount}>
<option>7</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</Form.Select>
</div>
<p className="mt-3">Emails will be sent to Email</p>
</div>
<Button variant="warning" className="m-2" onClick={()=>onSave()}>Save</Button>
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<boolean>(false);
const [status, setStatus] = useState<boolean>(false);
const [evidence, setEvidance] = useState<boolean>(true)
const [userId, setUserId] = useState<string>("")

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 (
<div className={appStyles.mainContainer}>
<h1 className={styles.header}>Manage Notifications</h1>
<Form.Group className="mb-3" controlId="formBasicCheckbox">
<Form.Check type="checkbox" label="Disable all notifications"  onChange={()=>handleStatus()}/>
</Form.Group>

<Form.Label className="fw-bold">Frequency</Form.Label>
<Form.Select aria-label="Default select example" value={frequency} defaultValue={1} onChange={(e)=>handleValueChange("frequency",e.target.value)} className={styles.selectFrequecy}>
<option value = "1">Daily</option>
<option value="7">Every 7 days</option>
<option value="14">Every 14 days</option>
<option value="28">Every 28 days</option>
</Form.Select>

<div className="mt-5">
<p className="fw-bold">Reasons for sending a notification</p>
<Form.Group className="mb-3" controlId="formBasicCheckbox">
<Form.Check type="checkbox" label="A new publication has been accepted on your behalf" onChange={()=>handleAccept()}/>
</Form.Group>
<Form.Group className="mb-3" controlId="formBasicCheckbox">
<Form.Check type="checkbox" label="A new publication has been suggested" />
</Form.Group>
<div className={styles.nestedMenu}>
<Form.Group className="mb-3" controlId="formBasicCheckbox">
<Form.Check type="checkbox" label="Minimum evidence score for triggering a notification(higher scores indicate greater confidence)" onChange={()=>handleEvidence()}/>
</Form.Group>
<Form.Select aria-label="Default select example" value={minimumThreshold} disabled={evidence} onChange={(e)=>handleValueChange("minimumThreshold",e.target.value)} className={styles.selectCount}>
{/* <option>7</option> */}
<option value="10">10</option>
<option value="9">9</option>
<option value="8">8</option>
<option value="7">7</option>
<option value="6">6</option>
<option value="5">5</option>
<option value="4">4</option>
</Form.Select>
</div>
)
<p className="mt-3">Emails will be sent to Email</p>
</div>
<Button variant="warning" className="m-2" onClick={()=>onSave()}>Save</Button>
</div>
)
}

export default Notifications;



export default Notifications;
Loading

0 comments on commit 20a1370

Please sign in to comment.