8000 fix: duplicate workspace update entries by Kira-Pilot · Pull Request #4513 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

fix: duplicate workspace update entries #4513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: duplicate workspace update entries
  • Loading branch information
Kira-Pilot committed Oct 12, 2022
commit 20c6bfa39437154d78a39e73228a225dcdc15bb7
4 changes: 4 additions & 0 deletions coderd/audit/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func InitRequest[T Auditable](w http.ResponseWriter, p *RequestParams) (*Request
if sw.Status < 400 {
diff := Diff(p.Audit, req.Old, req.New)

if len(diff) == 0 {
return
}

var err error
diffRaw, err = json.Marshal(diff)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions site/src/pages/AuditPage/AuditPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import {
history,
MockAuditLog,
MockAuditLog2,
MockAuditLogWithEmptyDiff,
render,
waitForLoaderToBeRemoved,
} from "testHelpers/renderHelpers"
import * as CreateDayString from "util/createDayString"
import AuditPage from "./AuditPage"
import { server } from "testHelpers/server"
import { rest } from "msw"

describe("AuditPage", () => {
beforeEach(() => {
Expand All @@ -27,6 +30,21 @@ describe("AuditPage", () => {
screen.getByTestId(`audit-log-row-${MockAuditLog2.id}`)
})

it("filters out audit logs with empty diffs", async () => {
server.use(
rest.get(`/api/v2/audit`, (_, res, ctx) => {
return res(ctx.status(200), ctx.json(MockAuditLogWithEmptyDiff))
}),
)

// When
render(<AuditPage />)

// Then
const logRow = screen.queryByTestId(`audit-log-row-${MockAuditLogWithEmptyDiff.id}`)
expect(logRow).not.toBeInTheDocument()
})

describe("Filtering", () => {
it("filters by typing", async () => {
const getAuditLogsSpy = jest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ export const WorkspaceSchedulePage: React.FC = () => {
navigate(`/@${username}/${workspaceName}`)
}}
onSubmit={(values) => {
console.log("values", values)
scheduleSend({
type: "SUBMIT_SCHEDULE",
autoStart: formValuesToAutoStartRequest(values),
autoStart: values.autoStartEnabled ? formValuesToAutoStartRequest(values) : undefined,
ttl: formValuesToTTLRequest(values),
})
}}
Expand Down
28 changes: 27 additions & 1 deletion site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,13 @@ export const MockAuditLog: TypesGen.AuditLog = {
resource_target: "bruno-dev",
resource_icon: "",
action: "create",
diff: {},
diff: {
ttl: {
old: 0,
new: 3600000000000,
secret: false,
},
},
status_code: 200,
additional_fields: "",
description: "{user} updated workspace {target}",
Expand Down Expand Up @@ -864,6 +870,26 @@ export const MockAuditLog2: TypesGen.AuditLog = {
},
}

export const MockAuditLogWithEmptyDiff: TypesGen.AuditLog = {
id: "958d5bdc-d034-4857-891e-33393ba07e55",
request_id: "0585f890-2659-4761-bcb4-3bbca1fe4ab7",
time: "2022-10-12T13:36:31.682107Z",
organization_id: "fc0774ce-cc9e-48d4-80ae-88f7a4d4a8b0",
ip: "127.0.0.1",
user_agent:
'"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"',
resource_type: "workspace",
resource_id: "ef8d1cf4-82de-4fd9-8980-047dad6d06b5",
resource_target: "bruno-dev",
resource_icon: "",
action: "create",
diff: {},
status_code: 200,
additional_fields: "",
description: "{user} updated workspace {target}",
user: MockUser,
}

export const MockWorkspaceQuota: TypesGen.WorkspaceQuota = {
user_workspace_count: 0,
user_workspace_limit: 100,
Expand Down
4 changes: 3 additions & 1 deletion site/src/xServices/audit/auditXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ export const auditMachine = createMachine(
}).then((data) => data.count),
])

// Filter out any logs that don't have an actual diff to present to the user
const filteredLogs = auditLogs.filter((log) => Object.entries(log.diff).length > 0)
return {
auditLogs,
auditLogs: filteredLogs,
count,
}
},
Expand Down
341A
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type WorkspaceScheduleEvent =
| { type: "GET_WORKSPACE"; username: string; workspaceName: string }
| {
type: "SUBMIT_SCHEDULE"
autoStart: TypesGen.UpdateWorkspaceAutostartRequest
autoStart: TypesGen.UpdateWorkspaceAutostartRequest | undefined
ttl: TypesGen.UpdateWorkspaceTTLRequest
}

Expand Down Expand Up @@ -190,10 +190,9 @@ export const workspaceSchedule = createMachine(
throw new Error("Failed to load workspace.")
}

// REMARK: These calls are purposefully synchronous because if one
// value contradicts the other, we don't want a race condition
// on re-submission.
await API.putWorkspaceAutostart(context.workspace.id, event.autoStart)
if (event.autoStart?.schedule !== undefined) {
await API.putWorkspaceAutostart(context.workspace.id, event.autoStart)
}
await API.putWorkspaceAutostop(context.workspace.id, event.ttl)
},
},
Expand Down
0