diff --git a/classes/components/forms/emailTemplate/EmailTemplateForm.php b/classes/components/forms/emailTemplate/EmailTemplateForm.php index 3c83f56c8f3..49a355e7526 100644 --- a/classes/components/forms/emailTemplate/EmailTemplateForm.php +++ b/classes/components/forms/emailTemplate/EmailTemplateForm.php @@ -33,13 +33,12 @@ public function __construct(string $action, array $locales) $this->action = $action; $this->method = 'POST'; $this->locales = $locales; - $userGroups = collect(); - Repo::userGroup()->getCollector() - ->filterByContextIds([Application::get()->getRequest()->getContext()->getId()]) - ->getMany()->each(fn (UserGroup $group) => $userGroups->add([ - 'value' => $group->getId(), - 'label' => $group->getLocalizedName() + + collect(UserGroup::all()) + ->each(fn(UserGroup $group) => $userGroups->add([ + 'value' => $group->id, + 'label' => $group->getLocalizedData('name', null) ])); $this->addField(new FieldText('name', [ diff --git a/classes/emailTemplate/Repository.php b/classes/emailTemplate/Repository.php index 6bf1aa9215c..3c23592dc3c 100644 --- a/classes/emailTemplate/Repository.php +++ b/classes/emailTemplate/Repository.php @@ -24,6 +24,7 @@ use PKP\security\Role; use PKP\services\PKPSchemaService; use PKP\user\User; +use PKP\userGroup\UserGroup; use PKP\validation\ValidatorFactory; class Repository @@ -134,9 +135,11 @@ public function validate(?EmailTemplate $object, array $props, Context $context) // If assignedUserGroupIds were passed to limit email access, check that the user groups exists within the context if (isset($props['assignedUserGroupIds'])) { $validator->after(function () use ($validator, $props, $context) { - $existingGroupIds = Repo::userGroup()->getCollector() - ->filterByContextIds([$context->getId()]) - ->filterByUserGroupIds($props['assignedUserGroupIds'])->getIds()->toArray(); + $existingGroupIds = UserGroup::withContextIds([$context->getId()]) + ->withUserGroupIds($props['assignedUserGroupIds']) + ->get() + ->pluck('userGroupId') + ->toArray(); if (!empty(array_diff($existingGroupIds, $props['assignedUserGroupIds']))) { $validator->errors()->add('assignedUserGroupIds', __('api.emailTemplates.404.userGroupIds')); @@ -200,7 +203,7 @@ public function deleteMany(Collector $collector): void { foreach ($collector->getMany() as $emailTemplate) { $this->delete($emailTemplate); - $this->deleteTemplateGroupAccess(Application::get()->getRequest()->getContext()->getId(), $emailTemplate); + $this->deleteTemplateGroupAccess(Application::get()->getRequest()->getContext()->getId(), [$emailTemplate->getData('key')]); } } @@ -267,7 +270,7 @@ public function isTemplateAccessibleToUser(User $user, EmailTemplate $template, $templateUserGroups = $this->getAssignedGroupsIds($template->getData('key'), $contextId); foreach ($userUserGroups as $userGroup) { - if (in_array($userGroup->getId(), $templateUserGroups)) { + if (in_array($userGroup->id, $templateUserGroups)) { return true; } }