Skip to content

Commit

Permalink
Rebase with main and remove usage of deleted methods
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham committed Dec 19, 2024
1 parent eb2a161 commit 0b673c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
11 changes: 5 additions & 6 deletions classes/components/forms/emailTemplate/EmailTemplateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down
13 changes: 8 additions & 5 deletions classes/emailTemplate/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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')]);
}
}

Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 0b673c4

Please sign in to comment.