diff --git a/dev/documentation/en/email-templates.md b/dev/documentation/en/email-templates.md index e5b7683ed029..8a95f07f113d 100644 --- a/dev/documentation/en/email-templates.md +++ b/dev/documentation/en/email-templates.md @@ -105,3 +105,54 @@ These templates can not be edited or deleted. However, each context can override Only the overriden templates will be deleted when a context is deleted or has its email templates reset. The default data will remain. When using the email templates repository, no extra consideration is required to fetch the correct email template. The repository's `delete` method will only delete custom data. + + +## Template access restrictions + +Version 3.6 of OJS, OMP, and OPS allows Admins and managers to restrict email templates to specific user groups within a Context. By default, templates are open to all user groups, similar to previous versions. + +Before displaying an email template to a user, you should check if the template is accessible to that user's user group. + +```php +use APP\facades\Repo; +use PKP\mail\mailables\DiscussionCopyediting; + +$emailTemplate = Repo::emailTemplate() + ->getByKey( + $contextId, + DiscussionCopyediting::getEmailTemplateKey() + ); + +return Repo::emailTemplate()->isTemplateAccessibleToUser($user, $emailTemplate, $contextId) ? $emailTemplate : null; +``` + +You can also assign user groups to a template. + +```php +Repo::emailTemplate()->setEmailTemplateAccess($emailTemplate, $contextId, $userGroupIds); +``` +*Note: the values passed in $userGroupIds will overwrite the existing groups assigned to the template.* + + +You can make a template unrestricted, thus open to all user groups. +```php +$isUnrestricted = true; + +Repo::emailTemplate()->setEmailTemplateAccess($emailTemplate, $contextId, null, $isUnrestricted); +``` + +If you have a list of templates, you can filter it to include only those accessible to the user. + +```php +$collector = Repo::emailTemplate()->getCollector($contextId)->getMany(); + +$emailTemplates = Repo::emailTemplate()->filterTemplatesByUserAccess($collector, $user, $contextId); +``` + +When describing the data for default emails templates in emailTemplates.xml, you can indicate if an template should be unrestricted by default via the `isUnrestricted` attribute. + +```xml + +``` + +In the above example, the email template is marked as unrestricted - available to all user groups. You can also mark a template as restricted by using `isUnrestricted="0"`. Restricted templates will only become accessible after being assigned to a user group or marked as unrestricted. diff --git a/learning-ojs/en/settings-workflow.md b/learning-ojs/en/settings-workflow.md index e760e543ea53..1a26f45faa0c 100644 --- a/learning-ojs/en/settings-workflow.md +++ b/learning-ojs/en/settings-workflow.md @@ -254,6 +254,16 @@ To add a template, click **Edit**, followed by **Add Template**. ![OJS 3.4 emails templates.](./assets/learning-ojs3.4-jm-settings-workflow-multi-email-templates.png) +#### Email template access + +You can restrict access to templates by user group. By default, all user groups have access to the default templates. + +1. Go to Workflow Settings > Emails > Add and Edit templates +2. Click **Edit** on the template you want to modify. +3. Choose the user groups that should have access, or select the Unrestricted option to make the template available to all. +4. When you’re finished, click Save. + +*Note: You can only change the access for templates that are related to the submission workflow.* #### Filters