Skip to content

Commit de75d4f

Browse files
committed
Add back OrganizationID to audit logs
But mark it as deprecated.
1 parent 8496240 commit de75d4f

File tree

9 files changed

+33
-3
lines changed

9 files changed

+33
-3
lines changed

coderd/apidoc/docs.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/audit.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,11 @@ func (api *API) convertAuditLog(ctx context.Context, dblog database.GetAuditLogs
239239
}
240240

241241
alog := codersdk.AuditLog{
242-
ID: dblog.ID,
243-
RequestID: dblog.RequestID,
244-
Time: dblog.Time,
242+
ID: dblog.ID,
243+
RequestID: dblog.RequestID,
244+
Time: dblog.Time,
245+
// OrganizationID is deprecated.
246+
OrganizationID: dblog.OrganizationID,
245247
IP: ip,
246248
UserAgent: dblog.UserAgent.String,
247249
ResourceType: codersdk.ResourceType(dblog.ResourceType),

coderd/audit_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ func TestAuditLogs(t *testing.T) {
133133
Icon: o.Icon,
134134
}, alogs.AuditLogs[0].Organization)
135135

136+
// OrganizationID is deprecated, but make sure it is set.
137+
require.Equal(t, o.ID, alogs.AuditLogs[0].OrganizationID)
138+
136139
// Delete the org and try again, should be mostly empty.
137140
err = client.DeleteOrganization(ctx, o.ID.String())
138141
require.NoError(t, err)
@@ -150,6 +153,9 @@ func TestAuditLogs(t *testing.T) {
150153
ID: o.ID,
151154
}, alogs.AuditLogs[0].Organization)
152155

156+
// OrganizationID is deprecated, but make sure it is set.
157+
require.Equal(t, o.ID, alogs.AuditLogs[0].OrganizationID)
158+
153159
// Some audit entries do not have an organization at all, in which case the
154160
// response omits the organization.
155161
err = client.CreateTestAuditLog(ctx, codersdk.CreateTestAuditLogRequest{
@@ -170,6 +176,9 @@ func TestAuditLogs(t *testing.T) {
170176

171177
// The other will have no organization.
172178
require.Equal(t, (*codersdk.MinimalOrganization)(nil), alogs.AuditLogs[0].Organization)
179+
180+
// OrganizationID is deprecated, but make sure it is empty.
181+
require.Equal(t, uuid.Nil, alogs.AuditLogs[0].OrganizationID)
173182
})
174183

175184
t.Run("WorkspaceBuildAuditLink", func(t *testing.T) {

codersdk/audit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ type AuditLog struct {
143143
ResourceLink string `json:"resource_link"`
144144
IsDeleted bool `json:"is_deleted"`
145145

146+
// Deprecated: Use 'organization.id' instead.
147+
OrganizationID uuid.UUID `json:"organization_id" format:"uuid"`
148+
146149
Organization *MinimalOrganization `json:"organization,omitempty"`
147150

148151
User *User `json:"user"`

docs/api/audit.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/schemas.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/src/api/typesGenerated.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/src/testHelpers/entities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,6 +2152,7 @@ export const MockAuditLog: TypesGen.AuditLog = {
21522152
id: "fbd2116a-8961-4954-87ae-e4575bd29ce0",
21532153
request_id: "53bded77-7b9d-4e82-8771-991a34d759f9",
21542154
time: "2022-05-19T16:45:57.122Z",
2155+
organization_id: MockOrganization.id,
21552156
organization: {
21562157
id: MockOrganization.id,
21572158
name: "mock name",

0 commit comments

Comments
 (0)