diff --git a/controllers/grid/users/stageParticipant/StageParticipantGridHandler.inc.php b/controllers/grid/users/stageParticipant/StageParticipantGridHandler.inc.php index 8645e5e70a9..e6a8f722967 100644 --- a/controllers/grid/users/stageParticipant/StageParticipantGridHandler.inc.php +++ b/controllers/grid/users/stageParticipant/StageParticipantGridHandler.inc.php @@ -39,7 +39,7 @@ function __construct() { // Managers and Editors additionally get administrative access $this->addRoleAssignment( array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR), - array_merge($peOps, array('addParticipant', 'deleteParticipant', 'saveParticipant', 'fetchUserList')) + array_merge($peOps, array('addParticipant', 'saveParticipant', 'fetchUserList', 'removeParticipant', 'removeStageAssignment')) ); $this->setTitle('editor.submission.stageParticipants'); } @@ -356,12 +356,34 @@ function saveParticipant($args, $request) { } /** - * Delete the participant from the user groups - * @param $args - * @param $request - * @return JSONMessage JSON object + * Show a confirmation form to remove a stage participant, with optional email notification. + * @param $args array + * @param $request PKPRequest + * @return JSONMessage + */ + function removeParticipant($args, $request) { + $submission = $this->getSubmission(); + $assignmentId = (int) $request->getUserVar('assignmentId'); + + $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */ + $stageAssignment = $stageAssignmentDao->getById($assignmentId); + if (!$stageAssignment || $stageAssignment->getSubmissionId() != $submission->getId()) { + return new JSONMessage(false); + } + + import('lib.pkp.controllers.grid.users.stageParticipant.form.RemoveParticipantForm'); + $form = new RemoveParticipantForm($submission, $stageAssignment, $this->getStageId()); + $form->initData(); + return new JSONMessage(true, $form->fetch($request)); + } + + /** + * Handle removal form submission: optionally email the user and then remove the assignment. + * @param $args array + * @param $request PKPRequest + * @return JSONMessage */ - function deleteParticipant($args, $request) { + function removeStageAssignment($args, $request) { $submission = $this->getSubmission(); $stageId = $this->getStageId(); $assignmentId = (int) $request->getUserVar('assignmentId'); @@ -372,40 +394,19 @@ function deleteParticipant($args, $request) { return new JSONMessage(false); } - // Delete the assignment - $stageAssignmentDao->deleteObject($stageAssignment); + import('lib.pkp.controllers.grid.users.stageParticipant.form.RemoveParticipantForm'); + $form = new RemoveParticipantForm($submission, $stageAssignment, $stageId); + $form->readInputData(); + if (!$form->validate()) { + return new JSONMessage(true, $form->fetch($request)); + } - // FIXME: perhaps we can just insert the notification on page load - // instead of having it there all the time? - $notificationMgr = new NotificationManager(); - import('classes.workflow.EditorDecisionActionsManager'); - $notificationMgr->updateNotification( - $request, - (new EditorDecisionActionsManager())->getStageNotifications(), - null, - ASSOC_TYPE_SUBMISSION, - $submission->getId() - ); + $form->execute(); - if ($stageId == WORKFLOW_STAGE_ID_EDITING || - $stageId == WORKFLOW_STAGE_ID_PRODUCTION) { + $stageAssignmentDao->deleteObject($stageAssignment); - // Update submission notifications - $notificationMgr->updateNotification( - $request, - array( - NOTIFICATION_TYPE_ASSIGN_COPYEDITOR, - NOTIFICATION_TYPE_AWAITING_COPYEDITS, - NOTIFICATION_TYPE_ASSIGN_PRODUCTIONUSER, - NOTIFICATION_TYPE_AWAITING_REPRESENTATIONS, - ), - null, - ASSOC_TYPE_SUBMISSION, - $submission->getId() - ); - } + $notificationMgr = new NotificationManager(); - // Log removal. $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */ $assignedUser = $userDao->getById($stageAssignment->getUserId()); $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */ @@ -413,7 +414,9 @@ function deleteParticipant($args, $request) { import('lib.pkp.classes.log.SubmissionLog'); SubmissionLog::logEvent($request, $submission, SUBMISSION_LOG_REMOVE_PARTICIPANT, 'submission.event.participantRemoved', array('name' => $assignedUser->getFullName(), 'username' => $assignedUser->getUsername(), 'userGroupName' => $userGroup->getLocalizedName())); - // Redraw the category + $currentUser = $request->getUser(); + $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS); + return DAO::getDataChangedEvent($stageAssignment->getUserGroupId()); } @@ -547,6 +550,4 @@ function fetchTemplateBody($args, $request) { public function getJSHandler() { return '$.pkp.controllers.grid.users.stageParticipant.StageParticipantGridHandler'; } -} - - +} \ No newline at end of file diff --git a/controllers/grid/users/stageParticipant/StageParticipantGridRow.inc.php b/controllers/grid/users/stageParticipant/StageParticipantGridRow.inc.php index 0bff7dfb3ac..1f8a76e3bd6 100644 --- a/controllers/grid/users/stageParticipant/StageParticipantGridRow.inc.php +++ b/controllers/grid/users/stageParticipant/StageParticipantGridRow.inc.php @@ -56,17 +56,14 @@ function initialize($request, $template = null) { if ($this->_canAdminister) { $this->addAction(new LinkAction( 'delete', - new RemoteActionConfirmationModal( - $request->getSession(), - __('editor.submission.removeStageParticipant.description'), - __('editor.submission.removeStageParticipant'), - $router->url($request, null, null, 'deleteParticipant', null, $this->getRequestArgs()), - 'modal_delete' - ), - __('grid.action.remove'), - 'delete' - ) - ); + new AjaxModal( + $router->url($request, null, null, 'removeParticipant', null, $this->getRequestArgs()), + __('editor.submission.removeStageParticipant'), + 'modal_delete' + ), + __('grid.action.remove'), + 'delete' + )); $this->addAction(new LinkAction( 'requestAccount', diff --git a/controllers/grid/users/stageParticipant/form/RemoveParticipantForm.inc.php b/controllers/grid/users/stageParticipant/form/RemoveParticipantForm.inc.php new file mode 100644 index 00000000000..5126539ef5e --- /dev/null +++ b/controllers/grid/users/stageParticipant/form/RemoveParticipantForm.inc.php @@ -0,0 +1,126 @@ +_submission = $submission; + $this->_stageAssignment = $stageAssignment; + $this->_stageId = $stageId; + + $this->addCheck(new FormValidatorPost($this)); + $this->addCheck(new FormValidatorCSRF($this)); + } + + /** + * Initialize form data + */ + function initData() { + $request = Application::get()->getRequest(); + $user = $request->getUser(); + $submission = $this->_submission; + $userTobeRemovedId = $this->_stageAssignment->getUserId(); + $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */ + $userToBeRemoved = $userDao->getById($userTobeRemovedId); + + $defaultMessage = __('editor.submission.removeStageParticipant.email.body', [ + 'userName' => $userToBeRemoved->getFullName(), + 'contextName' => $request->getContext()->getLocalizedName(), + 'submissionTitle' => $submission->getLocalizedTitle() + ]); + $defaultMessage .= $user->getContactSignature(); + + $this->setData('assignmentId', $this->_stageAssignment->getId()); + $this->setData('stageId', $this->_stageId); + $this->setData('submissionId', $submission->getId()); + $this->setData('personalMessage', $defaultMessage); + $this->setData('skipEmail', false); + } + + /** + * @copydoc Form::fetch() + */ + function fetch($request, $template = null, $display = false) { + $templateMgr = TemplateManager::getManager($request); + $templateMgr->assign(array( + 'reviewRoundId' => null, + 'reviewerId' => $this->_stageAssignment->getUserId(), + 'assignmentId' => $this->_stageAssignment->getId(), + 'stageId' => $this->_stageId, + 'submissionId' => $this->_submission->getId(), + 'personalMessage' => $this->getData('personalMessage'), + )); + return parent::fetch($request, $template, $display); + } + + /** + * @copydoc Form::readInputData() + */ + function readInputData() { + $this->readUserVars(array('assignmentId', 'stageId', 'submissionId', 'personalMessage', 'skipEmail')); + } + + /** + * @copydoc Form::validate() + */ + function validate(...$functionArgs) { + return parent::validate(...$functionArgs); + } + + /** + * @copydoc Form::execute() + */ + function execute(...$functionArgs) { + $request = Application::get()->getRequest(); + if ($this->getData('skipEmail')) return parent::execute(...$functionArgs); + + $submission = $this->_submission; + $fromUser = $request->getUser(); + + $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */ + $user = $userDao->getById($this->_stageAssignment->getUserId()); + if (!$user) return parent::execute(...$functionArgs); + + import('classes.mail.ArticleMailTemplate'); + $mail = new ArticleMailTemplate($submission, 'NOTIFICATION_CENTER_DEFAULT'); + $mail->addRecipient($user->getEmail(), $user->getFullName()); + $mail->setSubject(__('editor.submission.removeStageParticipant')); + $mail->setBody($this->getData('personalMessage')); + + if ($mail->isEnabled() && !$mail->send($request)) { + $notificationMgr = new NotificationManager(); + $notificationMgr->createTrivialNotification($fromUser->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => __('email.compose.error'))); + } + + return parent::execute(...$functionArgs); + } +} \ No newline at end of file diff --git a/locale/en_US/submission.po b/locale/en_US/submission.po index f318d60acb7..25af4392ad7 100644 --- a/locale/en_US/submission.po +++ b/locale/en_US/submission.po @@ -1388,6 +1388,15 @@ msgstr "" msgid "editor.submission.removeStageParticipant" msgstr "Remove Participant" +msgid "editor.submission.removeStageParticipant.email.body" +msgstr "" +"\n" +"\t\t\t{$userName}:
\n" +"
\n" +"You have been removed as a participant in the "{$submissionTitle}" submission, " +"on the {$contextName}.
\n" +"
\n" + msgid "editor.submission.removeStageParticipant.description" msgstr "" "You are about to remove this participant from all stages." diff --git a/locale/es_ES/submission.po b/locale/es_ES/submission.po index 4d6b9af608f..837719a4fa3 100644 --- a/locale/es_ES/submission.po +++ b/locale/es_ES/submission.po @@ -1412,6 +1412,15 @@ msgstr "" msgid "editor.submission.removeStageParticipant" msgstr "Eliminar participante" +msgid "editor.submission.removeStageParticipant.email.body" +msgstr "" +"\n" +"\t\t\t{$userName}:
\n" +"
\n" +"Has sido eliminado como participante de lo envío "{$submissionTitle}", " +"en {$contextName}.
\n" +"
\n" + msgid "editor.submission.removeStageParticipant.description" msgstr "" "Está a punto de eliminar a este participante de todas las " @@ -2209,4 +2218,4 @@ msgstr "" #~ msgstr "Explorar {$numTitles} títulos" #~ msgid "catalog.noTitlesSection" -#~ msgstr "No se ha publicado ningún título aún para esta sección." +#~ msgstr "No se ha publicado ningún título aún para esta sección." \ No newline at end of file diff --git a/locale/pt_BR/submission.po b/locale/pt_BR/submission.po index a8cafe1eb17..552bf12fd41 100644 --- a/locale/pt_BR/submission.po +++ b/locale/pt_BR/submission.po @@ -1398,6 +1398,15 @@ msgstr "" msgid "editor.submission.removeStageParticipant" msgstr "Remover Participante" +msgid "editor.submission.removeStageParticipant.email.body" +msgstr "" +"\n" +"\t\t\t{$userName}:
\n" +"
\n" +"Você foi removido como participante da submissão "{$submissionTitle}", " +"em {$contextName}.
\n" +"
\n" + msgid "editor.submission.removeStageParticipant.description" msgstr "" "Você está prestes a remover este participante de todos os " @@ -2555,4 +2564,4 @@ msgstr "Por favor, divulgue quaisquer conflitos de interesse que este autor poss #~ msgstr "{$numTitles} títulos" #~ msgid "catalog.noTitlesSection" -#~ msgstr "Sem publicações para esta seção no momento." +#~ msgstr "Sem publicações para esta seção no momento." \ No newline at end of file diff --git a/templates/controllers/grid/users/stageParticipant/removeParticipantForm.tpl b/templates/controllers/grid/users/stageParticipant/removeParticipantForm.tpl new file mode 100644 index 00000000000..fd3896bc06a --- /dev/null +++ b/templates/controllers/grid/users/stageParticipant/removeParticipantForm.tpl @@ -0,0 +1,32 @@ +{** + * templates/controllers/grid/users/stageParticipant/removeParticipantForm.tpl + * + * Copyright (c) 2014-2021 Simon Fraser University + * Copyright (c) 2003-2021 John Willinsky + * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. + * + * Form to optionally notify a user when removing them as a stage participant. + *} + + + +
+ {csrf} + + + + + {fbvFormSection title="stageParticipants.notify.message" for="personalMessage"} + {fbvElement type="textarea" name="personalMessage" id="personalMessage" value=$personalMessage rich=true} + {/fbvFormSection} + + {fbvFormSection for="skipEmail" size=$fbvStyles.size.MEDIUM list=true} + {fbvElement type="checkbox" id="skipEmail" name="skipEmail" label="email.skip"} + {/fbvFormSection} + + {fbvFormButtons submitText="grid.action.remove"} +
\ No newline at end of file