Skip to content

chore: change build audit log string to be clearer #6093

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 10 commits into from
Feb 8, 2023
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
Next Next commit
changed bbuild string
  • Loading branch information
Kira-Pilot committed Feb 7, 2023
commit f9d28b0f8b9c02658f14392d9537ae08a9af55fe
6 changes: 2 additions & 4 deletions site/src/components/AuditLogRow/AuditLogDescription.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ describe("AuditLogDescription", () => {
it("renders the correct string for a workspace_build stop audit log", async () => {
render(<AuditLogDescription auditLog={MockAuditLogWithWorkspaceBuild} />)

expect(
getByTextContent("TestUser stopped build for workspace test2"),
).toBeDefined()
expect(getByTextContent("TestUser stopped workspace test2")).toBeDefined()
})

it("renders the correct string for a workspace_build audit log with a duplicate word", async () => {
Expand All @@ -48,7 +46,7 @@ describe("AuditLogDescription", () => {
render(<AuditLogDescription auditLog={AuditLogWithRepeat} />)

expect(
getByTextContent("TestUser stopped build for workspace workspace"),
getByTextContent("TestUser stopped workspace workspace"),
).toBeDefined()
})
it("renders the correct string for a workspace created for a different owner", async () => {
Expand Down
54 changes: 43 additions & 11 deletions site/src/components/AuditLogRow/AuditLogDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,56 @@ import Link from "@material-ui/core/Link"
import { makeStyles } from "@material-ui/core/styles"
import i18next from "i18next"

const BuildAuditDescription: FC<{ auditLog: AuditLog }> = ({
auditLog,
}): JSX.Element => {
const { t } = i18next

// audit logs with a resource_type of workspace build use workspace name as a target
const target = auditLog.additional_fields?.workspace_name?.trim()
// workspaces can be started/stopped by a user, or kicked off automatically by Coder
const user =
auditLog.additional_fields?.build_reason &&
auditLog.additional_fields?.build_reason !== "initiator"
? t("auditLog:table.logRow.buildReason")
: auditLog.user?.username.trim()

const actionVerb =
auditLog.action === "start"
? t("auditLog:table.logRow.started")
: t("auditLog:table.logRow.stopped")

return (
<span>
<>
{user}{" "}
{auditLog.resource_link ? (
<Link component={RouterLink} to={auditLog.resource_link}>
<strong>{actionVerb}</strong>
</Link>
) : (
{ actionVerb }
)}{" "}
{t("auditLog:table.logRow.workspace")}
<strong>{target}</strong>
</>
</span>
)
}

export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
auditLog,
}): JSX.Element => {
const classes = useStyles()
const { t } = i18next

let target = auditLog.resource_target.trim()
let user = auditLog.user
const target = auditLog.resource_target.trim()
const user = auditLog.user
? auditLog.user.username.trim()
: t("auditLog:table.logRow.unknownUser")

if (auditLog.resource_type === "workspace_build") {
// audit logs with a resource_type of workspace build use workspace name as a target
target = auditLog.additional_fields?.workspace_name?.trim()
// workspaces can be started/stopped by a user, or kicked off automatically by Coder
user =
auditLog.additional_fields?.build_reason &&
auditLog.additional_fields?.build_reason !== "initiator"
? t("auditLog:table.logRow.buildReason")
: user
return <BuildAuditDescription auditLog={auditLog} />
}

// SSH key entries have no links
Expand Down Expand Up @@ -59,7 +89,9 @@ export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
)}
{/* logs for workspaces created on behalf of other users indicate ownership in the description */}
{auditLog.additional_fields.workspace_owner &&
auditLog.additional_fields.workspace_owner !== "unknown" && (
auditLog.additional_fields.workspace_owner !== "unknown" &&
auditLog.additional_fields.workspace_owner !==
auditLog.user?.username && (
<span>
<>
{t("auditLog:table.logRow.onBehalfOf", {
Expand Down
5 changes: 4 additions & 1 deletion site/src/i18n/en/auditLog.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"browser": "Browser: ",
"onBehalfOf": " on behalf of {{owner}}",
"buildReason": "Coder automatically",
"unknownUser": "an unknown user"
"unknownUser": "an unknown user",
"started": "started",
"stopped": "stopped",
"workspace": " workspace "
}
},
"paywall": {
Expand Down