Skip to content

Sending activation email that fails to send causes user permissions to get wiped #38

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 · 1 comment
Labels
bug Something isn't working

Comments

@jalendport
Copy link

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.

Additional info

  • Craft version: Craft Pro 4.4.3
  • PHP version: 8.1.16
  • Database driver & version: MySQL 8.0.27
@jalendport jalendport added the bug Something isn't working label Apr 6, 2023
@jalendport
Copy link
Author

Blerghh created the issue in the wrong tab 🤦‍♂️

Moved to craftcms/cms#13061

@jalendport jalendport closed this as not planned Won't fix, can't repro, duplicate, stale Apr 6, 2023
@angrybrad angrybrad transferred this issue from craftcms/.github Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant