MCPcopy Index your code
hub / github.com/coder/coder / chatAuditLogDescription

Function chatAuditLogDescription

coderd/audit.go:358–402  ·  view source on GitHub ↗

chatAuditLogDescription returns a description for successful chat write operations based on the diff contents. It returns false for non-chat resources, non-write actions, or error/redirect status codes, letting the caller fall through to the generic description.

(alog database.GetAuditLogsOffsetRow)

Source from the content-addressed store, hash-verified

356// resources, non-write actions, or error/redirect status codes, letting
357// the caller fall through to the generic description.
358func chatAuditLogDescription(alog database.GetAuditLogsOffsetRow) (string, bool) {
359 if alog.AuditLog.ResourceType != database.ResourceTypeChat ||
360 alog.AuditLog.Action != database.AuditActionWrite ||
361 alog.AuditLog.StatusCode >= 400 ||
362 alog.AuditLog.StatusCode == int32(http.StatusSeeOther) {
363 return "", false
364 }
365
366 var diff codersdk.AuditDiff
367 if err := json.Unmarshal(alog.AuditLog.Diff, &diff); err != nil {
368 return "", false
369 }
370
371 // Single "archived" field: archive or unarchive.
372 if len(diff) == 1 {
373 if field, ok := diff["archived"]; ok {
374 oldVal, oldOK := field.Old.(bool)
375 newVal, newOK := field.New.(bool)
376 if oldOK && newOK {
377 if !oldVal && newVal {
378 return "archived chat {target}", true
379 }
380 if oldVal && !newVal {
381 return "unarchived chat {target}", true
382 }
383 }
384 }
385 }
386
387 // All fields are ACL changes: sharing update.
388 if len(diff) > 0 {
389 aclOnly := true
390 for field := range diff {
391 if field != "user_acl" && field != "group_acl" {
392 aclOnly = false
393 break
394 }
395 }
396 if aclOnly {
397 return "updated sharing for chat {target}", true
398 }
399 }
400
401 return "", false
402}
403
404func (api *API) auditLogIsResourceDeleted(ctx context.Context, alog database.GetAuditLogsOffsetRow) bool {
405 switch alog.AuditLog.ResourceType {

Callers 1

auditLogDescriptionFunction · 0.85

Calls 1

UnmarshalMethod · 0.45

Tested by

no test coverage detected