@@ -5,26 +5,56 @@ import Link from "@material-ui/core/Link"
5
5
import { makeStyles } from "@material-ui/core/styles"
6
6
import i18next from "i18next"
7
7
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
+
8
45
export const AuditLogDescription : FC < { auditLog : AuditLog } > = ( {
9
46
auditLog,
10
47
} ) : JSX . Element => {
11
48
const classes = useStyles ( )
12
49
const { t } = i18next
13
50
14
- let target = auditLog . resource_target . trim ( )
15
- let user = auditLog . user
51
+ const target = auditLog . resource_target . trim ( )
52
+ const user = auditLog . user
16
53
? auditLog . user . username . trim ( )
17
54
: t ( "auditLog:table.logRow.unknownUser" )
18
55
19
56
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 } />
28
58
}
29
59
30
60
// SSH key entries have no links
@@ -59,7 +89,9 @@ export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
59
89
) }
60
90
{ /* logs for workspaces created on behalf of other users indicate ownership in the description */ }
61
91
{ 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 && (
63
95
< span >
64
96
< >
65
97
{ t ( "auditLog:table.logRow.onBehalfOf" , {
0 commit comments