Skip to content
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

Reupload files bug #117

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions tasky/src/handler/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ pub async fn handle_update_multipart(
/// Creates files and updates the correlated object_ids
/// Also updates files in file_structure, because the actual_files are referenced from the file structure
async fn create_files_and_update_ids(
#[allow(clippy::ptr_arg)]
actual_files: &mut Vec<&mut AssignmentFile>,
#[allow(clippy::ptr_arg)] actual_files: &mut Vec<&mut AssignmentFile>,
mongodb: &Database,
filename_map: HashMap<String, (bool, &TempFile)>,
assignment: &Assignment,
Expand Down
4 changes: 2 additions & 2 deletions tasky/src/response/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
use super::{group::MinifiedGroupResponse, shared::User, Enrich};

/// An file on an assignment
#[derive(Serialize, Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AssignmentFile {
pub filename: String,
pub object_id: Option<String>,
Expand All @@ -26,7 +26,7 @@ pub struct AssignmentFile {
}

/// File structure of an assignment / solution
#[derive(Serialize, Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AssignmentFileStructure {
pub files: Option<Vec<AssignmentFile>>,
pub folders: Option<Vec<AssignmentFileStructure>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import useApiServiceClient from "@/hooks/useApiServiceClient";
import { useForm } from "@mantine/form";
import {Assignment, RunnerConfig} from "@/service/types/tasky";
import {useTranslation} from "react-i18next";
import {removeObjectIds} from "@/utils/FileStructure";

interface AssignmentCreateOrUpdateCodeTestModalProps {
onClose: () => void;
Expand Down Expand Up @@ -66,9 +67,11 @@ const AssignmentCreateOrUpdateCodeTestModal = ({

const submit = form.onSubmit(async (values) => {
try {
await api.createOrUpdateCodeTests(groupId, assignment.id, fileStructure, files, {
const fileNames = files.map((file) => file.name);
const withoutUpdatedFilesObjectIds = removeObjectIds(fileStructure, fileNames);
await api.createOrUpdateCodeTests(groupId, assignment.id, withoutUpdatedFilesObjectIds, files, {
...values,
} as RunnerConfig);
} as RunnerConfig, assignment.file_structure !== null);
refetch();
onClose();
} catch (e: any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const CreateOrUpdateAssignmentModal = ({
values.language,
);
notifications.show({
message: `${t('messages.successfully-created-assignment')} ${res.title}`,
message: `${t('assignment:messages.successfully-created-assignment')} ${res.title}`,
color: "green",
});
}
Expand Down
20 changes: 20 additions & 0 deletions web/utils/FileStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
FileStructureFile,
FileStructureTree,
} from "@/components/FileStructure";
import {FileWithPath} from "@mantine/dropzone";

/**
* Builds the mantine tree data from structure
Expand Down Expand Up @@ -253,3 +254,22 @@ export const extractFilesFromFileStructure = (
}
return files;
};

/**
* Removes all object IDs from the files listed in the second parameter.
* This is required for the backend to notice new files.
*
* @param structure The file structure
* @param fileNames All new uploaded files
*/
export const removeObjectIds = (structure: FileStructureTree, fileNames: string[]): FileStructureTree => {

structure.folders = (structure.folders ?? []).map((folder) => removeObjectIds(folder, fileNames));
structure.files = structure.files.map((file) => {
if (fileNames.indexOf(file.filename) > -1) {
return {...file, object_id: null};
}
return file;
});
return structure;
}
Loading