Skip to content

Add build number to workspace_build audit logs #5267

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

Merged
merged 15 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
added translations
  • Loading branch information
Kira-Pilot committed Nov 23, 2022
commit c988b1a8590bc5bb192d68e04f317827cc0d0bb8
66 changes: 23 additions & 43 deletions site/src/components/AuditLogRow/AuditLogRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,25 @@ import { PaletteIndex } from "theme/palettes"
import userAgentParser from "ua-parser-js"
import { combineClasses } from "util/combineClasses"
import { AuditLogDiff } from "./AuditLogDiff"
import { Link } from "react-router-dom"
import { Link as RouterLink } from "react-router-dom"
import i18next from "i18next"
import Link from "@material-ui/core/Link"

// const determineInitiator = (auditLog: AuditLog): string => {
// return auditLog.
// }
const determineResourceLink = (auditLog: AuditLog): string => {
const { t } = i18next
let linkTarget = auditLog.resource_target.trim()

const determineResourceTarget = (auditLog: AuditLog): string => {
let target = auditLog.resource_target.trim()

// audit logs with a resource_type of workspace build use workspace name as a target
if (auditLog.resource_type === "workspace_build") {
// target = auditLog.additional_fields.workspaceName.trim()
target = "build"
linkTarget = t("auditLog:table.logRow.buildTarget")
}

return target
return linkTarget
}

export const readableActionMessage = (auditLog: AuditLog): string => {
// let target = auditLog.resource_target.trim()

// audit logs with a resource_type of workspace build use workspace name as a target
// if (
// auditLog.resource_type === "workspace_build" &&
// auditLog.additional_fields.workspaceName
// ) {
// target = auditLog.additional_fields.workspaceName.trim()
// }

return auditLog.description
.replace("{user}", `${auditLog.user?.username.trim()}`)
.replace("{target}", "")

// return auditLog.description
// .replace("{user}", `<strong>${auditLog.user?.username.trim()}</strong>`)
// .replace(
// "{target}",
// `<Link to=/@${auditLog.user?.username.trim()}/${target}>${target}</Link>`,
// )
}

const httpStatusColor = (httpStatus: number): PaletteIndex => {
Expand All @@ -79,6 +59,7 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
defaultIsDiffOpen = false,
}) => {
const styles = useStyles()
const { t } = i18next
const [isDiffOpen, setIsDiffOpen] = useState(defaultIsDiffOpen)
const diffs = Object.entries(auditLog.diff)
const shouldDisplayDiff = diffs.length > 0
Expand Down Expand Up @@ -145,23 +126,19 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
>
<span>
{readableActionMessage(auditLog)}{" "}
<Link to={auditLog.resource_link}>
{determineResourceTarget(auditLog)}
</Link>
{auditLog.resource_link && (
<Link component={RouterLink} to={auditLog.resource_link}>
{determineResourceLink(auditLog)}
</Link>
)}
{auditLog.resource_type === "workspace_build" &&
auditLog.additional_fields.workspaceName && (
<span>
{" "}
for workspace{" "}
<>
{t("auditLog:table.logRow.buildFriendlyString")}
{auditLog.additional_fields.workspaceName}
</span>
</>
)}
</span>
{/* <span
dangerouslySetInnerHTML={{
__html: readableActionMessage(auditLog),
}}
/> */}
<span className={styles.auditLogTime}>
{new Date(auditLog.time).toLocaleTimeString()}
</span>
Expand All @@ -170,15 +147,18 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
<Stack direction="row" alignItems="center">
<Stack direction="row" spacing={1} alignItems="baseline">
<span className={styles.auditLogInfo}>
IP: <strong>{auditLog.ip ?? notAvailableLabel}</strong>
<>{t("auditLog:table.logRow.ip")}</>
<strong>{auditLog.ip ?? notAvailableLabel}</strong>
</span>

<span className={styles.auditLogInfo}>
OS: <strong>{os.name ?? notAvailableLabel}</strong>
<>{t("auditLog:table.logRow.os")}</>
<strong>{os.name ?? notAvailableLabel}</strong>
</span>

<span className={styles.auditLogInfo}>
Browser: <strong>{displayBrowserInfo}</strong>
<>{t("auditLog:table.logRow.browser")}</>
<strong>{displayBrowserInfo}</strong>
</span>
</Stack>

Expand Down
9 changes: 8 additions & 1 deletion site/src/i18n/en/auditLog.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
},
"table": {
"emptyPage": "No audit logs available on this page",
"noLogs": "No audit logs available"
"noLogs": "No audit logs available",
"logRow": {
"buildTarget": "build",
"buildFriendlyString": " for workspace ",
"ip": "IP: ",
"os": "OS: ",
"Browser": "Browser: "
}
}
}