From d20a0e810a5aaf74d12eee393f20d1ec9bf74bb1 Mon Sep 17 00:00:00 2001 From: Jhon Date: Tue, 1 Oct 2024 18:34:37 -0400 Subject: [PATCH 01/10] Extracts function to new class Intention is to reuse it in other classes Issue: documentacao-e-tarefas/scielo#702 Signed-off-by: Jhon --- classes/ModerationReminderHelper.inc.php | 37 +++++++++++++++++++ classes/tasks/SendModerationReminders.inc.php | 28 ++------------ 2 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 classes/ModerationReminderHelper.inc.php diff --git a/classes/ModerationReminderHelper.inc.php b/classes/ModerationReminderHelper.inc.php new file mode 100644 index 0000000..513a147 --- /dev/null +++ b/classes/ModerationReminderHelper.inc.php @@ -0,0 +1,37 @@ +moderationStageDao = new ModerationStageDAO(); + } + + public function getResponsiblesAssignments(int $contextId): array + { + $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); + $contextUserGroups = $userGroupDao->getByContextId($contextId)->toArray(); + + foreach ($contextUserGroups as $userGroup) { + $userGroupAbbrev = strtolower($userGroupDao->getSetting($userGroup->getId(), 'abbrev', 'en_US')); + + if ($userGroupAbbrev === 'resp') { + $responsiblesUserGroup = $userGroup; + break; + } + } + + if (!$responsiblesUserGroup) { + return []; + } + + $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); + $responsiblesAssignments = $stageAssignmentDao->getByUserGroupId($responsiblesUserGroup->getId(), $contextId); + + return $responsiblesAssignments->toArray(); + } +} diff --git a/classes/tasks/SendModerationReminders.inc.php b/classes/tasks/SendModerationReminders.inc.php index b4101c5..4660fb8 100644 --- a/classes/tasks/SendModerationReminders.inc.php +++ b/classes/tasks/SendModerationReminders.inc.php @@ -4,6 +4,7 @@ import('plugins.generic.scieloModerationStages.classes.ModerationStage'); import('plugins.generic.scieloModerationStages.classes.ModerationStageDAO'); import('plugins.generic.scieloModerationStages.classes.ModerationReminderEmailBuilder'); +import('plugins.generic.scieloModerationStages.classes.ModerationReminderHelper'); class SendModerationReminders extends ScheduledTask { @@ -15,7 +16,8 @@ public function executeActions() $this->plugin = PluginRegistry::getPlugin('generic', 'scielomoderationstagesplugin'); $context = Application::get()->getRequest()->getContext(); - $responsiblesAssignments = $this->getResponsiblesAssignments($context->getId()); + $moderationReminderHelper = new ModerationReminderHelper(); + $responsiblesAssignments = $moderationReminderHelper->getResponsiblesAssignments($context->getId()); $preModerationAssignments = $this->filterPreModerationAssignments($responsiblesAssignments); if (empty($preModerationAssignments)) { @@ -36,30 +38,6 @@ public function executeActions() return true; } - private function getResponsiblesAssignments(int $contextId) - { - $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); - $contextUserGroups = $userGroupDao->getByContextId($contextId)->toArray(); - - foreach ($contextUserGroups as $userGroup) { - $userGroupAbbrev = strtolower($userGroupDao->getSetting($userGroup->getId(), 'abbrev', 'en_US')); - - if ($userGroupAbbrev === 'resp') { - $responsiblesUserGroup = $userGroup; - break; - } - } - - if (!$responsiblesUserGroup) { - return []; - } - - $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); - $responsiblesAssignments = $stageAssignmentDao->getByUserGroupId($responsiblesUserGroup->getId(), $contextId); - - return $responsiblesAssignments->toArray(); - } - private function filterPreModerationAssignments($responsiblesAssignments): array { $moderationStageDao = new ModerationStageDAO(); From 0bb61dd539fc2a1aae503cee316b22cc1ef4e154 Mon Sep 17 00:00:00 2001 From: Jhon Date: Wed, 2 Oct 2024 14:59:05 -0400 Subject: [PATCH 02/10] Creates base form for sending moderation reminder Issue: documentacao-e-tarefas/scielo#702 Signed-off-by: Jhon --- ScieloModerationStagesPlugin.inc.php | 44 ++++++++++++------- ...ScieloModerationStagesSettingsForm.inc.php | 0 form/SendModerationReminderForm.inc.php | 24 ++++++++++ locale/en_US/locale.po | 3 ++ locale/es_ES/locale.po | 3 ++ locale/pt_BR/locale.po | 3 ++ templates/sendModerationReminderForm.tpl | 15 +++++++ 7 files changed, 77 insertions(+), 15 deletions(-) rename ScieloModerationStagesSettingsForm.inc.php => form/ScieloModerationStagesSettingsForm.inc.php (100%) create mode 100644 form/SendModerationReminderForm.inc.php create mode 100644 templates/sendModerationReminderForm.tpl diff --git a/ScieloModerationStagesPlugin.inc.php b/ScieloModerationStagesPlugin.inc.php index 47126c1..aa1f01b 100644 --- a/ScieloModerationStagesPlugin.inc.php +++ b/ScieloModerationStagesPlugin.inc.php @@ -97,15 +97,22 @@ public function getActions($request, $actionArgs) import('lib.pkp.classes.linkAction.request.AjaxModal'); return array_merge( [ + new LinkAction( + 'sendModerationReminder', + new AjaxModal( + $router->url($request, null, null, 'manage', null, ['verb' => 'sendModerationReminder', 'plugin' => $this->getName(), 'category' => 'generic']), + __('plugins.generic.scieloModerationStages.sendModerationReminder') + ), + __('plugins.generic.scieloModerationStages.sendModerationReminder') + ), new LinkAction( 'settings', new AjaxModal( $router->url($request, null, null, 'manage', null, ['verb' => 'settings', 'plugin' => $this->getName(), 'category' => 'generic']), __('plugins.generic.scieloModerationStages.settings.title') ), - __('manager.plugins.settings'), - null - ), + __('manager.plugins.settings') + ) ], parent::getActions($request, $actionArgs) ); @@ -118,22 +125,29 @@ public function manage($args, $request) switch ($request->getUserVar('verb')) { case 'settings': - $this->import('ScieloModerationStagesSettingsForm'); - $form = new ScieloModerationStagesSettingsForm($this, $contextId); - if ($request->getUserVar('save')) { - $form->readInputData(); - if ($form->validate()) { - $form->execute(); - return new JSONMessage(true); - } - } else { - $form->initData(); - } - return new JSONMessage(true, $form->fetch($request)); + return $this->handlePluginForm($request, $contextId, 'ScieloModerationStagesSettingsForm'); + case 'sendModerationReminder': + return $this->handlePluginForm($request, $contextId, 'SendModerationReminderForm'); } return parent::manage($args, $request); } + private function handlePluginForm($request, $contextId, $formClass) + { + $this->import('form.'.$formClass); + $form = new $formClass($this, $contextId); + if ($request->getUserVar('save')) { + $form->readInputData(); + if ($form->validate()) { + $form->execute(); + return new JSONMessage(true); + } + } else { + $form->initData(); + } + return new JSONMessage(true, $form->fetch($request)); + } + public function setupScieloModerationStagesHandler($hookName, $params) { $component = &$params[0]; diff --git a/ScieloModerationStagesSettingsForm.inc.php b/form/ScieloModerationStagesSettingsForm.inc.php similarity index 100% rename from ScieloModerationStagesSettingsForm.inc.php rename to form/ScieloModerationStagesSettingsForm.inc.php diff --git a/form/SendModerationReminderForm.inc.php b/form/SendModerationReminderForm.inc.php new file mode 100644 index 0000000..eced13c --- /dev/null +++ b/form/SendModerationReminderForm.inc.php @@ -0,0 +1,24 @@ +contextId = $contextId; + $this->plugin = $plugin; + parent::__construct($plugin->getTemplateResource('sendModerationReminderForm.tpl')); + } + + public function fetch($request, $template = null, $display = false) + { + $templateMgr = TemplateManager::getManager($request); + $templateMgr->assign('pluginName', $this->plugin->getName()); + $templateMgr->assign('applicationName', Application::get()->getName()); + return parent::fetch($request, $template, $display); + } +} diff --git a/locale/en_US/locale.po b/locale/en_US/locale.po index e5c26bf..60ad71b 100644 --- a/locale/en_US/locale.po +++ b/locale/en_US/locale.po @@ -136,6 +136,9 @@ msgid "plugins.generic.scieloModerationStages.settings.remindersDayOfWeek" msgstr "Note: Moderation reminders will be sent every Monday." +msgid "plugins.generic.scieloModerationStages.sendModerationReminder" +msgstr "Send moderation reminder" + msgid "plugins.generic.scieloModerationStages.submissionMade.lessThanADayAgo" msgstr "Submission made less than a day ago" diff --git a/locale/es_ES/locale.po b/locale/es_ES/locale.po index a07c441..180e91c 100644 --- a/locale/es_ES/locale.po +++ b/locale/es_ES/locale.po @@ -136,6 +136,9 @@ msgid "plugins.generic.scieloModerationStages.settings.remindersDayOfWeek" msgstr "Nota: Los recordatorios de moderación se enviarán todos los lunes." +msgid "plugins.generic.scieloModerationStages.sendModerationReminder" +msgstr "Enviar recordatorio de moderación" + msgid "plugins.generic.scieloModerationStages.submissionMade.lessThanADayAgo" msgstr "Envío realizado hace menos de un día" diff --git a/locale/pt_BR/locale.po b/locale/pt_BR/locale.po index d0f57fd..55353f3 100644 --- a/locale/pt_BR/locale.po +++ b/locale/pt_BR/locale.po @@ -136,6 +136,9 @@ msgid "plugins.generic.scieloModerationStages.settings.remindersDayOfWeek" msgstr "Obs.: Os lembretes de moderação serão enviados todas as segundas-feiras." +msgid "plugins.generic.scieloModerationStages.sendModerationReminder" +msgstr "Enviar lembrete de moderação" + msgid "plugins.generic.scieloModerationStages.submissionMade.lessThanADayAgo" msgstr "Submissão realizada há menos de um dia" diff --git a/templates/sendModerationReminderForm.tpl b/templates/sendModerationReminderForm.tpl new file mode 100644 index 0000000..bb2af32 --- /dev/null +++ b/templates/sendModerationReminderForm.tpl @@ -0,0 +1,15 @@ + + +
+
+ {csrf} + {include file="controllers/notification/inPlaceNotification.tpl" notificationId="sendModerationReminderFormNotification"} + {fbvFormButtons} +

