Closed
Description
Description
If for whatever reason activation emails won't send successfully (e.g. a misconfigured Email setting), any selected checkboxes on the Permissions tab are cleared, which can cause issues if the user is then saved without reloading the page or reselecting the desired permissions.
In my case I'm actually using Yii DI containers to add a simple conditional to the sendActivationEmail
method on the Users service:
public function sendActivationEmail(User $user): bool
{
$url = $this->getActivationUrl($user);
// Prevent activation email from being sent if user conditions are not met
if ($user->isInGroup('clients') && !$user->accountManager->one() && !$user->tier->one())
{
return false;
}
return Craft::$app->getMailer()
->composeFromKey('account_activation', ['link' => Template::raw($url)])
->setTo($user)
->send();
}
So that's why the activation emails are erroring out for me, but the same should be true in any case where the Mailer failed to successfully send, with perhaps one of the biggest potential reason being misconfigured email settings.
Steps to reproduce
- Add a new or "Pending" user to a group or customize individual permissions, and make sure it's saved.
- Prevent the activation email from being sent successfully, either by returning
false
from thesendActivationEmail
method or by intentionally misconfiguring the email settings. - Click "Send activation email" from the sidebar, and you should get the "Couldn’t send activation email. Check your email settings." flash message.
- Inspect the Permissions tab and notice all the permissions are unchecked.
Craft CMS version
Craft Pro 4.4.3
PHP version
8.1.16
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
No response