Skip to content

Commit

Permalink
pkp#10571 Make default templates unrestricted on Context creation
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham committed Dec 18, 2024
1 parent 90fc383 commit be851c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions classes/emailTemplate/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,34 @@ public function installEmailTemplateLocaleData(
return true;
}


/**
* Registers default templates as unrestricted for the specified context ID.
*/
public function registerDefaultTemplatesAsUnrestricted(int $contextId): void
{
$templates = Repo::emailTemplate()->getCollector($contextId)->getMany()->all();
$keys = array_map(fn (EmailTemplate $template) => $template->getData('key'), $templates);

$existingUnrestrictedTemplates = EmailTemplateAccessGroup::withContextId($contextId)
->whereNull('user_group_id')
->select('email_key')
->pluck('email_key')->all();

// Identify templates to add as unrestricted
$defaultKeysToRegister = array_diff($keys, $existingUnrestrictedTemplates);

$data = array_map(function ($key) use ($contextId) {
return [
'email_key' => $key,
'context_id' => $contextId,
'user_group_id' => null
];
}, $defaultKeysToRegister);

EmailTemplateAccessGroup::insert($data);
}

/**
* Installs the "extra" email templates for a context
*
Expand Down
1 change: 1 addition & 0 deletions classes/services/PKPContextService.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ public function add($context, $request)
$navigationMenuDao->installSettings($context->getId(), 'registry/navigationMenus.xml');

Repo::emailTemplate()->dao->installAlternateEmailTemplates($context->getId());
Repo::emailTemplate()->dao->registerDefaultTemplatesAsUnrestricted($context->getId());

// Load all plugins so they can hook in and add their installation settings
PluginRegistry::loadAllPlugins();
Expand Down

0 comments on commit be851c8

Please sign in to comment.