-
Notifications
You must be signed in to change notification settings - Fork 887
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f9d28b0
changed bbuild string
Kira-Pilot 7f71c2a
clean up friendly string
Kira-Pilot 0125d4f
using Trans component
Kira-Pilot c182357
general cleanup
Kira-Pilot 7ca2a8b
fixed tests
Kira-Pilot 57c1529
fix lint
Kira-Pilot ec75fb7
Merge remote-tracking branch 'origin/main' into fix-build-string/kira…
Kira-Pilot d0ba8eb
fixing bolding
Kira-Pilot 3a34e5e
removing dead strings in auditLogRow
Kira-Pilot a2b461e
fix tests
Kira-Pilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,13 @@ import { | |
MockAuditLogUnsuccessfulLoginUnknownUser, | ||
} from "testHelpers/entities" | ||
import { AuditLogDescription } from "./AuditLogDescription" | ||
import { AuditLogRow } from "./AuditLogRow" | ||
import { render } from "../../testHelpers/renderHelpers" | ||
import { AuditLogRow } from "../AuditLogRow" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests aren't perfect - I was having difficulty testing strings with an embedded |
||
import { render } from "testHelpers/renderHelpers" | ||
import { screen } from "@testing-library/react" | ||
import { i18n } from "i18n" | ||
|
||
const t = (str: string, variables?: Record<string, unknown>) => | ||
i18n.t<string>(str, variables) | ||
|
||
const getByTextContent = (text: string) => { | ||
return screen.getByText((_, element) => { | ||
|
@@ -25,17 +29,14 @@ describe("AuditLogDescription", () => { | |
it("renders the correct string for a workspace create audit log", async () => { | ||
render(<AuditLogDescription auditLog={MockAuditLog} />) | ||
|
||
expect( | ||
getByTextContent("TestUser created workspace bruno-dev"), | ||
).toBeDefined() | ||
expect(screen.getByText("TestUser created workspace")).toBeDefined() | ||
expect(screen.getByText("bruno-dev")).toBeDefined() | ||
}) | ||
|
||
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 () => { | ||
|
@@ -48,7 +49,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 () => { | ||
|
@@ -57,27 +58,68 @@ describe("AuditLogDescription", () => { | |
auditLog={MockWorkspaceCreateAuditLogForDifferentOwner} | ||
/>, | ||
) | ||
|
||
expect( | ||
getByTextContent( | ||
`TestUser created workspace bruno-dev on behalf of ${MockWorkspaceCreateAuditLogForDifferentOwner.additional_fields.workspace_owner}`, | ||
screen.getByText( | ||
`on behalf of ${MockWorkspaceCreateAuditLogForDifferentOwner.additional_fields.workspace_owner}`, | ||
{ exact: false }, | ||
), | ||
).toBeDefined() | ||
}) | ||
it("renders the correct string for successful login", async () => { | ||
render(<AuditLogRow auditLog={MockAuditLogSuccessfulLogin} />) | ||
expect(getByTextContent(`TestUser logged in`)).toBeDefined() | ||
|
||
expect( | ||
screen.getByText( | ||
t("auditLog:table.logRow.description.unlinkedAuditDescription", { | ||
truncatedDescription: `${MockAuditLogSuccessfulLogin.user?.username} logged in`, | ||
target: "", | ||
onBehalfOf: undefined, | ||
}) | ||
.replace(/<[^>]*>/g, " ") | ||
.replace(/\s{2,}/g, " ") | ||
.trim(), | ||
), | ||
).toBeInTheDocument() | ||
|
||
const statusPill = screen.getByRole("status") | ||
expect(statusPill).toHaveTextContent("201") | ||
}) | ||
it("renders the correct string for unsuccessful login for a known user", async () => { | ||
render(<AuditLogRow auditLog={MockAuditLogUnsuccessfulLoginKnownUser} />) | ||
expect(getByTextContent(`TestUser logged in`)).toBeDefined() | ||
|
||
expect( | ||
screen.getByText( | ||
t("auditLog:table.logRow.description.unlinkedAuditDescription", { | ||
truncatedDescription: `${MockAuditLogUnsuccessfulLoginKnownUser.user?.username} logged in`, | ||
target: "", | ||
onBehalfOf: undefined, | ||
}) | ||
.replace(/<[^>]*>/g, " ") | ||
.replace(/\s{2,}/g, " ") | ||
.trim(), | ||
), | ||
).toBeInTheDocument() | ||
|
||
const statusPill = screen.getByRole("status") | ||
expect(statusPill).toHaveTextContent("401") | ||
}) | ||
it("renders the correct string for unsuccessful login for an unknown user", async () => { | ||
render(<AuditLogRow auditLog={MockAuditLogUnsuccessfulLoginUnknownUser} />) | ||
expect(getByTextContent(`an unknown user logged in`)).toBeDefined() | ||
|
||
expect( | ||
screen.getByText( | ||
t("auditLog:table.logRow.description.unlinkedAuditDescription", { | ||
truncatedDescription: "an unknown user logged in", | ||
target: "", | ||
onBehalfOf: undefined, | ||
}) | ||
.replace(/<[^>]*>/g, " ") | ||
.replace(/\s{2,}/g, " ") | ||
.trim(), | ||
), | ||
).toBeInTheDocument() | ||
|
||
const statusPill = screen.getByRole("status") | ||
expect(statusPill).toHaveTextContent("401") | ||
}) | ||
|
68 changes: 68 additions & 0 deletions
68
site/src/components/AuditLogRow/AuditLogDescription/AuditLogDescription.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { FC } from "react" | ||
import { AuditLog } from "api/typesGenerated" | ||
import { Link as RouterLink } from "react-router-dom" | ||
import Link from "@material-ui/core/Link" | ||
import { Trans, useTranslation } from "react-i18next" | ||
import { BuildAuditDescription } from "./BuildAuditDescription" | ||
|
||
export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({ | ||
auditLog, | ||
}): JSX.Element => { | ||
const { t } = useTranslation("auditLog") | ||
|
||
let target = auditLog.resource_target.trim() | ||
const user = auditLog.user ? auditLog.user.username.trim() : "an unknown user" | ||
|
||
if (auditLog.resource_type === "workspace_build") { | ||
return <BuildAuditDescription auditLog={auditLog} /> | ||
} | ||
|
||
// SSH key entries have no links | ||
if (auditLog.resource_type === "git_ssh_key") { | ||
target = "" | ||
} | ||
|
||
const truncatedDescription = auditLog.description | ||
.replace("{user}", `${user}`) | ||
.replace("{target}", "") | ||
|
||
// logs for workspaces created on behalf of other users indicate ownership in the description | ||
const onBehalfOf = | ||
auditLog.additional_fields.workspace_owner && | ||
auditLog.additional_fields.workspace_owner !== "unknown" && | ||
auditLog.additional_fields.workspace_owner !== auditLog.user?.username | ||
? `on behalf of ${auditLog.additional_fields.workspace_owner}` | ||
: "" | ||
|
||
if (auditLog.resource_link) { | ||
return ( | ||
<span> | ||
<Trans | ||
t={t} | ||
i18nKey="table.logRow.description.linkedAuditDescription" | ||
values={{ truncatedDescription, target, onBehalfOf }} | ||
> | ||
{"{{truncatedDescription}}"} | ||
<Link component={RouterLink} to={auditLog.resource_link}> | ||
<strong>{"{{target}}"}</strong> | ||
</Link> | ||
{"{{onBehalfOf}}"} | ||
</Trans> | ||
</span> | ||
) | ||
} | ||
|
||
return ( | ||
<span> | ||
<Trans | ||
t={t} | ||
i18nKey="table.logRow.description.unlinkedAuditDescription" | ||
values={{ truncatedDescription, target, onBehalfOf }} | ||
> | ||
{"{{truncatedDescription}}"} | ||
<strong>{"{{target}}"}</strong> | ||
{"{{onBehalfOf}}"} | ||
</Trans> | ||
</span> | ||
) | ||
} |
52 changes: 52 additions & 0 deletions
52
site/src/components/AuditLogRow/AuditLogDescription/BuildAuditDescription.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Trans, useTranslation } from "react-i18next" | ||
import { AuditLog } from "api/typesGenerated" | ||
import { FC } from "react" | ||
import { Link as RouterLink } from "react-router-dom" | ||
import Link from "@material-ui/core/Link" | ||
|
||
export const BuildAuditDescription: FC<{ auditLog: AuditLog }> = ({ | ||
auditLog, | ||
}): JSX.Element => { | ||
const { t } = useTranslation("auditLog") | ||
|
||
const workspaceName = 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" | ||
? "Coder automatically" | ||
: auditLog.user?.username.trim() | ||
|
||
const action = auditLog.action === "start" ? "started" : "stopped" | ||
|
||
if (auditLog.resource_link) { | ||
return ( | ||
<span> | ||
<Trans | ||
t={t} | ||
i18nKey="table.logRow.description.linkedWorkspaceBuild" | ||
values={{ user, action, workspaceName }} | ||
> | ||
{"{{user}}"} | ||
<Link component={RouterLink} to={auditLog.resource_link}> | ||
{"{{action}}"} | ||
</Link> | ||
workspace{"{{workspaceName}}"} | ||
</Trans> | ||
</span> | ||
) | ||
} | ||
|
||
return ( | ||
<span> | ||
<Trans | ||
t={t} | ||
i18nKey="table.logRow.description.unlinkedWorkspaceBuild" | ||
values={{ user, action, workspaceName }} | ||
> | ||
{"{{user}}"} | ||
{"{{action}}"}workspace{"{{workspaceName}}"} | ||
</Trans> | ||
</span> | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { AuditLogDescription } from "./AuditLogDescription" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { AuditLogDiff } from "./AuditLogDiff" | ||
export { determineGroupDiff } from "./auditUtils" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're getting changes here because I ran into this issue and had to re-add canvas.