Skip to content

Commit

Permalink
fix: Audit details fixes RELEASE (#792)
Browse files Browse the repository at this point in the history
## Related Issues

Fixes descope/etc#7270

---------

Co-authored-by: Doron Sharon <[email protected]>
  • Loading branch information
nirgur and dorsha authored Sep 5, 2024
1 parent 92cb855 commit f681085
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type Sdk = ReturnType<typeof createWebSdk>;
export type HttpClient = Sdk['httpClient'];

export type Audit = {
ID?: string;
id: string;
userId: string;
action: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const initAuditTableMixin = createSingletonMixin(
loggerMixin,
initWidgetRootMixin,
)(superclass) {
auditTable: GridDriver<Audit>;
auditTable: GridDriver<Partial<Audit>>;

#initAuditTable() {
this.auditTable = new GridDriver(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const capitalize = (s: string) => s && s[0].toUpperCase() + s.slice(1);

export const conditionalObj = <T extends any>(key: string, val: T) =>
val ? { [key]: val } : {};

export const conditionalJsonParse = (str: string) => {
if (!str) return undefined;

const res = JSON.parse(str);

if (Array.isArray(res) && res.length === 0) return undefined;

return res;
};
Original file line number Diff line number Diff line change
@@ -1,17 +1,66 @@
import { createSelector } from 'reselect';
import { State } from './types';
import { capitalize, conditionalJsonParse, conditionalObj } from './helpers';

export const getRawAuditList = (state: State) => state.auditList.data;
export const getSelectedAuditId = (state: State) => state.selectedAuditId;
export const getSearchParams = (state: State) => state.searchParams;

export const getAuditList = createSelector(getRawAuditList, (audits) =>
audits.map((audit) => ({
...audit,
occurredFormatted: !audit?.occurred
? 'N/A'
: new Date(Number(audit?.occurred) || 0).toLocaleString(),
})),
audits.map((audit) => {
const {
occurred,
ID,
type,
data: {
// eslint-disable-next-line @typescript-eslint/naming-convention
saml_request,
// eslint-disable-next-line @typescript-eslint/naming-convention
saml_response,
// eslint-disable-next-line @typescript-eslint/naming-convention
saml_generated_user,
// eslint-disable-next-line @typescript-eslint/naming-convention
saml_generated_roles,
// eslint-disable-next-line @typescript-eslint/naming-convention
oidc_response,
// eslint-disable-next-line @typescript-eslint/naming-convention
oidc_generated_user,
...data
} = {
saml_request: '',
saml_response: '',
saml_generated_user: '',
saml_generated_roles: '',
oidc_response: '',
oidc_generated_user: '',
},
...auditRest
} = audit || {};

return {
...auditRest,
data,
...conditionalObj('type', capitalize(type)),
...conditionalObj('saml_request', saml_request),
...conditionalObj('saml_response', saml_response),
...conditionalObj(
'saml_generated_user',
conditionalJsonParse(saml_generated_user),
),
...conditionalObj(
'saml_generated_roles',
conditionalJsonParse(saml_generated_roles),
),
...conditionalObj('oidc_response', conditionalJsonParse(oidc_response)),
...conditionalObj(
'oidc_generated_user',
conditionalJsonParse(oidc_generated_user),
),
occurredFormatted: !occurred
? 'N/A'
: new Date(Number(occurred) || 0).toLocaleString(),
};
}),
);

export const getSelectedAudit = createSelector(
Expand Down
48 changes: 25 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f681085

Please sign in to comment.