Skip to content

Commit

Permalink
pkp#10571 WIP: Allow admins and managers to assign user groups to ema…
Browse files Browse the repository at this point in the history
…il templates within a mailable
  • Loading branch information
taslangraham committed Jan 14, 2025
1 parent 4d0c0e3 commit 2a0d14c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
33 changes: 33 additions & 0 deletions classes/components/forms/FieldEmailTemplateUserGroupSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* @file classes/components/form/FieldEmailTemplateUserGroupSettings.php
*
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2000-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class FieldEmailTemplateUserGroupSettings
*
* @ingroup classes_controllers_form
*
* @brief A component managing user groups assignable to an email template
*/

namespace PKP\components\forms;

class FieldEmailTemplateUserGroupSettings extends Field
{
/** @copydoc Field::$component */
public $component = 'field-email-template-user-group-settings';

/**
* @copydoc Field::getConfig()
*/
public function getConfig()
{
$config = parent::getConfig();

return $config;
}
}
9 changes: 8 additions & 1 deletion classes/emailTemplate/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,25 @@ public function add(EmailTemplate $emailTemplate): string
}

/** @copydoc DAO::update() */
public function edit(EmailTemplate $emailTemplate, array $params)
public function edit(EmailTemplate $emailTemplate, array $params, $contextId)
{
$newEmailTemplate = clone $emailTemplate;
$newEmailTemplate->setAllData(array_merge($newEmailTemplate->_data, $params));

$userGroupIds = $params['userGroupIds'];
unset($params['userGroupIds']);

Hook::call('EmailTemplate::edit', [$newEmailTemplate, $emailTemplate, $params]);

if ($newEmailTemplate->getId()) {
$this->dao->update($newEmailTemplate);
} else {
$this->dao->insert($newEmailTemplate);
}

if($userGroupIds) {
$this->dao->updateTemplateAccessGroups($emailTemplate, $userGroupIds, $contextId);
}
}

/** @copydoc DAO::delete() */
Expand Down
1 change: 1 addition & 0 deletions classes/mail/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function summarizeMailable(string $class): array
'supportsTemplates' => $class::getSupportsTemplates(),
'toRoleIds' => $class::getToRoleIds(),
'canAssignUserGroupToTemplates' => $this->isGroupsAssignableToTemplates($class),
'assignableTemplateUserGroups' => $userGroups
];
}

Expand Down

0 comments on commit 2a0d14c

Please sign in to comment.