mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: index template versions by template and name (#5993)
* fix: index template versions by template and name We were incorrectly returning template versions by name relative to organizations. This could result in an incorrect version being returned if multiple templates had versions with the same name. * Fix auth referencing * Fix route location * Fix authorize route name * Fix previous call * Fix authorize route name
This commit is contained in:
+4
-2
@@ -231,10 +231,11 @@ export const getTemplateVersions = async (
|
||||
|
||||
export const getTemplateVersionByName = async (
|
||||
organizationId: string,
|
||||
templateName: string,
|
||||
versionName: string,
|
||||
): Promise<TypesGen.TemplateVersion> => {
|
||||
const response = await axios.get<TypesGen.TemplateVersion>(
|
||||
`/api/v2/organizations/${organizationId}/templateversions/${versionName}`,
|
||||
`/api/v2/organizations/${organizationId}/templates/${templateName}/versions/${versionName}`,
|
||||
)
|
||||
return response.data
|
||||
}
|
||||
@@ -245,11 +246,12 @@ export type GetPreviousTemplateVersionByNameResponse =
|
||||
|
||||
export const getPreviousTemplateVersionByName = async (
|
||||
organizationId: string,
|
||||
templateName: string,
|
||||
versionName: string,
|
||||
): Promise<GetPreviousTemplateVersionByNameResponse> => {
|
||||
try {
|
||||
const response = await axios.get<TypesGen.TemplateVersion>(
|
||||
`/api/v2/organizations/${organizationId}/templateversions/${versionName}/previous`,
|
||||
`/api/v2/organizations/${organizationId}/templates/${templateName}/versions/${versionName}/previous`,
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
|
||||
@@ -18,7 +18,7 @@ export const TemplateVersionPage: FC = () => {
|
||||
const { version: versionName, template: templateName } = useParams() as Params
|
||||
const orgId = useOrganizationId()
|
||||
const [state] = useMachine(templateVersionMachine, {
|
||||
context: { versionName, orgId },
|
||||
context: { templateName, versionName, orgId },
|
||||
})
|
||||
const tab = useTab("file", "0")
|
||||
const { t } = useTranslation("templateVersionPage")
|
||||
|
||||
@@ -90,13 +90,13 @@ export const handlers = [
|
||||
},
|
||||
),
|
||||
rest.get(
|
||||
"api/v2/organizations/:organizationId/templateversions/:templateVersionName",
|
||||
"api/v2/organizations/:organizationId/templates/:templateName/versions/:templateVersionName",
|
||||
async (req, res, ctx) => {
|
||||
return res(ctx.status(200), ctx.json(M.MockTemplateVersion))
|
||||
},
|
||||
),
|
||||
rest.get(
|
||||
"api/v2/organizations/:organizationId/templateversions/:templateVersionName/previous",
|
||||
"api/v2/organizations/:organizationId/templates/:templateName/versions/:templateVersionName/previous",
|
||||
async (req, res, ctx) => {
|
||||
return res(ctx.status(200), ctx.json(M.MockTemplateVersion2))
|
||||
},
|
||||
|
||||
@@ -12,6 +12,7 @@ import { assign, createMachine } from "xstate"
|
||||
|
||||
export interface TemplateVersionMachineContext {
|
||||
orgId: string
|
||||
templateName: string
|
||||
versionName: string
|
||||
currentVersion?: TemplateVersion
|
||||
currentFiles?: TemplateVersionFiles
|
||||
@@ -94,10 +95,10 @@ export const templateVersionMachine = createMachine(
|
||||
}),
|
||||
},
|
||||
services: {
|
||||
loadVersions: async ({ orgId, versionName }) => {
|
||||
loadVersions: async ({ orgId, templateName, versionName }) => {
|
||||
const [currentVersion, previousVersion] = await Promise.all([
|
||||
getTemplateVersionByName(orgId, versionName),
|
||||
getPreviousTemplateVersionByName(orgId, versionName),
|
||||
getTemplateVersionByName(orgId, templateName, versionName),
|
||||
getPreviousTemplateVersionByName(orgId, templateName, versionName),
|
||||
])
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user