{translate key="common.requiredField"}

+
+
+ From c1d6eec5f49313ddcaae9f121148c9db41aa5375 Mon Sep 17 00:00:00 2001 From: Jhon Date: Wed, 2 Oct 2024 17:52:49 -0400 Subject: [PATCH 03/10] Adds fields to reminder sending form Issue: documentacao-e-tarefas/scielo#702 Signed-off-by: Jhon --- form/SendModerationReminderForm.inc.php | 4 ++++ locale/en_US/locale.po | 15 +++++++++++++++ locale/es_ES/locale.po | 15 +++++++++++++++ locale/pt_BR/locale.po | 15 +++++++++++++++ templates/sendModerationReminderForm.tpl | 11 ++++++++++- 5 files changed, 59 insertions(+), 1 deletion(-) diff --git a/form/SendModerationReminderForm.inc.php b/form/SendModerationReminderForm.inc.php index eced13c..245abd3 100644 --- a/form/SendModerationReminderForm.inc.php +++ b/form/SendModerationReminderForm.inc.php @@ -1,6 +1,7 @@ getContext()->getId(); + $moderationReminderHelper = new ModerationReminderHelper(); + $templateMgr->assign('pluginName', $this->plugin->getName()); $templateMgr->assign('applicationName', Application::get()->getName()); return parent::fetch($request, $template, $display); diff --git a/locale/en_US/locale.po b/locale/en_US/locale.po index 60ad71b..995396a 100644 --- a/locale/en_US/locale.po +++ b/locale/en_US/locale.po @@ -139,6 +139,21 @@ msgstr "Note: Moderation reminders will be sent every Monday." msgid "plugins.generic.scieloModerationStages.sendModerationReminder" msgstr "Send moderation reminder" +msgid "plugins.generic.scieloModerationStages.sendModerationReminder.responsible.title" +msgstr "Responsible" + +msgid "plugins.generic.scieloModerationStages.sendModerationReminder.responsible.description" +msgstr "Select to which responsible person the moderation reminder should be sent" + +msgid "plugins.generic.scieloModerationStages.sendModerationReminder.reminderBody.title" +msgstr "Reminder body" + +msgid "plugins.generic.scieloModerationStages.sendModerationReminder.reminderBody.description" +msgstr "Body of the reminder message to be sent" + +msgid "plugins.generic.scieloModerationStages.send" +msgstr "Send" + msgid "plugins.generic.scieloModerationStages.submissionMade.lessThanADayAgo" msgstr "Submission made less than a day ago" diff --git a/locale/es_ES/locale.po b/locale/es_ES/locale.po index 180e91c..7d781b5 100644 --- a/locale/es_ES/locale.po +++ b/locale/es_ES/locale.po @@ -139,6 +139,21 @@ msgstr "Nota: Los recordatorios de moderación se enviarán tod msgid "plugins.generic.scieloModerationStages.sendModerationReminder" msgstr "Enviar recordatorio de moderación" +msgid "plugins.generic.scieloModerationStages.sendModerationReminder.responsible.title" +msgstr "Responsable" + +msgid "plugins.generic.scieloModerationStages.sendModerationReminder.responsible.description" +msgstr "Seleccione a quién debe enviarse el recordatorio de moderación" + +msgid "plugins.generic.scieloModerationStages.sendModerationReminder.reminderBody.title" +msgstr "Cuerpo del recordatorio" + +msgid "plugins.generic.scieloModerationStages.sendModerationReminder.reminderBody.description" +msgstr "Cuerpo del mensaje de recordatorio que se enviará" + +msgid "plugins.generic.scieloModerationStages.send" +msgstr "Enviar" + msgid "plugins.generic.scieloModerationStages.submissionMade.lessThanADayAgo" msgstr "Envío realizado hace menos de un día" diff --git a/locale/pt_BR/locale.po b/locale/pt_BR/locale.po index 55353f3..12419b7 100644 --- a/locale/pt_BR/locale.po +++ b/locale/pt_BR/locale.po @@ -139,6 +139,21 @@ msgstr "Obs.: Os lembretes de moderação serão enviados todas msgid "plugins.generic.scieloModerationStages.sendModerationReminder" msgstr "Enviar lembrete de moderação" +msgid "plugins.generic.scieloModerationStages.sendModerationReminder.responsible.title" +msgstr "Responsável" + +msgid "plugins.generic.scieloModerationStages.sendModerationReminder.responsible.description" +msgstr "Selecione para qual responsável deve ser enviado o lembrete de moderação" + +msgid "plugins.generic.scieloModerationStages.sendModerationReminder.reminderBody.title" +msgstr "Corpo do lembrete" + +msgid "plugins.generic.scieloModerationStages.sendModerationReminder.reminderBody.description" +msgstr "Corpo da mensagem de lembrete a ser enviada" + +msgid "plugins.generic.scieloModerationStages.send" +msgstr "Enviar" + msgid "plugins.generic.scieloModerationStages.submissionMade.lessThanADayAgo" msgstr "Submissão realizada há menos de um dia" diff --git a/templates/sendModerationReminderForm.tpl b/templates/sendModerationReminderForm.tpl index bb2af32..8b16624 100644 --- a/templates/sendModerationReminderForm.tpl +++ b/templates/sendModerationReminderForm.tpl @@ -8,7 +8,16 @@
{csrf} {include file="controllers/notification/inPlaceNotification.tpl" notificationId="sendModerationReminderFormNotification"} - {fbvFormButtons} + + {fbvFormSection id="responsibleSection" label="plugins.generic.scieloModerationStages.sendModerationReminder.responsible.title"} + {fbvElement type="select" id="responsible" name="responsible" from=$responsibles required="true" label="plugins.generic.scieloModerationStages.sendModerationReminder.responsible.description" size=$fbvStyles.size.MEDIUM} + {/fbvFormSection} + + {fbvFormSection id="reminderBodySection" label="plugins.generic.scieloModerationStages.sendModerationReminder.reminderBody.title"} + {fbvElement type="textarea" id="reminderBody" name="reminderBody" label="plugins.generic.scieloModerationStages.sendModerationReminder.reminderBody.description" rich=true value=$reminderBody} + {/fbvFormSection} + + {fbvFormButtons submitText="plugins.generic.scieloModerationStages.send"}

