From 1fe352e2fc79ebce41871142fe43022d95a8cd97 Mon Sep 17 00:00:00 2001 From: Taslan Graham Date: Mon, 25 Nov 2024 15:53:00 -0500 Subject: [PATCH] pkp/pkp-lib#10571 Remove unnecessary email form components and clean up code --- .../PKPEmailTemplateController.php | 15 ++++++--- .../forms/FieldEmailTemplateUnrestricted.php | 33 ------------------- .../FieldEmailTemplateUserGroupSettings.php | 33 ------------------- .../forms/emailTemplate/EmailTemplateForm.php | 32 ++++++++++++++---- classes/decision/steps/Email.php | 6 ++-- classes/emailTemplate/DAO.php | 2 +- .../EmailTemplateAccessGroup.php | 30 +++++++++++++++-- classes/emailTemplate/Repository.php | 30 ++++++++--------- classes/emailTemplate/maps/Schema.php | 33 +++++-------------- classes/invitation/sections/Email.php | 6 ++-- classes/mail/Repository.php | 25 +++++--------- .../EmailTemplateUserGroupAccessMigration.php | 4 +-- .../I10403_EmailTemplateUserGroupAccess.php | 16 +++++++-- .../V3_6_0/PreflightCheckMigration.php | 6 ++-- controllers/grid/queries/form/QueryForm.php | 2 +- .../form/AdvancedSearchReviewerForm.php | 4 +-- .../grid/users/reviewer/form/ReviewerForm.php | 2 +- schemas/emailTemplate.json | 22 ++----------- 18 files changed, 125 insertions(+), 176 deletions(-) delete mode 100644 classes/components/forms/FieldEmailTemplateUnrestricted.php delete mode 100644 classes/components/forms/FieldEmailTemplateUserGroupSettings.php diff --git a/api/v1/emailTemplates/PKPEmailTemplateController.php b/api/v1/emailTemplates/PKPEmailTemplateController.php index 723d5445d81..d8943e859e1 100644 --- a/api/v1/emailTemplates/PKPEmailTemplateController.php +++ b/api/v1/emailTemplates/PKPEmailTemplateController.php @@ -205,7 +205,7 @@ public function add(Request $illuminateRequest): JsonResponse $emailTemplate = Repo::emailTemplate()->newDataObject($params); Repo::emailTemplate()->add($emailTemplate); - Repo::emailTemplate()->setEmailTemplateAccess($emailTemplate, $requestContext->getId(), $params['userGroupIds'], $params['isUnrestricted']); + Repo::emailTemplate()->setEmailTemplateAccess($emailTemplate, $requestContext->getId(), $params['assignedUserGroupIds'], $params['isUnrestricted']); $emailTemplate = Repo::emailTemplate()->getByKey($emailTemplate->getData('contextId'), $emailTemplate->getData('key')); @@ -247,7 +247,7 @@ public function edit(Request $illuminateRequest): JsonResponse // If the user submitted an empty list (meaning all user groups were unchecked), the empty array is converted to null in the request's data. // Convert back to an empty array. - $params['userGroupIds'] = $params['userGroupIds'] ?: []; + $params['assignedUserGroupIds'] = $params['assignedUserGroupIds'] ?: []; $errors = Repo::emailTemplate()->validate( $emailTemplate, @@ -260,7 +260,7 @@ public function edit(Request $illuminateRequest): JsonResponse } Repo::emailTemplate()->edit($emailTemplate, $params); - Repo::emailTemplate()->setEmailTemplateAccess($emailTemplate, $requestContext->getId(), $params['userGroupIds'], $params['isUnrestricted']); + Repo::emailTemplate()->setEmailTemplateAccess($emailTemplate, $requestContext->getId(), $params['assignedUserGroupIds'], $params['isUnrestricted']); $emailTemplate = Repo::emailTemplate()->getByKey( // context ID is null if edited for the first time @@ -290,7 +290,14 @@ public function delete(Request $illuminateRequest): JsonResponse $props = Repo::emailTemplate()->getSchemaMap()->map($emailTemplate); Repo::emailTemplate()->delete($emailTemplate); - Repo::emailTemplate()->deleteTemplateGroupAccess($requestContext->getId(), [$illuminateRequest->route('key')]); + + // Default templates are not deleted - instead, their body and subject fields are reset. + // Only delete access group data for custom templates. + // Custom templates will have an alternateTo (which is the default) + if($emailTemplate->getData('alternateTo')) { + Repo::emailTemplate()->deleteTemplateGroupAccess($requestContext->getId(), [$illuminateRequest->route('key')]); + } + return response()->json($props, Response::HTTP_OK); } diff --git a/classes/components/forms/FieldEmailTemplateUnrestricted.php b/classes/components/forms/FieldEmailTemplateUnrestricted.php deleted file mode 100644 index f16a2a65e3c..00000000000 --- a/classes/components/forms/FieldEmailTemplateUnrestricted.php +++ /dev/null @@ -1,33 +0,0 @@ -subNote; - return $config; - } -} diff --git a/classes/components/forms/FieldEmailTemplateUserGroupSettings.php b/classes/components/forms/FieldEmailTemplateUserGroupSettings.php deleted file mode 100644 index e68cc07d5f4..00000000000 --- a/classes/components/forms/FieldEmailTemplateUserGroupSettings.php +++ /dev/null @@ -1,33 +0,0 @@ -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() + ])); + $this->addField(new FieldText('name', [ 'label' => __('common.name'), 'description' => __('manager.emailTemplate.name.description'), @@ -48,14 +58,22 @@ public function __construct(string $action, array $locales) 'isMultilingual' => true, 'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist', 'plugins' => 'paste,link,lists', - ]))->addField(new FieldEmailTemplateUnrestricted('isUnrestricted', [ - 'type' => 'checkbox', - 'label' => __('admin.workflow.email.userGroup.assign.unrestricted'), - 'subNote' => __('admin.workflow.email.userGroup.unrestricted.template.note') ])) - ->addField(new FieldEmailTemplateUserGroupSettings('userGroupIds', [ + ->addField(new FieldOptions('isUnrestricted', [ + 'label' => __('admin.workflow.email.userGroup.assign.unrestricted'), + 'groupId' => 'isUnrestricted', + 'description' => __('admin.workflow.email.userGroup.unrestricted.template.note'), 'type' => 'checkbox', + 'options' => [ + ['value' => true, 'label' => __('admin.workflow.email.userGroup.assign.unrestricted')], + ], + 'value' => true + ])) + ->addField(new FieldOptions('assignedUserGroupIds', [ 'label' => __('admin.workflow.email.userGroup.allowed'), + 'type' => 'checkbox', + 'value' => [], + 'options' => $userGroups ])); } } diff --git a/classes/decision/steps/Email.php b/classes/decision/steps/Email.php index aee87ada299..4f2649aefd4 100644 --- a/classes/decision/steps/Email.php +++ b/classes/decision/steps/Email.php @@ -135,9 +135,9 @@ protected function getEmailTemplates(): array ->getCollector($context->getId()) ->alternateTo([$this->mailable::getEmailTemplateKey()]) ->getMany() - ->each(function (EmailTemplate $e) use ($context, $request, $emailTemplates) { - if (Repo::emailTemplate()->isTemplateAccessibleToUser($request->getUser(), $e, $context->getId())) { - $emailTemplates->add($e); + ->each(function (EmailTemplate $template) use ($context, $request, $emailTemplates) { + if (Repo::emailTemplate()->isTemplateAccessibleToUser($request->getUser(), $template, $context->getId())) { + $emailTemplates->add($template); } }); } diff --git a/classes/emailTemplate/DAO.php b/classes/emailTemplate/DAO.php index 469ab30354e..6afeb5e160c 100644 --- a/classes/emailTemplate/DAO.php +++ b/classes/emailTemplate/DAO.php @@ -235,7 +235,7 @@ public function getMainEmailTemplatesFilename() * skipping others * @param bool $skipExisting If true, do not install email templates * that already exist in the database - * @param bool $recordTemplateGroupAccess - If true, records the templates as unrestricted. + * @param bool $recordTemplateGroupAccess - If true, records the templates as unrestricted. For versions 3.6 or higher, this value should be set to true when calling `installEmailTemplates`. * By default, it is set to false to ensure compatibility with older processes (e.g., migrations) * where the `email_template_user_group_access` table may not exist at the time of execution. * diff --git a/classes/emailTemplate/EmailTemplateAccessGroup.php b/classes/emailTemplate/EmailTemplateAccessGroup.php index bb139a53f9a..391f7dd1cb1 100644 --- a/classes/emailTemplate/EmailTemplateAccessGroup.php +++ b/classes/emailTemplate/EmailTemplateAccessGroup.php @@ -1,20 +1,38 @@ when(!empty($keys), function ($query) use ($keys) { @@ -22,11 +40,17 @@ public function scopeWithEmailKey(Builder $query, ?array $keys): Builder }); } + /** + * Scope a query to only include email template access records that are related to a specific context ID. + */ public function scopeWithContextId(Builder $query, int $contextId): Builder { return $query->where('context_id', $contextId); } + /** + * Scope a query to only include email template access records for specific user group IDs. + */ public function scopeWithGroupIds(Builder $query, array $ids): Builder { return $query->whereIn('user_group_id', $ids); diff --git a/classes/emailTemplate/Repository.php b/classes/emailTemplate/Repository.php index 373cad7d150..6bf1aa9215c 100644 --- a/classes/emailTemplate/Repository.php +++ b/classes/emailTemplate/Repository.php @@ -131,15 +131,15 @@ public function validate(?EmailTemplate $object, array $props, Context $context) }); } - // If groupIds were passed to limit email access, check that the user groups exists within the context - if (isset($props['userGroupIds'])) { + // 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['userGroupIds'])->getIds()->toArray(); + ->filterByUserGroupIds($props['assignedUserGroupIds'])->getIds()->toArray(); - if (!empty(array_diff($existingGroupIds, $props['userGroupIds']))) { - $validator->errors()->add('userGroupIds', __('api.emailTemplates.404.userGroupIds')); + if (!empty(array_diff($existingGroupIds, $props['assignedUserGroupIds']))) { + $validator->errors()->add('assignedUserGroupIds', __('api.emailTemplates.404.userGroupIds')); } }); } @@ -224,16 +224,14 @@ public function restoreDefaults($contextId): array $this->delete($emailTemplate); }); - $this->dao->installAlternateEmailTemplates($contextId); Repo::emailTemplate()->restoreTemplateUserGroupAccess($contextId, $deletedKeys); Hook::call('EmailTemplate::restoreDefaults', [&$deletedKeys, $contextId]); return $deletedKeys; } - /*** - * Gets the IDs of the user groups assigned to an email template + * Gets the IDs of the user groups assigned to an email template. */ public function getAssignedGroupsIds(string $templateKey, int $contextId): array { @@ -246,7 +244,7 @@ public function getAssignedGroupsIds(string $templateKey, int $contextId): array } /*** - * Checks if an Email Template is unrestricted + * Checks if an Email Template is unrestricted. */ public function isTemplateUnrestricted(string $templateKey, int $contextId): bool { @@ -256,9 +254,8 @@ public function isTemplateUnrestricted(string $templateKey, int $contextId): boo ->first(); } - /** - * Checks if an email template is accessible to a user. A template is accessible if it is assigned to a user group that the user belongs to or if the template is unrestricted + * Checks if an email template is accessible to a user. A template is accessible if it is assigned to a user group that the user belongs to or if the template is unrestricted. */ public function isTemplateAccessibleToUser(User $user, EmailTemplate $template, int $contextId): bool { @@ -300,7 +297,7 @@ public function filterTemplatesByUserAccess(Enumerable $templates, User $user, i } /*** - * Internal method used to assign user group IDs to an email template + * Internal method used to assign user group IDs to an email template. */ private function updateTemplateAccessGroups(EmailTemplate $emailTemplate, array $newUserGroupIds, int $contextId): void { @@ -327,7 +324,8 @@ private function updateTemplateAccessGroups(EmailTemplate $emailTemplate, array } /** - * Pass empty array in $userGroupIds to delete all existing user groups for a template + * Sets the restrictions for an email template. + * Pass empty array in $userGroupIds to delete all existing user groups for a template. */ public function setEmailTemplateAccess(EmailTemplate $emailTemplate, int $contextId, ?array $userGroupIds, ?bool $isUnrestricted): void { @@ -340,7 +338,6 @@ public function setEmailTemplateAccess(EmailTemplate $emailTemplate, int $contex } } - /** * Mark an email template as unrestricted or not. * An unrestricted email template is available to all user groups. @@ -372,9 +369,8 @@ public function markTemplateAsUnrestricted(string $emailKey, bool $isUnrestricte } } - /** - * Deletes all user group access for an email + * Deletes all user group access for an email. */ public function deleteTemplateGroupAccess(int $contextId, array $emailKey): void { @@ -382,7 +378,7 @@ public function deleteTemplateGroupAccess(int $contextId, array $emailKey): void } /** - * Deletes all user group access for an email template and set unrestricted to their default + * Deletes all user group access for an email template and set unrestricted to their default. */ public function restoreTemplateUserGroupAccess(int $contextId, array $emailKeys) { diff --git a/classes/emailTemplate/maps/Schema.php b/classes/emailTemplate/maps/Schema.php index a250048ceda..26d6d3fa017 100644 --- a/classes/emailTemplate/maps/Schema.php +++ b/classes/emailTemplate/maps/Schema.php @@ -19,7 +19,6 @@ use PKP\core\PKPApplication; use PKP\emailTemplate\EmailTemplate; use PKP\services\PKPSchemaService; -use PKP\userGroup\UserGroup; class Schema extends \PKP\core\maps\Schema { @@ -43,10 +42,8 @@ public function map(EmailTemplate $item): array * Summarize an email template * * Includes properties with the apiSummary flag in the email template schema. - * - * @param null|mixed $mailableClass */ - public function summarize(EmailTemplate $item, $mailableClass = null): array + public function summarize(EmailTemplate $item, ?string $mailableClass = null): array { return $this->mapByProperties($this->getSummaryProps(), $item, $mailableClass); } @@ -69,7 +66,7 @@ public function mapMany(Enumerable $collection): Enumerable * * @see self::summarize */ - public function summarizeMany(Enumerable $collection, string $mailableClass = null): Enumerable + public function summarizeMany(Enumerable $collection, ?string $mailableClass = null): Enumerable { $this->collection = $collection; return $collection->map(function ($item) use ($mailableClass) { @@ -80,10 +77,12 @@ public function summarizeMany(Enumerable $collection, string $mailableClass = nu /** * Map schema properties of an Email Template to an assoc array */ - protected function mapByProperties(array $props, EmailTemplate $item, string $mailableClass = null): array + protected function mapByProperties(array $props, EmailTemplate $item, ?string $mailableClass = null): array { $output = []; - $mailableClass = $mailableClass ?? Repo::mailable()->get($item->getData('key'), Application::get()->getRequest()->getContext()); + $context = Application::get()->getRequest()->getContext(); + $contextId = $context->getId(); + $mailableClass = $mailableClass ?? Repo::mailable()->get($item->getData('alternateTo') ?? $item->getData('key'), $context); foreach ($props as $prop) { switch ($prop) { @@ -96,31 +95,15 @@ protected function mapByProperties(array $props, EmailTemplate $item, string $ma ); break; case 'isUnrestricted': - $output['isUnrestricted'] = Repo::emailTemplate()->isTemplateUnrestricted($item->getData('key'), Application::get()->getRequest()->getContext()->getId()); + $output['isUnrestricted'] = Repo::emailTemplate()->isTemplateUnrestricted($item->getData('key'), $contextId); break; case 'assignedUserGroupIds': if ($mailableClass && Repo::mailable()->isGroupsAssignableToTemplates($mailableClass)) { - $output['assignedUserGroupIds'] = Repo::emailTemplate()->getAssignedGroupsIds($item->getData('key'), Application::get()->getRequest()->getContext()->getId()); + $output['assignedUserGroupIds'] = Repo::emailTemplate()->getAssignedGroupsIds($item->getData('key'), $contextId); } else { $output['assignedUserGroupIds'] = []; } break; - case 'assignableTemplateUserGroups': - if($mailableClass && Repo::mailable()->isGroupsAssignableToTemplates($mailableClass)) { - $userGroups = collect(); - - Repo::userGroup()->getCollector() - ->filterByContextIds([Application::get()->getRequest()->getContext()->getId()]) - ->getMany()->each(fn (UserGroup $group) => $userGroups->add([ - 'id' => $group->getId(), - 'name' => $group->getLocalizedName() - ])); - - $output['assignableTemplateUserGroups'] = $userGroups; - } else { - $output['assignableTemplateUserGroups'] = []; - } - break; default: $output[$prop] = $item->getData($prop); break; diff --git a/classes/invitation/sections/Email.php b/classes/invitation/sections/Email.php index 317336edfc3..9036abe9aa0 100644 --- a/classes/invitation/sections/Email.php +++ b/classes/invitation/sections/Email.php @@ -101,9 +101,9 @@ protected function getEmailTemplates(): array ->getCollector($context->getId()) ->alternateTo([$this->mailable::getEmailTemplateKey()]) ->getMany() - ->each(function (EmailTemplate $e) use ($context, $user, $emailTemplates) { - if(Repo::emailTemplate()->isTemplateAccessibleToUser($user, $e, $context->getId())) { - $emailTemplates->add($e); + ->each(function (EmailTemplate $template) use ($context, $user, $emailTemplates) { + if(Repo::emailTemplate()->isTemplateAccessibleToUser($user, $template, $context->getId())) { + $emailTemplates->add($template); } }); } diff --git a/classes/mail/Repository.php b/classes/mail/Repository.php index 71b193cb226..586fab1b40a 100644 --- a/classes/mail/Repository.php +++ b/classes/mail/Repository.php @@ -28,7 +28,6 @@ use PKP\mail\mailables\SubmissionSavedForLater; use PKP\mail\traits\Configurable; use PKP\plugins\Hook; -use PKP\userGroup\UserGroup; class Repository { @@ -101,15 +100,6 @@ public function summarizeMailable(string $class): array { $dataDescriptions = $class::getDataDescriptions(); ksort($dataDescriptions); - - $userGroups = collect(); - Repo::userGroup()->getCollector() - ->filterByContextIds([Application::get()->getRequest()->getContext()->getId()]) - ->getMany()->each(fn (UserGroup $group) => $userGroups->add([ - 'id' => $group->getId(), - 'name' => $group->getLocalizedName() - ])); - return [ '_href' => Application::get()->getRequest()->getDispatcher()->url( Application::get()->getRequest(), @@ -126,13 +116,12 @@ public function summarizeMailable(string $class): array 'supportsTemplates' => $class::getSupportsTemplates(), 'toRoleIds' => $class::getToRoleIds(), 'canAssignUserGroupToTemplates' => $this->isGroupsAssignableToTemplates($class), - 'assignableTemplateUserGroups' => $userGroups ]; } /** * Get a full description of a mailable's properties, including any - * assigned email templates that are accessible to user + * assigned email templates that are accessible to user. */ public function describeMailable(string $class, int $contextId): array { @@ -152,14 +141,18 @@ public function describeMailable(string $class, int $contextId): array $user = $request->getUser(); // Limit templates to only those accessible to the user's user group(s) - $userAccessibleTemplates = Repo::emailTemplate()->filterTemplatesByUserAccess(collect(array_merge([$defaultTemplate], $templates->values()->toArray())), $user, $contextId); + $userAccessibleTemplates = Repo::emailTemplate()->filterTemplatesByUserAccess( + collect(array_merge([$defaultTemplate], $templates->values()->toArray())), + $user, + $contextId + ); + $data['emailTemplates'] = Repo::emailTemplate() ->getSchemaMap() ->summarizeMany($userAccessibleTemplates, $class) ->values(); } - return $data; } @@ -217,13 +210,13 @@ protected function isMailableConfigurable(string $class, Context $context): bool /** - * Check if the templates of a given mailable can be assigned to specific groups + * Check if the templates of a given mailable can be assigned to specific groups. * * @param Mailable|string $mailable - Mailable class or qualified string referencing the class */ public function isGroupsAssignableToTemplates(Mailable|string $mailable): bool { - return !in_array(Mailable::FROM_SYSTEM, $mailable::getFromRoleIds()); + return !in_array(Mailable::FROM_SYSTEM, $mailable::getFromRoleIds()) && !in_array(Mailable::GROUP_OTHER, $mailable::getGroupIds()); } /** diff --git a/classes/migration/install/EmailTemplateUserGroupAccessMigration.php b/classes/migration/install/EmailTemplateUserGroupAccessMigration.php index cd6498eea3c..45f2c3c8333 100644 --- a/classes/migration/install/EmailTemplateUserGroupAccessMigration.php +++ b/classes/migration/install/EmailTemplateUserGroupAccessMigration.php @@ -31,8 +31,8 @@ public function up(): void $table->bigInteger('context_id')->comment('The ID of the context for which the user group assignment is defined.'); $table->bigInteger('user_group_id')->nullable()->comment('The user group ID. A null value indicates that the email template is accessible to all user groups.'); - $table->foreign('context_id')->references($contextDao->primaryKeyColumn)->on($contextDao->tableName)->onDelete('cascade')->onDelete('cascade'); - $table->foreign('user_group_id')->references('user_group_id')->on('user_groups')->onDelete('cascade')->onDelete('cascade'); + $table->foreign('context_id')->references($contextDao->primaryKeyColumn)->on($contextDao->tableName)->onDelete('cascade')->onUpdate('cascade'); + $table->foreign('user_group_id')->references('user_group_id')->on('user_groups')->onDelete('cascade')->onUpdate('cascade'); }); } diff --git a/classes/migration/upgrade/V3_6_0/I10403_EmailTemplateUserGroupAccess.php b/classes/migration/upgrade/V3_6_0/I10403_EmailTemplateUserGroupAccess.php index 74b2c8faa7a..57d265a9e6c 100644 --- a/classes/migration/upgrade/V3_6_0/I10403_EmailTemplateUserGroupAccess.php +++ b/classes/migration/upgrade/V3_6_0/I10403_EmailTemplateUserGroupAccess.php @@ -1,5 +1,17 @@ bigInteger('context_id')->comment('The ID of the context for which the user group assignment is defined.'); $table->bigInteger('user_group_id')->nullable()->comment('The user group ID. A null value indicates that the email template is accessible to all user groups.'); - $table->foreign('context_id')->references($contextDao->primaryKeyColumn)->on($contextDao->tableName)->onDelete('cascade')->onDelete('cascade'); - $table->foreign('user_group_id')->references('user_group_id')->on('user_groups')->onDelete('cascade')->onDelete('cascade'); + $table->foreign('context_id')->references($contextDao->primaryKeyColumn)->on($contextDao->tableName)->onDelete('cascade')->onUpdate('cascade'); + $table->foreign('user_group_id')->references('user_group_id')->on('user_groups')->onDelete('cascade')->onUpdate('cascade'); }); $contextIds = app()->get('context')->getIds(); diff --git a/classes/migration/upgrade/V3_6_0/PreflightCheckMigration.php b/classes/migration/upgrade/V3_6_0/PreflightCheckMigration.php index 39119348639..b35a9252d0c 100644 --- a/classes/migration/upgrade/V3_6_0/PreflightCheckMigration.php +++ b/classes/migration/upgrade/V3_6_0/PreflightCheckMigration.php @@ -1,10 +1,10 @@ getData(); $defaultTemplate = Repo::emailTemplate()->getByKey($context->getId(), $mailable::getEmailTemplateKey()); - if(Repo::emailTemplate()->isTemplateAccessibleToUser($user, $defaultTemplate, $context->getId())) { + if (Repo::emailTemplate()->isTemplateAccessibleToUser($user, $defaultTemplate, $context->getId())) { $templateKeySubjectPairs[$mailable::getEmailTemplateKey()] = $defaultTemplate->getLocalizedData('name'); } diff --git a/controllers/grid/users/reviewer/form/AdvancedSearchReviewerForm.php b/controllers/grid/users/reviewer/form/AdvancedSearchReviewerForm.php index a6f300cc12b..0b1e06813e1 100644 --- a/controllers/grid/users/reviewer/form/AdvancedSearchReviewerForm.php +++ b/controllers/grid/users/reviewer/form/AdvancedSearchReviewerForm.php @@ -79,14 +79,14 @@ public function initData() ->filterByKeys([ReviewRequest::getEmailTemplateKey(), ReviewRequestSubsequent::getEmailTemplateKey()]) ->getMany(); - $templates = Repo::emailTemplate() + $accessibleTemplates = Repo::emailTemplate() ->filterTemplatesByUserAccess($templates, $request->getUser(), $context->getId()) ->mapWithKeys(function (EmailTemplate $item, int $key) use ($mailable) { return [$item->getData('key') => Mail::compileParams($item->getLocalizedData('body'), $mailable->viewData)]; }); $this->setData('personalMessage', ''); - $this->setData('reviewerMessages', $templates->toArray()); + $this->setData('reviewerMessages', $accessibleTemplates->toArray()); } /** diff --git a/controllers/grid/users/reviewer/form/ReviewerForm.php b/controllers/grid/users/reviewer/form/ReviewerForm.php index c695385ff25..bf4aab57131 100644 --- a/controllers/grid/users/reviewer/form/ReviewerForm.php +++ b/controllers/grid/users/reviewer/form/ReviewerForm.php @@ -494,7 +494,7 @@ protected function getEmailTemplates(): array ); $user = Application::get()->getRequest()->getUser(); - if($defaultTemplate && Repo::emailTemplate()->isTemplateAccessibleToUser($user, $defaultTemplate, $contextId)) { + if ($defaultTemplate && Repo::emailTemplate()->isTemplateAccessibleToUser($user, $defaultTemplate, $contextId)) { $templateKeys = [ReviewRequest::getEmailTemplateKey() => $defaultTemplate->getLocalizedData('name')]; } diff --git a/schemas/emailTemplate.json b/schemas/emailTemplate.json index d0140565b8b..d37f215abd9 100644 --- a/schemas/emailTemplate.json +++ b/schemas/emailTemplate.json @@ -71,34 +71,16 @@ }, "isUnrestricted": { "type": "boolean", - "description": "Boolean indicating if an email template is available to all user groups within the roles associated with the template's mailable.", + "description": "Boolean indicating if an email template is available to all user groups.", "apiSummary": true }, "assignedUserGroupIds": { "type": "array", - "description": "IDs of the user groups that currently has access to this email template.", + "description": "IDs of the user groups that can access to this email template.", "apiSummary": true, "items": { "type": "integer" } - }, - "assignableTemplateUserGroups": { - "type": "array", - "description": "List of User Groups that can be assigned to the template", - "apiSummary": true, - "items": { - "type": "object", - "properties": { - "id": { - "type": "integer", - "apiSummary": true - }, - "name": { - "type": "integer", - "apiSummary": true - } - } - } } } }