Skip to content

Commit

Permalink
#10571 Make templates assignable to all user groups
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham committed Nov 14, 2024
1 parent 37d1e42 commit ba47e2b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion api/v1/emailTemplates/PKPEmailTemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function edit(Request $illuminateRequest): JsonResponse
return response()->json($errors, Response::HTTP_BAD_REQUEST);
}

Repo::emailTemplate()->edit($emailTemplate, $params, $requestContext->getId());
Repo::emailTemplate()->edit($emailTemplate, $params);
Repo::emailTemplate()->setEmailTemplateAccess($emailTemplate, $requestContext->getId(), $params['userGroupIds'], $params['isUnrestricted']);

$emailTemplate = Repo::emailTemplate()->getByKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class FieldEmailTemplateUnrestricted extends Field
public function getConfig()
{
$config = parent::getConfig();
$config['label'] = $this->label;
return $config;
}
}
7 changes: 0 additions & 7 deletions classes/decision/steps/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use PKP\facades\Locale;
use PKP\mail\Mailable;
use PKP\user\User;
use Role;
use stdClass;

class Email extends Step
Expand Down Expand Up @@ -125,12 +124,6 @@ protected function getEmailTemplates(): array
{
$request = Application::get()->getRequest();
$context = $request->getContext();
$userRoles = array_map(fn (Role $role) => $role->getId(), $request->getUser()->getRoles($context->getId()));

// Ensure user has access to mailable before proceeding
if(empty(array_intersect($this->mailable::getFromRoleIds(), $userRoles))) {
return [];
}

$emailTemplates = collect();
if ($this->mailable::getEmailTemplateKey()) {
Expand Down
2 changes: 1 addition & 1 deletion classes/emailTemplate/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function add(EmailTemplate $emailTemplate): string
}

/** @copydoc DAO::update() */
public function edit(EmailTemplate $emailTemplate, array $params, $contextId)
public function edit(EmailTemplate $emailTemplate, array $params)
{
$newEmailTemplate = clone $emailTemplate;
$newEmailTemplate->setAllData(array_merge($newEmailTemplate->_data, $params));
Expand Down
15 changes: 9 additions & 6 deletions classes/mail/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use PKP\mail\mailables\SubmissionSavedForLater;
use PKP\mail\traits\Configurable;
use PKP\plugins\Hook;
use PKP\userGroup\UserGroup;

class Repository
{
Expand Down Expand Up @@ -108,14 +109,16 @@ public function summarizeMailable(string $class): array
$userGroups = [];
$roleNames = Application::get()->getRoleNames();

foreach (Repo::userGroup()->getByRoleIds($roles, Application::get()->getRequest()->getContext()->getId())->all() as $group) {
$roleId = $group->getRoleId();
$userGroups[] = [
$userGroups = collect();

Repo::userGroup()->getCollector()
->filterByContextIds([Application::get()->getRequest()->getContext()->getId()])
->getMany()->each(fn (UserGroup $group) => $userGroups->add([
'id' => $group->getId(),
'name' => $group->getLocalizedName(),
'roleId' => $roleId,
'roleName' => $roleNames[$roleId]];
}
'roleId' => $group->getRoleId(),
'roleName' => $roleNames[$group->getRoleId()]
]));

return [
'_href' => Application::get()->getRequest()->getDispatcher()->url(
Expand Down
6 changes: 3 additions & 3 deletions locale/en/admin.po
Original file line number Diff line number Diff line change
Expand Up @@ -1016,10 +1016,10 @@ msgid "admin.cli.tool.scheduler.run.prompt"
msgstr "Which command would you like to run?"

msgid "admin.workflow.email.userGroup.allowed"
msgstr "Allowed User Groups"
msgstr "Limit Access to Specific User Groups"

msgid "workflow.email.userGroup.assign.unrestricted"
msgid "admin.workflow.email.userGroup.assign.unrestricted"
msgstr "Mark as unrestricted"

msgid "workflow.email.userGroup.unrestricted.template.note"
msgid "admin.workflow.email.userGroup.unrestricted.template.note"
msgstr "Unrestricted templates will be accessible to all user groups(listed below) associated with this template."

0 comments on commit ba47e2b

Please sign in to comment.