Skip to content

Commit 6ab4b1a

Browse files
committed
pkp/pkp-lib#10403 Add docs for template access feature
1 parent aa63a8d commit 6ab4b1a

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

dev/documentation/en/email-templates.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,54 @@ These templates can not be edited or deleted. However, each context can override
105105
Only the overriden templates will be deleted when a context is deleted or has its email templates reset. The default data will remain.
106106

107107
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.
108+
109+
110+
## Template access restrictions
111+
112+
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.
113+
114+
Before displaying an email template to a user, you should check if the template is accessible to that user's user group.
115+
116+
```php
117+
use APP\facades\Repo;
118+
use PKP\mail\mailables\DiscussionCopyediting;
119+
120+
$emailTemplate = Repo::emailTemplate()
121+
->getByKey(
122+
$contextId,
123+
DiscussionCopyediting::getEmailTemplateKey()
124+
);
125+
126+
return Repo::emailTemplate()->isTemplateAccessibleToUser($user, $emailTemplate, $contextId) ? $emailTemplate : null;
127+
```
128+
129+
You can also assign user groups to a template.
130+
131+
```php
132+
Repo::emailTemplate()->setEmailTemplateAccess($emailTemplate, $contextId, $userGroupIds);
133+
```
134+
*Note: the values passed in $userGroupIds will overwrite the existing groups assigned to the template.*
135+
136+
137+
You can make a template unrestricted, thus open to all user groups.
138+
```php
139+
$isUnrestricted = true;
140+
141+
Repo::emailTemplate()->setEmailTemplateAccess($emailTemplate, $contextId, null, $isUnrestricted);
142+
```
143+
144+
If you have a list of templates, you can filter it to include only those accessible to the user.
145+
146+
```php
147+
$collector = Repo::emailTemplate()->getCollector($contextId)->getMany();
148+
149+
$emailTemplates = Repo::emailTemplate()->filterTemplatesByUserAccess($collector, $user, $contextId);
150+
```
151+
152+
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.
153+
154+
```xml
155+
<email key="EXAMPLE_TEMPLATE" name="mailable.example.name" subject="emails.example.subject" body="emails.example.body" isUnrestricted="1"/>
156+
```
157+
158+
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.

learning-ojs/en/settings-workflow.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,16 @@ To add a template, click **Edit**, followed by **Add Template**.
254254

255255
![OJS 3.4 emails templates.](./assets/learning-ojs3.4-jm-settings-workflow-multi-email-templates.png)
256256

257+
#### Email template access
258+
259+
You can restrict access to templates by user group. By default, all user groups have access to the default templates.
260+
261+
1. Go to Workflow Settings > Emails > Add and Edit templates
262+
2. Click **Edit** on the template you want to modify.
263+
3. Choose the user groups that should have access, or select the Unrestricted option to make the template available to all.
264+
4. When you’re finished, click Save.
265+
266+
*Note: You can only change the access for templates that are related to the submission workflow.*
257267

258268
#### Filters
259269

0 commit comments

Comments
 (0)