Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9d28b0

Browse files
committed
changed bbuild string
1 parent 3724d81 commit f9d28b0

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

site/src/components/AuditLogRow/AuditLogDescription.test.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ describe("AuditLogDescription", () => {
3333
it("renders the correct string for a workspace_build stop audit log", async () => {
3434
render(<AuditLogDescription auditLog={MockAuditLogWithWorkspaceBuild} />)
3535

36-
expect(
37-
getByTextContent("TestUser stopped build for workspace test2"),
38-
).toBeDefined()
36+
expect(getByTextContent("TestUser stopped workspace test2")).toBeDefined()
3937
})
4038

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

5048
expect(
51-
getByTextContent("TestUser stopped build for workspace workspace"),
49+
getByTextContent("TestUser stopped workspace workspace"),
5250
).toBeDefined()
5351
})
5452
it("renders the correct string for a workspace created for a different owner", async () => {

site/src/components/AuditLogRow/AuditLogDescription.tsx

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,56 @@ import Link from "@material-ui/core/Link"
55
import { makeStyles } from "@material-ui/core/styles"
66
import i18next from "i18next"
77

8+
const BuildAuditDescription: FC<{ auditLog: AuditLog }> = ({
9+
auditLog,
10+
}): JSX.Element => {
11+
const { t } = i18next
12+
13+
// audit logs with a resource_type of workspace build use workspace name as a target
14+
const target = auditLog.additional_fields?.workspace_name?.trim()
15+
// workspaces can be started/stopped by a user, or kicked off automatically by Coder
16+
const user =
17+
auditLog.additional_fields?.build_reason &&
18+
auditLog.additional_fields?.build_reason !== "initiator"
19+
? t("auditLog:table.logRow.buildReason")
20+
: auditLog.user?.username.trim()
21+
22+
const actionVerb =
23+
auditLog.action === "start"
24+
? t("auditLog:table.logRow.started")
25+
: t("auditLog:table.logRow.stopped")
26+
27+
return (
28+
<span>
29+
<>
30+
{user}{" "}
31+
{auditLog.resource_link ? (
32+
<Link component={RouterLink} to={auditLog.resource_link}>
33+
<strong>{actionVerb}</strong>
34+
</Link>
35+
) : (
36+
{ actionVerb }
37+
)}{" "}
38+
{t("auditLog:table.logRow.workspace")}
39+
<strong>{target}</strong>
40+
</>
41+
</span>
42+
)
43+
}
44+
845
export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
946
auditLog,
1047
}): JSX.Element => {
1148
const classes = useStyles()
1249
const { t } = i18next
1350

14-
let target = auditLog.resource_target.trim()
15-
let user = auditLog.user
51+
const target = auditLog.resource_target.trim()
52+
const user = auditLog.user
1653
? auditLog.user.username.trim()
1754
: t("auditLog:table.logRow.unknownUser")
1855

1956
if (auditLog.resource_type === "workspace_build") {
20-
// audit logs with a resource_type of workspace build use workspace name as a target
21-
target = auditLog.additional_fields?.workspace_name?.trim()
22-
// workspaces can be started/stopped by a user, or kicked off automatically by Coder
23-
user =
24-
auditLog.additional_fields?.build_reason &&
25-
auditLog.additional_fields?.build_reason !== "initiator"
26-
? t("auditLog:table.logRow.buildReason")
27-
: user
57+
return <BuildAuditDescription auditLog={auditLog} />
2858
}
2959

3060
// SSH key entries have no links
@@ -59,7 +89,9 @@ export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
5989
)}
6090
{/* logs for workspaces created on behalf of other users indicate ownership in the description */}
6191
{auditLog.additional_fields.workspace_owner &&
62-
auditLog.additional_fields.workspace_owner !== "unknown" && (
92+
auditLog.additional_fields.workspace_owner !== "unknown" &&
93+
auditLog.additional_fields.workspace_owner !==
94+
auditLog.user?.username && (
6395
<span>
6496
<>
6597
{t("auditLog:table.logRow.onBehalfOf", {

site/src/i18n/en/auditLog.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
"browser": "Browser: ",
1515
"onBehalfOf": " on behalf of {{owner}}",
1616
"buildReason": "Coder automatically",
17-
"unknownUser": "an unknown user"
17+
"unknownUser": "an unknown user",
18+
"started": "started",
19+
"stopped": "stopped",
20+
"workspace": " workspace "
1821
}
1922
},
2023
"paywall": {

0 commit comments

Comments
 (0)