validation on changing assignment name

This commit is contained in:
2025-11-24 16:06:25 -07:00
parent 8aec682974
commit ae19b5a075
2 changed files with 30 additions and 13 deletions

View File

@@ -40,20 +40,25 @@ export function UpdateAssignmentName({
if (name === assignmentName) closeModal(); if (name === assignmentName) closeModal();
setIsLoading(true); // page refresh resets flag setIsLoading(true); // page refresh resets flag
await updateAssignment.mutateAsync({ try{
assignment: assignment,
moduleName,
assignmentName: name,
previousModuleName: moduleName,
previousAssignmentName: assignmentName,
courseName,
});
// update url (will trigger reload...) await updateAssignment.mutateAsync({
router.replace( assignment: assignment,
getModuleItemUrl(courseName, moduleName, "assignment", name), moduleName,
{} assignmentName: name,
); previousModuleName: moduleName,
previousAssignmentName: assignmentName,
courseName,
});
// update url (will trigger reload...)
router.replace(
getModuleItemUrl(courseName, moduleName, "assignment", name),
{}
);
}finally {
setIsLoading(false);
}
}} }}
> >
<TextInput <TextInput

View File

@@ -133,6 +133,18 @@ export async function updateOrCreateAssignmentFile({
assignmentName: string; assignmentName: string;
assignment: LocalAssignment; assignment: LocalAssignment;
}) { }) {
const illegalCharacters = ["<", ">", ":", '"', "/", "\\", "|", "?", "*"];
const foundIllegalCharacters = illegalCharacters.filter((char) =>
assignmentName.includes(char)
);
if (foundIllegalCharacters.length > 0) {
throw new Error(
`"${assignmentName}" cannot contain the following characters: ${foundIllegalCharacters.join(
" "
)}`
);
}
const courseDirectory = await getCoursePathByName(courseName); const courseDirectory = await getCoursePathByName(courseName);
const folder = path.join(courseDirectory, moduleName, "assignments"); const folder = path.join(courseDirectory, moduleName, "assignments");
await fs.mkdir(folder, { recursive: true }); await fs.mkdir(folder, { recursive: true });