Skip to content

Commit

Permalink
Frontend logging: add DEA and roles
Browse files Browse the repository at this point in the history
  • Loading branch information
Amy Chen authored and Amy Chen committed Dec 24, 2024
1 parent 572e5fa commit a3dbe86
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/helpers/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ export function writeToLog(message, level, params) {
const logLevel = level ? level : "info";
// use Object.assign to prevent modification of original params
const logParams = Object.assign({}, params ? params : {});

if (!logParams.tags) logParams.tags = [];
const COSRI_FRONTEND_TAG = "cosri-frontend";
if (logParams.tags.indexOf(COSRI_FRONTEND_TAG) === -1) {
Expand All @@ -588,6 +589,21 @@ export function writeToLog(message, level, params) {
};
}
}

if (Object.keys(logParams).indexOf("DEA") === -1) {
const dea = getDEAFromAccessToken();
if (dea) {
logParams.DEA = dea;
}
}

if (Object.keys(logParams).indexOf("roles") === -1) {
const roles = getRealmRolesFromAccessToken();
if (roles) {
logParams.roles = roles;
}
}

const auditURL = `${getEnvConfidentialAPIURL()}/auditlog`;
const patientName = params.patientName ? params.patientName : "";
let messageString = "";
Expand Down Expand Up @@ -732,6 +748,19 @@ export function getUserIdFromAccessToken() {
return accessToken["preferred_username"];
}

export function getDEAFromAccessToken() {
const accessToken = getTokenInfoFromStorage();
if (!accessToken) return null;
return accessToken.DEA;
}

export function getRealmRolesFromAccessToken() {
const accessToken = getTokenInfoFromStorage();
if (!accessToken) return null;
if (!accessToken["realm_access"]) return null;
return accessToken["realm_access"].roles;
}

export function addMatomoTracking() {
// already generated script, return
if (document.querySelector("#matomoScript")) return;
Expand Down

0 comments on commit a3dbe86

Please sign in to comment.