Skip to content

Commit

Permalink
pkp/pkp-lib#10403 Add docs for template access feature
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham committed Nov 28, 2024
1 parent aa63a8d commit 6ab4b1a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
51 changes: 51 additions & 0 deletions dev/documentation/en/email-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<email key="EXAMPLE_TEMPLATE" name="mailable.example.name" subject="emails.example.subject" body="emails.example.body" isUnrestricted="1"/>
```

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.
10 changes: 10 additions & 0 deletions learning-ojs/en/settings-workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6ab4b1a

Please sign in to comment.