Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend logging: add DEA and roles #222

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading