From 9eea25d77aef4b6b84e458cd88d8289ede2b7d3b Mon Sep 17 00:00:00 2001 From: lazysoundsystem Date: Thu, 16 Jan 2025 16:09:44 +0100 Subject: [PATCH] chore: remove patch and update user_expire module Refs: OPS-11223 --- ..._expire-customize-notification-email.patch | 179 ------------------ composer.json | 4 +- composer.lock | 44 +++-- composer.patches.json | 1 - config/user_expire.settings.yml | 13 +- 5 files changed, 37 insertions(+), 204 deletions(-) delete mode 100644 PATCHES/user_expire-customize-notification-email.patch diff --git a/PATCHES/user_expire-customize-notification-email.patch b/PATCHES/user_expire-customize-notification-email.patch deleted file mode 100644 index fc67957..0000000 --- a/PATCHES/user_expire-customize-notification-email.patch +++ /dev/null @@ -1,179 +0,0 @@ -diff --git a/config/install/user_expire.settings.yml b/config/install/user_expire.settings.yml -index 62f9e8c7d5a064d87448b0faf5811a08709370c7..ea9fb144d2add8031bcafc516fb46cca209eb6c9 100644 ---- a/config/install/user_expire.settings.yml -+++ b/config/install/user_expire.settings.yml -@@ -1,3 +1,7 @@ - frequency: 172800 - offset: 604800 - user_expire_roles: {} -+send_mail: true -+mail: -+ subject: "[site:name]: Account expiration warning" -+ body: "Hello [user:display-name]\r\n\r\nBecause you have not logged in recently, your account at [site:name] will be blocked in the near future. If you still use this site, please log in [site:login-url] to prevent your account being blocked.\r\n\r\n-- [site:name] team" -diff --git a/config/schema/user_expire.schema.yml b/config/schema/user_expire.schema.yml -index a46bc68eeea8b41fa1e7bde72008daf77d54032d..be0c3fca4e7604994e5c0070942ef79920eab454 100644 ---- a/config/schema/user_expire.schema.yml -+++ b/config/schema/user_expire.schema.yml -@@ -7,9 +7,21 @@ user_expire.settings: - frequency: - type: integer - label: 'Frequency time in seconds' -+ mail: -+ type: mapping -+ mapping: -+ subject: -+ type: string -+ label: 'Subject line for the notification email' -+ body: -+ type: string -+ label: 'Body for the notification email' - offset: - type: integer - label: 'Warning offset time in seconds' -+ send_mail: -+ type: boolean -+ label: 'Flag that enables or disables expiry emails' - user_expire_roles: - type: sequence - label: 'Roles and expire value' -diff --git a/src/Form/UserExpireSettingsForm.php b/src/Form/UserExpireSettingsForm.php -index f7824c09ad10612818c2cc3e2cc2a85e590377a7..cd2c4e515d0887df9a70fe0c7c72bc599de84033 100644 ---- a/src/Form/UserExpireSettingsForm.php -+++ b/src/Form/UserExpireSettingsForm.php -@@ -109,6 +109,50 @@ class UserExpireSettingsForm extends ConfigFormBase { - ]; - } - -+ // Enable or disable email notifications. -+ $form['send_mail'] = [ -+ '#type' => 'checkbox', -+ '#title' => $this->t('Send notification emails'), -+ '#default_value' => $config->get('send_mail') ?: TRUE, -+ '#description' => $this->t('Send a notification email to the user, starting at the defined offset time before account expiry.'), -+ ]; -+ -+ // Notification email template. -+ $form['mail'] = [ -+ '#type' => 'fieldset', -+ '#title' => $this->t('Notification email'), -+ ]; -+ -+ $form['mail']['settings'] = [ -+ '#type' => 'container', -+ '#states' => [ -+ // Hide the additional settings when this email is disabled. -+ 'invisible' => [ -+ 'input[name="send_mail"]' => ['checked' => FALSE], -+ ], -+ ], -+ ]; -+ -+ $form['mail']['settings']['notification_subject'] = [ -+ '#type' => 'textfield', -+ '#title' => $this->t('Subject'), -+ '#default_value' => $config->get('mail.subject') ?: '', -+ '#description' => $this->t('Subject line for the notification email.'), -+ '#maxlength' => 180, -+ ]; -+ -+ $form['mail']['settings']['notification_body'] = [ -+ '#type' => 'textarea', -+ '#title' => $this->t('Body'), -+ '#default_value' => $config->get('mail.body') ?: '', -+ '#description' => $this->t('Body for the notification email.'), -+ '#rows' => 15, -+ ]; -+ -+ $form['mail']['settings']['help'] = [ -+ '#markup' => $this->t('Available token variables for use in the email are: [site:name], [site:url], [site:mail], [user:display-name], [user:account-name], [user:mail], [site:login-url], [site:url-brief], [user:edit-url], [user:one-time-login-url], [user:cancel-url]'), -+ ]; -+ - return parent::buildForm($form, $form_state); - } - -@@ -160,6 +204,13 @@ class UserExpireSettingsForm extends ConfigFormBase { - } - - $config->set('user_expire_roles', $rules); -+ -+ // The notification email. -+ $config->set('send_mail', $form_state->getValue('send_mail')); -+ -+ $config->set('mail.subject', $form_state->getValue('notification_subject')); -+ $config->set('mail.body', $form_state->getValue('notification_body')); -+ - $config->save(); - } - -diff --git a/user_expire.module b/user_expire.module -index d4dcd8ba28b51ee8f54a7626d8b10443244520d9..9365c5db3b87e88dd03611a03656370e2b4f99cb 100644 ---- a/user_expire.module -+++ b/user_expire.module -@@ -5,6 +5,7 @@ - * Main module file for User expire module. - */ - -+use Drupal\Component\Render\PlainTextOutput; - use Drupal\Core\Database\Query\Condition; - use Drupal\Core\Database\StatementInterface; - use Drupal\Core\Datetime\DrupalDateTime; -@@ -332,12 +333,15 @@ function user_expire_expire_by_role_warning(): void { - ]); - } - else { -- $logger->info('Warning about expiring account @name by role', ['@name' => $account->getAccountName()]); -- \Drupal::service('plugin.manager.mail')->mail('user_expire', 'expiration_warning', $account->getEmail(), $account->getPreferredLangcode(), -- [ -- 'account' => $account, -- ] -- ); -+ // Send a notification email if configured to do so. -+ if ($config->get('send_mail')) { -+ $logger->info('Sending warning about expiring account @name by role', ['@name' => $account->getAccountName()]); -+ \Drupal::service('plugin.manager.mail')->mail('user_expire', 'expiration_warning', $account->getEmail(), $account->getPreferredLangcode(), -+ [ -+ 'account' => $account, -+ ] -+ ); -+ } - } - } - } -@@ -439,20 +443,22 @@ function user_expire_get_role_rules(): mixed { - */ - function user_expire_mail($key, &$message, $params): void { - if ($key == 'expiration_warning') { -- $site_name = \Drupal::config('system.site')->get('name'); -- // The subject. -- $message['subject'] = t('@site_name: Account expiration warning', ['@site_name' => $site_name]); -- // The body. -- $message['body'][] = t('Hello @user', ['@user' => $params['account']->getAccountName()]); -- // An empty string gives a newline. -- $message['body'][] = ''; -- $message['body'][] = t('Because you have not logged in recently, your account at @site_name will be blocked in the near future. If you still use this site, please log in @login_url to avoid having your account blocked.', -- [ -- '@site_name' => $site_name, -- '@login_url' => Url::fromRoute('entity.user.canonical', ['user' => \Drupal::currentUser()->id()], ['absolute' => TRUE])->toString(), -- ] -- ); -- $message['body'][] = ''; -- $message['body'][] = t('Thanks, @site_name', ['@site_name' => $site_name]); -+ $token_service = \Drupal::token(); -+ $language_manager = \Drupal::languageManager(); -+ $langcode = $message['langcode']; -+ $variables = ['user' => $params['account']]; -+ -+ $language = $language_manager->getLanguage($params['account']->getPreferredLangcode()); -+ $original_language = $language_manager->getConfigOverrideLanguage(); -+ $language_manager->setConfigOverrideLanguage($language); -+ -+ $config_factory = \Drupal::configFactory(); -+ $config = $config_factory->get('user_expire.settings'); -+ -+ $token_options = ['langcode' => $langcode, 'callback' => 'user_mail_tokens', 'clear' => TRUE]; -+ $message['subject'] .= PlainTextOutput::renderFromHtml($token_service->replace($config->get('mail.subject'), $variables, $token_options)); -+ $message['body'][] = $token_service->replace($config->get('mail.body'), $variables, $token_options); -+ -+ $language_manager->setConfigOverrideLanguage($original_language); - } - } diff --git a/composer.json b/composer.json index 99aa608..2db2cfe 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "drupal/seckit": "^2.0", "drupal/social_auth_hid": "^3.2", "drupal/stage_file_proxy": "^3", - "drupal/user_expire": "^1.1", + "drupal/user_expire": "^2", "drupal/username_enumeration_prevention": "^1.3", "drupal/view_unpublished": "^1.1", "drush/drush": "^12", @@ -190,4 +190,4 @@ } }, "version": "2.1.10" -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index 99d41aa..3caa163 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1f477d924f0c5afcb6ac774479bfb991", + "content-hash": "c92de35594e9d416918fb91f95c47b5f", "packages": [ { "name": "asm89/stack-cors", @@ -2556,7 +2556,7 @@ "shasum": "6ffe6724692ec8f59a2feb2f1a17e416912ac84f" }, "require": { - "drupal/core": "^9 || ^10 || ^11" + "drupal/core": "^10" }, "type": "drupal-module", "extra": { @@ -3782,7 +3782,7 @@ "shasum": "fc8ea60619b6b4682bade340e13fb4565d3a7e0c" }, "require": { - "drupal/core": "^9.1 || ^10" + "drupal/core": "^10" }, "type": "drupal-module", "extra": { @@ -4733,29 +4733,29 @@ }, { "name": "drupal/user_expire", - "version": "1.3.0", + "version": "2.1.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/user_expire.git", - "reference": "8.x-1.3" + "reference": "2.1.0" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/user_expire-8.x-1.3.zip", - "reference": "8.x-1.3", - "shasum": "58f6225567a854a3d7f7b5eaa7c15bf37873cb49" + "url": "https://ftp.drupal.org/files/projects/user_expire-2.1.0.zip", + "reference": "2.1.0", + "shasum": "cdaf39f4813d75f65d7a4579631487a3b49604d8" }, "require": { - "drupal/core": "^9 || ^10" + "drupal/core": "^10.3 || ^11 || ^12" }, "require-dev": { - "drupal/rules": "^3.0@alpha" + "drupal/rules": "^4.0" }, "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-1.3", - "datestamp": "1725558574", + "version": "2.1.0", + "datestamp": "1736892990", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -4778,16 +4778,24 @@ "role": "Co-maintainer" }, { - "name": "joegraduate", - "homepage": "https://www.drupal.org/user/789384" + "name": "Shelane French (shelane)", + "homepage": "https://www.drupal.org/u/shelane", + "role": "Co-maintainer" + }, + { + "name": "Joe Parsons (joegraduate)", + "homepage": "https://www.drupal.org/u/joegraduate", + "role": "Co-maintainer" }, { - "name": "shelane", - "homepage": "https://www.drupal.org/user/2674989" + "name": "Troy Dean (tadean)", + "homepage": "https://www.drupal.org/u/tadean", + "role": "Co-maintainer" }, { - "name": "trackleft2", - "homepage": "https://www.drupal.org/user/2860655" + "name": "Chris Green (trackleft2)", + "homepage": "https://www.drupal.org/u/trackleft2", + "role": "Co-maintainer" } ], "description": "Allows an administrator to define a date on which to expire a user account.", diff --git a/composer.patches.json b/composer.patches.json index 632a65d..7d99b6f 100644 --- a/composer.patches.json +++ b/composer.patches.json @@ -10,7 +10,6 @@ "Consolidated fixes for issues 3345123 and 3345129": "PATCHES/paragraphs_viewmode-consolidated-fixes-3345123-3345129.patch" }, "drupal/user_expire": { - "Allow the notification email to be customised": "PATCHES/user_expire-customize-notification-email.patch", "Reset expiration when user is reactivated": "PATCHES/user_expire-reset-expiration-on-reactivation.patch" }, "drupal/username_enumeration_prevention": { diff --git a/config/user_expire.settings.yml b/config/user_expire.settings.yml index a21f2d3..3daed6f 100644 --- a/config/user_expire.settings.yml +++ b/config/user_expire.settings.yml @@ -1,10 +1,15 @@ _core: default_config_hash: PeDvVH4C3IZ7QFkvC1BUv3BZJVc7jLwQmJAEttVuVOw frequency: 432000 -mail: - subject: '[site:name]: Account expiration warning' - body: "Hello [user:display-name]\r\n\r\nBecause you have not logged in recently, your account at [site:name] will be de-activated in the near future. If you still use this site, please log in [site:login-url] to avoid having your account de-activated.\r\n\r\nThanks, [site:name]" offset: 604800 -send_mail: 1 user_expire_roles: authenticated: 15552000 +send_expiration_warnings: true +expiration_warning_mail: + subject: "[site:name]: Account expiration warning" + body: |- + Hello [user:display-name] + + Because you have not logged in recently, your account at [site:name] will be blocked in the near future. If you still use this site, log in now [site:login-url] to prevent your account being blocked. + + -- [site:name] team