Skip to content
Open
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
43 changes: 36 additions & 7 deletions PlagiarismPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,39 @@ class PlagiarismPlugin extends GenericPlugin
'allowViewerUpdate' => 'bool',
];


/**
* List of archive mime type that will not be uploaded to iThenticate service
* List of archive mime type that can be uploaded to iThenticate service
* https://guides.ithenticate.com/hc/en-us/articles/27835492585997-Uploading-a-file-to-generate-a-Similarity-Report
*/
public array $uploadRestrictedArchiveMimeTypes = [
'application/gzip',
'application/zip',
'application/x-tar',
public array $uploadAllowedArchiveMimeTypes = [
// Microsoft Word (DOC and DOCX)
'application/msword',
'application/word',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
// Excel (XLS and XLSX)'application/excel'
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
// PowerPoint (PPT and PPTX); each slide is counted as a page
'application/vnd.ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
// PostScript
'application/postscript',
// PDF
'application/pdf',
'application/x-pdf',
'text/pdf',
'text/x-pdf',
// HTML
'text/html',
// Rich Text Format (RTF)
'application/rtf',
// OpenOffice (ODT)
'application/vnd.oasis.opendocument.text',
// WordPerfect
'application/wordperfect',
// Plain text (TXT)
'text/plain'
];

/**
Expand Down Expand Up @@ -653,14 +679,17 @@ public function submitForPlagiarismCheck(Context $context, Submission $submissio

try {
foreach($submissionFiles as $submissionFile) { /** @var SubmissionFile $submissionFile */
if ( ! in_array($submissionFile->getData('mimetype'), $this->uploadAllowedArchiveMimeTypes)) {
continue;
}
if (!$this->createNewSubmission($request, $user, $submission, $submissionFile, $ithenticate)) {
return false;
}
}

$submission->setData('ithenticateSubmissionCompletedAt', Core::getCurrentDate());
} catch (Throwable $exception) {
error_log('submit for plagiarism check failed with excaption ' . $exception->__toString());
error_log('submit for plagiarism check failed with exception ' . $exception->__toString());
$this->sendErrorMessage(__('plugins.generic.plagiarism.ithenticate.upload.complete.failed'), $submission->getId());
return false;
}
Expand Down Expand Up @@ -802,7 +831,7 @@ public function createNewSubmission(
$pkpFileService = Services::get('file'); /** @var \PKP\Services\PKPFileService $pkpFileService */
$file = $pkpFileService->get($submissionFile->getData('fileId'));

if (in_array($file->mimetype, $this->uploadRestrictedArchiveMimeTypes)) {
if (!in_array($file->mimetype, $this->uploadAllowedArchiveMimeTypes)) {
return true;
}

Expand Down
12 changes: 6 additions & 6 deletions grids/SimilarityActionGridColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public function getTemplateVarsFromRow($row)

assert($submissionFile instanceof SubmissionFile);

// Not going to allow plagiarism action on a zip file
if ($this->isSubmissionFileTypeRestricted($submissionFile)) {
// Not going to allow plagiarism action on all files
if (!$this->isSubmissionFileTypeAllowed($submissionFile)) {
return ['label' => __('plugins.generic.plagiarism.similarity.action.invalidFileType')];
}

Expand Down Expand Up @@ -164,8 +164,8 @@ public function getCellActions($request, $row, $position = GridHandler::GRID_ACT
$submissionFile = $submissionFileData['submissionFile']; /** @var SubmissionFile $submissionFile */
}

// Not going to allow plagiarism action on a zip file
if ($this->isSubmissionFileTypeRestricted($submissionFile)) {
// Restrict plagiarism action to allowed file types
if (!$this->isSubmissionFileTypeAllowed($submissionFile)) {
return $cellActions;
}

Expand Down Expand Up @@ -327,12 +327,12 @@ protected function isEulaConfirmationRequired(Context $context, Submission $subm
* Check if submission file type in valid for plagiarism action
* Restricted for ZIP file
*/
protected function isSubmissionFileTypeRestricted(SubmissionFile $submissionFile): bool
protected function isSubmissionFileTypeAllowed(SubmissionFile $submissionFile): bool
{
$pkpFileService = Services::get('file'); /** @var \PKP\Services\PKPFileService $pkpFileService */
$file = $pkpFileService->get($submissionFile->getData('fileId'));

return in_array($file->mimetype, $this->_plugin->uploadRestrictedArchiveMimeTypes);
return in_array($file->mimetype, $this->_plugin->uploadAllowedArchiveMimeTypes);
}

/**
Expand Down