@@ -786,6 +786,19 @@ export const getMyCases = (loggedInUserId) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getMyInvolvements = async (loggedInUserId) => {
|
||||||
|
try {
|
||||||
|
const res = await axios.get(
|
||||||
|
BASE_URL +
|
||||||
|
"/api/endpoint/getmyinvolvements_api?loggedInUserId=" +
|
||||||
|
loggedInUserId
|
||||||
|
);
|
||||||
|
return res.data;
|
||||||
|
} catch (error) {
|
||||||
|
consoleLogger(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const getMyLPACases = (lpaid) => {
|
export const getMyLPACases = (lpaid) => {
|
||||||
return axios
|
return axios
|
||||||
.get(BASE_URL + "/api/endpoint/getmylpacases_api?lpaid=" + lpaid)
|
.get(BASE_URL + "/api/endpoint/getmylpacases_api?lpaid=" + lpaid)
|
||||||
@@ -2087,3 +2100,74 @@ export const getAddressSearch = async (searchString) => {
|
|||||||
return ErrResponse;
|
return ErrResponse;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getNewAppeals = async (searchString) => {
|
||||||
|
try {
|
||||||
|
const res = await axios.get(BASE_URL + "/api/admin/getnewappeals_api");
|
||||||
|
return res.data;
|
||||||
|
} catch (error) {
|
||||||
|
consoleLogger(error);
|
||||||
|
return error.response;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getNewAppealsPage = async (
|
||||||
|
searchString,
|
||||||
|
pageNumber,
|
||||||
|
orderBy,
|
||||||
|
fieldSort,
|
||||||
|
showNumberOfRecords
|
||||||
|
) => {
|
||||||
|
return axios
|
||||||
|
.get(
|
||||||
|
"/api/admin/getnewappeals_api?searchString=" +
|
||||||
|
searchString +
|
||||||
|
"&pageNumber=" +
|
||||||
|
pageNumber +
|
||||||
|
"&orderby=" +
|
||||||
|
orderBy +
|
||||||
|
"&fieldSort=" +
|
||||||
|
fieldSort +
|
||||||
|
"&showNumberOfRecords=" +
|
||||||
|
showNumberOfRecords
|
||||||
|
)
|
||||||
|
.then((res) => {
|
||||||
|
return res.data;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
consoleLogger(error);
|
||||||
|
return error.response;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getNewDocumentsPaged = async (
|
||||||
|
pageNumber,
|
||||||
|
orderBy,
|
||||||
|
fieldSort,
|
||||||
|
showNumberOfRecords,
|
||||||
|
documentType,
|
||||||
|
selectedWeeks
|
||||||
|
) => {
|
||||||
|
return axios
|
||||||
|
.get(
|
||||||
|
"/api/admin/getlatestdocuments_api?pageNumber=" +
|
||||||
|
pageNumber +
|
||||||
|
"&orderby=" +
|
||||||
|
orderBy +
|
||||||
|
"&fieldSort=" +
|
||||||
|
fieldSort +
|
||||||
|
"&showNumberOfRecords=" +
|
||||||
|
showNumberOfRecords +
|
||||||
|
"&documentType=" +
|
||||||
|
documentType +
|
||||||
|
"&numberWeeks=" +
|
||||||
|
selectedWeeks
|
||||||
|
)
|
||||||
|
.then((res) => {
|
||||||
|
return res.data;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
consoleLogger(error);
|
||||||
|
return error.response;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// components/admin/tabs/AccountsTab.js
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
export default function AccountsTab({ userData }) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>User Accounts</h1>
|
||||||
|
<p>Number of accounts created: {userData.length}</p>
|
||||||
|
|
||||||
|
<dl className="govuk-summary-list govuk-!-margin-bottom-9 results">
|
||||||
|
<div className="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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,562 @@
|
|||||||
|
// components/admin/tabs/AppealsTab.js
|
||||||
|
import useTranslation from "next-translate/useTranslation";
|
||||||
|
import { useCallback, useState, useEffect } from "react";
|
||||||
|
import { JSONPath as jsonpath } from "jsonpath-plus";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
import PaginationControl from "../../../components/search/pagination";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
|
||||||
|
import {
|
||||||
|
setSearchResults,
|
||||||
|
setSearchDetails,
|
||||||
|
} from "../../../store/searchOutput/action";
|
||||||
|
|
||||||
|
import { getDetailsProxy, getSearchDetailsPaged } from "../../utils";
|
||||||
|
import { getAdvancedSearchPaged, getNewAppealsPage } from "../../../actions";
|
||||||
|
import {
|
||||||
|
setCurrentPage,
|
||||||
|
setCurrentReference,
|
||||||
|
} from "../../../store/currentView/action";
|
||||||
|
|
||||||
|
function AppealsTab(props) {
|
||||||
|
const [searchLoaded, setSearchLoaded] = useState(false);
|
||||||
|
const [showSpinnerState, setShowSpinnerState] = useState(false);
|
||||||
|
const [selectedOption, setSelectedOption] = useState(10);
|
||||||
|
const [orderByState, setOrderbyState] = useState("createdon");
|
||||||
|
const [fieldSortState, setfieldSortState] = useState("desc");
|
||||||
|
const [loginToWatch, setLoginToWatch] = useState("true");
|
||||||
|
|
||||||
|
const searchDetailsObj = props.searchResultsObj.searchDetailsObj || {};
|
||||||
|
const resultsArr = props.searchResultsObj.searchResultsObj.value || [];
|
||||||
|
const searchResultsObj = props.searchResultsObj.searchResultsObj;
|
||||||
|
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const router = useRouter();
|
||||||
|
const myportal = false;
|
||||||
|
const advancedSearch = false;
|
||||||
|
const searchString = "";
|
||||||
|
|
||||||
|
const spinnerState = () => {
|
||||||
|
setShowSpinnerState((prev) => !prev);
|
||||||
|
};
|
||||||
|
|
||||||
|
const pagesCount = Math.ceil(searchResultsObj["@odata.count"] / 10);
|
||||||
|
|
||||||
|
let currentPage = 0;
|
||||||
|
try {
|
||||||
|
currentPage = decodeURI(searchResultsObj["@odata.nextLink"]).split(
|
||||||
|
"skiptoken="
|
||||||
|
)[1];
|
||||||
|
currentPage =
|
||||||
|
typeof currentPage !== "undefined"
|
||||||
|
? parseInt(
|
||||||
|
decodeURI(currentPage)
|
||||||
|
.split('pagenumber="')[1]
|
||||||
|
.slice(
|
||||||
|
0,
|
||||||
|
decodeURI(currentPage)
|
||||||
|
.split('pagenumber="')[1]
|
||||||
|
.indexOf('"')
|
||||||
|
) - 1
|
||||||
|
)
|
||||||
|
: pagesCount;
|
||||||
|
} catch (e) {
|
||||||
|
currentPage = pagesCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getSearchPageResults = useCallback(
|
||||||
|
(pageNumber, orderBy, fieldSort) => {
|
||||||
|
getNewAppealsPage(
|
||||||
|
searchString,
|
||||||
|
pageNumber,
|
||||||
|
orderBy,
|
||||||
|
fieldSort,
|
||||||
|
selectedOption
|
||||||
|
).then((data) => {
|
||||||
|
props.setSearchResults(data); // ✅ use props, not import
|
||||||
|
return getSearchDetailsPaged(data).then((details) => {
|
||||||
|
props.setSearchDetails(details); // ✅ use props, not import
|
||||||
|
setShowSpinnerState(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[
|
||||||
|
advancedSearch,
|
||||||
|
searchString,
|
||||||
|
selectedOption,
|
||||||
|
props.setSearchDetails,
|
||||||
|
props.setSearchResults,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (searchLoaded) {
|
||||||
|
if (selectedOption) {
|
||||||
|
setShowSpinnerState(true);
|
||||||
|
getSearchPageResults(1, orderByState, fieldSortState);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setSearchLoaded(true);
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
selectedOption,
|
||||||
|
fieldSortState,
|
||||||
|
orderByState,
|
||||||
|
searchLoaded,
|
||||||
|
getSearchPageResults,
|
||||||
|
router.query,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const ResultsView = (resultsArr) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<dl className="govuk-summary-list govuk-!-margin-bottom-9 results">
|
||||||
|
<div className="govuk-summary-list__row results-headings">
|
||||||
|
<dd className="govuk-summary-list__key govuk-!-font-size-16 results_wider ">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => sortDataBy("title")}
|
||||||
|
className={
|
||||||
|
orderByState == "title"
|
||||||
|
? fieldSortState == "asc"
|
||||||
|
? `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortAsc`
|
||||||
|
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortDesc`
|
||||||
|
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16`
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{t("search:searchresults-case-reference-label")}
|
||||||
|
</button>
|
||||||
|
</dd>
|
||||||
|
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
||||||
|
{t("search:searchresults-site-address-label")}
|
||||||
|
</dd>
|
||||||
|
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => sortDataBy("_customerid_value")}
|
||||||
|
className={
|
||||||
|
orderByState == "_customerid_value"
|
||||||
|
? fieldSortState == "asc"
|
||||||
|
? `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortAsc`
|
||||||
|
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortDesc`
|
||||||
|
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16`
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{t("search:searchresults-applicant-label")}
|
||||||
|
</button>
|
||||||
|
</dd>
|
||||||
|
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() =>
|
||||||
|
sortDataBy("_pinswg_associatedlpa_value")
|
||||||
|
}
|
||||||
|
className={
|
||||||
|
orderByState ==
|
||||||
|
"_pinswg_associatedlpa_value"
|
||||||
|
? fieldSortState == "asc"
|
||||||
|
? `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortAsc`
|
||||||
|
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortDesc`
|
||||||
|
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16`
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{t("search:searchresults-authority-label")}
|
||||||
|
</button>
|
||||||
|
</dd>
|
||||||
|
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() =>
|
||||||
|
sortDataBy("pinswg_appealcasetype")
|
||||||
|
}
|
||||||
|
className={
|
||||||
|
orderByState == "pinswg_appealcasetype"
|
||||||
|
? fieldSortState == "asc"
|
||||||
|
? `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortAsc`
|
||||||
|
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortDesc`
|
||||||
|
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16`
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{t("search:searchresults-case-type-label")}
|
||||||
|
</button>
|
||||||
|
</dd>
|
||||||
|
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
||||||
|
{/* {t("search:searchresults-status-label")} */}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => sortDataBy("statuscode")}
|
||||||
|
className={
|
||||||
|
orderByState == "statuscode"
|
||||||
|
? fieldSortState == "asc"
|
||||||
|
? `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortAsc`
|
||||||
|
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortDesc`
|
||||||
|
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16`
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{t("search:searchresults-status-label")}
|
||||||
|
</button>
|
||||||
|
</dd>
|
||||||
|
|
||||||
|
<dd className="govuk-summary-list__key govuk-!-font-size-16 govuk-summary-list__action"></dd>
|
||||||
|
</div>
|
||||||
|
{showSpinnerState == true ? (
|
||||||
|
<div className="govuk-summary-list__row">
|
||||||
|
<div className="govuk-!-margin-top-9 govuk-!-margin-bottom-9 govuk-!-font-weight-bold govuk-!-font-size-20 ">
|
||||||
|
{t("common:spinner-fetching-data")}
|
||||||
|
<img
|
||||||
|
className="data-loading-icon"
|
||||||
|
src="/assets/images/loading.gif"
|
||||||
|
alt={
|
||||||
|
router.locale == "cy"
|
||||||
|
? "Nôl data"
|
||||||
|
: "Fetching data"
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
resultsArr.map((item, key) => {
|
||||||
|
let detailsObj = jsonpath({
|
||||||
|
path:
|
||||||
|
'$..value[?(@ && @.ticketnumber=="' +
|
||||||
|
item.ticketnumber +
|
||||||
|
'")]',
|
||||||
|
json: searchDetailsObj,
|
||||||
|
eval: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
detailsObj = detailsObj[0] || {};
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="govuk-summary-list__row"
|
||||||
|
key={key}
|
||||||
|
>
|
||||||
|
<dd className="govuk-summary-list__value govuk-!-font-size-16 ">
|
||||||
|
<div></div>
|
||||||
|
<Link
|
||||||
|
href={
|
||||||
|
(router.locale == "cy"
|
||||||
|
? myportal == true
|
||||||
|
? "/fymhorth/achos"
|
||||||
|
: "/achos"
|
||||||
|
: myportal == true
|
||||||
|
? "/myportal/case"
|
||||||
|
: "/case") +
|
||||||
|
"/" +
|
||||||
|
item.ticketnumber
|
||||||
|
}
|
||||||
|
className="govuk-link--no-underline"
|
||||||
|
onClick={() => {
|
||||||
|
sendGAEvent(
|
||||||
|
"event",
|
||||||
|
"CaseViewed",
|
||||||
|
{
|
||||||
|
caseReference:
|
||||||
|
item.ticketnumber,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
setCurrentReference({
|
||||||
|
"ticketnumber":
|
||||||
|
item.ticketnumber,
|
||||||
|
"currentReference":
|
||||||
|
item.title,
|
||||||
|
"currentType":
|
||||||
|
"searchResultsObj",
|
||||||
|
"incidentid":
|
||||||
|
item.incidentid,
|
||||||
|
"appealType":
|
||||||
|
item.pinswg_appealcasetype,
|
||||||
|
"showLoginCheck":
|
||||||
|
props.showLoginCheck,
|
||||||
|
"specialistProcess":
|
||||||
|
detailsObj.hasOwnProperty(
|
||||||
|
"pinswg_speacialistcaseprocess"
|
||||||
|
)
|
||||||
|
? detailsObj.pinswg_speacialistcaseprocess
|
||||||
|
: detailsObj.hasOwnProperty(
|
||||||
|
"pinswg_specialistcaseprocess"
|
||||||
|
)
|
||||||
|
? detailsObj.pinswg_specialistcaseprocess
|
||||||
|
: "",
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="results-visually-hidden">
|
||||||
|
{t(
|
||||||
|
"search:searchresults-case-reference-label"
|
||||||
|
)}
|
||||||
|
:
|
||||||
|
</span>
|
||||||
|
{item.title}
|
||||||
|
</Link>
|
||||||
|
<br />
|
||||||
|
{new Date(
|
||||||
|
item.createdon
|
||||||
|
).toLocaleString()}
|
||||||
|
</dd>
|
||||||
|
<dd className="govuk-summary-list__value govuk-!-font-size-16">
|
||||||
|
<span className="results-visually-hidden">
|
||||||
|
{t(
|
||||||
|
"search:searchresults-site-address-label"
|
||||||
|
)}
|
||||||
|
:
|
||||||
|
</span>
|
||||||
|
{_.has(
|
||||||
|
detailsObj,
|
||||||
|
"pinswg_projectlocation"
|
||||||
|
)
|
||||||
|
? detailsObj.pinswg_projectlocation !=
|
||||||
|
null
|
||||||
|
? detailsObj.pinswg_projectlocation.indexOf(
|
||||||
|
";"
|
||||||
|
) < 0
|
||||||
|
? detailsObj.pinswg_projectlocation
|
||||||
|
: router.locale == "cy"
|
||||||
|
? detailsObj.pinswg_projectlocation.split(
|
||||||
|
";"
|
||||||
|
)[1]
|
||||||
|
: detailsObj.pinswg_projectlocation.split(
|
||||||
|
";"
|
||||||
|
)[0]
|
||||||
|
: ""
|
||||||
|
: ""}
|
||||||
|
{_.has(
|
||||||
|
detailsObj,
|
||||||
|
"pinswg_siteaddressline1"
|
||||||
|
)
|
||||||
|
? detailsObj.pinswg_siteaddressline1
|
||||||
|
: ""}
|
||||||
|
|
||||||
|
{/* {detailsObj.pinswg_siteaddressline1 !=
|
||||||
|
null && <br />} */}
|
||||||
|
|
||||||
|
{_.has(
|
||||||
|
detailsObj,
|
||||||
|
"pinswg_siteaddressline1"
|
||||||
|
) &&
|
||||||
|
detailsObj.pinswg_siteaddressline1 !=
|
||||||
|
null && <br />}
|
||||||
|
|
||||||
|
{_.has(
|
||||||
|
detailsObj,
|
||||||
|
"pinswg_siteaddressline1"
|
||||||
|
)
|
||||||
|
? detailsObj.pinswg_siteaddressline2
|
||||||
|
: ""}
|
||||||
|
|
||||||
|
{_.has(
|
||||||
|
detailsObj,
|
||||||
|
"pinswg_siteaddressline2"
|
||||||
|
) &&
|
||||||
|
detailsObj.pinswg_siteaddressline2 !=
|
||||||
|
null && <br />}
|
||||||
|
{_.has(
|
||||||
|
detailsObj,
|
||||||
|
"pinswg_siteaddresstown"
|
||||||
|
)
|
||||||
|
? detailsObj.pinswg_siteaddresstown
|
||||||
|
: ""}
|
||||||
|
{_.has(
|
||||||
|
detailsObj,
|
||||||
|
"pinswg_siteaddresstown"
|
||||||
|
) &&
|
||||||
|
detailsObj.pinswg_siteaddresstown !=
|
||||||
|
null && <br />}
|
||||||
|
|
||||||
|
{_.has(
|
||||||
|
detailsObj,
|
||||||
|
"pinswg_siteaddresscounty"
|
||||||
|
)
|
||||||
|
? detailsObj.pinswg_siteaddresscounty
|
||||||
|
: ""}
|
||||||
|
{_.has(
|
||||||
|
detailsObj,
|
||||||
|
"pinswg_siteaddresscounty"
|
||||||
|
) &&
|
||||||
|
detailsObj.pinswg_siteaddresscounty !=
|
||||||
|
null && <br />}
|
||||||
|
{_.has(
|
||||||
|
detailsObj,
|
||||||
|
"pinswg_siteaddresspostcode"
|
||||||
|
)
|
||||||
|
? detailsObj.pinswg_siteaddresspostcode
|
||||||
|
: ""}
|
||||||
|
</dd>
|
||||||
|
<dd className="govuk-summary-list__value govuk-!-font-size-16">
|
||||||
|
<span className="results-visually-hidden">
|
||||||
|
{t(
|
||||||
|
"search:searchresults-applicant-label"
|
||||||
|
)}
|
||||||
|
:
|
||||||
|
</span>
|
||||||
|
{item.pinswg_appellantagent == 846040001
|
||||||
|
? item.pinswg_appellantfirstname +
|
||||||
|
" " +
|
||||||
|
item.pinswg_appellantlastname
|
||||||
|
: _.has(detailsObj, [
|
||||||
|
"_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue",
|
||||||
|
])
|
||||||
|
? detailsObj[
|
||||||
|
"_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue"
|
||||||
|
]
|
||||||
|
: ""}
|
||||||
|
</dd>
|
||||||
|
<dd className="govuk-summary-list__value govuk-!-font-size-16">
|
||||||
|
<span className="results-visually-hidden">
|
||||||
|
{t(
|
||||||
|
"search:searchresults-authority-label"
|
||||||
|
)}
|
||||||
|
:
|
||||||
|
</span>
|
||||||
|
{_.has(item, [
|
||||||
|
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue",
|
||||||
|
])
|
||||||
|
? router.locale == "cy"
|
||||||
|
? jsonpath({
|
||||||
|
path:
|
||||||
|
'$..[?(@ && @.value=="' +
|
||||||
|
item[
|
||||||
|
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
||||||
|
] +
|
||||||
|
'")].value_cy',
|
||||||
|
json: transLookup,
|
||||||
|
eval: true,
|
||||||
|
})
|
||||||
|
: item[
|
||||||
|
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
||||||
|
] || "N/A"
|
||||||
|
: ""}
|
||||||
|
</dd>
|
||||||
|
<dd className="govuk-summary-list__value govuk-!-font-size-16">
|
||||||
|
<span className="results-visually-hidden">
|
||||||
|
{t(
|
||||||
|
"search:searchresults-case-type-label"
|
||||||
|
)}
|
||||||
|
:
|
||||||
|
</span>
|
||||||
|
{router.locale == "cy"
|
||||||
|
? jsonpath({
|
||||||
|
path:
|
||||||
|
'$..[?(@ && @.value=="' +
|
||||||
|
item[
|
||||||
|
"pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue"
|
||||||
|
] +
|
||||||
|
'")].value_cy',
|
||||||
|
json: transLookup,
|
||||||
|
eval: true,
|
||||||
|
})
|
||||||
|
: item[
|
||||||
|
"pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue"
|
||||||
|
] || "N/A"}
|
||||||
|
</dd>
|
||||||
|
<dd className="govuk-summary-list__value govuk-!-font-size-16">
|
||||||
|
<span className="results-visually-hidden">
|
||||||
|
{t(
|
||||||
|
"search:searchresults-status-label"
|
||||||
|
)}
|
||||||
|
:
|
||||||
|
</span>
|
||||||
|
|
||||||
|
{router.locale == "cy"
|
||||||
|
? jsonpath({
|
||||||
|
path:
|
||||||
|
'$..[?(@ && @.value=="' +
|
||||||
|
item[
|
||||||
|
"statuscode@OData.Community.Display.V1.FormattedValue"
|
||||||
|
] +
|
||||||
|
'")].value_cy',
|
||||||
|
json: transLookup,
|
||||||
|
eval: true,
|
||||||
|
})
|
||||||
|
: item[
|
||||||
|
"statuscode@OData.Community.Display.V1.FormattedValue"
|
||||||
|
] || "N/A"}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
)}
|
||||||
|
</dl>
|
||||||
|
<PaginationControl
|
||||||
|
showNoOfRecords={selectedOption}
|
||||||
|
currentPage={currentPage}
|
||||||
|
searchResultsObj={props.searchResultsObj.searchResultsObj}
|
||||||
|
orderBy={orderByState}
|
||||||
|
fieldSort={fieldSortState}
|
||||||
|
spinnerState={spinnerState}
|
||||||
|
getSearchPageResults={getSearchPageResults}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Appeals</h1>
|
||||||
|
{searchResultsObj["@odata.count"] > 5 && (
|
||||||
|
<div id="recordCountSelect" className="">
|
||||||
|
<div className="govuk-form-group">
|
||||||
|
<label
|
||||||
|
className="govuk-label-s "
|
||||||
|
htmlFor="showNumberOfRecords"
|
||||||
|
>
|
||||||
|
{t("search:searchresults-show-records-label-a")}
|
||||||
|
<select
|
||||||
|
onChange={(e) => {
|
||||||
|
setSelectedOption(e.target.value);
|
||||||
|
props.setCurrentPage(1);
|
||||||
|
}}
|
||||||
|
value={selectedOption}
|
||||||
|
className="govuk-select"
|
||||||
|
id="showNumberOfRecords"
|
||||||
|
name="showNumberOfRecords"
|
||||||
|
>
|
||||||
|
<option value="5">5</option>
|
||||||
|
<option value="10">10</option>
|
||||||
|
<option value="20">20</option>
|
||||||
|
<option value="30">30</option>
|
||||||
|
<option value="50">50</option>
|
||||||
|
</select>{" "}
|
||||||
|
{t("search:searchresults-show-records-label-b")}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{resultsArr.length > 0 ? (
|
||||||
|
ResultsView(resultsArr)
|
||||||
|
) : (
|
||||||
|
<div className="govuk-grid-row">
|
||||||
|
<div className="govuk-grid-column-two-thirds">
|
||||||
|
<h3>{t("search:searchresults-no-records-label")}</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => {
|
||||||
|
return {
|
||||||
|
setCurrentReference: (currentReference) => {
|
||||||
|
dispatch(setCurrentReference(currentReference));
|
||||||
|
},
|
||||||
|
setSearchResults: (searchResultsObj) => {
|
||||||
|
dispatch(setSearchResults(searchResultsObj));
|
||||||
|
},
|
||||||
|
setSearchDetails: (searchDetailsObj) => {
|
||||||
|
dispatch(setSearchDetails(searchDetailsObj));
|
||||||
|
},
|
||||||
|
setCurrentPage: (currentPage) => {
|
||||||
|
dispatch(setCurrentPage(currentPage));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => {
|
||||||
|
return {
|
||||||
|
searchResultsObj: state.searchResultsObj,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(AppealsTab);
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,266 @@
|
|||||||
|
// components/admin/tabs/StorageTab.js
|
||||||
|
import { useState } from "react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { bytesToSize } from "../../../components/utils";
|
||||||
|
import {
|
||||||
|
deleteMyRepresentationsFromBlob,
|
||||||
|
deleteAwaitingSubmissionsFromBlob,
|
||||||
|
sendRepCompleteMessage,
|
||||||
|
} from "../../../actions";
|
||||||
|
|
||||||
|
import { formatBlobDates } from "../utils/adminHelper";
|
||||||
|
|
||||||
|
export default function StorageTab({ data, repCompleteCount }) {
|
||||||
|
const [showRepJson, setShowRepJson] = useState(true);
|
||||||
|
const [showTmpFile, setShowTmpFile] = useState(true);
|
||||||
|
const [listData, setListData] = useState(data);
|
||||||
|
|
||||||
|
const toggleAll = () => {
|
||||||
|
const newState = !(showRepJson || showTmpFile);
|
||||||
|
setShowRepJson(newState);
|
||||||
|
setShowTmpFile(newState);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
{/* Render users & containers */}
|
||||||
|
{listData.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>
|
||||||
|
{/* folders */}
|
||||||
|
{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>
|
||||||
|
|
||||||
|
{/* Buttons for TMP + Rep actions go here (same logic as before) */}
|
||||||
|
|
||||||
|
{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
|
||||||
|
)}&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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
// components/admin/utils/adminStorage.js
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the folder path up to the last slash.
|
||||||
|
* Used for grouping blobs by "case folder".
|
||||||
|
*/
|
||||||
|
export 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a stream (Azure blob download) to a string.
|
||||||
|
*/
|
||||||
|
export 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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format how long ago a date occurred.
|
||||||
|
*/
|
||||||
|
export 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`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format Azure blob created/modified dates into a readable string.
|
||||||
|
*/
|
||||||
|
export 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)})`;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// lib/prisma.js
|
||||||
|
import { PrismaClient } from "@prisma/client";
|
||||||
|
|
||||||
|
const globalForPrisma = globalThis;
|
||||||
|
|
||||||
|
export const prisma =
|
||||||
|
globalForPrisma.prisma ||
|
||||||
|
new PrismaClient({
|
||||||
|
log: ["query", "error", "warn"],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV !== "production") {
|
||||||
|
globalForPrisma.prisma = prisma;
|
||||||
|
}
|
||||||
@@ -0,0 +1,166 @@
|
|||||||
|
// components/admin/utils/serverStorage.js
|
||||||
|
import { DefaultAzureCredential } from "@azure/identity";
|
||||||
|
import { BlobServiceClient } from "@azure/storage-blob";
|
||||||
|
import { PrismaClient } from "@prisma/client";
|
||||||
|
import CryptoJS from "crypto-js";
|
||||||
|
import { getUpToLastSlash, streamToString } from "../utils/adminHelper";
|
||||||
|
import { listContainersForUser } from "../../../actions/azurestorage";
|
||||||
|
|
||||||
|
const prisma = global.prisma || new PrismaClient();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate HMAC hash for blob API link.
|
||||||
|
*/
|
||||||
|
function hashAPIPath(queryPath, WORDKEY) {
|
||||||
|
let hashlink = CryptoJS.HmacSHA256(
|
||||||
|
queryPath,
|
||||||
|
CryptoJS.enc.Hex.parse(WORDKEY)
|
||||||
|
);
|
||||||
|
return hashlink.toString(CryptoJS.enc.Hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch blob structure + users for admin storage page.
|
||||||
|
*/
|
||||||
|
export async function fetchAdminStorageData() {
|
||||||
|
const accountName = process.env.AZURE_STORAGE_ACCOUNT_NAME;
|
||||||
|
const creds = new DefaultAzureCredential();
|
||||||
|
const blobServiceClient = new BlobServiceClient(
|
||||||
|
`https://${accountName}.blob.core.windows.net`,
|
||||||
|
creds
|
||||||
|
);
|
||||||
|
|
||||||
|
const prisma = global.prisma || new PrismaClient();
|
||||||
|
|
||||||
|
const users = await prisma.user.findMany();
|
||||||
|
|
||||||
|
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) => {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// rep.json handling
|
||||||
|
if (blob.name.toLowerCase().endsWith("rep.json")) {
|
||||||
|
folderGroup.hasRepJson = true;
|
||||||
|
folderGroup.repJsonBlob = blobWithHash;
|
||||||
|
|
||||||
|
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 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;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
data = data.filter(Boolean);
|
||||||
|
|
||||||
|
let userData = users
|
||||||
|
.filter((user) => user.email && user.email.trim() !== "")
|
||||||
|
.map((user) => ({
|
||||||
|
id: user.id,
|
||||||
|
email: user.email,
|
||||||
|
created: user.emailVerified?.toLocaleString("en-GB") || "",
|
||||||
|
}));
|
||||||
|
|
||||||
|
let repCompleteCount = 0;
|
||||||
|
data.forEach((user) => {
|
||||||
|
user.containers.forEach((container) => {
|
||||||
|
container.folders.forEach((folder) => {
|
||||||
|
if (folder.repComplete === true) repCompleteCount++;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return { data, userData, repCompleteCount };
|
||||||
|
}
|
||||||
@@ -75,5 +75,6 @@ module.exports = {
|
|||||||
"/auth/signin": ["common", "common", "auth"],
|
"/auth/signin": ["common", "common", "auth"],
|
||||||
"/auth/verify-request": ["common", "common", "auth"],
|
"/auth/verify-request": ["common", "common", "auth"],
|
||||||
"/auth/error": ["common", "common", "auth"],
|
"/auth/error": ["common", "common", "auth"],
|
||||||
|
"/admin": ["case"],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,215 @@
|
|||||||
|
// pages/admin/storage.js
|
||||||
|
import { useState } from "react";
|
||||||
|
import Head from "next/head";
|
||||||
|
import CookieBanner from "../../components/cookieBanner";
|
||||||
|
import Header from "../../components/header";
|
||||||
|
import Footer from "../../components/footer";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { wrapper } from "../../store/store";
|
||||||
|
|
||||||
|
import StorageTab from "../../components/admin/tabs/storage";
|
||||||
|
import AccountsTab from "../../components/admin/tabs/accounts";
|
||||||
|
import AppealsTab from "../../components/admin/tabs/appeals";
|
||||||
|
import DocumentsTab from "../../components/admin/tabs/documents";
|
||||||
|
|
||||||
|
import { fetchAdminStorageData } from "../../components/admin/utils/serverside";
|
||||||
|
import { getNewAppeals } from "../../actions";
|
||||||
|
|
||||||
|
import { getSearchDetails } from "../../components/utils";
|
||||||
|
|
||||||
|
import {
|
||||||
|
setSearchDetails,
|
||||||
|
setSearchResults,
|
||||||
|
} from "../../store/searchOutput/action";
|
||||||
|
import { setCurrentPage } from "../../store/currentView/action";
|
||||||
|
|
||||||
|
const StoragePage = (props) => {
|
||||||
|
const {
|
||||||
|
data,
|
||||||
|
userData,
|
||||||
|
repCompleteCount,
|
||||||
|
searchResultsObj,
|
||||||
|
docsOffline,
|
||||||
|
showFilteredDocs,
|
||||||
|
} = props;
|
||||||
|
const [whichTab, setWhichTab] = useState("documents");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Head>
|
||||||
|
<title>Admin Browser</title>
|
||||||
|
</Head>
|
||||||
|
<div id="page_wrapper">
|
||||||
|
<CookieBanner />
|
||||||
|
<Header />
|
||||||
|
|
||||||
|
<div
|
||||||
|
className="govuk-width-containera"
|
||||||
|
style={{ width: "90%", margin: "auto" }}
|
||||||
|
>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
{/* Tabs */}
|
||||||
|
<ul className="govuk-tabs__list">
|
||||||
|
{[
|
||||||
|
"storage",
|
||||||
|
"accounts",
|
||||||
|
"appeals",
|
||||||
|
"documents",
|
||||||
|
].map((tab) => (
|
||||||
|
<li
|
||||||
|
key={tab}
|
||||||
|
className={
|
||||||
|
whichTab === tab
|
||||||
|
? "govuk-tabs__list-item govuk-tabs__list-item--selected"
|
||||||
|
: "govuk-tabs__list-item"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
className="govuk-tabs__tab"
|
||||||
|
href={`#${tab}`}
|
||||||
|
onClick={() => {
|
||||||
|
setWhichTab(tab);
|
||||||
|
tab === "appeals" &&
|
||||||
|
props.setCurrentPage(1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{tab === "storage" &&
|
||||||
|
"Storage Account"}
|
||||||
|
{tab === "accounts" &&
|
||||||
|
"User Accounts"}
|
||||||
|
{tab === "appeals" &&
|
||||||
|
"Latest Appeals"}
|
||||||
|
{tab === "documents" &&
|
||||||
|
"Latest Documents"}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{/* Panels */}
|
||||||
|
<div
|
||||||
|
className={
|
||||||
|
whichTab === "storage"
|
||||||
|
? "govuk-tabs__panel"
|
||||||
|
: "govuk-tabs__panel govuk-tabs__panel--hidden"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<StorageTab
|
||||||
|
data={data}
|
||||||
|
repCompleteCount={repCompleteCount}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className={
|
||||||
|
whichTab === "accounts"
|
||||||
|
? "govuk-tabs__panel"
|
||||||
|
: "govuk-tabs__panel govuk-tabs__panel--hidden"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<AccountsTab userData={userData} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className={
|
||||||
|
whichTab === "appeals"
|
||||||
|
? "govuk-tabs__panel"
|
||||||
|
: "govuk-tabs__panel govuk-tabs__panel--hidden"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<AppealsTab
|
||||||
|
searchResultsObj={searchResultsObj}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className={
|
||||||
|
whichTab === "documents"
|
||||||
|
? "govuk-tabs__panel"
|
||||||
|
: "govuk-tabs__panel govuk-tabs__panel--hidden"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<DocumentsTab
|
||||||
|
documentDetailsObj={
|
||||||
|
props.searchResultsObj
|
||||||
|
.documentDetailsObj
|
||||||
|
}
|
||||||
|
docsOffline={docsOffline}
|
||||||
|
showFilteredDocs={props.showFilteredDocs}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Footer />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getServerSideProps = wrapper.getServerSideProps(
|
||||||
|
(store) => async (ctx) => {
|
||||||
|
const { query, req, res } = ctx;
|
||||||
|
// IP restriction check
|
||||||
|
const ALLOWED_IPS = process.env.ALLOWED_IPS
|
||||||
|
? process.env.ALLOWED_IPS.split(",").map((ip) => ip.trim())
|
||||||
|
: [];
|
||||||
|
const LOCALHOST_IPS = ["127.0.0.1", "::1"];
|
||||||
|
const forwarded = req.headers["x-forwarded-for"];
|
||||||
|
const ip =
|
||||||
|
typeof forwarded === "string"
|
||||||
|
? forwarded.split(",")[0]
|
||||||
|
: req.socket.remoteAddress;
|
||||||
|
|
||||||
|
if (![...ALLOWED_IPS, ...LOCALHOST_IPS].includes(ip)) {
|
||||||
|
return {
|
||||||
|
redirect: { destination: "/403", permanent: false },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 fetch actual data
|
||||||
|
const { data, userData, repCompleteCount } =
|
||||||
|
await fetchAdminStorageData();
|
||||||
|
|
||||||
|
const newAppeals = await getNewAppeals();
|
||||||
|
|
||||||
|
const searchDetailsObj = await getSearchDetails(newAppeals);
|
||||||
|
|
||||||
|
store.dispatch(setSearchResults(newAppeals));
|
||||||
|
store.dispatch(setSearchDetails(searchDetailsObj));
|
||||||
|
const state = store.getState();
|
||||||
|
|
||||||
|
store.dispatch(setCurrentPage(1));
|
||||||
|
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
data,
|
||||||
|
userData,
|
||||||
|
repCompleteCount,
|
||||||
|
docsOffline: process.env.DOCAPI_OFFLINE || false,
|
||||||
|
showFilteredDocs: process.env.SHOWFILTERDOCS || false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => {
|
||||||
|
return {
|
||||||
|
setCurrentPage: (currentPage) => {
|
||||||
|
dispatch(setCurrentPage(currentPage));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => {
|
||||||
|
console.log("===============================\n state:", state);
|
||||||
|
return {
|
||||||
|
searchResultsObj: state.searchResultsObj,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(StoragePage);
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/endpoint/getbasicsearch_api:
|
||||||
|
* get:
|
||||||
|
* tags: [Search]
|
||||||
|
* description: Basic search
|
||||||
|
* parameters:
|
||||||
|
* - name: searchString
|
||||||
|
* in: query
|
||||||
|
* required: true
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Success
|
||||||
|
*/
|
||||||
|
|
||||||
|
import axios from "axios";
|
||||||
|
import CryptoJS from "crypto-js";
|
||||||
|
import _ from "lodash";
|
||||||
|
import {
|
||||||
|
azureHeadersPagedCustom,
|
||||||
|
consoleLogger,
|
||||||
|
getToken,
|
||||||
|
} from "../../../actions";
|
||||||
|
import { number } from "prop-types";
|
||||||
|
|
||||||
|
const WORDKEY = process.env.HASHKEY;
|
||||||
|
|
||||||
|
const WEBAPI_URL =
|
||||||
|
process.env.RELAY_ROOT ||
|
||||||
|
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||||
|
|
||||||
|
const hashAPIPath = (queryPath) => {
|
||||||
|
var hashlink = CryptoJS.HmacSHA256(
|
||||||
|
queryPath,
|
||||||
|
CryptoJS.enc.Hex.parse(WORDKEY)
|
||||||
|
);
|
||||||
|
hashlink = hashlink.toString(CryptoJS.enc.Hex);
|
||||||
|
|
||||||
|
//return "&hash=" + hashlink;
|
||||||
|
|
||||||
|
return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
|
||||||
|
};
|
||||||
|
|
||||||
|
const encryptDocReference = (documentRef) => {
|
||||||
|
var hashlink = CryptoJS.HmacSHA256(
|
||||||
|
"documents/download/" + documentRef,
|
||||||
|
CryptoJS.enc.Hex.parse(WORDKEY)
|
||||||
|
);
|
||||||
|
hashlink = hashlink.toString(CryptoJS.enc.Hex);
|
||||||
|
|
||||||
|
var hashStr =
|
||||||
|
"/api/documents/download/" + documentRef + "?hash=" + hashlink;
|
||||||
|
|
||||||
|
return hashStr;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function ApiProxy(req, res) {
|
||||||
|
var pageNumber = req.query.pageNumber || 1;
|
||||||
|
var token = await getToken();
|
||||||
|
|
||||||
|
var orderby = req.query.orderby || "createdon";
|
||||||
|
var fieldSort = req.query.fieldSort || "desc";
|
||||||
|
var showNumberOfRecords = req.query.showNumberOfRecords || 10;
|
||||||
|
var documentType = req.query.documentType || "all";
|
||||||
|
var numberOfWeeks = req.query.numberWeeks || 1;
|
||||||
|
|
||||||
|
var docTypeQueryString = "";
|
||||||
|
|
||||||
|
if (documentType != "all") {
|
||||||
|
if (documentType.indexOf(",") >= 0) {
|
||||||
|
const documentTypeArr = documentType.split(",");
|
||||||
|
|
||||||
|
docTypeQueryString = " and (";
|
||||||
|
documentTypeArr.forEach(function (item, index) {
|
||||||
|
console.log(item, index);
|
||||||
|
|
||||||
|
if (item != "all") {
|
||||||
|
docTypeQueryString +=
|
||||||
|
" pinswg_isharedocumentlocations eq " + item;
|
||||||
|
|
||||||
|
docTypeQueryString +=
|
||||||
|
index < documentTypeArr.length - 1 ? " or " : "";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
docTypeQueryString += " )";
|
||||||
|
} else {
|
||||||
|
docTypeQueryString +=
|
||||||
|
" and pinswg_isharedocumentlocations eq " + documentType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function daysAgoISO(days) {
|
||||||
|
const today = new Date();
|
||||||
|
const resultDate = new Date(today);
|
||||||
|
resultDate.setUTCDate(today.getUTCDate() - days); // subtract weeks
|
||||||
|
resultDate.setUTCHours(0, 0, 0, 0); // reset time to 00:00:00
|
||||||
|
return resultDate.toISOString().replace(/\.000Z$/, "Z"); // format as 'YYYY-MM-DDT00:00:00Z'
|
||||||
|
}
|
||||||
|
|
||||||
|
function flattenDocuments(response) {
|
||||||
|
return {
|
||||||
|
...response,
|
||||||
|
value: Array.isArray(response.value)
|
||||||
|
? response.value.map((doc) => ({
|
||||||
|
...doc,
|
||||||
|
ticketnumber:
|
||||||
|
doc.pinswg_DocumentIds?.ticketnumber || null,
|
||||||
|
}))
|
||||||
|
: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var queryUrl =
|
||||||
|
"pinswg_documents?$select=pinswg_name,createdon,pinswg_publishtoweb,_pinswg_documentids_value,pinswg_isharedocumentlocations,pinswg_isharedocumentreference,pinswg_uploadurl,pinswg_uploadstatus,pinswg_origin&$filter=createdon ge " +
|
||||||
|
daysAgoISO(numberOfWeeks) +
|
||||||
|
docTypeQueryString +
|
||||||
|
"&$orderby=" +
|
||||||
|
orderby +
|
||||||
|
" " +
|
||||||
|
fieldSort +
|
||||||
|
"&$count=true" +
|
||||||
|
"&$expand=pinswg_DocumentIds($select = ticketnumber)" +
|
||||||
|
(typeof pageNumber != "undefined"
|
||||||
|
? "&$skiptoken=" + '<cookie pagenumber="' + pageNumber + '" />'
|
||||||
|
: "");
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"\n==========================================\n",
|
||||||
|
"\nnew docs search ",
|
||||||
|
"\n\nQuery url: " + queryUrl,
|
||||||
|
"\n\nRelay link: " + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||||
|
"\n==========================================\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
var apiResponse = axios
|
||||||
|
.get(
|
||||||
|
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||||
|
azureHeadersPagedCustom(token.access_token, showNumberOfRecords)
|
||||||
|
)
|
||||||
|
.then(({ data }) => {
|
||||||
|
let flattened = data.value.map((r) => ({
|
||||||
|
...r,
|
||||||
|
ticketnumber: r.pinswg_DocumentIds?.ticketnumber || null,
|
||||||
|
}));
|
||||||
|
|
||||||
|
data.value = flattened;
|
||||||
|
data.value.forEach(function (element) {
|
||||||
|
element.pinswg_hashlink = encryptDocReference(
|
||||||
|
element.pinswg_isharedocumentreference
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
var dataStr;
|
||||||
|
|
||||||
|
_.has(data, "@odata.nextLink") == true &&
|
||||||
|
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
||||||
|
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
||||||
|
res.status(200).json(data);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
consoleLogger(error);
|
||||||
|
res.status(400).json(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
return apiResponse;
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/endpoint/getbasicsearch_api:
|
||||||
|
* get:
|
||||||
|
* tags: [Search]
|
||||||
|
* description: Basic search
|
||||||
|
* parameters:
|
||||||
|
* - name: searchString
|
||||||
|
* in: query
|
||||||
|
* required: true
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Success
|
||||||
|
*/
|
||||||
|
|
||||||
|
import axios from "axios";
|
||||||
|
import CryptoJS from "crypto-js";
|
||||||
|
import _ from "lodash";
|
||||||
|
import {
|
||||||
|
azureHeadersPagedCustom,
|
||||||
|
consoleLogger,
|
||||||
|
getToken,
|
||||||
|
} from "../../../actions";
|
||||||
|
|
||||||
|
const WORDKEY = process.env.HASHKEY;
|
||||||
|
|
||||||
|
const WEBAPI_URL =
|
||||||
|
process.env.RELAY_ROOT ||
|
||||||
|
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||||
|
|
||||||
|
const hashAPIPath = (queryPath) => {
|
||||||
|
var hashlink = CryptoJS.HmacSHA256(
|
||||||
|
queryPath,
|
||||||
|
CryptoJS.enc.Hex.parse(WORDKEY)
|
||||||
|
);
|
||||||
|
hashlink = hashlink.toString(CryptoJS.enc.Hex);
|
||||||
|
|
||||||
|
//return "&hash=" + hashlink;
|
||||||
|
|
||||||
|
return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function ApiProxy(req, res) {
|
||||||
|
var searchString = req.query.searchString;
|
||||||
|
var pageNumber = req.query.pageNumber || 1;
|
||||||
|
var token = await getToken();
|
||||||
|
|
||||||
|
var orderby = req.query.orderby || "createdon";
|
||||||
|
var fieldSort = req.query.fieldSort || "desc";
|
||||||
|
var showNumberOfRecords = req.query.showNumberOfRecords || 10;
|
||||||
|
|
||||||
|
var queryUrl =
|
||||||
|
"incidents?$select=modifiedon,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference,pinswg_appellantagent,pinswg_appellantfirstname,pinswg_appellantlastname&$expand=primarycontactid($select=fullname)&$filter=caseorigincode eq 3&$orderby=" +
|
||||||
|
orderby +
|
||||||
|
" " +
|
||||||
|
fieldSort +
|
||||||
|
"&$count=true" +
|
||||||
|
(typeof pageNumber != "undefined"
|
||||||
|
? "&$skiptoken=" + '<cookie pagenumber="' + pageNumber + '" />'
|
||||||
|
: "");
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"\n==========================================\n",
|
||||||
|
"\nnew appeal search ",
|
||||||
|
"\n\nQuery url: " + queryUrl,
|
||||||
|
"\n\nRelay link: " + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||||
|
"\n==========================================\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
var apiResponse = axios
|
||||||
|
.get(
|
||||||
|
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||||
|
azureHeadersPagedCustom(token.access_token, showNumberOfRecords)
|
||||||
|
)
|
||||||
|
.then(({ data }) => {
|
||||||
|
var dataStr;
|
||||||
|
_.has(data, "@odata.nextLink") == true &&
|
||||||
|
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
||||||
|
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
||||||
|
res.status(200).json(data);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
consoleLogger(error);
|
||||||
|
res.status(400).json(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
return apiResponse;
|
||||||
|
}
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
import { DefaultAzureCredential } from "@azure/identity";
|
|
||||||
import { BlobServiceClient, ContainerClient } from "@azure/storage-blob";
|
|
||||||
import { v4 as uuidv4 } from "uuid";
|
|
||||||
import { wrapper } from "../store/store";
|
|
||||||
|
|
||||||
import { getIP } from "../actions";
|
|
||||||
|
|
||||||
const ShowStorage = (props) => {
|
|
||||||
const { container } = props;
|
|
||||||
//console.log("Containers:");
|
|
||||||
// // for await (const container of blobServiceClient.listContainers()) {
|
|
||||||
// // console.log(`- ${container.name}`);
|
|
||||||
// // }
|
|
||||||
|
|
||||||
console.log(container);
|
|
||||||
|
|
||||||
return <div>hello</div>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getServerSideProps = wrapper.getServerSideProps(
|
|
||||||
(store) => async (ctx) => {
|
|
||||||
const { query, req, res } = ctx;
|
|
||||||
getIP(req);
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
"have therese?:",
|
|
||||||
process.env.AZURE_TENANT_ID,
|
|
||||||
process.env.AZURE_CLIENT_ID,
|
|
||||||
process.env.AZURE_CLIENT_SECRET
|
|
||||||
);
|
|
||||||
|
|
||||||
const creds = new DefaultAzureCredential();
|
|
||||||
|
|
||||||
const blobServiceClient = new BlobServiceClient(
|
|
||||||
`https://pedwdev.blob.core.windows.net`,
|
|
||||||
creds
|
|
||||||
);
|
|
||||||
|
|
||||||
const containerName = `CAS-999999-22222`;
|
|
||||||
|
|
||||||
const containerClient = new ContainerClient(
|
|
||||||
`https://pedwdev.blob.core.windows.net/${containerName}`,
|
|
||||||
creds
|
|
||||||
);
|
|
||||||
|
|
||||||
//const createContainerResponse = await containerClient.create();
|
|
||||||
//console.log(
|
|
||||||
// `Created container ${containerName} successfully`,
|
|
||||||
// createContainerResponse.requestId
|
|
||||||
// );
|
|
||||||
|
|
||||||
console.log("Containers:");
|
|
||||||
for await (const container of blobServiceClient.listContainers()) {
|
|
||||||
console.log(`- ${container.name}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const appealID = uuidv4();
|
|
||||||
const uploadOptions = {
|
|
||||||
metadata: { reviewer: "john", reviewDate: "2022-04-01" },
|
|
||||||
tags: { owner: appealID },
|
|
||||||
};
|
|
||||||
// for (let index = 0; index < 7; index++) {
|
|
||||||
// // Create a blob
|
|
||||||
// const content = "hello";
|
|
||||||
// const blobName = appealID + "/BOBnewblob" + new Date().getTime();
|
|
||||||
// const blockBlobClient =
|
|
||||||
// containerClient.getBlockBlobClient(blobName);
|
|
||||||
|
|
||||||
// //const uploadBlobResponse = await blockBlobClient.upload(
|
|
||||||
// // content,
|
|
||||||
// // Buffer.byteLength(content),
|
|
||||||
// // uploadOptions
|
|
||||||
// // );
|
|
||||||
|
|
||||||
// const uploadBlobResponse = await blockBlobClient.uploadFile(
|
|
||||||
// "public/assets/images/HM-Govt-Supplier-to-Govt.jpg"
|
|
||||||
// // uploadOptions
|
|
||||||
// );
|
|
||||||
|
|
||||||
// const tags = {
|
|
||||||
// owner: appealID,
|
|
||||||
// };
|
|
||||||
|
|
||||||
// //console.log(tags);
|
|
||||||
// //await blockBlobClient.setTags(tags);
|
|
||||||
|
|
||||||
// //console.log(
|
|
||||||
// // `Uploaded block blob ${blobName} successfully`,
|
|
||||||
// // uploadBlobResponse.requestId
|
|
||||||
// // );
|
|
||||||
// }
|
|
||||||
|
|
||||||
console.log("Blobs:");
|
|
||||||
for await (const blob of containerClient.listBlobsFlat()) {
|
|
||||||
console.log(`- ${blob.name}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export default ShowStorage;
|
|
||||||
@@ -1,759 +0,0 @@
|
|||||||
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