@@ -159,6 +159,11 @@ func (api *API) convertAuditLogs(ctx context.Context, dblogs []database.GetAudit
159
159
return alogs
160
160
}
161
161
162
+ type AdditionalFields struct {
163
+ WorkspaceName string
164
+ BuildNumber string
165
+ }
166
+
162
167
func (api * API ) convertAuditLog (ctx context.Context , dblog database.GetAuditLogsOffsetRow ) codersdk.AuditLog {
163
168
ip , _ := netip .AddrFromSlice (dblog .Ip .IPNet .IP )
164
169
@@ -184,6 +189,13 @@ func (api *API) convertAuditLog(ctx context.Context, dblog database.GetAuditLogs
184
189
}
185
190
}
186
191
192
+ additionalFieldsBytes := []byte (dblog .AdditionalFields )
193
+ var additionalFields AdditionalFields
194
+ err := json .Unmarshal (additionalFieldsBytes , & additionalFields )
195
+ if err != nil {
196
+ api .Logger .Error (ctx , "unmarshal additional fields" , slog .Error (err ))
197
+ }
198
+
187
199
return codersdk.AuditLog {
188
200
ID : dblog .ID ,
189
201
RequestID : dblog .RequestID ,
@@ -200,23 +212,24 @@ func (api *API) convertAuditLog(ctx context.Context, dblog database.GetAuditLogs
200
212
StatusCode : dblog .StatusCode ,
201
213
AdditionalFields : dblog .AdditionalFields ,
202
214
User : user ,
203
- Description : auditLogDescription (dblog ),
204
- ResourceLink : api .auditLogResourceLink (ctx , dblog ),
215
+ Description : auditLogDescription (dblog , additionalFields ),
216
+ ResourceLink : api .auditLogResourceLink (ctx , dblog , additionalFields ),
205
217
IsDeleted : api .auditLogIsResourceDeleted (ctx , dblog ),
206
218
}
207
219
}
208
220
209
- func auditLogDescription (alog database.GetAuditLogsOffsetRow ) string {
221
+ func auditLogDescription (alog database.GetAuditLogsOffsetRow , additionalFields AdditionalFields ) string {
210
222
str := fmt .Sprintf ("{user} %s" ,
211
223
codersdk .AuditAction (alog .Action ).FriendlyString (),
212
224
)
213
225
214
226
// Strings for starting/stopping workspace builds follow the below format:
215
- // "{user} started build for workspace {target}"
227
+ // "{user} started build #{build_number} for workspace {target}"
216
228
// where target is a workspace instead of a workspace build
217
229
// passed in on the FE via AuditLog.AdditionalFields rather than derived in request.go:35
218
230
if alog .ResourceType == database .ResourceTypeWorkspaceBuild && alog .Action != database .AuditActionDelete {
219
- str += " build for"
231
+ str += fmt .Sprintf (" build #%s for" ,
232
+ additionalFields .BuildNumber )
220
233
}
221
234
222
235
// We don't display the name (target) for git ssh keys. It's fairly long and doesn't
@@ -271,12 +284,7 @@ func (api *API) auditLogIsResourceDeleted(ctx context.Context, alog database.Get
271
284
}
272
285
}
273
286
274
- type AdditionalFields struct {
275
- WorkspaceName string
276
- BuildNumber string
277
- }
278
-
279
- func (api * API ) auditLogResourceLink (ctx context.Context , alog database.GetAuditLogsOffsetRow ) string {
287
+ func (api * API ) auditLogResourceLink (ctx context.Context , alog database.GetAuditLogsOffsetRow , additionalFields AdditionalFields ) string {
280
288
if api .auditLogIsResourceDeleted (ctx , alog ) {
281
289
return ""
282
290
}
@@ -292,12 +300,6 @@ func (api *API) auditLogResourceLink(ctx context.Context, alog database.GetAudit
292
300
return fmt .Sprintf ("/@%s/%s" ,
293
301
alog .UserUsername .String , alog .ResourceTarget )
294
302
case database .ResourceTypeWorkspaceBuild :
295
- additionalFieldsBytes := []byte (alog .AdditionalFields )
296
- var additionalFields AdditionalFields
297
- err := json .Unmarshal (additionalFieldsBytes , & additionalFields )
298
- if err != nil {
299
- api .Logger .Error (ctx , "could not unmarshal workspace name" , slog .Error (err ))
300
- }
301
303
return fmt .Sprintf ("/@%s/%s/builds/%s" ,
302
304
alog .UserUsername .String , additionalFields .WorkspaceName , additionalFields .BuildNumber )
303
305
default :
0 commit comments