Skip to content

Commit e90c526

Browse files
committed
The feature to block the publiscation, in case of invalid codecheck status now works #32
1 parent 4d95f50 commit e90c526

5 files changed

Lines changed: 20 additions & 7 deletions

File tree

CodecheckPlugin.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616
use PKP\components\forms\FieldOptions;
1717
use APP\facades\Repo;
1818
use APP\plugins\generic\codecheck\api\v1\CodecheckApiHandler;
19+
use APP\plugins\generic\codecheck\api\v1\CurlApiClient;
1920
use PKP\core\JSONMessage;
2021
use APP\plugins\generic\codecheck\classes\Constants;
2122
use APP\plugins\generic\codecheck\classes\Workflow\CodecheckStatusHandler;
2223
use APP\plugins\generic\codecheck\controllers\page\CodecheckPageHandler;
2324
use APP\plugins\generic\codecheck\classes\CodecheckRoles\CodecheckRoleArray;
2425
use APP\plugins\generic\codecheck\classes\CodecheckRoles\CodecheckRoleManager;
26+
use APP\plugins\generic\codecheck\classes\Submission\CodecheckMetadataDAO;
27+
use APP\plugins\generic\codecheck\classes\Workflow\CodecheckMetadataHandler;
2528
use PKP\core\Request;
29+
use \Github\Client;
2630

2731
class CodecheckPlugin extends GenericPlugin
2832
{
@@ -89,15 +93,21 @@ public function validateCodecheckStatus(string $hookName, array $args): bool
8993
$publication = $args[1]; // sometimes passed by reference depending on version
9094
$request = Application::get()->getRequest();
9195
$context = $request->getContext();
96+
$codecheckMetadataHandler = new CodecheckMetadataHandler($request, new Client(), new CurlApiClient());
97+
$codecheckStatus = CodecheckStatusHandler::getCurrentStatusData($codecheckMetadataHandler->getSubmissionId());
9298

93-
error_log("[CODECHECK Plugin] Validating CODECHECK before publication!");
99+
CodecheckLogger::debug("Validating CODECHECK before publication!");
94100

95-
$codecheckStatus = 'plugins.generic.codecheck.status.completed.partialReproduction';
96101
$codecheckStatusKeysSelected = $this->getSetting($context->getId(), Constants::CODECHECK_STATUS_KEYS_SELECTED);
97102

98-
if (!in_array($codecheckStatus, $codecheckStatusKeysSelected)) {
103+
if (empty($codecheckStatus)) {
104+
$errors[] = __('plugins.generic.codecheck.status.validation.failed.noStatusSet');
105+
return false;
106+
}
107+
108+
if (!in_array($codecheckStatus->status, $codecheckStatusKeysSelected)) {
99109
$errors[] = __('plugins.generic.codecheck.status.validation.failed', [
100-
'codecheckStatus' => __($codecheckStatus)
110+
'codecheckStatus' => __($codecheckStatus->status)
101111
]);
102112
return false;
103113
}

classes/Settings/SettingsForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public function execute(...$functionArgs): mixed
261261
$context->getId(),
262262
Constants::GITHUB_CUSTOM_LABELS,
263263
array_values(array_filter(
264-
(array) $this->getData(Constants::GITHUB_CUSTOM_LABELS),
264+
(array) $this->getData(Constants::CODECHECK_GITHUB_CUSTOM_LABELS),
265265
fn ($label) => !empty($label)
266266
))
267267
);

locale/en/locale.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ msgstr "Complete"
359359
msgid "plugins.generic.codecheck.status.validation.failed"
360360
msgstr "The mandatory CODECHECK for this submission has a status ({$codecheckStatus}), which is not allowed for publication by the journal. Please get in touch with the codechecker(s) to resolve all errors, before this submission can be published!"
361361

362+
msgid "plugins.generic.codecheck.status.validation.failed.noStatusSet"
363+
msgstr "The mandatory CODECHECK for this submission has no status (so it was not yet started), which is not allowed for publication by the journal. Please get in touch with the codechecker(s) to resolve all errors, before this submission can be published!"
364+
362365
msgid "plugins.generic.codecheck.status.pending"
363366
msgstr "Pending"
364367

public/build/build.iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/Components/CodecheckMetadataForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207

208208
<div class="field-group">
209209
<div class="field-header">
210-
<label class="field-label">{{ t('plugins.generic.codecheck.codecheckers.title') }} <span class="required">*</span></label>
210+
<label class="field-label">{{ t('plugins.generic.codecheck.codecheckers.title') }}</label>
211211
<button type="button" class="pkpButton btn-add" @click="showCodecheckerModal">{{ t('plugins.generic.codecheck.codecheckers.add') }}</button>
212212
</div>
213213

0 commit comments

Comments
 (0)