feat: add description to audit log responses (#3949)

This commit is contained in:
Colin Adler
2022-09-08 09:36:34 -05:00
committed by GitHub
parent 5e04a2f800
commit 7dc73ed6c6
10 changed files with 75 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package coderd
import (
"encoding/json"
"fmt"
"net"
"net/http"
"net/netip"
@ -167,7 +168,14 @@ func convertAuditLog(dblog database.GetAuditLogsOffsetRow) codersdk.AuditLog {
Diff: diff,
StatusCode: dblog.StatusCode,
AdditionalFields: dblog.AdditionalFields,
Description: "",
Description: auditLogDescription(dblog),
User: user,
}
}
func auditLogDescription(alog database.GetAuditLogsOffsetRow) string {
return fmt.Sprintf("{user} %s %s {target}",
codersdk.AuditAction(alog.Action).FriendlyString(),
codersdk.ResourceType(alog.ResourceType).FriendlyString(),
)
}

View File

@ -2308,7 +2308,7 @@ func (q *fakeQuerier) GetAuditLogsOffset(ctx context.Context, arg database.GetAu
OrganizationID: alog.OrganizationID,
Ip: alog.Ip,
UserAgent: alog.UserAgent,
ResourceType: database.ResourceType(alog.UserAgent),
ResourceType: alog.ResourceType,
ResourceID: alog.ResourceID,
ResourceTarget: alog.ResourceTarget,
ResourceIcon: alog.ResourceIcon,

View File

@ -73,7 +73,9 @@ CREATE TYPE resource_type AS ENUM (
'template',
'template_version',
'user',
'workspace'
'workspace',
'git_ssh_key',
'api_key'
);
CREATE TYPE user_status AS ENUM (

View File

@ -1,9 +1,9 @@
-- It's not possible to drop enum values from enum types, so the UP has "IF NOT
-- EXISTS".
-- Delete all jobs that use the new enum value.
-- Delete all audit logs that use the new enum values.
DELETE FROM
provisioner_jobs
audit_logs
WHERE
type = 'template_version_dry_run'
;
resource_type = 'git_ssh_key' OR
resource_type = 'api_key';

View File

@ -0,0 +1,8 @@
-- It's not possible to drop enum values from enum types, so the UP has "IF NOT
-- EXISTS".
-- Delete all jobs that use the new enum value.
DELETE FROM
provisioner_jobs
WHERE
type = 'template_version_dry_run';

View File

@ -0,0 +1,2 @@
ALTER TYPE resource_type ADD VALUE IF NOT EXISTS 'git_ssh_key';
ALTER TYPE resource_type ADD VALUE IF NOT EXISTS 'api_key';

View File

@ -258,6 +258,8 @@ const (
ResourceTypeTemplateVersion ResourceType = "template_version"
ResourceTypeUser ResourceType = "user"
ResourceTypeWorkspace ResourceType = "workspace"
ResourceTypeGitSshKey ResourceType = "git_ssh_key"
ResourceTypeApiKey ResourceType = "api_key"
)
func (e *ResourceType) Scan(src interface{}) error {