updated storage account stuff to take auth id

This commit is contained in:
2022-08-26 15:19:34 +01:00
parent 671d49c394
commit 862a953aae
18 changed files with 346 additions and 133 deletions
+12 -13
View File
@@ -1,35 +1,34 @@
import {
createContainer,
getContainers,
getBlobs,
createBlob,
uploadFile,
deleteBlob,
} from "../../../actions/azurestorage";
import { hashAPIPath } from "../../../actions";
import { deleteBlob } from "../../../actions/azurestorage";
import middleware from "../middleware/middleware";
import nextConnect from "next-connect";
import middleware from "../middleware/middleware";
const ApiProxy = nextConnect();
ApiProxy.use(middleware);
ApiProxy.get(async (req, res) => {
var containerName = req.query.container;
var casefolderID = req.query.casefolderID;
var blobName = req.query.blobname;
var checkHash = req.query.hash;
var checkquerypath =
"/api/file/deleteblob?container=" +
containerName.toLowerCase() +
containerName +
"&casefolderID=" +
casefolderID +
"&blobname=" +
blobName;
console.log(hashAPIPath(checkquerypath), checkHash);
console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash);
// console.log(hashAPIPath(checkquerypath), checkHash);
// console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash);
if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
await deleteBlob(containerName, "files/" + blobName).then((data) => {
await deleteBlob(
containerName,
casefolderID + "/files/" + blobName
).then((data) => {
return res.status(200).json({ data: data });
});
} else {
+11 -21
View File
@@ -1,24 +1,8 @@
import {
createContainer,
getContainers,
getBlobs,
createBlob,
uploadFile,
deleteBlob,
downloadFile,
} from "../../../actions/azurestorage";
import { BlobServiceClient, ContainerClient } from "@azure/storage-blob";
import {
DefaultAzureCredential,
InteractiveBrowserCredential,
EnvironmentCredential,
ClientSecretCredential,
} from "@azure/identity";
import { downloadFile } from "../../../actions/azurestorage";
import middleware from "../middleware/middleware";
import nextConnect from "next-connect";
import CryptoJS from "crypto-js";
import { hashAPIPath } from "../../../actions";
import middleware from "../middleware/middleware";
const WORDKEY = process.env.HASHKEY;
@@ -28,21 +12,27 @@ ApiProxy.use(middleware);
ApiProxy.get(async (req, res) => {
var containerName = req.query.container;
var casefolderID = req.query.casefolderID;
var blobName = req.query.blobname;
var checkHash = req.query.hash;
var checkquerypath =
"/api/file/downloadblob?container=" +
containerName +
"&casefolderID=" +
casefolderID +
"&blobname=" +
blobName;
blobName.trim();
if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
const downloaded = await downloadFile(containerName, blobName);
const downloaded = await downloadFile(
containerName,
casefolderID + "/files/" + decodeURI(blobName)
);
res.setHeader(
"content-disposition",
"attachment; filename=" + blobName
"attachment; filename=" + decodeURI(blobName)
);
return res.status(200).send(downloaded);
} else {
+16 -16
View File
@@ -1,33 +1,33 @@
import {
createContainer,
getContainers,
getBlobs,
createBlob,
uploadFile,
} from "../../../actions/azurestorage";
import { hashAPIPath } from "../../../actions";
import { getBlobs } from "../../../actions/azurestorage";
import middleware from "../middleware/middleware";
import nextConnect from "next-connect";
import middleware from "../middleware/middleware";
const ApiProxy = nextConnect();
ApiProxy.use(middleware);
ApiProxy.get(async (req, res) => {
var containerName = req.query.container;
var casefolderID = req.query.casefolderID;
var checkHash = req.query.hash;
var checkquerypath = "/api/file/getbloblist?container=" + containerName;
var checkquerypath =
"/api/file/getbloblist?container=" +
containerName +
"&casefolderID=" +
casefolderID;
// console.log(hashAPIPath(checkquerypath), checkHash);
// console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash);
if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
await getBlobs(containerName).then((data) => {
return res.status(200).json({ files: data });
});
} else {
return res.status(400).json();
}
//if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
await getBlobs(containerName, casefolderID).then((data) => {
return res.status(200).json({ files: data });
});
// } else {
// return res.status(400).json();
// }
});
export const config = {
+12 -11
View File
@@ -1,32 +1,33 @@
import {
createContainer,
getContainers,
getBlobs,
createBlob,
uploadFile,
getProgressBlobs,
downloadProgressFile,
getProgressBlobs,
} from "../../../actions/azurestorage";
import { hashAPIPath } from "../../../actions";
import middleware from "../middleware/middleware";
import nextConnect from "next-connect";
import middleware from "../middleware/middleware";
const ApiProxy = nextConnect();
ApiProxy.use(middleware);
ApiProxy.get(async (req, res) => {
var containerName = req.query.container;
var casefolderID = req.query.casefolderID;
var checkHash = req.query.hash;
var checkquerypath =
"/api/file/getprogressobjblob?container=" + containerName;
"/api/file/getprogressobjblob?container=" +
containerName +
"&casefolderID=" +
casefolderID;
// console.log(hashAPIPath(checkquerypath), checkHash);
// console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash);
//if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
const blobObj = await getProgressBlobs(containerName)
.then((data) => downloadProgressFile(containerName, data.path))
const blobObj = await getProgressBlobs(containerName, casefolderID)
.then((data) =>
downloadProgressFile(containerName, data.path, casefolderID)
)
.then((data) => {
return res.status(200).json(data);
});
+47
View File
@@ -0,0 +1,47 @@
import {
createContainer,
getContainers,
getBlobs,
createBlob,
uploadFile,
} from "../../../actions/azurestorage";
import { hashAPIPath } from "../../../actions";
import middleware from "../middleware/middleware";
import nextConnect from "next-connect";
const ApiProxy = nextConnect();
ApiProxy.use(middleware);
ApiProxy.get(async (req, res) => {
var containerName = req.query.ident;
var checkHash = req.query.hash;
var checkquerypath = "/api/file/setupcontainer?ident=" + containerName;
console.log(req.query);
console.log(checkquerypath.length);
console.log(hashAPIPath(checkquerypath));
// console.log(checkquerypath, hashAPIPath(checkquerypath), checkHash);
// console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash);
//if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
await createContainer(containerName)
.then((data) => {
return res.status(200).json({ data: "success" });
})
.catch((err) => {
console.log(consoleLogger(err));
res.status(400).json(err);
});
// } else {
// return res.status(400).json();
// }
});
export const config = {
api: {
bodyParser: false,
},
};
export default ApiProxy;
+19 -7
View File
@@ -14,10 +14,15 @@ ApiProxy.use(middleware);
ApiProxy.post(async (req, res) => {
var checkHash = req.query.hash;
console.log(JSON.parse(req.body.appealData));
console.log(req.files);
// console.log(JSON.stringify(req.body));
// console.log(JSON.stringify(req.body.appealData));
// console.log(req.files);
const appealData = JSON.parse(req.body.appealData);
const appealData = req.body.appealData;
const containerID = req.body.containerID;
const casefolderID = req.body.casefolderID;
console.log("there are files:", Object.keys(req.files).length);
// var checkquerypath = "/api/file/upload";
@@ -25,11 +30,18 @@ ApiProxy.post(async (req, res) => {
// console.log(hashAPIPath(checkquerypath) == "?hash=" + checkHash);
// if (hashAPIPath(checkquerypath) == "?hash=" + checkHash) {
createContainer(appealData.pinswg_name.trim()).then((containerName) => {
createBlob(appealData, containerName).then((data) => {
uploadFile(req.files, containerName, data);
});
//createContainer(containerID).then((containerName) => {
console.log(
"does this et folder name:",
appealData.pinswg_name,
casefolderID
);
createBlob(appealData, containerID, casefolderID).then((data) => {
Object.keys(req.files).length > 0 &&
uploadFile(req.files, containerID, casefolderID);
});
//});
return res.status(200).json({ data: "success" });
// } else {
+9 -6
View File
@@ -16,7 +16,10 @@ import Footer from "../components/footer";
import Header from "../components/header";
import Main from "../components/main";
import ServiceBanner from "../components/servicebanner";
import { setAccountDetails } from "../store/accountDetails/action";
import {
setAccountDetails,
setContainerID,
} from "../store/accountDetails/action";
import { getGovGatewayConfig } from "../store/govgateway/action";
import { wrapper } from "../store/store";
import { getSession, useSession, signIn, signOut } from "next-auth/react";
@@ -169,12 +172,10 @@ export const getServerSideProps = wrapper.getServerSideProps(
let thisSession = await getSession(ctx);
console.log(ctx);
var relayToken = await getToken();
relayToken = relayToken.access_token;
console.log("auth sess:", thisSession);
console.log("\n///////////////\nauth sess:", thisSession);
const showLoginCheck = process.env.SHOWLOGIN || false;
const showMapCheck = process.env.SHOWMAPS || false;
@@ -187,7 +188,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
let ggLocale =
typeof query.ui_locales != "undefined" && query.ui_locales;
console.log("\n", "hasloginCode:", hasLoginCode);
console.log("hasloginCode:", hasLoginCode);
// store.dispatch(getGovGatewayConfig(providerConfig));
@@ -198,6 +199,8 @@ export const getServerSideProps = wrapper.getServerSideProps(
if (hasLoginCode == true) {
loginEmailStr = hashString(thisSession.user.email);
store.dispatch(setContainerID(thisSession.user.id));
portalUserObj = await getPortalLogin(
thisSession.user.email,
relayToken
@@ -220,7 +223,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
} else {
console.log("empty session");
}
console.log("///////////////\n");
if (ggToken.status == 400) {
return {
redirect: {
+16 -4
View File
@@ -24,7 +24,10 @@ import BuildSection from "../../components/newappeal/buildsection";
import CompleteAppeal from "../../components/newappeal/complete";
import TimeOut from "../../components/timeout";
import { setLoggedInUserId } from "../../store/accountDetails/action";
import {
setLoggedInUserId,
setContainerID,
} from "../../store/accountDetails/action";
import {
setAppealLPA,
setAppealType,
@@ -38,6 +41,7 @@ import { getGovGatewayConfig } from "../../store/govgateway/action";
import { wrapper } from "../../store/store";
import { getPartSavedDetails } from "../../components/utils";
import { getProgressBlobs } from "../../actions/azurestorage";
import { getSession, useSession } from "next-auth/react";
let Home = (props) => {
const { footerLinks, pages, formData } = props;
@@ -217,6 +221,13 @@ export const getServerSideProps = wrapper.getServerSideProps(
console.log("the query", query.appealtypes);
let loggedInUser = cookies.pinsUser;
let thisSession = await getSession(ctx);
console.log("nextAuth Session:", thisSession);
let loggedInUserIdent = thisSession.user.id;
console.log("logged ident:", loggedInUserIdent);
const [
appealTypeData,
mandatoryFieldsData,
@@ -227,11 +238,11 @@ export const getServerSideProps = wrapper.getServerSideProps(
await getAppealsTypes(),
await getMandatoryFields(query.appealtypes),
await getPickLists(query.appealtypes),
await getFilesFromBlob(query.casereference),
await getProgressFromBlob(query.casereference),
await getFilesFromBlob(loggedInUserIdent, query.casereference),
await getProgressFromBlob(loggedInUserIdent, query.casereference),
]);
console.log("has blobprgess:", blobProgress);
console.log("has blobprogess:", loggedInUserIdent, query.casereference);
//
// Removed to make progress from Blob not CRM
@@ -283,6 +294,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
store.dispatch(setForm(xmlStr, mandatoryFieldsData, pickListData));
store.dispatch(setAppealType(appealTypeData));
store.dispatch(setFilesForAppeal(blobList));
store.dispatch(setContainerID(thisSession.user.id));
}
);
+19 -1
View File
@@ -12,6 +12,7 @@ import {
getPortalModuleDetails,
getWatchedCases,
} from "../../actions";
import { createContainer } from "../../actions/azurestorage";
import { getProviderConfig } from "../../actions/govgateway";
import Breadcrumbs from "../../components/breadcrumbs";
import CookieBanner from "../../components/cookieBanner";
@@ -21,6 +22,7 @@ import MyPortal from "../../components/myportal";
import { getFormCollectionByID } from "../../components/utils";
import {
setAccountDetails,
setContainerID,
setLoggedInUserId,
} from "../../store/accountDetails/action";
import {
@@ -161,6 +163,18 @@ export const getServerSideProps = wrapper.getServerSideProps(
console.log("nextAuth Session:", thisSession);
if (_.has(thisSession, "user") == false) {
return {
redirect: {
destination: "/error",
permanent: false,
},
};
}
//Create Storage container for logged in user
await createContainer(thisSession.user.id);
let providerConfig = await getProviderConfig();
store.dispatch(getGovGatewayConfig(providerConfig));
@@ -213,9 +227,13 @@ export const getServerSideProps = wrapper.getServerSideProps(
store.dispatch(
setAwaitingSubmissionDetails(awaitingSubmissionDetails)
);
store.dispatch(setContainerID(thisSession.user.id));
return {
props: { showFileUpload: process.env.SHOWFILEUPLOAD },
props: {
showFileUpload: process.env.SHOWFILEUPLOAD,
containerID: thisSession.user.id,
},
};
}
}
+19 -2
View File
@@ -7,12 +7,12 @@ import { useEffect } from "react";
import { connect } from "react-redux";
import xpath from "xpath";
import {
createCase,
getCase,
getAppealsTypes,
getMandatoryFields,
getPickLists,
getFilesFromBlob,
getProgressFromBlob,
} from "../../actions";
import { getProviderConfig } from "../../actions/govgateway";
import Breadcrumbs from "../../components/breadcrumbs";
@@ -24,7 +24,10 @@ import BuildSection from "../../components/newappeal/buildsection";
import CompleteAppeal from "../../components/newappeal/complete";
import TimeOut from "../../components/timeout";
import { setLoggedInUserId } from "../../store/accountDetails/action";
import {
setLoggedInUserId,
setContainerID,
} from "../../store/accountDetails/action";
import {
setAppealLPA,
setAppealType,
@@ -36,6 +39,8 @@ import {
import { setForm } from "../../store/formData/action";
import { getGovGatewayConfig } from "../../store/govgateway/action";
import { wrapper } from "../../store/store";
import { getProgressBlobs } from "../../actions/azurestorage";
import { getSession, useSession } from "next-auth/react";
let Home = (props) => {
const { footerLinks, pages, formData } = props;
@@ -217,17 +222,27 @@ export const getServerSideProps = wrapper.getServerSideProps(
console.log("ref:", query.id);
let loggedInUser = cookies.pinsUser;
let thisSession = await getSession(ctx);
console.log("nextAuth Session:", thisSession);
let loggedInUserIdent = thisSession.user.id;
console.log("logged ident:", loggedInUserIdent);
const [
caseReferenceData,
appealTypeData,
mandatoryFieldsData,
pickListData,
//blobList,
blobProgress,
] = await Promise.all([
await getCase(query.id),
await getAppealsTypes(),
await getMandatoryFields(query.appealtypes),
await getPickLists(query.appealtypes),
await getProgressFromBlob(loggedInUserIdent, query.casereference),
//await getFilesFromBlob(query.casereference),
]);
@@ -255,6 +270,8 @@ export const getServerSideProps = wrapper.getServerSideProps(
store.dispatch(setCaseReference(caseReference));
store.dispatch(setForm(xmlStr, mandatoryFieldsData, pickListData));
store.dispatch(setAppealType(appealTypeData));
store.dispatch(setContainerID(thisSession.user.id));
//store.dispatch(setFilesForAppeal(blobList));
}
);
+12 -1
View File
@@ -1,6 +1,7 @@
import useTranslation from "next-translate/useTranslation";
import Head from "next/head";
import { getSession, useSession } from "next-auth/react";
import _ from "lodash";
import { useRouter } from "next/router";
import { connect } from "react-redux";
@@ -16,6 +17,7 @@ import Header from "../../components/header";
import CreateCase from "../../components/newappeal/createCase";
import {
setAccountDetails,
setContainerID,
setLoggedInUserId,
} from "../../store/accountDetails/action";
import { setAppealType } from "../../store/appealType/action";
@@ -120,7 +122,7 @@ const Home = (props) => {
appealType={props.setAppealType}
loggedInUser={props.accountDetails.loggedinUserId}
whichForm={props.form}
loggedInUserIdent={loggedInUserIdent}
containerID={props.accountDetails.containerID}
/>
</main>
</div>
@@ -141,6 +143,14 @@ export const getServerSideProps = wrapper.getServerSideProps(
let thisSession = await getSession(ctx);
console.log("nextAuth Session:", thisSession);
if (_.has(thisSession, "user") == false) {
return {
redirect: {
destination: "/error",
permanent: false,
},
};
}
let loggedInUserIdent = thisSession.user.id;
let loggedInUser = cookies.pinsUser;
@@ -163,6 +173,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
store.dispatch(setLPA(lpaData));
store.dispatch(setLoggedInUserId(loggedInUser));
store.dispatch(setAccountDetails(accountDetails));
store.dispatch(setContainerID(thisSession.user.id));
return {
props: { loggedInUserIdent: loggedInUserIdent },