mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
fix: Audit log human parse message and nullable diffs (#3978)
* fix: Audit log human parse message and nullable diffs * Fix diff values
This commit is contained in:
@ -4,11 +4,20 @@ import { colors } from "theme/colors"
|
|||||||
import { MONOSPACE_FONT_FAMILY } from "theme/constants"
|
import { MONOSPACE_FONT_FAMILY } from "theme/constants"
|
||||||
import { combineClasses } from "util/combineClasses"
|
import { combineClasses } from "util/combineClasses"
|
||||||
|
|
||||||
const getDiffValue = (value: number | string | boolean) => {
|
const getDiffValue = (value: unknown): string => {
|
||||||
if (typeof value === "string") {
|
if (typeof value === "string") {
|
||||||
return `"${value}"`
|
return `"${value}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
const values = value.map((v) => getDiffValue(v))
|
||||||
|
return `[${values.join(", ")}]`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value === null || value === undefined) {
|
||||||
|
return "null"
|
||||||
|
}
|
||||||
|
|
||||||
return value.toString()
|
return value.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import { CloseDropdown, OpenDropdown } from "components/DropdownArrows/DropdownA
|
|||||||
import { Pill } from "components/Pill/Pill"
|
import { Pill } from "components/Pill/Pill"
|
||||||
import { Stack } from "components/Stack/Stack"
|
import { Stack } from "components/Stack/Stack"
|
||||||
import { UserAvatar } from "components/UserAvatar/UserAvatar"
|
import { UserAvatar } from "components/UserAvatar/UserAvatar"
|
||||||
import { t } from "i18next"
|
|
||||||
import { ComponentProps, useState } from "react"
|
import { ComponentProps, useState } from "react"
|
||||||
import { MONOSPACE_FONT_FAMILY } from "theme/constants"
|
import { MONOSPACE_FONT_FAMILY } from "theme/constants"
|
||||||
import userAgentParser from "ua-parser-js"
|
import userAgentParser from "ua-parser-js"
|
||||||
@ -26,26 +25,10 @@ const pillTypeByHttpStatus = (httpStatus: number): ComponentProps<typeof Pill>["
|
|||||||
return "success"
|
return "success"
|
||||||
}
|
}
|
||||||
|
|
||||||
const actionLabelByAction: Record<AuditLog["action"], string> = {
|
|
||||||
create: t("actions.create", { ns: "auditLog" }),
|
|
||||||
write: t("actions.write", { ns: "auditLog" }),
|
|
||||||
delete: t("actions.delete", { ns: "auditLog" }),
|
|
||||||
}
|
|
||||||
|
|
||||||
const resourceLabelByResourceType: Record<AuditLog["resource_type"], string> = {
|
|
||||||
organization: "organization",
|
|
||||||
template: "template",
|
|
||||||
template_version: "template version",
|
|
||||||
user: "user",
|
|
||||||
workspace: "workspace",
|
|
||||||
git_ssh_key: "git ssh key",
|
|
||||||
api_key: "api key",
|
|
||||||
}
|
|
||||||
|
|
||||||
const readableActionMessage = (auditLog: AuditLog) => {
|
const readableActionMessage = (auditLog: AuditLog) => {
|
||||||
return `${actionLabelByAction[auditLog.action]} ${
|
return auditLog.description
|
||||||
resourceLabelByResourceType[auditLog.resource_type]
|
.replace("{user}", `<strong>${auditLog.user?.username}</strong>`)
|
||||||
}`
|
.replace("{target}", `<strong>${auditLog.resource_target}</strong>`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AuditLogRowProps {
|
export interface AuditLogRowProps {
|
||||||
@ -98,10 +81,10 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
|
|||||||
avatarURL={auditLog.user?.avatar_url}
|
avatarURL={auditLog.user?.avatar_url}
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
<span className={styles.auditLogResume}>
|
<span
|
||||||
<strong>{auditLog.user?.username}</strong> {readableActionMessage(auditLog)}{" "}
|
className={styles.auditLogResume}
|
||||||
<strong>{auditLog.resource_target}</strong>
|
dangerouslySetInnerHTML={{ __html: readableActionMessage(auditLog) }}
|
||||||
</span>
|
/>
|
||||||
<span className={styles.auditLogTime}>{createDayString(auditLog.time)}</span>
|
<span className={styles.auditLogTime}>{createDayString(auditLog.time)}</span>
|
||||||
</div>
|
</div>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
@ -775,7 +775,7 @@ export const MockAuditLog: TypesGen.AuditLog = {
|
|||||||
diff: {},
|
diff: {},
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
additional_fields: "",
|
additional_fields: "",
|
||||||
description: "Colin Adler updated the workspace bruno-dev",
|
description: "{user} updated workspace {target}",
|
||||||
user: MockUser,
|
user: MockUser,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -799,5 +799,10 @@ export const MockAuditLog2: TypesGen.AuditLog = {
|
|||||||
new: "53bded77-7b9d-4e82-8771-991a34d759f9",
|
new: "53bded77-7b9d-4e82-8771-991a34d759f9",
|
||||||
secret: false,
|
secret: false,
|
||||||
},
|
},
|
||||||
|
roles: {
|
||||||
|
old: null,
|
||||||
|
new: ["admin", "auditor"],
|
||||||
|
secret: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user