Problem

Setting notify to FALSE on "status_activated" doesn't block _user_mail_notify() to send the email.

function _user_mail_notify($op, $account, $langcode = NULL) {
  // By default, we always notify except for canceled and blocked.
  $notify = \Drupal::config('user.settings')->get('notify.' . $op);
  if ($notify || ($op != 'status_canceled' && $op != 'status_blocked')) {

Proposed resolution

I think it lacks condition "&& $op != 'status_activated'" :

function _user_mail_notify($op, $account, $langcode = NULL) {
  // By default, we always notify except for canceled and blocked.
  $notify = \Drupal::config('user.settings')->get('notify.' . $op);
  if ($notify || ($op != 'status_canceled' && $op != 'status_blocked' && $op != 'status_activated' )) {

How to reproduce

- Set notification to false on "account activation" on Administration > Configuration > People > Account settings
- Set user.settings.notify.status_activated FALSE
- Block user
- Activate user

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

djidane35 created an issue. See original summary.

ozin’s picture

Status: Active » Needs review
FileSize
1.36 KB

Hi @djidane35

Please check my patch if it works for you. Thanks.

smaz’s picture

I've just tested the patch in #2 by doing the following:

  1. Visiting /admin/config/people/accounts, selecting the 'Account activation' tab in the 'Emails' field and unchecking the 'Notify user when account is activated' checkbox.
  2. Setting user.settings.notify.status_activated to false using drush:
    drush config-set user.settings notify.status_activated 0
  3. Creating a new user, ensuring they are active.
  4. Edited & blocked the user
  5. Edited & activated the user.

I received the activation email.

After the patch, I re-blocked & re-activated the user, and this time didn't receive the email notification.

The patch looks fine code wise, too.

However, does this need an automated test? I can see that there are tests currently that set notification settings etc., but as there currently isn't a test for activating a user I'm not sure if one is needed or what to start with.

Cheers

ozin’s picture

Hi @smaz, thanks for your testing. Regarding Automated tests, I think we do not need it since it is not a new functionality or feature.

markdorison’s picture

Status: Needs review » Needs work
Issue tags: -user user.module _user_mail_notify status_activated +Needs tests

@ozin, I believe @smaz is correct; this is going to need a test.

ozin’s picture

Ok, then I will add tests as soon as possible.

djidane35’s picture

Hi, in my opinion this kind of fix is ​​not sustainable over time.

For example, in the future, if a notification is deactivale for another operation, it will think about going to add the operation into the array $configurable_ops.

I think we should handle this with a global configuration to be effective.

lhangea’s picture

ozin’s picture

Status: Needs work » Closed (duplicate)