Skip to content

fix(site): Fix template version editor rename #6251

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 13 commits into from
Mar 6, 2023
Prev Previous commit
Next Next commit
Do not allow creation of not allowed extensions
  • Loading branch information
BrunoQuaresma committed Mar 2, 2023
commit 19d84a245896ac9c026c3b288d0159eb0260c00e
9 changes: 9 additions & 0 deletions site/src/components/TemplateVersionEditor/FileDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"
import { Stack } from "components/Stack/Stack"
import { ChangeEvent, FC, useState } from "react"
import Typography from "@material-ui/core/Typography"
import { allowedExtensions, isAllowedFile } from "util/templateVersion"

export const CreateFileDialog: FC<{
onClose: () => void
Expand All @@ -24,6 +25,14 @@ export const CreateFileDialog: FC<{
setError("File already exists")
return
}
if (!isAllowedFile(pathValue)) {
setError(
`This is not an allowed extension. Valid extensions are: ${allowedExtensions.join(
", ",
)}.`,
)
return
}
onConfirm(pathValue)
setPathValue("")
}
Expand Down
2 changes: 1 addition & 1 deletion site/src/util/templateVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const getTemplateVersionFiles = async (
return files
}

const allowedExtensions = ["tf", "md", "Dockerfile"]
export const allowedExtensions = ["tf", "md", "Dockerfile"]

export const isAllowedFile = (name: string) => {
return allowedExtensions.some((ext) => name.endsWith(ext))
Expand Down