Skip to content

Commit 59f6349

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

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

dev/documentation/en/email-templates.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,59 @@ 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+
## Template access restrictions
110+
111+
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.
112+
113+
Before displaying an email template to a user, you should check if the template is accessible to that user's user group.
114+
115+
```php
116+
use APP\facades\Repo;
117+
118+
$emailTemplate = Repo::emailTemplate()->getByKey($contextId, $emailTemplateKey());
119+
120+
return Repo::emailTemplate()->isTemplateAccessibleToUser($user, $emailTemplate, $contextId) ? $emailTemplate : null;
121+
```
122+
123+
You can also assign user groups to a template.
124+
125+
```php
126+
Repo::emailTemplate()->setEmailTemplateAccess($emailTemplate, $contextId, $userGroupIds);
127+
```
128+
129+
*Note: the values passed in `$userGroupIds` will overwrite the existing groups assigned to the template.*
130+
131+
You can make a template unrestricted, thus opened to all user groups.
132+
133+
```php
134+
$isUnrestricted = true;
135+
136+
Repo::emailTemplate()->setEmailTemplateAccess($emailTemplate, $contextId, null, $isUnrestricted);
137+
```
138+
139+
If you have a list of templates, you can filter it to include only those accessible to the user.
140+
141+
```php
142+
$collector = Repo::emailTemplate()->getCollector($contextId)->getMany();
143+
144+
$emailTemplates = Repo::emailTemplate()->filterTemplatesByUserAccess($collector, $user, $contextId);
145+
```
146+
147+
### Configuring Email Template Access in emailTemplates.xml
148+
149+
When describing the data for email templates in `emailTemplates.xml`, you can specify if a template should be unrestricted by default using the `isUnrestricted` attribute.
150+
151+
```xml
152+
<email key="EXAMPLE_TEMPLATE" name="mailable.example.name" subject="emails.example.subject" body="emails.example.body" isUnrestricted="1"/>
153+
```
154+
155+
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.
156+
157+
If the `isUnrestricted` attribute is omitted, the template will be treated as unrestricted by default.
158+
159+
```xml
160+
<email key="EXAMPLE_TEMPLATE" name="mailable.example.name" subject="emails.example.subject" body="emails.example.body" />
161+
```
162+
163+
The email template in the above template will be marked as unrestricted when installed.

learning-ojs/en/settings-workflow.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,23 @@ 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. For the **Mark as unrestricted** option, select **Limit access to specific user groups**.
264+
4. Select the user group(s) that should have access.
265+
5. When you’re finished, click Save.
266+
267+
You can also mark an email template as unrestricted.
268+
1. Go to Workflow Settings > Emails > Add and Edit templates
269+
2. Click **Edit** on the template you want to modify.
270+
3. For the **Mark as unrestricted** option, select **Mark as unrestricted** to the make the template available to all user groups.
271+
4. When you’re finished, click Save.
272+
273+
*Note: You can only change the access for templates that are related to the submission workflow.*
257274

258275
#### Filters
259276

0 commit comments

Comments
 (0)