Skip to content

[4.x]: Sending activation email that fails to send causes user permissions to get wiped #13061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jalendport opened this issue Apr 6, 2023 · 3 comments
Assignees

Comments

@jalendport
Copy link
Contributor

jalendport commented Apr 6, 2023

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

  1. Add a new or "Pending" user to a group or customize individual permissions, and make sure it's saved.
  2. Prevent the activation email from being sent successfully, either by returning false from the sendActivationEmail method or by intentionally misconfiguring the email settings.
  3. Click "Send activation email" from the sidebar, and you should get the "Couldn’t send activation email. Check your email settings." flash message.
  4. 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

@i-just
Copy link
Contributor

i-just commented Apr 11, 2023

Hi, thanks for reporting and great replication steps. I raised a PR to address this.

@brandonkelly
Copy link
Member

Craft 4.4.7 is out now with a fix for this!

@jalendport
Copy link
Contributor Author

Thanks for the quick fix! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants