From 0352becf9c19227b3719e64dd513426c9bccb8fa Mon Sep 17 00:00:00 2001 From: Taslan Graham Date: Thu, 14 Nov 2024 12:31:58 -0500 Subject: [PATCH] pkp/pkp-lib#10571 Make templates assignable to all user groups --- .../emailTemplates/PKPEmailTemplateController.php | 2 +- .../forms/FieldEmailTemplateUnrestricted.php | 1 - classes/decision/steps/Email.php | 7 ------- classes/emailTemplate/Repository.php | 2 +- classes/mail/Repository.php | 15 +++++++++------ locale/en/admin.po | 6 +++--- 6 files changed, 14 insertions(+), 19 deletions(-) diff --git a/api/v1/emailTemplates/PKPEmailTemplateController.php b/api/v1/emailTemplates/PKPEmailTemplateController.php index ca361607236..39386af3b7b 100644 --- a/api/v1/emailTemplates/PKPEmailTemplateController.php +++ b/api/v1/emailTemplates/PKPEmailTemplateController.php @@ -256,7 +256,7 @@ public function edit(Request $illuminateRequest): JsonResponse return response()->json($errors, Response::HTTP_BAD_REQUEST); } - Repo::emailTemplate()->edit($emailTemplate, $params, $requestContext->getId()); + Repo::emailTemplate()->edit($emailTemplate, $params); Repo::emailTemplate()->setEmailTemplateAccess($emailTemplate, $requestContext->getId(), $params['userGroupIds'], $params['isUnrestricted']); $emailTemplate = Repo::emailTemplate()->getByKey( diff --git a/classes/components/forms/FieldEmailTemplateUnrestricted.php b/classes/components/forms/FieldEmailTemplateUnrestricted.php index 80e62146b57..fe035b48d13 100644 --- a/classes/components/forms/FieldEmailTemplateUnrestricted.php +++ b/classes/components/forms/FieldEmailTemplateUnrestricted.php @@ -27,7 +27,6 @@ class FieldEmailTemplateUnrestricted extends Field public function getConfig() { $config = parent::getConfig(); - $config['label'] = $this->label; return $config; } } diff --git a/classes/decision/steps/Email.php b/classes/decision/steps/Email.php index f8114728531..ab3200d6a9d 100644 --- a/classes/decision/steps/Email.php +++ b/classes/decision/steps/Email.php @@ -21,7 +21,6 @@ use PKP\facades\Locale; use PKP\mail\Mailable; use PKP\user\User; -use Role; use stdClass; class Email extends Step @@ -125,12 +124,6 @@ protected function getEmailTemplates(): array { $request = Application::get()->getRequest(); $context = $request->getContext(); - $userRoles = array_map(fn (Role $role) => $role->getId(), $request->getUser()->getRoles($context->getId())); - - // Ensure user has access to mailable before proceeding - if(empty(array_intersect($this->mailable::getFromRoleIds(), $userRoles))) { - return []; - } $emailTemplates = collect(); if ($this->mailable::getEmailTemplateKey()) { diff --git a/classes/emailTemplate/Repository.php b/classes/emailTemplate/Repository.php index 877859cc172..05a5aedf554 100644 --- a/classes/emailTemplate/Repository.php +++ b/classes/emailTemplate/Repository.php @@ -171,7 +171,7 @@ public function add(EmailTemplate $emailTemplate): string } /** @copydoc DAO::update() */ - public function edit(EmailTemplate $emailTemplate, array $params, $contextId) + public function edit(EmailTemplate $emailTemplate, array $params) { $newEmailTemplate = clone $emailTemplate; $newEmailTemplate->setAllData(array_merge($newEmailTemplate->_data, $params)); diff --git a/classes/mail/Repository.php b/classes/mail/Repository.php index a4eebf6265d..2b0322a2553 100644 --- a/classes/mail/Repository.php +++ b/classes/mail/Repository.php @@ -29,6 +29,7 @@ use PKP\mail\mailables\SubmissionSavedForLater; use PKP\mail\traits\Configurable; use PKP\plugins\Hook; +use PKP\userGroup\UserGroup; class Repository { @@ -108,14 +109,16 @@ public function summarizeMailable(string $class): array $userGroups = []; $roleNames = Application::get()->getRoleNames(); - foreach (Repo::userGroup()->getByRoleIds($roles, Application::get()->getRequest()->getContext()->getId())->all() as $group) { - $roleId = $group->getRoleId(); - $userGroups[] = [ + $userGroups = collect(); + + Repo::userGroup()->getCollector() + ->filterByContextIds([Application::get()->getRequest()->getContext()->getId()]) + ->getMany()->each(fn (UserGroup $group) => $userGroups->add([ 'id' => $group->getId(), 'name' => $group->getLocalizedName(), - 'roleId' => $roleId, - 'roleName' => $roleNames[$roleId]]; - } + 'roleId' => $group->getRoleId(), + 'roleName' => $roleNames[$group->getRoleId()] + ])); return [ '_href' => Application::get()->getRequest()->getDispatcher()->url( diff --git a/locale/en/admin.po b/locale/en/admin.po index 9f487320792..9e758598aa2 100644 --- a/locale/en/admin.po +++ b/locale/en/admin.po @@ -1016,10 +1016,10 @@ msgid "admin.cli.tool.scheduler.run.prompt" msgstr "Which command would you like to run?" msgid "admin.workflow.email.userGroup.allowed" -msgstr "Allowed User Groups" +msgstr "Limit Access to Specific User Groups" -msgid "workflow.email.userGroup.assign.unrestricted" +msgid "admin.workflow.email.userGroup.assign.unrestricted" msgstr "Mark as unrestricted" -msgid "workflow.email.userGroup.unrestricted.template.note" +msgid "admin.workflow.email.userGroup.unrestricted.template.note" msgstr "Unrestricted templates will be accessible to all user groups(listed below) associated with this template."