{translate key="common.requiredField"}

From 397ccc96a5acc1511cb5d0105092df88d1478163 Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 3 Oct 2024 12:38:50 -0400 Subject: [PATCH 04/10] WIP: Creation of moderation reminder helper test Issue: documentacao-e-tarefas/scielo#702 Signed-off-by: Jhon --- tests/ModerationReminderHelperTest.php | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/ModerationReminderHelperTest.php diff --git a/tests/ModerationReminderHelperTest.php b/tests/ModerationReminderHelperTest.php new file mode 100644 index 0000000..ce5b49c --- /dev/null +++ b/tests/ModerationReminderHelperTest.php @@ -0,0 +1,45 @@ +moderationReminderHelper = new ModerationReminderHelper(); + } + + private function createTestAssignments(): array + { + $firstAssignment = new StageAssignment(); + $firstAssignment->setData('submissionId', 256); + $firstAssignment->setData('stageId', WORKFLOW_STAGE_ID_SUBMISSION); + + $secondAssignment = new StageAssignment(); + $secondAssignment->setData('submissionId', 257); + $secondAssignment->setData('stageId', WORKFLOW_STAGE_ID_SUBMISSION); + + $thirdAssignment = new StageAssignment(); + $thirdAssignment->setData('submissionId', 258); + $thirdAssignment->setData('stageId', WORKFLOW_STAGE_ID_SUBMISSION); + + return [$firstAssignment, $secondAssignment, $thirdAssignment]; + } + + public function testFilterPreModerationAssignments(): void + { + $assignments = $this->createTestAssignments(); + $mockedModerationStageDao = null; + $this->moderationReminderHelper->setModerationStageDao($mockedModerationStageDao); + + $expectedFilteredAssignments = []; + $filteredAssignments = $this->moderationReminderHelper->filterPreModerationAssignments($assignments); + + $this->assertEquals($expectedFilteredAssignments, $filteredAssignments); + } +} From ff248a2808ddfa32695c97973957ed195cc76a94 Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 3 Oct 2024 14:27:22 -0400 Subject: [PATCH 05/10] Finishes test for filtering of pre-moderation assignments Issue: documentacao-e-tarefas/scielo#702 Signed-off-by: Jhon --- classes/ModerationReminderHelper.inc.php | 21 +++++++++++++++++++ classes/tasks/SendModerationReminders.inc.php | 19 +---------------- tests/ModerationReminderHelperTest.php | 18 ++++++++++++++-- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/classes/ModerationReminderHelper.inc.php b/classes/ModerationReminderHelper.inc.php index 513a147..5354790 100644 --- a/classes/ModerationReminderHelper.inc.php +++ b/classes/ModerationReminderHelper.inc.php @@ -11,6 +11,11 @@ public function __construct() $this->moderationStageDao = new ModerationStageDAO(); } + public function setModerationStageDao($moderationStageDao) + { + $this->moderationStageDao = $moderationStageDao; + } + public function getResponsiblesAssignments(int $contextId): array { $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); @@ -34,4 +39,20 @@ public function getResponsiblesAssignments(int $contextId): array return $responsiblesAssignments->toArray(); } + + public function filterPreModerationAssignments(array $assignments): array + { + $preModerationAssignments = []; + + foreach ($assignments as $assignment) { + $submissionId = $assignment->getData('submissionId'); + $submissionModerationStage = $this->moderationStageDao->getSubmissionModerationStage($submissionId); + + if ($submissionModerationStage === SCIELO_MODERATION_STAGE_CONTENT) { + $preModerationAssignments[] = $assignment; + } + } + + return $preModerationAssignments; + } } diff --git a/classes/tasks/SendModerationReminders.inc.php b/classes/tasks/SendModerationReminders.inc.php index 4660fb8..3feeec7 100644 --- a/classes/tasks/SendModerationReminders.inc.php +++ b/classes/tasks/SendModerationReminders.inc.php @@ -18,7 +18,7 @@ public function executeActions() $context = Application::get()->getRequest()->getContext(); $moderationReminderHelper = new ModerationReminderHelper(); $responsiblesAssignments = $moderationReminderHelper->getResponsiblesAssignments($context->getId()); - $preModerationAssignments = $this->filterPreModerationAssignments($responsiblesAssignments); + $preModerationAssignments = $moderationReminderHelper->filterPreModerationAssignments($responsiblesAssignments); if (empty($preModerationAssignments)) { return true; @@ -38,23 +38,6 @@ public function executeActions() return true; } - private function filterPreModerationAssignments($responsiblesAssignments): array - { - $moderationStageDao = new ModerationStageDAO(); - $preModerationAssignments = []; - - foreach ($responsiblesAssignments as $assignment) { - $submissionId = $assignment->getData('submissionId'); - $submissionModerationStage = $moderationStageDao->getSubmissionModerationStage($submissionId); - - if ($submissionModerationStage === SCIELO_MODERATION_STAGE_CONTENT) { - $preModerationAssignments[] = $assignment; - } - } - - return $preModerationAssignments; - } - private function getUsersWithOverduePreModeration($contextId, $preModerationAssignments): array { $usersIds = []; diff --git a/tests/ModerationReminderHelperTest.php b/tests/ModerationReminderHelperTest.php index ce5b49c..79e8005 100644 --- a/tests/ModerationReminderHelperTest.php +++ b/tests/ModerationReminderHelperTest.php @@ -3,6 +3,8 @@ use PHPUnit\Framework\TestCase; import('lib.pkp.classes.stageAssignment.StageAssignment'); +import('plugins.generic.scieloModerationStages.classes.ModerationStage'); +import('plugins.generic.scieloModerationStages.classes.ModerationStageDAO'); import('plugins.generic.scieloModerationStages.classes.ModerationReminderHelper'); class ModerationReminderHelperTest extends TestCase @@ -31,13 +33,25 @@ private function createTestAssignments(): array return [$firstAssignment, $secondAssignment, $thirdAssignment]; } + private function createModerationStageDaoMock() + { + $mockedDAO = $this->createMock(ModerationStageDAO::class); + $mockedDAO->method('getSubmissionModerationStage')->willReturnMap([ + [256, SCIELO_MODERATION_STAGE_CONTENT], + [257, SCIELO_MODERATION_STAGE_FORMAT], + [258, SCIELO_MODERATION_STAGE_CONTENT] + ]); + + return $mockedDAO; + } + public function testFilterPreModerationAssignments(): void { $assignments = $this->createTestAssignments(); - $mockedModerationStageDao = null; + $mockedModerationStageDao = $this->createModerationStageDaoMock(); $this->moderationReminderHelper->setModerationStageDao($mockedModerationStageDao); - $expectedFilteredAssignments = []; + $expectedFilteredAssignments = [$assignments[0], $assignments[2]]; $filteredAssignments = $this->moderationReminderHelper->filterPreModerationAssignments($assignments); $this->assertEquals($expectedFilteredAssignments, $filteredAssignments); From b98a7745e7738aada8d1c18ec69579fb784ce092 Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 3 Oct 2024 15:42:44 -0400 Subject: [PATCH 06/10] Creates method to get users from assignments Issue: documentacao-e-tarefas/scielo#702 Signed-off-by: Jhon --- classes/ModerationReminderHelper.inc.php | 18 +++++- classes/tasks/SendModerationReminders.inc.php | 2 +- tests/ModerationReminderHelperTest.php | 62 +++++++++++++++++-- 3 files changed, 76 insertions(+), 6 deletions(-) diff --git a/classes/ModerationReminderHelper.inc.php b/classes/ModerationReminderHelper.inc.php index 5354790..8dfe276 100644 --- a/classes/ModerationReminderHelper.inc.php +++ b/classes/ModerationReminderHelper.inc.php @@ -40,7 +40,7 @@ public function getResponsiblesAssignments(int $contextId): array return $responsiblesAssignments->toArray(); } - public function filterPreModerationAssignments(array $assignments): array + public function filterAssignmentsOfSubmissionsOnPreModeration(array $assignments): array { $preModerationAssignments = []; @@ -55,4 +55,20 @@ public function filterPreModerationAssignments(array $assignments): array return $preModerationAssignments; } + + public function getUsersFromAssignments(array $assignments): array + { + $users = []; + $userDao = DAORegistry::getDAO('UserDAO'); + + foreach ($assignments as $assignment) { + $user = $userDao->getById($assignment->getUserId()); + + if ($user and !isset($users[$user->getId()])) { + $users[$user->getId()] = $user; + } + } + + return $users; + } } diff --git a/classes/tasks/SendModerationReminders.inc.php b/classes/tasks/SendModerationReminders.inc.php index 3feeec7..15002e0 100644 --- a/classes/tasks/SendModerationReminders.inc.php +++ b/classes/tasks/SendModerationReminders.inc.php @@ -18,7 +18,7 @@ public function executeActions() $context = Application::get()->getRequest()->getContext(); $moderationReminderHelper = new ModerationReminderHelper(); $responsiblesAssignments = $moderationReminderHelper->getResponsiblesAssignments($context->getId()); - $preModerationAssignments = $moderationReminderHelper->filterPreModerationAssignments($responsiblesAssignments); + $preModerationAssignments = $moderationReminderHelper->filterAssignmentsOfSubmissionsOnPreModeration($responsiblesAssignments); if (empty($preModerationAssignments)) { return true; diff --git a/tests/ModerationReminderHelperTest.php b/tests/ModerationReminderHelperTest.php index 79e8005..2ab7359 100644 --- a/tests/ModerationReminderHelperTest.php +++ b/tests/ModerationReminderHelperTest.php @@ -2,6 +2,8 @@ use PHPUnit\Framework\TestCase; +import('lib.pkp.classes.user.User'); +import('lib.pkp.classes.user.UserDAO'); import('lib.pkp.classes.stageAssignment.StageAssignment'); import('plugins.generic.scieloModerationStages.classes.ModerationStage'); import('plugins.generic.scieloModerationStages.classes.ModerationStageDAO'); @@ -10,10 +12,35 @@ class ModerationReminderHelperTest extends TestCase { private $moderationReminderHelper; + private $moderatorUsers; + private $assignments; + private $locale = 'en_US'; public function setUp(): void { $this->moderationReminderHelper = new ModerationReminderHelper(); + $this->moderatorUsers = $this->createTestModeratorUsers(); + $this->assignments = $this->createTestAssignments(); + } + + protected function getMockedDAOs() + { + return ['UserDAO']; + } + + private function createTestModeratorUsers(): array + { + $firstModerator = new User(); + $firstModerator->setData('id', 312); + $firstModerator->setGivenName('Edgar', $this->locale); + $firstModerator->setFamilyName('Linton', $this->locale); + + $secondModerator = new User(); + $secondModerator->setData('id', 313); + $secondModerator->setGivenName('Catherine', $this->locale); + $secondModerator->setFamilyName('Earnshaw', $this->locale); + + return [$firstModerator, $secondModerator]; } private function createTestAssignments(): array @@ -21,14 +48,17 @@ private function createTestAssignments(): array $firstAssignment = new StageAssignment(); $firstAssignment->setData('submissionId', 256); $firstAssignment->setData('stageId', WORKFLOW_STAGE_ID_SUBMISSION); + $firstAssignment->setData('userId', $this->moderatorUsers[0]->getId()); $secondAssignment = new StageAssignment(); $secondAssignment->setData('submissionId', 257); $secondAssignment->setData('stageId', WORKFLOW_STAGE_ID_SUBMISSION); + $secondAssignment->setData('userId', $this->moderatorUsers[0]->getId()); $thirdAssignment = new StageAssignment(); $thirdAssignment->setData('submissionId', 258); $thirdAssignment->setData('stageId', WORKFLOW_STAGE_ID_SUBMISSION); + $thirdAssignment->setData('userId', $this->moderatorUsers[1]->getId()); return [$firstAssignment, $secondAssignment, $thirdAssignment]; } @@ -45,15 +75,39 @@ private function createModerationStageDaoMock() return $mockedDAO; } - public function testFilterPreModerationAssignments(): void + private function registerUserDaoMock() + { + $mockedUserDao = $this->getMockBuilder(UserDAO::class) + ->setMethods(['getById']) + ->getMock(); + $mockedUserDao->expects($this->any()) + ->method('getById') + ->will($this->onConsecutiveCalls($this->moderatorUsers[0], $this->moderatorUsers[1])); + + DAORegistry::registerDAO('UserDAO', $mockedUserDao); + } + + public function testFilterAssignmentsOfSubmissionsOnPreModeration(): void { - $assignments = $this->createTestAssignments(); $mockedModerationStageDao = $this->createModerationStageDaoMock(); $this->moderationReminderHelper->setModerationStageDao($mockedModerationStageDao); - $expectedFilteredAssignments = [$assignments[0], $assignments[2]]; - $filteredAssignments = $this->moderationReminderHelper->filterPreModerationAssignments($assignments); + $expectedFilteredAssignments = [$this->assignments[0], $this->assignments[2]]; + $filteredAssignments = $this->moderationReminderHelper->filterAssignmentsOfSubmissionsOnPreModeration($this->assignments); $this->assertEquals($expectedFilteredAssignments, $filteredAssignments); } + + public function testGetUsersFromAssignments(): void + { + $this->registerUserDaoMock(); + + $expectedAssignedUsers = [ + $this->moderatorUsers[1]->getId() => $this->moderatorUsers[1], + $this->moderatorUsers[0]->getId() => $this->moderatorUsers[0], + ]; + $usersFromAssignments = $this->moderationReminderHelper->getUsersFromAssignments($this->assignments); + + $this->assertEquals($expectedAssignedUsers, $usersFromAssignments); + } } From a976051b52bafc033968910598e9ebd16c1f1dda Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 3 Oct 2024 16:16:02 -0400 Subject: [PATCH 07/10] Shows responsibles users in form for sending reminder Issue: documentacao-e-tarefas/scielo#702 Signed-off-by: Jhon --- form/SendModerationReminderForm.inc.php | 43 ++++++++++++++++++++++-- templates/sendModerationReminderForm.tpl | 2 +- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/form/SendModerationReminderForm.inc.php b/form/SendModerationReminderForm.inc.php index 245abd3..29b37e6 100644 --- a/form/SendModerationReminderForm.inc.php +++ b/form/SendModerationReminderForm.inc.php @@ -15,14 +15,51 @@ public function __construct($plugin, $contextId) parent::__construct($plugin->getTemplateResource('sendModerationReminderForm.tpl')); } + private function getResponsibles(int $contextId): array + { + $moderationReminderHelper = new ModerationReminderHelper(); + $responsibleAssignments = $moderationReminderHelper->getResponsiblesAssignments($contextId); + + if (empty($responsibleAssignments)) { + return []; + } + + $filteredAssignments = $moderationReminderHelper->filterAssignmentsOfSubmissionsOnPreModeration($responsibleAssignments); + $usersFromAssignments = $moderationReminderHelper->getUsersFromAssignments($filteredAssignments); + + $mappedUsers = [null => null]; + foreach ($usersFromAssignments as $userId => $user) { + $fullName = $user->getFullName(); + $mappedUsers[$userId] = $fullName; + } + + asort($mappedUsers, SORT_STRING); + + return $mappedUsers; + } + public function fetch($request, $template = null, $display = false) { $templateMgr = TemplateManager::getManager($request); $contextId = $request->getContext()->getId(); - $moderationReminderHelper = new ModerationReminderHelper(); - $templateMgr->assign('pluginName', $this->plugin->getName()); - $templateMgr->assign('applicationName', Application::get()->getName()); + $templateMgr->assign([ + 'responsibles' => $this->getResponsibles($contextId), + 'pluginName' => $this->plugin->getName(), + 'applicationName' => Application::get()->getName() + ]); + return parent::fetch($request, $template, $display); } + + public function readInputData() + { + $this->readUserVars(['responsible', 'reminderBody']); + } + + public function execute(...$functionArgs) + { + error_log($this->getData('responsible')); + error_log($this->getData('reminderBody')); + } } diff --git a/templates/sendModerationReminderForm.tpl b/templates/sendModerationReminderForm.tpl index 8b16624..14c4ae0 100644 --- a/templates/sendModerationReminderForm.tpl +++ b/templates/sendModerationReminderForm.tpl @@ -10,7 +10,7 @@ {include file="controllers/notification/inPlaceNotification.tpl" notificationId="sendModerationReminderFormNotification"} {fbvFormSection id="responsibleSection" label="plugins.generic.scieloModerationStages.sendModerationReminder.responsible.title"} - {fbvElement type="select" id="responsible" name="responsible" from=$responsibles required="true" label="plugins.generic.scieloModerationStages.sendModerationReminder.responsible.description" size=$fbvStyles.size.MEDIUM} + {fbvElement type="select" id="responsible" name="responsible" from=$responsibles required="true" label="plugins.generic.scieloModerationStages.sendModerationReminder.responsible.description" translate=false size=$fbvStyles.size.MEDIUM} {/fbvFormSection} {fbvFormSection id="reminderBodySection" label="plugins.generic.scieloModerationStages.sendModerationReminder.reminderBody.title"} From d2def5a77f022e054ba8676480d97b9699f60696 Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 3 Oct 2024 19:09:40 -0400 Subject: [PATCH 08/10] Shows reminder body when responsible is selected in form Issue: documentacao-e-tarefas/scielo#702 Signed-off-by: Jhon --- classes/ModerationReminderHelper.inc.php | 31 ++++++++++++++++++- classes/tasks/SendModerationReminders.inc.php | 31 +++---------------- .../ScieloModerationStagesHandler.inc.php | 27 ++++++++++++++++ form/SendModerationReminderForm.inc.php | 3 +- templates/sendModerationReminderForm.tpl | 23 ++++++++++++++ 5 files changed, 86 insertions(+), 29 deletions(-) diff --git a/classes/ModerationReminderHelper.inc.php b/classes/ModerationReminderHelper.inc.php index 8dfe276..227fd6a 100644 --- a/classes/ModerationReminderHelper.inc.php +++ b/classes/ModerationReminderHelper.inc.php @@ -16,7 +16,7 @@ public function setModerationStageDao($moderationStageDao) $this->moderationStageDao = $moderationStageDao; } - public function getResponsiblesAssignments(int $contextId): array + public function getResponsiblesUserGroup(int $contextId) { $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); $contextUserGroups = $userGroupDao->getByContextId($contextId)->toArray(); @@ -30,6 +30,11 @@ public function getResponsiblesAssignments(int $contextId): array } } + return $responsiblesUserGroup; + } + + public function getResponsibleAssignments($responsiblesUserGroup, $contextId): array + { if (!$responsiblesUserGroup) { return []; } @@ -71,4 +76,28 @@ public function getUsersFromAssignments(array $assignments): array return $users; } + + private function mapUsersAndSubmissions($users, $assignments) + { + $usersMap = []; + $submissionDao = DAORegistry::getDAO('SubmissionDAO'); + + foreach ($users as $userId) { + foreach ($assignments as $assignment) { + if ($userId != $assignment->getData('userId')) { + continue; + } + + $submission = $submissionDao->getById($assignment->getData('submissionId')); + + if (isset($usersMap[$userId])) { + $usersMap[$userId] = array_merge($usersMap[$userId], [$submission]); + } else { + $usersMap[$userId] = [$submission]; + } + } + } + + return $usersMap; + } } diff --git a/classes/tasks/SendModerationReminders.inc.php b/classes/tasks/SendModerationReminders.inc.php index 15002e0..7a79fdd 100644 --- a/classes/tasks/SendModerationReminders.inc.php +++ b/classes/tasks/SendModerationReminders.inc.php @@ -17,15 +17,16 @@ public function executeActions() $context = Application::get()->getRequest()->getContext(); $moderationReminderHelper = new ModerationReminderHelper(); - $responsiblesAssignments = $moderationReminderHelper->getResponsiblesAssignments($context->getId()); - $preModerationAssignments = $moderationReminderHelper->filterAssignmentsOfSubmissionsOnPreModeration($responsiblesAssignments); + $responsiblesUserGroup = $moderationReminderHelper->getResponsiblesUserGroup($context->getId()); + $responsibleAssignments = $moderationReminderHelper->getResponsibleAssignments($responsiblesUserGroup, $context->getId()); + $preModerationAssignments = $moderationReminderHelper->filterAssignmentsOfSubmissionsOnPreModeration($responsibleAssignments); if (empty($preModerationAssignments)) { return true; } $usersWithOverduePreModeration = $this->getUsersWithOverduePreModeration($context->getId(), $preModerationAssignments); - $mapModeratorsAndOverdueSubmissions = $this->mapModeratorsAndOverdueSubmissions($usersWithOverduePreModeration, $preModerationAssignments); + $mapModeratorsAndOverdueSubmissions = $moderationReminderHelper->mapUsersAndSubmissions($usersWithOverduePreModeration, $preModerationAssignments); foreach ($mapModeratorsAndOverdueSubmissions as $userId => $submissions) { $moderator = DAORegistry::getDAO('UserDAO')->getById($userId); @@ -55,28 +56,4 @@ private function getUsersWithOverduePreModeration($contextId, $preModerationAssi return $usersIds; } - - private function mapModeratorsAndOverdueSubmissions($moderators, $preModerationAssignments) - { - $moderatorsMap = []; - $submissionDao = DAORegistry::getDAO('SubmissionDAO'); - - foreach ($moderators as $moderatorId) { - foreach ($preModerationAssignments as $assignment) { - if ($moderatorId != $assignment->getData('userId')) { - continue; - } - - $submission = $submissionDao->getById($assignment->getData('submissionId')); - - if (isset($moderatorsMap[$moderatorId])) { - $moderatorsMap[$moderatorId] = array_merge($moderatorsMap[$moderatorId], [$submission]); - } else { - $moderatorsMap[$moderatorId] = [$submission]; - } - } - } - - return $moderatorsMap; - } } diff --git a/controllers/ScieloModerationStagesHandler.inc.php b/controllers/ScieloModerationStagesHandler.inc.php index 6a27a4f..527fc94 100644 --- a/controllers/ScieloModerationStagesHandler.inc.php +++ b/controllers/ScieloModerationStagesHandler.inc.php @@ -5,12 +5,39 @@ import('classes.handler.Handler'); import('classes.workflow.EditorDecisionActionsManager'); import('plugins.generic.scieloModerationStages.classes.ModerationStageDAO'); +import('plugins.generic.scieloModerationStages.classes.ModerationReminderHelper'); +import('plugins.generic.scieloModerationStages.classes.ModerationReminderEmailBuilder'); class ScieloModerationStagesHandler extends Handler { private const SUBMISSION_STAGE_ID = 5; private const THRESHOLD_TIME_EXHIBITORS = 2; + public function getReminderBody($args, $request) + { + $responsible = DAORegistry::getDAO('UserDAO')->getById((int) $args['responsible']); + + $moderationReminderHelper = new ModerationReminderHelper(); + $context = $request->getContext(); + $responsiblesUserGroup = $moderationReminderHelper->getResponsiblesUserGroup($context->getId()); + $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); + $assignments = $stageAssignmentDao->_getByIds(null, null, $responsiblesUserGroup->getId(), $responsible->getId())->toArray(); + + $submissions = []; + foreach ($assignments as $assignment) { + $submission = DAORegistry::getDAO('SubmissionDAO')->getById($assignment->getSubmissionId()); + + if ($submission) { + $submissions[] = $submission; + } + } + + $moderationReminderEmailBuilder = new ModerationReminderEmailBuilder($context, $responsible, $submissions); + $reminderEmail = $moderationReminderEmailBuilder->buildEmail(); + + return json_encode(['reminderBody' => $reminderEmail->getBody()]); + } + public function updateSubmissionStageData($args, $request) { $submissionDao = DAORegistry::getDAO('SubmissionDAO'); diff --git a/form/SendModerationReminderForm.inc.php b/form/SendModerationReminderForm.inc.php index 29b37e6..b9e6ea1 100644 --- a/form/SendModerationReminderForm.inc.php +++ b/form/SendModerationReminderForm.inc.php @@ -18,7 +18,8 @@ public function __construct($plugin, $contextId) private function getResponsibles(int $contextId): array { $moderationReminderHelper = new ModerationReminderHelper(); - $responsibleAssignments = $moderationReminderHelper->getResponsiblesAssignments($contextId); + $responsiblesUserGroup = $moderationReminderHelper->getResponsiblesUserGroup($contextId); + $responsibleAssignments = $moderationReminderHelper->getResponsibleAssignments($responsiblesUserGroup, $contextId); if (empty($responsibleAssignments)) { return []; diff --git a/templates/sendModerationReminderForm.tpl b/templates/sendModerationReminderForm.tpl index 14c4ae0..7a3ca6b 100644 --- a/templates/sendModerationReminderForm.tpl +++ b/templates/sendModerationReminderForm.tpl @@ -22,3 +22,26 @@ +{capture assign=getReminderBodyUrl}{url router=$smarty.const.ROUTE_COMPONENT component="plugins.generic.scieloModerationStages.controllers.ScieloModerationStagesHandler" op="getReminderBody" escape=false}{/capture} + \ No newline at end of file From dce14941e42f88fef4530f5e8508650a6fb253b3 Mon Sep 17 00:00:00 2001 From: Jhon Date: Fri, 4 Oct 2024 15:02:45 -0400 Subject: [PATCH 09/10] Send moderation reminder on form saving Issue: documentacao-e-tarefas/scielo#702 Signed-off-by: Jhon --- classes/ModerationReminderHelper.inc.php | 2 +- form/SendModerationReminderForm.inc.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/classes/ModerationReminderHelper.inc.php b/classes/ModerationReminderHelper.inc.php index 227fd6a..70e6d5f 100644 --- a/classes/ModerationReminderHelper.inc.php +++ b/classes/ModerationReminderHelper.inc.php @@ -77,7 +77,7 @@ public function getUsersFromAssignments(array $assignments): array return $users; } - private function mapUsersAndSubmissions($users, $assignments) + public function mapUsersAndSubmissions($users, $assignments) { $usersMap = []; $submissionDao = DAORegistry::getDAO('SubmissionDAO'); diff --git a/form/SendModerationReminderForm.inc.php b/form/SendModerationReminderForm.inc.php index b9e6ea1..6e945d3 100644 --- a/form/SendModerationReminderForm.inc.php +++ b/form/SendModerationReminderForm.inc.php @@ -2,6 +2,7 @@ import('lib.pkp.classes.form.Form'); import('plugins.generic.scieloModerationStages.classes.ModerationReminderHelper'); +import('plugins.generic.scieloModerationStages.classes.ModerationReminderEmailBuilder'); class SendModerationReminderForm extends Form { @@ -60,7 +61,16 @@ public function readInputData() public function execute(...$functionArgs) { - error_log($this->getData('responsible')); - error_log($this->getData('reminderBody')); + $responsibleUserId = $this->getData('responsible'); + $reminderBody = $this->getData('reminderBody'); + + $responsible = DAORegistry::getDAO('UserDAO')->getById($responsibleUserId); + $context = Application::get()->getRequest()->getContext(); + + $moderationReminderEmailBuilder = new ModerationReminderEmailBuilder($context, $responsible, []); + $reminderEmail = $moderationReminderEmailBuilder->buildEmail(); + $reminderEmail->setBody($reminderBody); + + $reminderEmail->send(); } } From e56f38dbc134f8360aaa92e5c67d05c13cc70f48 Mon Sep 17 00:00:00 2001 From: Jhon Date: Fri, 4 Oct 2024 15:30:03 -0400 Subject: [PATCH 10/10] Updates version.xml Issue: documentacao-e-tarefas/scielo#702 Signed-off-by: Jhon --- version.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.xml b/version.xml index 8729e65..168bb60 100644 --- a/version.xml +++ b/version.xml @@ -13,7 +13,7 @@ scieloModerationStages plugins.generic 0 - 1.6.0.0 - 2024-08-26 + 1.6.1.0 + 2024-10-04 ScieloModerationStagesPlugin