Merge branch 'Development' into SIPS-Development
This commit is contained in:
@@ -37,7 +37,7 @@ export default async function ApiProxy(req, res) {
|
||||
var queryUrl =
|
||||
"stringmaps?$filter=objecttypecode eq 'incident' and attributename eq 'pinswg_appealcasetype' " +
|
||||
(process.env.SHOWSIPS !== "true"
|
||||
? "and pinswg_appealcasetype ne 846040002"
|
||||
? "and attributevalue ne 846040002"
|
||||
: "") +
|
||||
"&$count=true&$select=value,stringmapid,organizationid,attributevalue&$orderby=value asc";
|
||||
|
||||
@@ -47,7 +47,7 @@ export default async function ApiProxy(req, res) {
|
||||
// "stringmaps?$filter=objecttypecode eq 'incident' and attributename eq 'pinswg_appealcasetype' and value ne 'Misc Casework'&$count=true&$select=value,stringmapid,organizationid,attributevalue&$orderby=value asc";
|
||||
//"stringmaps?$filter=objecttypecode eq 'incident' and attributename eq 'pinswg_appealcasetype' and value ne 'Developments of National Significance' and value ne 'LDP' and value ne 'Misc Casework'&$count=true&$select=value,stringmapid,organizationid,attributevalue&$orderby=value asc";
|
||||
|
||||
//console.log(queryUrl);
|
||||
console.log(queryUrl);
|
||||
|
||||
return axios
|
||||
.get(
|
||||
|
||||
@@ -51,7 +51,7 @@ export default async function ApiProxy(req, res) {
|
||||
searchString +
|
||||
"')) and pinswg_appealcasetype ne null " +
|
||||
(process.env.SHOWSIPS !== "true"
|
||||
? "and pinswg_appealcasetype ne 846040002"
|
||||
? "and pinswg_appealcasetype ne 846040002 "
|
||||
: "") +
|
||||
"and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true";
|
||||
|
||||
|
||||
@@ -306,7 +306,7 @@ export default async function ApiProxy(req, res) {
|
||||
"MetadataId": "8d31911b-b8ea-ef11-ab08-00224800be9c",
|
||||
"appealTypeID": "846040002",
|
||||
"tmpNav": "pinswg_sipsid",
|
||||
"NavigationProperty": "pinswg_SIPSids",
|
||||
"NavigationProperty": "pinswg_sipscase",
|
||||
"value": "SIP",
|
||||
},
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import { azureHeaders, consoleLogger, getToken } from "../../../actions";
|
||||
import { getSelectQuery } from "../../../actions/selectQueryTypes";
|
||||
|
||||
import { getNavigationPropertyByPrimaryAttribute } from "../../../components/utils";
|
||||
const WORDKEY = process.env.HASHKEY;
|
||||
|
||||
const WEBAPI_URL =
|
||||
@@ -55,6 +55,11 @@ export default async function ApiProxy(req, res) {
|
||||
var incidentID = req.query.incidentID;
|
||||
var token = await getToken();
|
||||
|
||||
let navigationProperty =
|
||||
getNavigationPropertyByPrimaryAttribute(
|
||||
primaryIdAttribute
|
||||
).NavigationProperty;
|
||||
|
||||
var queryUrl =
|
||||
appealTypeName +
|
||||
"?$filter=_" +
|
||||
@@ -63,7 +68,11 @@ export default async function ApiProxy(req, res) {
|
||||
: primaryIdAttribute + "s_value ") +
|
||||
" eq " +
|
||||
incidentID +
|
||||
"&$count=true";
|
||||
"&$count=true" +
|
||||
"&$expand=" +
|
||||
navigationProperty +
|
||||
"($select=ticketnumber)";
|
||||
|
||||
//" and statuscode eq 1&$count=true";
|
||||
|
||||
// queryUrl =
|
||||
@@ -91,6 +100,13 @@ export default async function ApiProxy(req, res) {
|
||||
azureHeaders(token.access_token)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
let flattened = data.value.map((r) => ({
|
||||
...r,
|
||||
ticketnumber: r[navigationProperty]?.ticketnumber || null,
|
||||
}));
|
||||
|
||||
data.value = flattened;
|
||||
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
@@ -34,7 +34,7 @@ import CryptoJS from "crypto-js";
|
||||
import _ from "lodash";
|
||||
import { azureHeadersPaged, consoleLogger, getToken } from "../../../actions";
|
||||
import { getSelectQuery } from "../../../actions/selectQueryTypes";
|
||||
|
||||
import { getNavigationPropertyByPrimaryAttribute } from "../../../components/utils";
|
||||
const WORDKEY = process.env.HASHKEY;
|
||||
|
||||
const WEBAPI_URL =
|
||||
@@ -59,6 +59,11 @@ export default async function ApiProxy(req, res) {
|
||||
var incidentID = req.query.incidentID;
|
||||
var token = await getToken();
|
||||
|
||||
let navigationProperty =
|
||||
getNavigationPropertyByPrimaryAttribute(
|
||||
primaryIdAttribute
|
||||
).NavigationProperty;
|
||||
|
||||
var queryUrl =
|
||||
appealTypeName +
|
||||
"?$filter=_" +
|
||||
@@ -67,7 +72,11 @@ export default async function ApiProxy(req, res) {
|
||||
: primaryIdAttribute + "s_value ") +
|
||||
" eq " +
|
||||
incidentID +
|
||||
"&$count=true";
|
||||
"&$count=true" +
|
||||
"&$expand=" +
|
||||
navigationProperty +
|
||||
"($select=ticketnumber)";
|
||||
|
||||
//" and statuscode eq 1&$count=true";
|
||||
|
||||
queryUrl =
|
||||
@@ -86,10 +95,18 @@ export default async function ApiProxy(req, res) {
|
||||
azureHeadersPaged(token.access_token)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
let flattened = data.value.map((r) => ({
|
||||
...r,
|
||||
ticketnumber: r[navigationProperty]?.ticketnumber || null,
|
||||
}));
|
||||
|
||||
data.value = flattened;
|
||||
|
||||
var dataStr;
|
||||
_.has(data, "@odata.nextLink") == true &&
|
||||
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
||||
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
||||
|
||||
return res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
@@ -85,7 +85,7 @@ export default async function ApiProxy(req, res) {
|
||||
searchString +
|
||||
"')) and pinswg_appealcasetype ne null " +
|
||||
(process.env.SHOWSIPS !== "true"
|
||||
? "and pinswg_appealcasetype ne 846040002"
|
||||
? "and pinswg_appealcasetype ne 846040002 "
|
||||
: "") +
|
||||
"and pinswg_publishtoweb eq true&$orderby=" +
|
||||
orderby +
|
||||
|
||||
@@ -48,7 +48,9 @@ export default async function ApiProxy(req, res) {
|
||||
// "&$select=pinswg_emailnotifications,modifiedon,pinswg_appealcasetype,pinswg_watchlistid,_pinswg_watchedcase_value,statuscode,pinswg_representationsubmitted,pinswg_representationtype&$count=true&$orderby=createdon desc&$expand=pinswg_WatchedCase($select=pinswg_AssociatedLPA)";
|
||||
|
||||
var queryUrl =
|
||||
"/api/endpoint/getwatchedcases_api?loggedInUserId=" + loggedInUserId;
|
||||
"pinswg_watchlists?$filter= _pinswg_contact_value eq " +
|
||||
loggedInUserId +
|
||||
"&$select=modifiedon,pinswg_appealcasetype,pinswg_watchlistid,_pinswg_watchedcase_value,statuscode,pinswg_representationsubmitted,pinswg_representationtype&$count=true&$orderby=createdon desc&$expand=pinswg_WatchedCase($select=pinswg_AssociatedLPA)";
|
||||
|
||||
return axios
|
||||
.get(
|
||||
@@ -56,32 +58,33 @@ export default async function ApiProxy(req, res) {
|
||||
azureHeaders(token.access_token)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
// data.value.forEach(function (element) {
|
||||
// element.ticketnumber = element.pinswg_WatchedCase?.ticketnumber;
|
||||
// element.pinswg_title =
|
||||
// element[
|
||||
// "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
||||
// ];
|
||||
data.value.forEach(function (element) {
|
||||
element.ticketnumber = element.pinswg_WatchedCase.ticketnumber;
|
||||
element.pinswg_title =
|
||||
element[
|
||||
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
||||
];
|
||||
|
||||
// element[
|
||||
// "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
||||
// ] =
|
||||
// element.pinswg_WatchedCase?.[
|
||||
// "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
||||
// ];
|
||||
// element._pinswg_associatedlpa_value =
|
||||
// element.pinswg_WatchedCase?._pinswg_associatedlpa_value;
|
||||
// element[
|
||||
// "_ownerid_value@OData.Community.Display.V1.FormattedValue"
|
||||
// ] =
|
||||
// element.pinswg_WatchedCase?.[
|
||||
// "_ownerid_value@OData.Community.Display.V1.FormattedValue"
|
||||
// ];
|
||||
// element._ownerid_value =
|
||||
// element.pinswg_WatchedCase?._ownerid_value;
|
||||
element[
|
||||
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
||||
] =
|
||||
element.pinswg_WatchedCase[
|
||||
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
||||
];
|
||||
element._pinswg_associatedlpa_value =
|
||||
element.pinswg_WatchedCase._pinswg_associatedlpa_value;
|
||||
element[
|
||||
"_ownerid_value@OData.Community.Display.V1.FormattedValue"
|
||||
] =
|
||||
element.pinswg_WatchedCase[
|
||||
"_ownerid_value@OData.Community.Display.V1.FormattedValue"
|
||||
];
|
||||
element._ownerid_value =
|
||||
element.pinswg_WatchedCase._ownerid_value;
|
||||
|
||||
delete element.pinswg_WatchedCase;
|
||||
});
|
||||
|
||||
// delete element.pinswg_WatchedCase;
|
||||
// });
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
@@ -24,10 +24,19 @@ ApiProxy.get(async (req, res) => {
|
||||
"&blobname=" +
|
||||
blobName.trim();
|
||||
|
||||
// console.log(checkquerypath);
|
||||
|
||||
// console.log(hashAPIPath(checkquerypath));
|
||||
|
||||
// console.log(req.query);
|
||||
|
||||
if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
|
||||
const bloblocation =
|
||||
casefolderID + (blobName.indexOf(".json") > 0 ? "/" : "/files/");
|
||||
|
||||
const downloaded = await downloadFile(
|
||||
containerName,
|
||||
casefolderID + "/files/" + decodeURI(blobName)
|
||||
bloblocation + decodeURI(blobName)
|
||||
);
|
||||
|
||||
res.setHeader(
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import { DefaultAzureCredential } from "@azure/identity";
|
||||
import { BlobServiceClient } from "@azure/storage-blob";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
if (req.method !== "POST") {
|
||||
res.status(405).json({ error: "Method not allowed" });
|
||||
return;
|
||||
}
|
||||
|
||||
const { container, blobName } = req.body;
|
||||
|
||||
if (!container || !blobName) {
|
||||
res.status(400).json({ error: "Missing container or blobName" });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const accountName = process.env.AZURE_STORAGE_ACCOUNT_NAME;
|
||||
const creds = new DefaultAzureCredential();
|
||||
const blobServiceClient = new BlobServiceClient(
|
||||
`https://${accountName}.blob.core.windows.net`,
|
||||
creds
|
||||
);
|
||||
|
||||
const containerClient = blobServiceClient.getContainerClient(container);
|
||||
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
|
||||
|
||||
// Download blob content
|
||||
const downloadResponse = await blockBlobClient.download(0);
|
||||
const downloaded = await streamToString(
|
||||
downloadResponse.readableStreamBody
|
||||
);
|
||||
|
||||
// Parse JSON
|
||||
const json = JSON.parse(downloaded);
|
||||
|
||||
// Remove repComplete element if it exists
|
||||
if ("repComplete" in json) {
|
||||
delete json.repComplete;
|
||||
}
|
||||
|
||||
const tags = {
|
||||
containerid: json.containerID,
|
||||
caseID: json.ticketnumber,
|
||||
blobType: "Representation",
|
||||
};
|
||||
|
||||
// Convert back to string
|
||||
const updatedContent = JSON.stringify(json, null, 2);
|
||||
|
||||
// Upload updated content (overwrite)
|
||||
await blockBlobClient.upload(
|
||||
updatedContent,
|
||||
Buffer.byteLength(updatedContent),
|
||||
{
|
||||
blobHTTPHeaders: { blobContentType: "application/json" },
|
||||
}
|
||||
);
|
||||
|
||||
console.log("the tags:", tags);
|
||||
const withTags = await blockBlobClient.setTags(tags);
|
||||
const withMeta = await blockBlobClient.setMetadata(tags);
|
||||
|
||||
res.status(200).json({ message: "repComplete removed successfully" });
|
||||
} catch (error) {
|
||||
console.error("Error editing rep.json:", error);
|
||||
res.status(500).json({ error: "Failed to edit rep.json" });
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to read stream to string
|
||||
async function streamToString(readableStream) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const chunks = [];
|
||||
readableStream.on("data", (data) => {
|
||||
chunks.push(data.toString());
|
||||
});
|
||||
readableStream.on("end", () => {
|
||||
resolve(chunks.join(""));
|
||||
});
|
||||
readableStream.on("error", reject);
|
||||
});
|
||||
}
|
||||
@@ -166,7 +166,7 @@ export default async function handler(req, res) {
|
||||
|
||||
var containerID = reqBodyobj.containerID;
|
||||
var casefolderID = reqBodyobj.casefolderID;
|
||||
var caseRef = reqBodyobj.caseRef;
|
||||
var caseRef = reqBodyobj.ticketnumber;
|
||||
var representationType = reqBodyobj.representationType;
|
||||
var repRaiser = reqBodyobj.lastname;
|
||||
var localeSelect = reqBodyobj.locale;
|
||||
|
||||
@@ -207,6 +207,35 @@ const SignIn = (props) => {
|
||||
};
|
||||
|
||||
export async function getServerSideProps(context) {
|
||||
const { query, req, res } = context;
|
||||
|
||||
// Load allowed IPs from env and trim spaces
|
||||
const ALLOWED_IPS = process.env.ALLOWED_IPS
|
||||
? process.env.ALLOWED_IPS.split(",").map((ip) => ip.trim())
|
||||
: [];
|
||||
|
||||
// Always allow localhost addresses
|
||||
const LOCALHOST_IPS = ["127.0.0.1", "::1"];
|
||||
|
||||
// Get IP address from headers or socket
|
||||
const forwarded = req.headers["x-forwarded-for"];
|
||||
const ip =
|
||||
typeof forwarded === "string"
|
||||
? forwarded.split(",")[0]
|
||||
: req.socket.remoteAddress;
|
||||
|
||||
console.log("Visitor IP:", ip);
|
||||
|
||||
// Check whitelist + localhost
|
||||
if (![...ALLOWED_IPS, ...LOCALHOST_IPS].includes(ip)) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/403", // custom "Access Denied" page
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (process.env.SHOWLOGIN == false) {
|
||||
return {
|
||||
redirect: {
|
||||
|
||||
@@ -85,6 +85,13 @@ const CaseHome = (props) => {
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.ticketnumber
|
||||
}
|
||||
ticketnumber={
|
||||
props.currentView.caseReference.ticketnumber
|
||||
}
|
||||
ticketnumber={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.ticketnumber
|
||||
}
|
||||
currentType={props.currentType}
|
||||
appealTypeID={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
|
||||
@@ -46,7 +46,9 @@ const CaseHome = (props) => {
|
||||
<Head>
|
||||
<title>
|
||||
Reference:{" "}
|
||||
{props.currentView.caseReference.currentReference}{" "}
|
||||
{props.currentView.caseReference.currentReference ||
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.title}{" "}
|
||||
Developments of National Significance
|
||||
</title>
|
||||
</Head>
|
||||
@@ -81,9 +83,16 @@ const CaseHome = (props) => {
|
||||
props.awaitingSubmission.awaitingSubmission
|
||||
}
|
||||
caseReference={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.caseReference
|
||||
}
|
||||
ticketnumber={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.ticketnumber
|
||||
}
|
||||
// ticketnumber={
|
||||
// props.currentView.caseReference.ticketnumber
|
||||
// }
|
||||
currentType={props.currentType}
|
||||
appealTypeID={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
|
||||
@@ -20,7 +20,7 @@ import { wrapper } from "../store/store";
|
||||
import ServiceBanner from "../components/servicebanner";
|
||||
|
||||
const Home = (props) => {
|
||||
const { footerLinks, pages, showMap } = props;
|
||||
const { footerLinks, pages, showMap, showLoginCheck } = props;
|
||||
let { t, lang } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
@@ -105,6 +105,7 @@ const Home = (props) => {
|
||||
showMap={showMap}
|
||||
searchString="DNS"
|
||||
searchResultsObj={props.searchResultsObj}
|
||||
showLoginCheck={showLoginCheck}
|
||||
/>
|
||||
</div>
|
||||
<Footer footerLinks={footerLinks} ticketnumber={props} />
|
||||
@@ -134,6 +135,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
}
|
||||
: searchResultsObj;
|
||||
|
||||
const showLoginCheck = process.env.SHOWLOGIN || false;
|
||||
const showMapCheck = process.env.SHOWMAPS || false;
|
||||
|
||||
if (_.has(searchResultsObj, "status") == true) {
|
||||
@@ -156,7 +158,10 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
}
|
||||
|
||||
return {
|
||||
props: { showMap: showMapCheck },
|
||||
props: {
|
||||
showMap: showMapCheck,
|
||||
showLoginCheck: showLoginCheck,
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
@@ -70,7 +70,9 @@ const CaseHome = (props) => {
|
||||
<Head>
|
||||
<title>
|
||||
Reference:{" "}
|
||||
{props.currentView.caseReference.currentReference}{" "}
|
||||
{props.currentView.caseReference.currentReference ||
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.title}{" "}
|
||||
</title>
|
||||
</Head>
|
||||
<div id="page_wrapper">
|
||||
@@ -107,6 +109,10 @@ const CaseHome = (props) => {
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.ticketnumber
|
||||
}
|
||||
ticketnumber={
|
||||
props.currentView.caseReference.ticketnumber ||
|
||||
router.query.ticketnumber
|
||||
}
|
||||
currentType={props.currentType}
|
||||
appealTypeID={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
@@ -129,9 +135,7 @@ const CaseHome = (props) => {
|
||||
<Footer
|
||||
footerLinks={footerLinks}
|
||||
props={props}
|
||||
ticketnumber={
|
||||
props.currentView.caseReference.currentReference
|
||||
}
|
||||
ticketnumber={props.currentView.caseReference.ticketnumber}
|
||||
/>
|
||||
<TimeOut />
|
||||
</div>
|
||||
@@ -182,10 +186,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
store.dispatch(setAccountDetails(accountDetails));
|
||||
store.dispatch(setLoggedInUserId(loggedInUser));
|
||||
|
||||
let developmentQuery =
|
||||
query.ticketnumber.indexOf("CAS-") == 0
|
||||
? query.ticketnumber
|
||||
: query.ticketnumber.split("-").join(" ");
|
||||
let developmentQuery = query.ticketnumber;
|
||||
|
||||
const pattern = /CAS-\d{5}-[A-Z0-9]{6}/;
|
||||
const match = query.ticketnumber.match(pattern);
|
||||
@@ -220,10 +221,10 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
|
||||
store.dispatch(setSearch(developmentQuery));
|
||||
|
||||
console.log(
|
||||
searchResultsObj["@odata.count"] > 1 ||
|
||||
searchResultsObj["@odata.count"] < 1
|
||||
);
|
||||
// console.log(
|
||||
// searchResultsObj["@odata.count"] > 1 ||
|
||||
// searchResultsObj["@odata.count"] < 1
|
||||
// );
|
||||
|
||||
if (searchResultsObj["@odata.count"] < 1) {
|
||||
return {
|
||||
@@ -432,7 +433,6 @@ const getDetails = (resultsObj, detailsType) => {
|
||||
case "myCases":
|
||||
caseID = data.pinswg_title;
|
||||
break;
|
||||
case "myWatchedCases":
|
||||
case "mySubmittedReps":
|
||||
caseID =
|
||||
data[
|
||||
@@ -440,6 +440,7 @@ const getDetails = (resultsObj, detailsType) => {
|
||||
];
|
||||
break;
|
||||
case "awaitingSubmission":
|
||||
case "myWatchedCases":
|
||||
case "myRepresentations":
|
||||
caseID = data.ticketnumber;
|
||||
break;
|
||||
|
||||
@@ -46,7 +46,9 @@ const CaseHome = (props) => {
|
||||
<Head>
|
||||
<title>
|
||||
Reference:{" "}
|
||||
{props.currentView.caseReference.currentReference}{" "}
|
||||
{props.currentView.caseReference.currentReference ||
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.title}{" "}
|
||||
Developments of National Significance
|
||||
</title>
|
||||
</Head>
|
||||
@@ -81,6 +83,10 @@ const CaseHome = (props) => {
|
||||
props.awaitingSubmission.awaitingSubmission
|
||||
}
|
||||
caseReference={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.caseReference
|
||||
}
|
||||
ticketnumber={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.ticketnumber
|
||||
}
|
||||
|
||||
@@ -190,6 +190,9 @@ const RepresentationF = (props) => {
|
||||
caseReference={
|
||||
props.currentView.caseReference.currentReference
|
||||
}
|
||||
ticketnumber={
|
||||
props.currentView.caseReference.ticketnumber
|
||||
}
|
||||
currentType={
|
||||
props.currentView.caseReference.currentType
|
||||
}
|
||||
|
||||
@@ -0,0 +1,759 @@
|
||||
import CookieBanner from "../components/cookieBanner";
|
||||
import Footer from "../components/footer";
|
||||
import Header from "../components/header";
|
||||
import { DefaultAzureCredential } from "@azure/identity";
|
||||
import { BlobServiceClient, ContainerClient } from "@azure/storage-blob";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import {
|
||||
createContainerSas,
|
||||
listContainers,
|
||||
listBlobHierarchical,
|
||||
listContainersForUser,
|
||||
} from "../actions/azurestorage";
|
||||
import Head from "next/head";
|
||||
import Link from "next/link";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import {
|
||||
bytesToSize,
|
||||
getThumbnailIconByExtension,
|
||||
updateLinks,
|
||||
} from "../components/utils";
|
||||
import {
|
||||
consoleLogger,
|
||||
getIP,
|
||||
sendRepCompleteMessage,
|
||||
deleteMyRepresentationsFromBlob,
|
||||
deleteAwaitingSubmissionsFromBlob,
|
||||
} from "../actions";
|
||||
import CryptoJS from "crypto-js";
|
||||
import { useState } from "react";
|
||||
|
||||
function getUpToLastSlash(url) {
|
||||
let lastSlash = url.lastIndexOf("/");
|
||||
|
||||
url = url.substring(0, lastSlash);
|
||||
|
||||
url =
|
||||
url.lastIndexOf("/files") > 0
|
||||
? url.substring(0, url.lastIndexOf("/files"))
|
||||
: url;
|
||||
return url;
|
||||
}
|
||||
|
||||
async function streamToString(readableStream) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const chunks = [];
|
||||
readableStream.on("data", (data) => {
|
||||
chunks.push(data.toString());
|
||||
});
|
||||
readableStream.on("end", () => {
|
||||
resolve(chunks.join(""));
|
||||
});
|
||||
readableStream.on("error", reject);
|
||||
});
|
||||
}
|
||||
|
||||
function formatTimeSince(date) {
|
||||
if (!date) return "Unknown date";
|
||||
|
||||
const now = new Date();
|
||||
const diffMs = now - date;
|
||||
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
|
||||
|
||||
if (diffDays < 7) {
|
||||
return `${diffDays} day${diffDays !== 1 ? "s" : ""} ago`;
|
||||
} else {
|
||||
const diffWeeks = Math.floor(diffDays / 7);
|
||||
return `${diffWeeks} week${diffWeeks !== 1 ? "s" : ""} ago`;
|
||||
}
|
||||
}
|
||||
|
||||
function formatBlobDates(blob) {
|
||||
const created = blob.createdOn ? new Date(blob.createdOn) : null;
|
||||
const modified = blob.lastModified ? new Date(blob.lastModified) : null;
|
||||
|
||||
if (!created && !modified) return "Unknown";
|
||||
|
||||
// If both exist and are the same
|
||||
if (created && modified && created.getTime() === modified.getTime()) {
|
||||
return `${created.toLocaleString("en-GB")} (${formatTimeSince(
|
||||
created
|
||||
)})`;
|
||||
}
|
||||
|
||||
// If modified exists and is newer than created
|
||||
if (created && modified && modified.getTime() > created.getTime()) {
|
||||
return `Created: ${created.toLocaleString("en-GB")} (${formatTimeSince(
|
||||
created
|
||||
)}), Modified: ${modified.toLocaleString("en-GB")} (${formatTimeSince(
|
||||
modified
|
||||
)})`;
|
||||
}
|
||||
|
||||
// Only one date exists
|
||||
const date = modified || created;
|
||||
return `${date.toLocaleString("en-GB")} (${formatTimeSince(date)})`;
|
||||
}
|
||||
|
||||
const deleteRepItem = (containerID, caseID, repfile) => {
|
||||
deleteMyRepresentationsFromBlob(containerID, caseID, repfile).then(
|
||||
(data) => {
|
||||
console.log("======== rep deleted =========");
|
||||
return data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// const deleteCaseItem = (containerID, caseID) => {
|
||||
// deleteAwaitingSubmissionsFromBlob(containerID, caseID).then((data) => {
|
||||
// return data;
|
||||
// });
|
||||
// };
|
||||
|
||||
const deleteCaseItem = async (containerID, caseID, setData) => {
|
||||
const result = await deleteAwaitingSubmissionsFromBlob(containerID, caseID);
|
||||
|
||||
if (result) {
|
||||
setData((prevData) =>
|
||||
prevData.map((user) => ({
|
||||
...user,
|
||||
containers: user.containers.map((c) =>
|
||||
c.container === containerID
|
||||
? {
|
||||
...c,
|
||||
folders: c.folders.filter(
|
||||
(f) => f.folderPath !== caseID
|
||||
),
|
||||
}
|
||||
: c
|
||||
),
|
||||
}))
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default function StoragePage(props) {
|
||||
const { userData, repCompleteCount } = props;
|
||||
const [data, setData] = useState(props.data);
|
||||
const [showRepJson, setShowRepJson] = useState(true);
|
||||
const [showTmpFile, setShowTmpFile] = useState(true);
|
||||
const [whichTab, setWhichTab] = useState("storage");
|
||||
|
||||
const toggleAll = () => {
|
||||
const newState = !(showRepJson || showTmpFile);
|
||||
setShowRepJson(newState);
|
||||
setShowTmpFile(newState);
|
||||
};
|
||||
return (
|
||||
<div>
|
||||
<Head>
|
||||
<title>Storage Account Browser</title>
|
||||
</Head>
|
||||
<div id="page_wrapper">
|
||||
<CookieBanner />
|
||||
<Header />
|
||||
<div className="govuk-width-container">
|
||||
<div className="js-enabled govuk-template__body govuk-frontend-supported">
|
||||
<div className="govuk-tabs" data-module="govuk-tabs">
|
||||
<h2 className="govuk-tabs__title">Contents</h2>
|
||||
<ul className="govuk-tabs__list">
|
||||
<li
|
||||
className={
|
||||
whichTab == "storage"
|
||||
? "govuk-tabs__list-item govuk-tabs__list-item--selected"
|
||||
: "govuk-tabs__list-item "
|
||||
}
|
||||
>
|
||||
<a
|
||||
className="govuk-tabs__tab"
|
||||
href="#storage"
|
||||
onClick={() => setWhichTab("storage")}
|
||||
>
|
||||
Storage Account
|
||||
</a>
|
||||
</li>
|
||||
<li
|
||||
className={
|
||||
whichTab == "accounts"
|
||||
? "govuk-tabs__list-item govuk-tabs__list-item--selected"
|
||||
: "govuk-tabs__list-item "
|
||||
}
|
||||
>
|
||||
<a
|
||||
className="govuk-tabs__tab"
|
||||
href="#accounts"
|
||||
onClick={() => setWhichTab("accounts")}
|
||||
>
|
||||
User Accounts
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div
|
||||
className={
|
||||
whichTab == "storage"
|
||||
? "govuk-tabs__panel "
|
||||
: "govuk-tabs__panel govuk-tabs__panel--hidden"
|
||||
}
|
||||
id="storage"
|
||||
>
|
||||
<h1>Storage Account Contents</h1>
|
||||
{repCompleteCount > 0 && (
|
||||
<p>
|
||||
Number of Orphaned Reps:{" "}
|
||||
{repCompleteCount}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{/* Toggle buttons */}
|
||||
<div style={{ marginBottom: "0.2rem" }}>
|
||||
<button
|
||||
className="govuk-button govuk-button--secondary"
|
||||
onClick={() =>
|
||||
setShowRepJson(!showRepJson)
|
||||
}
|
||||
>
|
||||
{showRepJson
|
||||
? "Hide Reps"
|
||||
: "Show Reps"}
|
||||
</button>
|
||||
<button
|
||||
className="govuk-button govuk-button--secondary"
|
||||
onClick={() =>
|
||||
setShowTmpFile(!showTmpFile)
|
||||
}
|
||||
style={{ marginLeft: "0.5rem" }}
|
||||
>
|
||||
{showTmpFile
|
||||
? "Hide Temp Appeal"
|
||||
: "Show Temp Appeal"}
|
||||
</button>
|
||||
<button
|
||||
className="govuk-button govuk-button--secondary"
|
||||
onClick={toggleAll}
|
||||
style={{ marginLeft: "0.5rem" }}
|
||||
>
|
||||
Show/Hide All
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{data.map((user) => (
|
||||
<div
|
||||
key={user.id}
|
||||
className="govuk-grid-row"
|
||||
>
|
||||
{user.containers.map((c) => (
|
||||
<div
|
||||
key={c.container}
|
||||
className="card"
|
||||
>
|
||||
<div className="card-body">
|
||||
<h3>
|
||||
{c.container} -{" "}
|
||||
<Link
|
||||
href={
|
||||
"/auth/signin2?email=" +
|
||||
user.email
|
||||
}
|
||||
>
|
||||
{user.email}
|
||||
</Link>
|
||||
</h3>
|
||||
{c.folders.map((folder) => (
|
||||
<div
|
||||
key={
|
||||
folder.folderPath
|
||||
}
|
||||
style={
|
||||
showRepJson &&
|
||||
folder.hasRepJson
|
||||
? {
|
||||
display:
|
||||
"block",
|
||||
}
|
||||
: showTmpFile &&
|
||||
folder.hasTmpFile
|
||||
? {
|
||||
display:
|
||||
"block",
|
||||
}
|
||||
: {
|
||||
display:
|
||||
"none",
|
||||
}
|
||||
}
|
||||
>
|
||||
<h4>
|
||||
{folder.folderPath ||
|
||||
"Root"}
|
||||
</h4>
|
||||
{/* {folder.hasRepJson && (
|
||||
<p>
|
||||
rep.json file found:{" "}
|
||||
{folder.repJsonBlob.name}
|
||||
</p>
|
||||
)} */}
|
||||
{folder.hasTmpFile && (
|
||||
<>
|
||||
<button
|
||||
onClick={() => {
|
||||
confirm(
|
||||
"Do you want to remove this unsubmitted appeal " +
|
||||
folder.folderPath +
|
||||
"?\n"
|
||||
) &&
|
||||
(deleteCaseItem(
|
||||
c.container,
|
||||
folder.folderPath,
|
||||
setData
|
||||
),
|
||||
alert(
|
||||
"Temp case Deleted!"
|
||||
));
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
this TMP
|
||||
appeal
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
{folder.hasRepJson && (
|
||||
<div>
|
||||
{" "}
|
||||
<button
|
||||
title={
|
||||
"Do you want to delete rep"
|
||||
}
|
||||
className=" cardModuleRemoveCase govuk-link govuk-link--no-underline govuk-link--inverse "
|
||||
onClick={() => {
|
||||
confirm(
|
||||
"Do you want tyo delete rep " +
|
||||
folder.repJsonBlob.name.split(
|
||||
"/"
|
||||
)[0] +
|
||||
"?\n"
|
||||
) &&
|
||||
(deleteRepItem(
|
||||
c.container,
|
||||
folder.repJsonBlob.name.split(
|
||||
"/"
|
||||
)[0],
|
||||
folder.repJsonBlob.name.split(
|
||||
"/"
|
||||
)[1]
|
||||
),
|
||||
alert(
|
||||
"Rep Deleted!"
|
||||
),
|
||||
window.location.reload());
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
Rep
|
||||
</button>
|
||||
{folder.repComplete && (
|
||||
<button
|
||||
onClick={async () => {
|
||||
const response =
|
||||
await fetch(
|
||||
"/api/file/editRepJson",
|
||||
{
|
||||
method: "POST",
|
||||
headers:
|
||||
{
|
||||
"Content-Type":
|
||||
"application/json",
|
||||
},
|
||||
body: JSON.stringify(
|
||||
{
|
||||
container:
|
||||
c.container,
|
||||
blobName:
|
||||
folder
|
||||
.repJsonBlob
|
||||
.name,
|
||||
}
|
||||
),
|
||||
}
|
||||
);
|
||||
const result =
|
||||
await response.json();
|
||||
if (
|
||||
response.ok
|
||||
) {
|
||||
alert(
|
||||
"repComplete removed!"
|
||||
),
|
||||
window.location.reload();
|
||||
// Optionally refresh the page or update UI state here
|
||||
} else {
|
||||
alert(
|
||||
"Error: " +
|
||||
result.error
|
||||
);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Remove
|
||||
repComplete
|
||||
</button>
|
||||
)}
|
||||
{folder.repComplete && (
|
||||
<button
|
||||
onClick={async () => {
|
||||
confirm(
|
||||
"Do you want resend the rep queue message " +
|
||||
folder.repJsonBlob.name.split(
|
||||
"/"
|
||||
)[0] +
|
||||
" --- " +
|
||||
folder.repJsonBlob.name.split(
|
||||
"/"
|
||||
)[1]
|
||||
) &&
|
||||
(sendRepCompleteMessage(
|
||||
c.container,
|
||||
folder.repJsonBlob.name.split(
|
||||
"/"
|
||||
)[0],
|
||||
folder.repJsonBlob.name.split(
|
||||
"/"
|
||||
)[1]
|
||||
),
|
||||
alert(
|
||||
"rep queue message sent!"
|
||||
),
|
||||
window.location.reload());
|
||||
}}
|
||||
>
|
||||
Recreate
|
||||
Queue
|
||||
Message
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ul>
|
||||
{folder.blobs.map(
|
||||
(blob) => (
|
||||
<li
|
||||
key={
|
||||
blob.name
|
||||
}
|
||||
>
|
||||
<Link
|
||||
scroll={
|
||||
false
|
||||
}
|
||||
href={
|
||||
"/api/file/downloadblob?container=" +
|
||||
c.container +
|
||||
"&casefolderID=" +
|
||||
folder.folderPath +
|
||||
"&blobname=" +
|
||||
blob.name
|
||||
.substring(
|
||||
blob.name.lastIndexOf(
|
||||
"/"
|
||||
) +
|
||||
1
|
||||
)
|
||||
.trim() +
|
||||
"&hash=" +
|
||||
blob.hashedfilepath
|
||||
}
|
||||
className="govuk-body govuk-!-font-size-14 govuk-link"
|
||||
>
|
||||
{
|
||||
blob.name
|
||||
}{" "}
|
||||
(
|
||||
{bytesToSize(
|
||||
blob.contentLength ||
|
||||
blob.size
|
||||
)}
|
||||
|
||||
)
|
||||
</Link>{" "}
|
||||
{blob.lastModified && (
|
||||
<span className="govuk-!-font-size-14">
|
||||
{/* {
|
||||
blob.displayDate
|
||||
} */}
|
||||
{formatBlobDates(
|
||||
blob
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</li>
|
||||
)
|
||||
)}
|
||||
</ul>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div
|
||||
className={
|
||||
whichTab == "accounts"
|
||||
? "govuk-tabs__panel "
|
||||
: "govuk-tabs__panel govuk-tabs__panel--hidden"
|
||||
}
|
||||
id="accounts"
|
||||
>
|
||||
<h1>User Accounts </h1>
|
||||
<p>
|
||||
Number of accounts created:{" "}
|
||||
{userData.length}
|
||||
</p>
|
||||
<dl className=" govuk-summary-list govuk-!-margin-bottom-9 results">
|
||||
<div class="govuk-summary-list__row results-headings">
|
||||
<dd className="govuk-summary-list__key govuk-!-font-size-16 ">
|
||||
Name
|
||||
</dd>
|
||||
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
||||
Last accessed
|
||||
</dd>
|
||||
</div>
|
||||
|
||||
{userData.map((user) => (
|
||||
<div
|
||||
key={user.id}
|
||||
className=" govuk-summary-list__row"
|
||||
>
|
||||
<dd className="govuk-summary-list__value govuk-!-font-size-16 ">
|
||||
<Link
|
||||
target="_blank"
|
||||
href={
|
||||
"/auth/signin2?email=" +
|
||||
user.email
|
||||
}
|
||||
>
|
||||
{user.email}
|
||||
</Link>
|
||||
</dd>
|
||||
<dd className="govuk-summary-list__value govuk-!-font-size-16 ">
|
||||
Last accessed: {user.created}{" "}
|
||||
</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Footer />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export async function getServerSideProps({ req }) {
|
||||
// Load allowed IPs from env and trim spaces
|
||||
const ALLOWED_IPS = process.env.ALLOWED_IPS
|
||||
? process.env.ALLOWED_IPS.split(",").map((ip) => ip.trim())
|
||||
: [];
|
||||
|
||||
// Always allow localhost addresses
|
||||
const LOCALHOST_IPS = ["127.0.0.1", "::1"];
|
||||
|
||||
// Get IP address from headers or socket
|
||||
const forwarded = req.headers["x-forwarded-for"];
|
||||
const ip =
|
||||
typeof forwarded === "string"
|
||||
? forwarded.split(",")[0]
|
||||
: req.socket.remoteAddress;
|
||||
|
||||
console.log("Visitor IP:", ip);
|
||||
|
||||
// Check whitelist + localhost
|
||||
if (![...ALLOWED_IPS, ...LOCALHOST_IPS].includes(ip)) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/403", // custom "Access Denied" page
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
const accountName = process.env.AZURE_STORAGE_ACCOUNT_NAME;
|
||||
|
||||
const creds = new DefaultAzureCredential();
|
||||
|
||||
const globalForPrisma = global;
|
||||
|
||||
const prisma = globalForPrisma.prisma || new PrismaClient();
|
||||
|
||||
const blobServiceClient = new BlobServiceClient(
|
||||
`https://${accountName}.blob.core.windows.net`,
|
||||
creds
|
||||
);
|
||||
|
||||
const users = await prisma.user.findMany();
|
||||
|
||||
const hashAPIPath = (queryPath, WORDKEY) => {
|
||||
var hashlink = CryptoJS.HmacSHA256(
|
||||
queryPath,
|
||||
CryptoJS.enc.Hex.parse(WORDKEY)
|
||||
);
|
||||
hashlink = hashlink.toString(CryptoJS.enc.Hex);
|
||||
return hashlink;
|
||||
};
|
||||
|
||||
let data = await Promise.all(
|
||||
users.map(async (user) => {
|
||||
const containers = await listContainersForUser(
|
||||
blobServiceClient,
|
||||
`${user.id}`,
|
||||
user.email
|
||||
);
|
||||
|
||||
const containersWithHashes = await Promise.all(
|
||||
containers.map(async (container) => {
|
||||
const groupedByFolder = await container.blobs.reduce(
|
||||
async (accP, blob) => {
|
||||
// Because we'll do async read, reduce needs to be async, so accP is a Promise
|
||||
const acc = await accP;
|
||||
|
||||
const folderPath =
|
||||
getUpToLastSlash(blob.name.trim()) || "";
|
||||
|
||||
const hashedfilepath = hashAPIPath(
|
||||
"/api/file/downloadblob?container=" +
|
||||
container.container +
|
||||
"&casefolderID=" +
|
||||
folderPath +
|
||||
"&blobname=" +
|
||||
blob.name
|
||||
.substring(
|
||||
blob.name.lastIndexOf("/") + 1
|
||||
)
|
||||
.trim(),
|
||||
process.env.HASHKEY
|
||||
);
|
||||
|
||||
const fileNameOnly = blob.name.substring(
|
||||
blob.name.lastIndexOf("/") + 1
|
||||
);
|
||||
const isTmpFile = fileNameOnly.startsWith("TMP-");
|
||||
|
||||
const blobWithHash = {
|
||||
...blob,
|
||||
hashedfilepath,
|
||||
isTmpFile,
|
||||
};
|
||||
|
||||
let folderGroup = acc.find(
|
||||
(f) => f.folderPath === folderPath
|
||||
);
|
||||
if (!folderGroup) {
|
||||
folderGroup = {
|
||||
folderPath,
|
||||
blobs: [],
|
||||
hasRepJson: false,
|
||||
repJsonBlob: null,
|
||||
repComplete: false,
|
||||
hasTmpFile: false,
|
||||
};
|
||||
acc.push(folderGroup);
|
||||
}
|
||||
|
||||
folderGroup.blobs.push(blobWithHash);
|
||||
|
||||
if (isTmpFile) {
|
||||
folderGroup.hasTmpFile = true;
|
||||
}
|
||||
|
||||
// If this blob ends with rep.json, fetch and parse JSON
|
||||
if (blob.name.toLowerCase().endsWith("rep.json")) {
|
||||
folderGroup.hasRepJson = true;
|
||||
folderGroup.repJsonBlob = blobWithHash;
|
||||
|
||||
// Read blob content from Azure Storage
|
||||
const containerClient =
|
||||
blobServiceClient.getContainerClient(
|
||||
container.container
|
||||
);
|
||||
const blockBlobClient =
|
||||
containerClient.getBlockBlobClient(
|
||||
blob.name
|
||||
);
|
||||
|
||||
try {
|
||||
const downloadResponse =
|
||||
await blockBlobClient.download(0);
|
||||
const downloaded = await streamToString(
|
||||
downloadResponse.readableStreamBody
|
||||
);
|
||||
|
||||
const json = JSON.parse(downloaded);
|
||||
folderGroup.repComplete = Boolean(
|
||||
json.repComplete
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"Error reading or parsing rep.json",
|
||||
err
|
||||
);
|
||||
folderGroup.repComplete = false;
|
||||
}
|
||||
}
|
||||
|
||||
return acc;
|
||||
},
|
||||
Promise.resolve([])
|
||||
);
|
||||
|
||||
return {
|
||||
...container,
|
||||
folders: groupedByFolder,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
return containersWithHashes.length > 0
|
||||
? {
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
containers: containersWithHashes,
|
||||
}
|
||||
: null;
|
||||
})
|
||||
);
|
||||
|
||||
let userData = await Promise.all(
|
||||
users
|
||||
.filter((user) => user.email && user.email.trim() !== "")
|
||||
.map(async (user) => ({
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
created: user.emailVerified?.toLocaleString("en-GB") || "",
|
||||
}))
|
||||
);
|
||||
|
||||
let repCompleteCount = 0;
|
||||
|
||||
data = data.filter(Boolean);
|
||||
|
||||
data.forEach((user) => {
|
||||
user.containers.forEach((container) => {
|
||||
container.folders.forEach((folder) => {
|
||||
if (folder.repComplete === true) {
|
||||
repCompleteCount++;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
props: {
|
||||
data: data,
|
||||
userData: userData,
|
||||
repCompleteCount,
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user