Skip to content

Commit

Permalink
Plagiarism checks: Use file extensions for plagiarism view (#9350)
Browse files Browse the repository at this point in the history
  • Loading branch information
magaupp authored Oct 12, 2024
1 parent ebc28b2 commit a893024
Show file tree
Hide file tree
Showing 11 changed files with 338 additions and 366 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,27 +250,6 @@ public byte[] getFile(Repository repository, String filename) throws IOException
return fileInBytes;
}

/**
* Get the mimetype of a single file from the repository
*
* @param repository in which the requested file is located.
* @param filename of the file to be probed.
* @return The mimetype of the file if found or throw an exception.
* @throws IOException if the file can't be found, is corrupt, etc.
*/
public String getFileType(Repository repository, String filename) throws IOException {
Optional<File> file = gitService.getFileByName(repository, filename);
if (file.isEmpty()) {
throw new FileNotFoundException();
}
String type = Files.probeContentType(file.get().toPath());
// fallback to text/plain in case content type can not be determined
if (type == null) {
return "text/plain";
}
return type;
}

/**
* Gets the files of the repository and checks whether they were changed during a student participation.
* Compares the files from the students' repository with the files of the template repository.
Expand Down Expand Up @@ -519,8 +498,6 @@ public boolean isClean(VcsRepositoryUri repositoryUri, String defaultBranch) thr
public ResponseEntity<byte[]> getFileFromRepository(String filename, Repository repository) throws IOException {
byte[] out = getFile(repository, filename);
HttpHeaders responseHeaders = new HttpHeaders();
var contentType = getFileType(repository, filename);
responseHeaders.add("Content-Type", contentType);
// Prevent the file from being interpreted as HTML by the browser when opened directly:
responseHeaders.setContentDisposition(ContentDisposition.builder("attachment").filename(filename).build());
return new ResponseEntity<>(out, responseHeaders, HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import { CodeEditorRepositoryFileService, CodeEditorRepositoryService } from 'ap
import { CodeEditorStatusComponent } from 'app/exercises/programming/shared/code-editor/status/code-editor-status.component';
import { CodeEditorFileBrowserDeleteComponent } from 'app/exercises/programming/shared/code-editor/file-browser/code-editor-file-browser-delete';
import { IFileDeleteDelegate } from 'app/exercises/programming/shared/code-editor/file-browser/code-editor-file-browser-on-file-delete-delegate';
import { supportedTextFileExtensions } from 'app/exercises/programming/shared/code-editor/file-browser/supported-file-extensions';
import { faAngleDoubleDown, faAngleDoubleUp, faChevronLeft, faChevronRight, faCircleNotch, faFile, faFolder, faFolderOpen, faPlus } from '@fortawesome/free-solid-svg-icons';
import { TreeItem, TreeviewItem } from 'app/exercises/programming/shared/code-editor/treeview/models/treeview-item';
import { TreeviewComponent } from 'app/exercises/programming/shared/code-editor/treeview/components/treeview/treeview.component';
import { findItemInList } from 'app/exercises/programming/shared/code-editor/treeview/helpers/treeview-helper';
import { TEXT_FILE_EXTENSIONS } from 'app/shared/constants/file-extensions.constants';

export type InteractableEvent = {
// Click event object; contains target information
Expand Down Expand Up @@ -582,7 +582,7 @@ export class CodeEditorFileBrowserComponent implements OnInit, OnChanges, AfterV
*/
private static shouldDisplayFileBasedOnExtension(fileName: string): boolean {
const fileSplit = fileName.split('.');
return fileSplit.length === 1 || supportedTextFileExtensions.includes(fileSplit.pop()!);
return fileSplit.length === 1 || TEXT_FILE_EXTENSIONS.includes(fileSplit.pop()!);
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,6 @@ export class CodeEditorRepositoryFileService extends DomainDependentEndpointServ
);
};

getFileHeaders = (fileName: string, domain?: DomainChange) => {
const restResourceUrl = domain ? this.calculateRestResourceURL(domain) : this.restResourceUrl;
return this.http
.head<Blob>(`${restResourceUrl}/file-plagiarism-view`, { observe: 'response', params: new HttpParams().set('file', fileName) })
.pipe(handleErrorResponse(this.conflictService));
};

getFilesWithContent = (domain?: DomainChange) => {
const restResourceUrl = domain ? this.calculateRestResourceURL(domain) : this.restResourceUrl;
return this.http.get(`${restResourceUrl}/files-content`).pipe(handleErrorResponse<{ [fileName: string]: string }>(this.conflictService));
Expand Down
Loading

0 comments on commit a893024

Please sign in to comment.