Merged PR 2315: Auth stabilistatiion and hardening
Related work items: #23020
This commit is contained in:
@@ -2,7 +2,7 @@ import useTranslation from "next-translate/useTranslation";
|
||||
import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
import { connect } from "react-redux";
|
||||
import { getIP } from "../../../actions/core/logger";
|
||||
import { consoleLogger, getIP } from "../../../actions/core/logger";
|
||||
import {
|
||||
getPersonalAccount,
|
||||
getPortalLogin
|
||||
@@ -61,17 +61,10 @@ import ServiceBanner from "../../../components/myportal/servicebanner";
|
||||
import TimeOut from "../../../components/timeout";
|
||||
|
||||
const CaseHome = (props) => {
|
||||
const {
|
||||
footerLinks,
|
||||
pages,
|
||||
setSearchResults,
|
||||
setSearchDetails,
|
||||
searchResultsObj
|
||||
} = props;
|
||||
let { t, lang } = useTranslation();
|
||||
const { footerLinks } = props;
|
||||
useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
const { ticketnumber } = router.query;
|
||||
|
||||
return (
|
||||
@@ -94,9 +87,6 @@ const CaseHome = (props) => {
|
||||
props={props}
|
||||
myCases={props.myCases.myCases}
|
||||
myCasesDetails={props.myCases.myCasesDetails}
|
||||
// directSearchResultsObj={
|
||||
// props.searchResultsObj.searchResultsObj
|
||||
// }
|
||||
searchResultsObj={
|
||||
props.searchResultsObj.searchResultsObj
|
||||
}
|
||||
@@ -150,28 +140,44 @@ const CaseHome = (props) => {
|
||||
|
||||
export const getServerSideProps = wrapper.getServerSideProps(
|
||||
(store) => async (ctx) => {
|
||||
const { query, req, res } = ctx;
|
||||
const { query, req } = ctx;
|
||||
getIP(req);
|
||||
const { cookies } = req;
|
||||
|
||||
console.log(cookies);
|
||||
console.log("the query :", query.ticketnumber);
|
||||
|
||||
console.log("viewkey: " + (query.hasOwnProperty("key") ? "yes" : "no"));
|
||||
consoleLogger({
|
||||
name: "MyPortalCaseTicketLoaderStart",
|
||||
message: "myportal case ticket loader invoked",
|
||||
hasTicketNumber: !!query?.ticketnumber,
|
||||
hasViewKey: Object.prototype.hasOwnProperty.call(query, "key")
|
||||
});
|
||||
|
||||
const showLoginCheck = process.env.SHOWLOGIN || false;
|
||||
let thisSession = await getSession(ctx);
|
||||
const thisSession = await getSession(ctx);
|
||||
let loggedInUser = {};
|
||||
|
||||
if (thisSession) {
|
||||
console.log(" has sesssion.......");
|
||||
[loggedInUser] = await Promise.all([
|
||||
await getPortalLogin(thisSession.user.email)
|
||||
]);
|
||||
loggedInUser = await getPortalLogin(thisSession.user.email);
|
||||
|
||||
loggedInUser = loggedInUser.value[0].contactid;
|
||||
loggedInUser = loggedInUser?.value?.[0]?.contactid;
|
||||
if (!loggedInUser) {
|
||||
consoleLogger({
|
||||
name: "MyPortalCaseTicketMissingContact",
|
||||
message:
|
||||
"myportal case ticket loader missing CRM contact id; redirecting to signin",
|
||||
hasSessionEmail: !!thisSession?.user?.email
|
||||
});
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
} else {
|
||||
console.log("not has sesssion.......");
|
||||
consoleLogger({
|
||||
name: "MyPortalCaseTicketMissingSession",
|
||||
message:
|
||||
"myportal case ticket loader missing session; redirecting to signin"
|
||||
});
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
@@ -191,22 +197,24 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
store.dispatch(setAccountDetails(accountDetails));
|
||||
store.dispatch(setLoggedInUserId(loggedInUser));
|
||||
|
||||
let developmentQuery = query.ticketnumber;
|
||||
const developmentQuery = query.ticketnumber;
|
||||
|
||||
const pattern = /CAS-\d{5}-[A-Z0-9]{6}/;
|
||||
const match = query.ticketnumber.match(pattern);
|
||||
|
||||
if (match) {
|
||||
console.log("Match found!", match[0]);
|
||||
} else {
|
||||
console.log("No match.");
|
||||
if (!match) {
|
||||
consoleLogger({
|
||||
name: "MyPortalCaseTicketUnexpectedFormat",
|
||||
message: "ticketnumber does not match CAS expected format",
|
||||
hasTicketNumber: !!query?.ticketnumber
|
||||
});
|
||||
}
|
||||
|
||||
const searchResultsObj = await getBasicSearch(developmentQuery);
|
||||
const searchDetailsObj = await getSearchDetails(searchResultsObj);
|
||||
|
||||
var eventsObj = {};
|
||||
var mediaObj = {};
|
||||
let eventsObj = {};
|
||||
let mediaObj = {};
|
||||
|
||||
if (searchResultsObj.value[0].pinswg_appealcasetype == 846040002) {
|
||||
eventsObj = await getSIPSEvents(
|
||||
@@ -220,25 +228,16 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
|
||||
store.dispatch(setMediaDetails(mediaObj));
|
||||
}
|
||||
//console.log(
|
||||
// "\n======================================\n",
|
||||
// searchResultsObj,
|
||||
// "\n======================================\n"
|
||||
// );
|
||||
//console.log(
|
||||
// "\n======================================\n",
|
||||
// searchDetailsObj[0],
|
||||
// "\n======================================\n"
|
||||
// );
|
||||
|
||||
store.dispatch(setSearch(developmentQuery));
|
||||
|
||||
// console.log(
|
||||
// searchResultsObj["@odata.count"] > 1 ||
|
||||
// searchResultsObj["@odata.count"] < 1
|
||||
// );
|
||||
|
||||
if (searchResultsObj["@odata.count"] < 1) {
|
||||
consoleLogger({
|
||||
name: "MyPortalCaseTicketSearchNotFound",
|
||||
message:
|
||||
"myportal case ticket loader search count < 1; redirecting to 404",
|
||||
ticketnumber: query?.ticketnumber
|
||||
});
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/404",
|
||||
@@ -247,6 +246,13 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
};
|
||||
} else {
|
||||
if (searchResultsObj["@odata.count"] > 1) {
|
||||
consoleLogger({
|
||||
name: "MyPortalCaseTicketSearchAmbiguous",
|
||||
message:
|
||||
"myportal case ticket loader search count > 1; redirecting to 404",
|
||||
ticketnumber: query?.ticketnumber,
|
||||
count: searchResultsObj["@odata.count"]
|
||||
});
|
||||
return {
|
||||
redirect: {
|
||||
//destination: "/dns-not-found",
|
||||
@@ -255,7 +261,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
}
|
||||
};
|
||||
} else {
|
||||
if (query.hasOwnProperty("key")) {
|
||||
if (Object.prototype.hasOwnProperty.call(query, "key")) {
|
||||
let whichViewKey = query.key;
|
||||
|
||||
switch (whichViewKey) {
|
||||
@@ -268,42 +274,6 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
);
|
||||
break;
|
||||
case "watchedCases":
|
||||
// const watchedCases = await getWatchedCases(
|
||||
// loggedInUser
|
||||
// );
|
||||
|
||||
// let showWatchedCases = (submittedArr) => {
|
||||
// const required = submittedArr.value.filter(
|
||||
// (el) => {
|
||||
// return (
|
||||
// el.pinswg_representationsubmitted ==
|
||||
// null
|
||||
// );
|
||||
// }
|
||||
// );
|
||||
|
||||
// let newObj = {};
|
||||
// return Object.assign(newObj, {
|
||||
// "@odata.count": required.length,
|
||||
// "value": required,
|
||||
// });
|
||||
// };
|
||||
|
||||
// let filteredWatchedCases =
|
||||
// showWatchedCases(watchedCases);
|
||||
|
||||
// const watchedCasesDetails = await getDetails(
|
||||
// filteredWatchedCases,
|
||||
// "myWatchedCases"
|
||||
// );
|
||||
|
||||
// store.dispatch(
|
||||
// setWatchedCases(filteredWatchedCases)
|
||||
// );
|
||||
// store.dispatch(
|
||||
// setWatchedCasesDetails(watchedCasesDetails)
|
||||
// );
|
||||
|
||||
store.dispatch(
|
||||
setCurrentView({
|
||||
"viewName": "Watched Cases",
|
||||
@@ -362,19 +332,19 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
}
|
||||
const watchedCases = await getWatchedCases(loggedInUser);
|
||||
|
||||
let showWatchedCases = (submittedArr) => {
|
||||
const showWatchedCases = (submittedArr) => {
|
||||
const required = submittedArr.value.filter((el) => {
|
||||
return el.pinswg_representationsubmitted == null;
|
||||
});
|
||||
|
||||
let newObj = {};
|
||||
const newObj = {};
|
||||
return Object.assign(newObj, {
|
||||
"@odata.count": required.length,
|
||||
"value": required
|
||||
});
|
||||
};
|
||||
|
||||
let filteredWatchedCases = showWatchedCases(watchedCases);
|
||||
const filteredWatchedCases = showWatchedCases(watchedCases);
|
||||
|
||||
const watchedCasesDetails = await getDetails(
|
||||
filteredWatchedCases,
|
||||
@@ -415,9 +385,10 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
(el) => el.pinswg_representationsubmitted != null
|
||||
);
|
||||
|
||||
const [mySubmittedRepsDetails] = await Promise.all([
|
||||
getDetails(mySubmittedReps, "mySubmittedReps")
|
||||
]);
|
||||
const mySubmittedRepsDetails = await getDetails(
|
||||
mySubmittedReps,
|
||||
"mySubmittedReps"
|
||||
);
|
||||
|
||||
store.dispatch(setMySubmittedReps(mySubmittedReps));
|
||||
store.dispatch(
|
||||
@@ -425,9 +396,6 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
);
|
||||
}
|
||||
}
|
||||
//console.log(searchResultsObj);
|
||||
|
||||
//console.log(loggedInUser);
|
||||
return {
|
||||
props: {
|
||||
searchResultsObj: {
|
||||
@@ -455,7 +423,7 @@ const getDetails = (resultsObj, detailsType) => {
|
||||
detailsType == "mySubmittedReps" ? resultsObj : resultsObj.value;
|
||||
|
||||
if (detailsType == "myRepresentations") {
|
||||
const repsObj = resultsObj.map((searchDetail, index) => {
|
||||
resultsObj.map((searchDetail) => {
|
||||
detailsArr.push(
|
||||
getCase(searchDetail["incidentID"]).then((data) => {
|
||||
let caseID = "";
|
||||
@@ -488,7 +456,7 @@ const getDetails = (resultsObj, detailsType) => {
|
||||
});
|
||||
}
|
||||
|
||||
const detailsObj = resultsObj.map((searchDetail, index) => {
|
||||
resultsObj.map((searchDetail) => {
|
||||
let caseID = "";
|
||||
|
||||
switch (detailsType) {
|
||||
@@ -512,25 +480,17 @@ const getDetails = (resultsObj, detailsType) => {
|
||||
caseID = searchDetail.pinswg_title;
|
||||
}
|
||||
|
||||
//console.log(detailsType, " case id : ", caseID);
|
||||
|
||||
searchDetail.pinswg_appealcasetype != null &&
|
||||
detailsArr.push(
|
||||
getPortalModuleDetails(
|
||||
getFormCollectionByID(searchDetail.pinswg_appealcasetype)
|
||||
.LogicalCollectionName,
|
||||
caseID
|
||||
// detailsType != "myWatchedCases"
|
||||
// ? searchDetail.ticketnumber
|
||||
// : searchDetail[
|
||||
// "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
||||
// ]
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
let detArr = Promise.all(detailsArr);
|
||||
console.log(detArr);
|
||||
const detArr = Promise.all(detailsArr);
|
||||
return detArr;
|
||||
};
|
||||
|
||||
@@ -539,7 +499,6 @@ const mapStateToProps = (state) => {
|
||||
accountDetails: state.accountDetails,
|
||||
currentView: state.currentView,
|
||||
search: state.search,
|
||||
//searchResultsObj: state.searchResultsObj,
|
||||
documentDetailsObj: state.searchResultsObj.documentDetailsObj,
|
||||
formData: state.formData,
|
||||
appealType: state.appealType,
|
||||
@@ -557,12 +516,6 @@ const mapDispatchToProps = (dispatch) => {
|
||||
setCurrentReference: (currentReference) => {
|
||||
dispatch(setCurrentReference(refno));
|
||||
},
|
||||
// setSearchResults: (searchResults) => {
|
||||
// dispatch(setSearchResults(searchResults));
|
||||
// },
|
||||
// setSearchDetails: (searchDetails) => {
|
||||
// dispatch(setSearchDetails(searchDetails));
|
||||
// },
|
||||
setLoggedInUserId: (loggedInUser) => {
|
||||
dispatch(setLoggedInUserId(loggedInUser));
|
||||
}
|
||||
|
||||
@@ -111,9 +111,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
|
||||
if (thisSession) {
|
||||
console.log(" has sesssion.......");
|
||||
[loggedInUser] = await Promise.all([
|
||||
await getPortalLogin(thisSession.user.email)
|
||||
]);
|
||||
loggedInUser = await getPortalLogin(thisSession.user.email);
|
||||
|
||||
loggedInUser = loggedInUser.value[0].contactid;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user