Skip to content

Commit

Permalink
Merge branch 'adaptToOPS-3_4_0' into 'main'
Browse files Browse the repository at this point in the history
Port plugin to OPS 3.4

See merge request softwares-pkp/plugins_ojs/scieloModerationStages!17
  • Loading branch information
iudizm committed Feb 1, 2024
2 parents 00655c7 + b96d5d0 commit 9c48a60
Show file tree
Hide file tree
Showing 30 changed files with 572 additions and 867 deletions.
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ include:
ref: main
file:
- 'templates/groups/pkp_plugin.yml'
- 'templates/groups/ops_plugins_unit_tests_model.yml'
- 'templates/groups/ops_3_4_plugins_unit_tests_model.yml'
- 'templates/groups/ops_3_4_plugins_cypress_tests_model.yml'
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ This plugin adds stages of moderation to OPS, giving moderators the possibility

The latest release of this plugin is compatible with the following PKP applications:

* OPS 3.3.0

* OPS 3.4.0

## Plugin Download

Expand All @@ -24,6 +23,6 @@ To download the plugin, go to the [Releases page](https://github.com/lepidus/sci
# License
__This plugin is licensed under the GNU General Public License v3.0__

__Copyright (c) 2022 Lepidus Tecnologia__
__Copyright (c) 2022 - 2024 Lepidus Tecnologia__

__Copyright (c) 2022 SciELO__
__Copyright (c) 2022 - 2024 SciELO__
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @file plugins/reports/scieloModerationStages/ScieloModerationStagesPlugin.inc.php
*
* Copyright (c) 2022 Lepidus Tecnologia
* Copyright (c) 2022 SciELO
* Copyright (c) 2022 - 2024 Lepidus Tecnologia
* Copyright (c) 2022 - 2024 SciELO
* Distributed under the GNU GPL v3. For full terms see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt.
*
* @class ScieloModerationStagesPlugin
Expand All @@ -13,45 +13,56 @@
* @brief SciELO Moderation Stages Plugin
*/

import('lib.pkp.classes.plugins.GenericPlugin');
import('plugins.generic.scieloModerationStages.classes.ModerationStage');
import('plugins.generic.scieloModerationStages.classes.ModerationStageRegister');
namespace APP\plugins\generic\scieloModerationStages;

define('SCIELO_BRASIL_EMAIL', '[email protected]');
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
use APP\core\Application;
use APP\template\TemplateManager;
use APP\facades\Repo;
use PKP\security\Role;
use PKP\db\DAORegistry;
use Illuminate\Support\Facades\Event;
use APP\plugins\generic\scieloModerationStages\classes\ModerationStage;
use APP\plugins\generic\scieloModerationStages\classes\ModerationStageRegister;
use APP\plugins\generic\scieloModerationStages\classes\observers\listeners\AssignFirstModerationStage;

class ScieloModerationStagesPlugin extends GenericPlugin
{
private const SCIELO_BRASIL_EMAIL = '[email protected]';

public function register($category, $path, $mainContextId = null)
{
$success = parent::register($category, $path, $mainContextId);

if (!Config::getVar('general', 'installed') || defined('RUNNING_UPGRADE')) {
return true;
if (Application::isUnderMaintenance()) {
return $success;
}

if ($success && $this->getEnabled($mainContextId)) {
HookRegistry::register('Schema::get::submission', array($this, 'addOurFieldsToSubmissionSchema'));
HookRegistry::register('submissionsubmitstep4form::execute', array($this, 'setSubmissionFirstModerationStage'));
HookRegistry::register('addparticipantform::display', array($this, 'addFieldsAssignForm'));
HookRegistry::register('addparticipantform::execute', array($this, 'sendSubmissionToNextModerationStage'));
HookRegistry::register('queryform::display', array($this, 'hideParticipantsOnDiscussionOpening'));
Event::subscribe(new AssignFirstModerationStage());

Hook::add('Schema::get::submission', [$this, 'addOurFieldsToSubmissionSchema']);
Hook::add('addparticipantform::display', [$this, 'addStageAdvanceToAssignForm']);
Hook::add('addparticipantform::execute', [$this, 'sendSubmissionToNextModerationStage']);
Hook::add('queryform::display', [$this, 'hideParticipantsOnDiscussionOpening']);

HookRegistry::register('Template::Workflow::Publication', array($this, 'addToWorkflowTabs'));
HookRegistry::register('Template::Workflow', array($this, 'addCurrentStageStatus'));
HookRegistry::register('LoadComponentHandler', array($this, 'setupScieloModerationStagesHandler'));
Hook::add('Template::Workflow::Publication', [$this, 'addToWorkflowTabs']);
Hook::add('Template::Workflow', [$this, 'addCurrentStageStatusToWorkflow']);
Hook::add('LoadComponentHandler', [$this, 'setupScieloModerationStagesHandler']);

Hook::add('TemplateManager::display', [$this, 'addJavaScriptAndStylesheet']);

HookRegistry::register('TemplateManager::display', array($this, 'addJavaScriptAndStylesheet'));
$this->addHandlerURLToJavaScript();
}

return $success;
}

public function addHandlerURLToJavaScript()
{
$request = Application::get()->getRequest();
$templateMgr = TemplateManager::getManager($request);
$handlerUrl = $request->getDispatcher()->url($request, ROUTE_COMPONENT) . 'plugins/generic/scielo-moderation-stages/controllers/scielo-moderation-stages/';
$handlerUrl = $request->getDispatcher()->url($request, Application::ROUTE_COMPONENT, null, 'plugins.generic.scieloModerationStages.controllers.ScieloModerationStagesHandler');
$data = ['moderationStagesHandlerUrl' => $handlerUrl];

$templateMgr->addJavaScript('ModerationStagesHandler', 'app = ' . json_encode($data) . ';', ['contexts' => 'backend', 'inline' => true]);
Expand Down Expand Up @@ -124,18 +135,9 @@ public function addOurFieldsToSubmissionSchema($hookName, $params)
return false;
}

public function setSubmissionFirstModerationStage($hookName, $params)
{
$submission = $params[0]->submission;
$moderationStage = new ModerationStage($submission);
$moderationStage->setToFirstStage();
$moderationStageRegister = new ModerationStageRegister();
$moderationStageRegister->registerModerationStageOnSubmissionLog($moderationStage);
}

public function addFieldsAssignForm($hookName, $params)
public function addStageAdvanceToAssignForm($hookName, $params)
{
$request = PKPApplication::get()->getRequest();
$request = Application::get()->getRequest();
$templateMgr = TemplateManager::getManager($request);

$submission = $params[0]->getSubmission();
Expand Down Expand Up @@ -171,7 +173,7 @@ public function addToWorkflowTabs($hookName, $params)
{
$templateMgr = &$params[1];
$output = &$params[2];
$submission = $templateMgr->get_template_vars('submission');
$submission = $templateMgr->getTemplateVars('submission');

$moderationStage = new ModerationStage($submission);
if ($moderationStage->submissionStageExists()) {
Expand All @@ -198,30 +200,30 @@ public function addToWorkflowTabs($hookName, $params)
}
}

public function addCurrentStageStatus($hookName, $params)
public function addCurrentStageStatusToWorkflow($hookName, $params)
{
$templateMgr = &$params[1];
$submission = $templateMgr->get_template_vars('submission');
$submission = $templateMgr->getTemplateVars('submission');

if (!is_null($submission->getData('currentModerationStage'))) {
$moderationStage = new ModerationStage($submission);

$templateMgr->assign('currentStageName', $moderationStage->getCurrentStageName());
$templateMgr->registerFilter("output", array($this, 'addCurrentStageStatusFilter'));
$templateMgr->registerFilter("output", [$this, 'addCurrentStageStatusToWorkflowFilter']);
}

return false;
}

public function addCurrentStageStatusFilter($output, $templateMgr)
public function addCurrentStageStatusToWorkflowFilter($output, $templateMgr)
{
if (preg_match('/<span[^>]+v-if="publicationList.length/', $output, $matches, PREG_OFFSET_CAPTURE)) {
$posMatch = $matches[0][1];

$currentStageStatus = $templateMgr->fetch($this->getTemplateResource('currentStageStatus.tpl'));

$output = substr_replace($output, $currentStageStatus, $posMatch, 0);
$templateMgr->unregisterFilter('output', array($this, 'addCurrentStageStatusFilter'));
$templateMgr->unregisterFilter('output', array($this, 'addCurrentStageStatusToWorkflowFilter'));
}
return $output;
}
Expand All @@ -233,24 +235,24 @@ public function getStyleSheet()

private function userIsAuthor($submission)
{
$currentUser = \Application::get()->getRequest()->getUser();
$currentUser = Application::get()->getRequest()->getUser();
$currentUserAssignedRoles = array();
if ($currentUser) {
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
$stageAssignmentsResult = $stageAssignmentDao->getBySubmissionAndUserIdAndStageId($submission->getId(), $currentUser->getId(), $submission->getData('stageId'));
$userGroupDao = DAORegistry::getDAO('UserGroupDAO');

while ($stageAssignment = $stageAssignmentsResult->next()) {
$userGroup = $userGroupDao->getById($stageAssignment->getUserGroupId(), $submission->getData('contextId'));
$userGroup = Repo::userGroup()->get($stageAssignment->getUserGroupId(), $submission->getData('contextId'));
$currentUserAssignedRoles[] = (int) $userGroup->getRoleId();
}
}

return $currentUserAssignedRoles[0] == ROLE_ID_AUTHOR;
return $currentUserAssignedRoles[0] == Role::ROLE_ID_AUTHOR;
}

public function sendSubmissionToNextModerationStage($hookName, $params)
{
$request = PKPApplication::get()->getRequest();
$request = Application::get()->getRequest();
$form = $params[0];
$requestVars = $request->getUserVars();

Expand All @@ -275,19 +277,18 @@ public function hideParticipantsOnDiscussionOpening($hookName, $params)
$allParticipants = $templateMgr->getTemplateVars('allParticipants');

$query = $form->getQuery();
$submission = Services::get('submission')->get($query->getData('assocId'));
$submission = Repo::submission()->get($query->getData('assocId'));

if ($this->userIsAuthor($submission)) {
$author = $request->getUser();
$newParticipantsList = [];
$allowedUsersEmails = [
$author->getEmail(),
SCIELO_BRASIL_EMAIL
self::SCIELO_BRASIL_EMAIL
];

foreach ($allParticipants as $participantId => $participantData) {
$userDao = DAORegistry::getDAO('UserDAO');
$participant = $userDao->getById($participantId);
$participant = Repo::user()->get($participantId);

if (in_array($participant->getEmail(), $allowedUsersEmails)) {
$newParticipantsList[$participantId] = $participantData;
Expand Down
33 changes: 19 additions & 14 deletions classes/ModerationStage.inc.php → classes/ModerationStage.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<?php

define('SCIELO_MODERATION_STAGE_FORMAT', 1);
define('SCIELO_MODERATION_STAGE_CONTENT', 2);
define('SCIELO_MODERATION_STAGE_AREA', 3);
namespace APP\plugins\generic\scieloModerationStages\classes;

use APP\submission\Submission;
use PKP\core\Core;

class ModerationStage
{
public const SCIELO_MODERATION_STAGE_FORMAT = 1;
public const SCIELO_MODERATION_STAGE_CONTENT = 2;
public const SCIELO_MODERATION_STAGE_AREA = 3;

public $submission;

public function __construct($submission)
Expand All @@ -16,9 +21,9 @@ public function __construct($submission)
private function getModerationStageName($stage)
{
$stageMap = [
SCIELO_MODERATION_STAGE_FORMAT => 'plugins.generic.scieloModerationStages.stages.formatStage',
SCIELO_MODERATION_STAGE_CONTENT => 'plugins.generic.scieloModerationStages.stages.contentStage',
SCIELO_MODERATION_STAGE_AREA => 'plugins.generic.scieloModerationStages.stages.areaStage',
self::SCIELO_MODERATION_STAGE_FORMAT => 'plugins.generic.scieloModerationStages.stages.formatStage',
self::SCIELO_MODERATION_STAGE_CONTENT => 'plugins.generic.scieloModerationStages.stages.contentStage',
self::SCIELO_MODERATION_STAGE_AREA => 'plugins.generic.scieloModerationStages.stages.areaStage',
];

return __($stageMap[$stage]);
Expand All @@ -27,8 +32,8 @@ private function getModerationStageName($stage)
private function getNextModerationStage($stage)
{
$nextStageMap = [
SCIELO_MODERATION_STAGE_FORMAT => SCIELO_MODERATION_STAGE_CONTENT,
SCIELO_MODERATION_STAGE_CONTENT => SCIELO_MODERATION_STAGE_AREA,
self::SCIELO_MODERATION_STAGE_FORMAT => self::SCIELO_MODERATION_STAGE_CONTENT,
self::SCIELO_MODERATION_STAGE_CONTENT => self::SCIELO_MODERATION_STAGE_AREA,
];

return $nextStageMap[$stage];
Expand All @@ -37,9 +42,9 @@ private function getNextModerationStage($stage)
private function getModerationStageEntryConfig($stage)
{
$stageMap = [
SCIELO_MODERATION_STAGE_FORMAT => 'formatStageEntryDate',
SCIELO_MODERATION_STAGE_CONTENT => 'contentStageEntryDate',
SCIELO_MODERATION_STAGE_AREA => 'areaStageEntryDate',
self::SCIELO_MODERATION_STAGE_FORMAT => 'formatStageEntryDate',
self::SCIELO_MODERATION_STAGE_CONTENT => 'contentStageEntryDate',
self::SCIELO_MODERATION_STAGE_AREA => 'areaStageEntryDate',
];

return $stageMap[$stage];
Expand Down Expand Up @@ -81,12 +86,12 @@ public function getNextStageName(): string

public function canAdvanceStage(): bool
{
if ($this->submission->getData('status') == STATUS_DECLINED || $this->submission->getData('status') == STATUS_PUBLISHED) {
if ($this->submission->getData('status') == Submission::STATUS_DECLINED || $this->submission->getData('status') == Submission::STATUS_PUBLISHED) {
return false;
}

$currentStage = $this->submission->getData('currentModerationStage');
if (is_null($currentStage) || $currentStage == SCIELO_MODERATION_STAGE_AREA) {
if (is_null($currentStage) || $currentStage == self::SCIELO_MODERATION_STAGE_AREA) {
return false;
}

Expand All @@ -100,7 +105,7 @@ public function submissionStageExists(): bool

public function setToFirstStage()
{
$this->setSubmissionToStage(SCIELO_MODERATION_STAGE_FORMAT);
$this->setSubmissionToStage(self::SCIELO_MODERATION_STAGE_FORMAT);
}

public function sendNextStage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
* Operations for retrieving data to help identify submissions' moderation stage
*/

import('lib.pkp.classes.db.DAO');
namespace APP\plugins\generic\scieloModerationStages\classes;

use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Support\Collection;
use PKP\db\DAO;
use Illuminate\Support\Facades\DB;

class ModerationStageDAO extends DAO
{
public function getSubmissionModerationStage($submissionId): ?int
{
$result = Capsule::table('submission_settings')
$result = DB::table('submission_settings')
->where('submission_id', $submissionId)
->where('setting_name', 'currentModerationStage')
->select('setting_value')
Expand Down
21 changes: 0 additions & 21 deletions classes/ModerationStageRegister.inc.php

This file was deleted.

37 changes: 37 additions & 0 deletions classes/ModerationStageRegister.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace APP\plugins\generic\scieloModerationStages\classes;

use APP\core\Application;
use APP\facades\Repo;
use PKP\core\Core;
use PKP\security\Validation;
use PKP\log\event\PKPSubmissionEventLogEntry;
use APP\plugins\generic\scieloModerationStages\classes\ModerationStage;

class ModerationStageRegister
{
public function registerModerationStageOnDatabase(ModerationStage $stage)
{
Repo::submission()->edit($stage->submission, []);
}

public function registerModerationStageOnSubmissionlog(ModerationStage $stage)
{
$stageName = $stage->getCurrentStageName();
$submission = $stage->submission;

$user = Application::get()->getRequest()->getUser();

$eventLog = Repo::eventLog()->newDataObject([
'assocType' => Application::ASSOC_TYPE_SUBMISSION,
'assocId' => $submission->getId(),
'eventType' => PKPSubmissionEventLogEntry::SUBMISSION_LOG_METADATA_UPDATE,
'userId' => Validation::loggedInAs() ?? $user->getId(),
'message' => __('plugins.generic.scieloModerationStages.log.submissionSentToModerationStage', ['moderationStageName' => $stageName]),
'isTranslated' => true,
'dateLogged' => Core::getCurrentDate(),
]);
Repo::eventLog()->add($eventLog);
}
}
Loading

0 comments on commit 9c48a60

Please sign in to comment.