From e35a6f7aa5616e9d3ffe46c22c10bda0f4d3bfb5 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 4 Jun 2024 08:26:21 -0700 Subject: [PATCH 1/9] [ticket/17333] ACP option to enable-disable all push notifications PHPBB-17333 Signed-off-by: Matt Friedman --- phpBB/includes/acp/acp_board.php | 1 + phpBB/install/schemas/schema_data.sql | 1 + phpBB/language/en/acp/board.php | 2 + .../data/v400/add_webpush_options.php | 45 +++++++++++++++++++ phpBB/phpbb/notification/method/webpush.php | 8 ++++ 5 files changed, 57 insertions(+) create mode 100644 phpBB/phpbb/db/migration/data/v400/add_webpush_options.php diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index d0ced6788f..8eaaa9fc88 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -494,6 +494,7 @@ class acp_board 'webpush_enable' => ['lang' => 'WEBPUSH_ENABLE', 'validate' => 'bool', 'type' => 'custom', 'method' => 'webpush_enable', 'explain' => true], 'webpush_vapid_public' => ['lang' => 'WEBPUSH_VAPID_PUBLIC', 'validate' => 'string', 'type' => 'text:25:255', 'explain' => true], 'webpush_vapid_private' => ['lang' => 'WEBPUSH_VAPID_PRIVATE', 'validate' => 'string', 'type' => 'password:25:255', 'explain' => true], + 'webpush_method_enables' => ['lang' => 'WEBPUSH_METHOD_ENABLES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true], 'legend3' => 'ACP_SUBMIT_CHANGES', ], diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 68a97decb7..f57a9f466b 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -329,6 +329,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\backup\con INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_enable', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_public', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_private', ''); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_method_enables', '0'); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cache_last_gc', '0', 1); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cron_lock', '0', 1); diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index c57cefe685..484d651c75 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -590,6 +590,8 @@ $lang = array_merge($lang, [ 'WEBPUSH_VAPID_PUBLIC_EXPLAIN' => 'The Voluntary Application Server Identification (VAPID) public key is shared to authenticate push messages from your site.
Caution: Modifying the VAPID public key will automatically render all Web Push subscriptions invalid.', 'WEBPUSH_VAPID_PRIVATE' => 'Server identification private key', 'WEBPUSH_VAPID_PRIVATE_EXPLAIN' => 'The Voluntary Application Server Identification (VAPID) private key is used to generate authenticated push messages dispatched from your site. The VAPID private key must form a valid public-private key pair alongside the VAPID public key.
Caution: Modifying the VAPID private key will automatically render all Web Push subscriptions invalid.', + 'WEBPUSH_METHOD_ENABLES' => 'Enable all user-based web push notification options by default', + 'WEBPUSH_METHOD_ENABLES_EXPLAIN'=> 'When this setting is enabled, users who subscribe and allow browser notifications will start receiving them automatically. Users only need to visit the UCP Notification settings to disable any unwanted notifications.

If this setting is disabled, users will not receive any notifications, even if they have subscribed, until they visit the UCP Notification settings to enable the specific notification options they wish to receive.', ]); // Jabber settings diff --git a/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php b/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php new file mode 100644 index 0000000000..99ef6bd28f --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php @@ -0,0 +1,45 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\db\migration\data\v400; + +use phpbb\db\migration\migration; + +class add_webpush_options extends migration +{ + public static function depends_on(): array + { + return [ + '\phpbb\db\migration\data\v400\add_webpush', + ]; + } + + public function effectively_installed(): bool + { + return $this->config->offsetExists('webpush_method_enables'); + } + + public function update_data(): array + { + return [ + ['config.add', ['webpush_method_enables', false]], + ]; + } + + public function revert_data(): array + { + return [ + ['config.remove', ['webpush_method_enables']], + ]; + } +} diff --git a/phpBB/phpbb/notification/method/webpush.php b/phpBB/phpbb/notification/method/webpush.php index e5b8910a07..e1fc1f04ee 100644 --- a/phpBB/phpbb/notification/method/webpush.php +++ b/phpBB/phpbb/notification/method/webpush.php @@ -91,6 +91,14 @@ class webpush extends messenger_base implements extended_method_interface && !empty($this->config['webpush_vapid_public']) && !empty($this->config['webpush_vapid_private']); } + /** + * {@inheritDoc} + */ + public function is_enabled_by_default() + { + return $this->config['webpush_method_enables']; + } + /** * {@inheritdoc} */ From d55ec608eceabe0b028ac33082545b2d205ff5a8 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 4 Jun 2024 09:34:02 -0700 Subject: [PATCH 2/9] [ticket/17333] Add push subscribe toggle to notification dropdown PHPBB-17333 Signed-off-by: Matt Friedman --- phpBB/includes/acp/acp_board.php | 1 + phpBB/includes/functions.php | 16 ++++++++++++++-- phpBB/install/schemas/schema_data.sql | 1 + phpBB/language/en/acp/board.php | 2 ++ phpBB/language/en/common.php | 3 +++ .../migration/data/v400/add_webpush_options.php | 4 +++- phpBB/phpbb/notification/method/webpush.php | 2 +- .../template/notification_dropdown.html | 7 +++++++ .../prosilver/template/overall_header.html | 4 ++++ .../template/ucp_notifications_options.html | 4 ---- phpBB/styles/prosilver/theme/buttons.css | 6 ++++++ phpBB/styles/prosilver/theme/common.css | 9 +++++++++ 12 files changed, 51 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 8eaaa9fc88..53faa4bc7d 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -495,6 +495,7 @@ class acp_board 'webpush_vapid_public' => ['lang' => 'WEBPUSH_VAPID_PUBLIC', 'validate' => 'string', 'type' => 'text:25:255', 'explain' => true], 'webpush_vapid_private' => ['lang' => 'WEBPUSH_VAPID_PRIVATE', 'validate' => 'string', 'type' => 'password:25:255', 'explain' => true], 'webpush_method_enables' => ['lang' => 'WEBPUSH_METHOD_ENABLES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true], + 'webpush_dropdown_subscribe'=> ['lang' => 'WEBPUSH_DROPDOWN_SUBSCRIBE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true], 'legend3' => 'ACP_SUBMIT_CHANGES', ], diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index bca9a97c48..fdc2d42ab9 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3853,6 +3853,9 @@ function page_header($page_title = '', $display_online_list = false, $item_id = $timezone_name = $user->lang['timezones'][$timezone_name]; } + /** @var \phpbb\controller\helper $controller_helper */ + $controller_helper = $phpbb_container->get('controller.helper'); + // Output the notifications $notifications = false; if ($config['load_notifications'] && $config['allow_board_notifications'] && $user->data['user_id'] != ANONYMOUS && $user->data['user_type'] != USER_IGNORE) @@ -3869,10 +3872,19 @@ function page_header($page_title = '', $display_online_list = false, $item_id = { $template->assign_block_vars('notifications', $notification->prepare_for_display()); } + + // Get web push notification data + $methods = $phpbb_notifications->get_subscription_methods(); + if ($config['webpush_dropdown_subscribe'] && array_key_exists('notification.method.webpush', $methods)) + { + /** @var \phpbb\form\form_helper $form_helper */ + $form_helper = $phpbb_container->get('form_helper'); + + $template_ary = $methods['notification.method.webpush']['method']->get_ucp_template_data($controller_helper, $form_helper); + $template->assign_vars($template_ary); + } } - /** @var \phpbb\controller\helper $controller_helper */ - $controller_helper = $phpbb_container->get('controller.helper'); $notification_mark_hash = generate_link_hash('mark_all_notifications_read'); $phpbb_version_parts = explode('.', PHPBB_VERSION, 3); diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index f57a9f466b..9cabeb3e27 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -330,6 +330,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_enable', ' INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_public', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_private', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_method_enables', '0'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_dropdown_subscribe', '0'); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cache_last_gc', '0', 1); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cron_lock', '0', 1); diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index 484d651c75..3353a360e8 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -592,6 +592,8 @@ $lang = array_merge($lang, [ 'WEBPUSH_VAPID_PRIVATE_EXPLAIN' => 'The Voluntary Application Server Identification (VAPID) private key is used to generate authenticated push messages dispatched from your site. The VAPID private key must form a valid public-private key pair alongside the VAPID public key.
Caution: Modifying the VAPID private key will automatically render all Web Push subscriptions invalid.', 'WEBPUSH_METHOD_ENABLES' => 'Enable all user-based web push notification options by default', 'WEBPUSH_METHOD_ENABLES_EXPLAIN'=> 'When this setting is enabled, users who subscribe and allow browser notifications will start receiving them automatically. Users only need to visit the UCP Notification settings to disable any unwanted notifications.

If this setting is disabled, users will not receive any notifications, even if they have subscribed, until they visit the UCP Notification settings to enable the specific notification options they wish to receive.', + 'WEBPUSH_DROPDOWN_SUBSCRIBE' => 'Show “Subscribe” button in notification dropdown', + 'WEBPUSH_DROPDOWN_SUBSCRIBE_EXPLAIN'=> 'Display a “Subscribe” button in the Notification dropdown, allowing users to easily subscribe to push notifications from anywhere in the forum.', ]); // Jabber settings diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 71790e499b..5933cc8f5c 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -512,6 +512,9 @@ $lang = array_merge($lang, array( ), 'NOTIFY_ADMIN' => 'Please notify the board administrator or webmaster.', 'NOTIFY_ADMIN_EMAIL' => 'Please notify the board administrator or webmaster: %1$s', + 'NOTIFY_WEB_PUSH_ENABLE' => 'Enable Web Push notifications', + 'NOTIFY_WEB_PUSH_SUBSCRIBE' => 'Subscribe', + 'NOTIFY_WEB_PUSH_SUBSCRIBED'=> 'Subscribed', 'NO_ACCESS_ATTACHMENT' => 'You are not allowed to access this file.', 'NO_ACTION' => 'No action specified.', 'NO_ADMINISTRATORS' => 'There are no administrators.', diff --git a/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php b/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php index 99ef6bd28f..d7478edfea 100644 --- a/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php +++ b/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php @@ -26,13 +26,14 @@ class add_webpush_options extends migration public function effectively_installed(): bool { - return $this->config->offsetExists('webpush_method_enables'); + return $this->config->offsetExists('webpush_method_enables') || $this->config->offsetExists('webpush_dropdown_subscribe'); } public function update_data(): array { return [ ['config.add', ['webpush_method_enables', false]], + ['config.add', ['webpush_dropdown_subscribe', false]], ]; } @@ -40,6 +41,7 @@ class add_webpush_options extends migration { return [ ['config.remove', ['webpush_method_enables']], + ['config.remove', ['webpush_dropdown_subscribe']], ]; } } diff --git a/phpBB/phpbb/notification/method/webpush.php b/phpBB/phpbb/notification/method/webpush.php index e1fc1f04ee..dcf1d1ebbf 100644 --- a/phpBB/phpbb/notification/method/webpush.php +++ b/phpBB/phpbb/notification/method/webpush.php @@ -355,7 +355,7 @@ class webpush extends messenger_base implements extended_method_interface } return [ - 'NOTIFICATIONS_WEBPUSH_ENABLE' => true, + 'NOTIFICATIONS_WEBPUSH_ENABLE' => $this->config['webpush_dropdown_subscribe'] || stripos($this->user->page['page'], 'notification_options'), 'U_WEBPUSH_SUBSCRIBE' => $controller_helper->route('phpbb_ucp_push_subscribe_controller'), 'U_WEBPUSH_UNSUBSCRIBE' => $controller_helper->route('phpbb_ucp_push_unsubscribe_controller'), 'VAPID_PUBLIC_KEY' => $this->config['webpush_vapid_public'], diff --git a/phpBB/styles/prosilver/template/notification_dropdown.html b/phpBB/styles/prosilver/template/notification_dropdown.html index 52bc546976..841f541744 100644 --- a/phpBB/styles/prosilver/template/notification_dropdown.html +++ b/phpBB/styles/prosilver/template/notification_dropdown.html @@ -44,6 +44,13 @@ + {% if NOTIFICATIONS_WEBPUSH_ENABLE and notification_types is not defined %} + + {% endif %} {% EVENT notification_dropdown_footer_after %} diff --git a/phpBB/styles/prosilver/template/overall_header.html b/phpBB/styles/prosilver/template/overall_header.html index b88de2aaa8..790f793d8f 100644 --- a/phpBB/styles/prosilver/template/overall_header.html +++ b/phpBB/styles/prosilver/template/overall_header.html @@ -63,6 +63,10 @@ +{% if NOTIFICATIONS_WEBPUSH_ENABLE %} + {% include('ucp_notifications_webpush.html') %} +{% endif %} + diff --git a/phpBB/styles/prosilver/template/ucp_notifications_options.html b/phpBB/styles/prosilver/template/ucp_notifications_options.html index a0d9caad12..b3be983f16 100644 --- a/phpBB/styles/prosilver/template/ucp_notifications_options.html +++ b/phpBB/styles/prosilver/template/ucp_notifications_options.html @@ -1,9 +1,5 @@ {% include('ucp_header.html') %} -{% if NOTIFICATIONS_WEBPUSH_ENABLE %} - {% include('ucp_notifications_webpush.html') %} -{% endif %} -

{{ TITLE }}

diff --git a/phpBB/styles/prosilver/theme/buttons.css b/phpBB/styles/prosilver/theme/buttons.css index e8f8fbe961..fda72c8613 100644 --- a/phpBB/styles/prosilver/theme/buttons.css +++ b/phpBB/styles/prosilver/theme/buttons.css @@ -220,3 +220,9 @@ button::-moz-focus-inner { .avatar-cropper-buttons > .button-group { margin: 4px; } + +/* Notification buttons +--------------------------------------------- */ +.notification-subscribe_toggle:disabled { + opacity: 0.7; +} diff --git a/phpBB/styles/prosilver/theme/common.css b/phpBB/styles/prosilver/theme/common.css index 240ba25d03..2300f9c611 100644 --- a/phpBB/styles/prosilver/theme/common.css +++ b/phpBB/styles/prosilver/theme/common.css @@ -1340,6 +1340,15 @@ ul.linklist:after, display: block; } +.dropdown-extended .notification-dropdown-footer { + white-space: nowrap; + border-top: solid 1px #b9b9b9; + display: flex; + flex-wrap: nowrap; + justify-content: space-between; + padding: 5px 10px; +} + .notification-avatar, .notification-menu .notification-list .notification-item .avatar, .notification-menu .notification-list .notification-item .gravatar { From 4afba5c9feec00a375a0ab86f05bc8aa0ba620ce Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 4 Jun 2024 10:15:54 -0700 Subject: [PATCH 3/9] [ticket/17333] Enable new configs by default PHPBB-17333 Signed-off-by: Matt Friedman --- phpBB/install/schemas/schema_data.sql | 4 ++-- phpBB/phpbb/db/migration/data/v400/add_webpush_options.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 9cabeb3e27..7756586c70 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -329,8 +329,8 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\backup\con INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_enable', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_public', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_private', ''); -INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_method_enables', '0'); -INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_dropdown_subscribe', '0'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_method_enables', '1'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_dropdown_subscribe', '1'); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cache_last_gc', '0', 1); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cron_lock', '0', 1); diff --git a/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php b/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php index d7478edfea..1a1727b256 100644 --- a/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php +++ b/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php @@ -32,8 +32,8 @@ class add_webpush_options extends migration public function update_data(): array { return [ - ['config.add', ['webpush_method_enables', false]], - ['config.add', ['webpush_dropdown_subscribe', false]], + ['config.add', ['webpush_method_enables', true]], + ['config.add', ['webpush_dropdown_subscribe', true]], ]; } From e162b67c48b0a84d8f388f5e705ffb95191554f3 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 4 Jun 2024 10:25:35 -0700 Subject: [PATCH 4/9] [ticket/17333] Fix toggle icon colors PHPBB-17333 Signed-off-by: Matt Friedman --- phpBB/styles/prosilver/template/notification_dropdown.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/styles/prosilver/template/notification_dropdown.html b/phpBB/styles/prosilver/template/notification_dropdown.html index 841f541744..ff52543d0a 100644 --- a/phpBB/styles/prosilver/template/notification_dropdown.html +++ b/phpBB/styles/prosilver/template/notification_dropdown.html @@ -47,8 +47,8 @@ {% if NOTIFICATIONS_WEBPUSH_ENABLE and notification_types is not defined %} {% endif %} {% EVENT notification_dropdown_footer_after %} From 5c58fd2055c2cb137af9f1759712fbff2eff81e9 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 4 Jun 2024 11:10:44 -0700 Subject: [PATCH 5/9] [ticket/17333] Add tests and fixes PHPBB-17333 Signed-off-by: Matt Friedman --- phpBB/phpbb/notification/method/webpush.php | 2 +- .../functional/notification_webpush_test.php | 127 ++++++++++++++++++ 2 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 tests/functional/notification_webpush_test.php diff --git a/phpBB/phpbb/notification/method/webpush.php b/phpBB/phpbb/notification/method/webpush.php index dcf1d1ebbf..a823aed6a0 100644 --- a/phpBB/phpbb/notification/method/webpush.php +++ b/phpBB/phpbb/notification/method/webpush.php @@ -96,7 +96,7 @@ class webpush extends messenger_base implements extended_method_interface */ public function is_enabled_by_default() { - return $this->config['webpush_method_enables']; + return (bool) $this->config['webpush_method_enables']; } /** diff --git a/tests/functional/notification_webpush_test.php b/tests/functional/notification_webpush_test.php new file mode 100644 index 0000000000..a07e0a8948 --- /dev/null +++ b/tests/functional/notification_webpush_test.php @@ -0,0 +1,127 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_notification_webpush_test extends phpbb_functional_test_case +{ + public function test_acp_module() + { + $this->login(); + $this->admin_login(); + + $this->add_lang(['acp/board', 'acp/common']); + + $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=webpush&sid=' . $this->sid); + + $this->assertContainsLang('ACP_WEBPUSH_SETTINGS', $crawler->filter('div.main > h1')->text()); + $this->assertContainsLang('ACP_WEBPUSH_SETTINGS_EXPLAIN', $crawler->filter('div.main > p')->text()); + $this->assertContainsLang('WEBPUSH_GENERATE_VAPID_KEYS', $crawler->filter('input[type="button"]')->attr('value')); + + $form_data = [ + 'config[webpush_enable]' => 1, + 'config[webpush_vapid_public]' => 'BDnYSJHVZBxq834LqDGr893IfazEez7q-jYH2QBNlT0ji2C9UwGosiqz8Dp_ZN23lqAngBZyRjXVWF4ZLA8X2zI', + 'config[webpush_vapid_private]' => 'IE5OYlmfWsMbBU1lzvr0bxrxVAXIteSkAnwGlZIhmRk', + 'config[webpush_method_enables]' => 1, + 'config[webpush_dropdown_subscribe]' => 1, + ]; + $form = $crawler->selectButton('submit')->form($form_data); + $crawler = self::submit($form); + $this->assertStringContainsString($this->lang('CONFIG_UPDATED'), $crawler->filter('.successbox')->text()); + + $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=webpush&sid=' . $this->sid); + + foreach ($form_data as $config_name => $config_value) + { + $config_value = ($config_name === 'config[webpush_vapid_private]') ? '********' : $config_value; + $this->assertEquals($config_value, $crawler->filter('input[name="' . $config_name . '"]')->attr('value')); + } + } + + public function test_ucp_module() + { + $this->login(); + $this->admin_login(); + + $this->add_lang('ucp'); + + $crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options'); + + $this->assertContainsLang('NOTIFY_WEBPUSH_ENABLE', $crawler->filter('label[for="subscribe_webpush"]')->text()); + $this->assertContainsLang('NOTIFICATION_METHOD_WEBPUSH', $crawler->filter('th.mark')->eq(2)->text()); + + // Assert checkbox is checked + $wp_list = $crawler->filter('.table1'); + $this->assert_checkbox_is_checked($wp_list, 'notification.type.bookmark_notification.method.webpush'); + $this->assert_checkbox_is_checked($wp_list, 'notification.type.mention_notification.method.webpush'); + $this->assert_checkbox_is_checked($wp_list, 'notification.type.post_notification.method.webpush'); + $this->assert_checkbox_is_checked($wp_list, 'notification.type.quote_notification.method.webpush'); + $this->assert_checkbox_is_checked($wp_list, 'notification.type.topic_notification.method.webpush'); + $this->assert_checkbox_is_checked($wp_list, 'notification.type.forum_notification.method.webpush'); + $this->assert_checkbox_is_checked($wp_list, 'notification.type.group_request_notification.method.webpush'); + $this->assert_checkbox_is_checked($wp_list, 'notification.type.pm_notification.method.webpush'); + $this->assert_checkbox_is_checked($wp_list, 'notification.type.report_pm_closed_notification.method.webpush'); + $this->assert_checkbox_is_checked($wp_list, 'notification.type.report_post_closed_notification.method.webpush'); + + $this->set_acp_option('webpush_method_enables', 0); + + $crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options'); + + // Assert checkbox is unchecked + $wp_list = $crawler->filter('.table1'); + $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.bookmark_notification.method.webpush'); + $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.mention_notification.method.webpush'); + $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.post_notification.method.webpush'); + $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.quote_notification.method.webpush'); + $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.topic_notification.method.webpush'); + $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.forum_notification.method.webpush'); + $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.group_request_notification.method.webpush'); + $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.pm_notification.method.webpush'); + $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.report_pm_closed_notification.method.webpush'); + $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.report_post_closed_notification.method.webpush'); + } + + public function test_dropdown_subscribe_button() + { + $this->login(); + $this->admin_login(); + + // Assert subscribe dropdown is present + $crawler = self::request('GET', 'index.php'); + $this->assertCount(1, $crawler->filter('.notification-dropdown-footer')); + $this->assertContainsLang('NOTIFY_WEB_PUSH_SUBSCRIBE', $crawler->filter('.notification-dropdown-footer #subscribe_webpush')->text()); + $this->assertContainsLang('NOTIFY_WEB_PUSH_SUBSCRIBED', $crawler->filter('.notification-dropdown-footer #unsubscribe_webpush')->text()); + + // Assert subscribe button is not displayed in UCP when dropdown subscribe is present + $crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options'); + $this->assertCount(0, $crawler->filter('.notification-dropdown-footer')); + + $this->set_acp_option('webpush_dropdown_subscribe', 0); + + // Assert subscribe dropdown is not present by default + $crawler = self::request('GET', 'index.php'); + $this->assertCount(0, $crawler->filter('.notification-dropdown-footer')); + } + + protected function set_acp_option($option, $value) + { + $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=webpush&sid=' . $this->sid); + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + $values["config[{$option}]"] = $value; + $form->setValues($values); + $crawler = self::submit($form); + $this->assertEquals(1, $crawler->filter('.successbox')->count()); + } +} From 0ca85246331043bdf031ec7d8b9340b19c91abbb Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 4 Jun 2024 12:29:42 -0700 Subject: [PATCH 6/9] [ticket/17333] Fix Subscribe text button color PHPBB-17333 Signed-off-by: Matt Friedman --- phpBB/styles/prosilver/theme/colours.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/styles/prosilver/theme/colours.css b/phpBB/styles/prosilver/theme/colours.css index 7bdd5f4b87..e803a3f6cf 100644 --- a/phpBB/styles/prosilver/theme/colours.css +++ b/phpBB/styles/prosilver/theme/colours.css @@ -1179,3 +1179,7 @@ input.disabled { background-color: #d41142; color: #ffffff; } + +.notification-subscribe_toggle { + color: #47536b; +} From 73e0412c88b38cd4a47b30202d93f3de41db9059 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 4 Jun 2024 14:19:37 -0700 Subject: [PATCH 7/9] [ticket/17333] Prevent double loading web push template data PHPBB-17333 Signed-off-by: Matt Friedman --- phpBB/includes/functions.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index fdc2d42ab9..8228b29e37 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3873,15 +3873,17 @@ function page_header($page_title = '', $display_online_list = false, $item_id = $template->assign_block_vars('notifications', $notification->prepare_for_display()); } - // Get web push notification data - $methods = $phpbb_notifications->get_subscription_methods(); - if ($config['webpush_dropdown_subscribe'] && array_key_exists('notification.method.webpush', $methods)) + // Assign notification web push template data (if not done already by ucp_notifications) + if ($config['webpush_dropdown_subscribe'] && $template->retrieve_var('NOTIFICATIONS_WEBPUSH_ENABLE') === null) { - /** @var \phpbb\form\form_helper $form_helper */ - $form_helper = $phpbb_container->get('form_helper'); + $methods = $phpbb_notifications->get_subscription_methods(); + if (isset($methods['notification.method.webpush'])) + { + $form_helper = $phpbb_container->get('form_helper'); - $template_ary = $methods['notification.method.webpush']['method']->get_ucp_template_data($controller_helper, $form_helper); - $template->assign_vars($template_ary); + $template_ary = $methods['notification.method.webpush']['method']->get_ucp_template_data($controller_helper, $form_helper); + $template->assign_vars($template_ary); + } } } From 36527a97b8ddc60b0dffea4d1ad53bc47a0afb1f Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 5 Jun 2024 18:47:57 -0700 Subject: [PATCH 8/9] [ticket/17333] Optimize loading web push data only when needed PHPBB-17333 Signed-off-by: Matt Friedman --- phpBB/includes/functions.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 8228b29e37..da22c4739d 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3873,15 +3873,18 @@ function page_header($page_title = '', $display_online_list = false, $item_id = $template->assign_block_vars('notifications', $notification->prepare_for_display()); } - // Assign notification web push template data (if not done already by ucp_notifications) - if ($config['webpush_dropdown_subscribe'] && $template->retrieve_var('NOTIFICATIONS_WEBPUSH_ENABLE') === null) + // Assign web push template vars globally (if not done already by ucp_notifications) for the dropdown subscribe button + if ($config['webpush_enable'] + && $config['webpush_dropdown_subscribe'] + && $template->retrieve_var('NOTIFICATIONS_WEBPUSH_ENABLE') === null) { $methods = $phpbb_notifications->get_subscription_methods(); - if (isset($methods['notification.method.webpush'])) - { - $form_helper = $phpbb_container->get('form_helper'); + $webpush = $methods['notification.method.webpush'] ?? null; - $template_ary = $methods['notification.method.webpush']['method']->get_ucp_template_data($controller_helper, $form_helper); + if ($webpush) + { + $formHelper = $phpbb_container->get('form_helper'); + $template_ary = $webpush['method']->get_ucp_template_data($controller_helper, $formHelper); $template->assign_vars($template_ary); } } From ca918f893e135b36f226a79e07db0dd36bb277d4 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 6 Jun 2024 19:37:36 -0700 Subject: [PATCH 9/9] [ticket/17333] Suggested code improvements PHPBB-17333 Signed-off-by: Matt Friedman --- phpBB/includes/acp/acp_board.php | 4 ++-- phpBB/includes/functions.php | 8 +++----- phpBB/install/schemas/schema_data.sql | 2 +- phpBB/language/en/acp/board.php | 6 +++--- .../phpbb/db/migration/data/v400/add_webpush_options.php | 6 +++--- phpBB/phpbb/notification/method/webpush.php | 2 +- tests/functional/notification_webpush_test.php | 4 ++-- 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 53faa4bc7d..a7b31cfe20 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -494,8 +494,8 @@ class acp_board 'webpush_enable' => ['lang' => 'WEBPUSH_ENABLE', 'validate' => 'bool', 'type' => 'custom', 'method' => 'webpush_enable', 'explain' => true], 'webpush_vapid_public' => ['lang' => 'WEBPUSH_VAPID_PUBLIC', 'validate' => 'string', 'type' => 'text:25:255', 'explain' => true], 'webpush_vapid_private' => ['lang' => 'WEBPUSH_VAPID_PRIVATE', 'validate' => 'string', 'type' => 'password:25:255', 'explain' => true], - 'webpush_method_enables' => ['lang' => 'WEBPUSH_METHOD_ENABLES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true], - 'webpush_dropdown_subscribe'=> ['lang' => 'WEBPUSH_DROPDOWN_SUBSCRIBE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true], + 'webpush_method_default_enable' => ['lang' => 'WEBPUSH_METHOD_DEFAULT_ENABLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true], + 'webpush_dropdown_subscribe' => ['lang' => 'WEBPUSH_DROPDOWN_SUBSCRIBE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true], 'legend3' => 'ACP_SUBMIT_CHANGES', ], diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index da22c4739d..355a3342bd 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3874,8 +3874,7 @@ function page_header($page_title = '', $display_online_list = false, $item_id = } // Assign web push template vars globally (if not done already by ucp_notifications) for the dropdown subscribe button - if ($config['webpush_enable'] - && $config['webpush_dropdown_subscribe'] + if ($config['webpush_enable'] && $config['webpush_dropdown_subscribe'] && $template->retrieve_var('NOTIFICATIONS_WEBPUSH_ENABLE') === null) { $methods = $phpbb_notifications->get_subscription_methods(); @@ -3883,9 +3882,8 @@ function page_header($page_title = '', $display_online_list = false, $item_id = if ($webpush) { - $formHelper = $phpbb_container->get('form_helper'); - $template_ary = $webpush['method']->get_ucp_template_data($controller_helper, $formHelper); - $template->assign_vars($template_ary); + $form_helper = $phpbb_container->get('form_helper'); + $template->assign_vars($webpush['method']->get_ucp_template_data($controller_helper, $form_helper)); } } } diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 7756586c70..ba8f654a90 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -329,7 +329,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\backup\con INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_enable', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_public', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_private', ''); -INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_method_enables', '1'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_method_default_enable', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_dropdown_subscribe', '1'); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cache_last_gc', '0', 1); diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index 3353a360e8..3228db126b 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -590,10 +590,10 @@ $lang = array_merge($lang, [ 'WEBPUSH_VAPID_PUBLIC_EXPLAIN' => 'The Voluntary Application Server Identification (VAPID) public key is shared to authenticate push messages from your site.
Caution: Modifying the VAPID public key will automatically render all Web Push subscriptions invalid.', 'WEBPUSH_VAPID_PRIVATE' => 'Server identification private key', 'WEBPUSH_VAPID_PRIVATE_EXPLAIN' => 'The Voluntary Application Server Identification (VAPID) private key is used to generate authenticated push messages dispatched from your site. The VAPID private key must form a valid public-private key pair alongside the VAPID public key.
Caution: Modifying the VAPID private key will automatically render all Web Push subscriptions invalid.', - 'WEBPUSH_METHOD_ENABLES' => 'Enable all user-based web push notification options by default', - 'WEBPUSH_METHOD_ENABLES_EXPLAIN'=> 'When this setting is enabled, users who subscribe and allow browser notifications will start receiving them automatically. Users only need to visit the UCP Notification settings to disable any unwanted notifications.

If this setting is disabled, users will not receive any notifications, even if they have subscribed, until they visit the UCP Notification settings to enable the specific notification options they wish to receive.', + 'WEBPUSH_METHOD_DEFAULT_ENABLE' => 'Enable all user-based web push notification options by default', + 'WEBPUSH_METHOD_DEFAULT_ENABLE_EXPLAIN' => 'When this setting is enabled, users who subscribe and allow browser notifications will start receiving them automatically. Users only need to visit the UCP Notification settings to disable any unwanted notifications.

If this setting is disabled, users will not receive any notifications, even if they have subscribed, until they visit the UCP Notification settings to enable the specific notification options they wish to receive.', 'WEBPUSH_DROPDOWN_SUBSCRIBE' => 'Show “Subscribe” button in notification dropdown', - 'WEBPUSH_DROPDOWN_SUBSCRIBE_EXPLAIN'=> 'Display a “Subscribe” button in the Notification dropdown, allowing users to easily subscribe to push notifications from anywhere in the forum.', + 'WEBPUSH_DROPDOWN_SUBSCRIBE_EXPLAIN' => 'Display a “Subscribe” button in the Notification dropdown, allowing users to easily subscribe to push notifications from anywhere in the forum.', ]); // Jabber settings diff --git a/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php b/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php index 1a1727b256..751ab9e5f4 100644 --- a/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php +++ b/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php @@ -26,13 +26,13 @@ class add_webpush_options extends migration public function effectively_installed(): bool { - return $this->config->offsetExists('webpush_method_enables') || $this->config->offsetExists('webpush_dropdown_subscribe'); + return $this->config->offsetExists('webpush_method_default_enable') || $this->config->offsetExists('webpush_dropdown_subscribe'); } public function update_data(): array { return [ - ['config.add', ['webpush_method_enables', true]], + ['config.add', ['webpush_method_default_enable', true]], ['config.add', ['webpush_dropdown_subscribe', true]], ]; } @@ -40,7 +40,7 @@ class add_webpush_options extends migration public function revert_data(): array { return [ - ['config.remove', ['webpush_method_enables']], + ['config.remove', ['webpush_method_default_enable']], ['config.remove', ['webpush_dropdown_subscribe']], ]; } diff --git a/phpBB/phpbb/notification/method/webpush.php b/phpBB/phpbb/notification/method/webpush.php index a823aed6a0..902880104d 100644 --- a/phpBB/phpbb/notification/method/webpush.php +++ b/phpBB/phpbb/notification/method/webpush.php @@ -96,7 +96,7 @@ class webpush extends messenger_base implements extended_method_interface */ public function is_enabled_by_default() { - return (bool) $this->config['webpush_method_enables']; + return (bool) $this->config['webpush_method_default_enable']; } /** diff --git a/tests/functional/notification_webpush_test.php b/tests/functional/notification_webpush_test.php index a07e0a8948..61478cec98 100644 --- a/tests/functional/notification_webpush_test.php +++ b/tests/functional/notification_webpush_test.php @@ -33,7 +33,7 @@ class phpbb_functional_notification_webpush_test extends phpbb_functional_test_c 'config[webpush_enable]' => 1, 'config[webpush_vapid_public]' => 'BDnYSJHVZBxq834LqDGr893IfazEez7q-jYH2QBNlT0ji2C9UwGosiqz8Dp_ZN23lqAngBZyRjXVWF4ZLA8X2zI', 'config[webpush_vapid_private]' => 'IE5OYlmfWsMbBU1lzvr0bxrxVAXIteSkAnwGlZIhmRk', - 'config[webpush_method_enables]' => 1, + 'config[webpush_method_default_enable]' => 1, 'config[webpush_dropdown_subscribe]' => 1, ]; $form = $crawler->selectButton('submit')->form($form_data); @@ -74,7 +74,7 @@ class phpbb_functional_notification_webpush_test extends phpbb_functional_test_c $this->assert_checkbox_is_checked($wp_list, 'notification.type.report_pm_closed_notification.method.webpush'); $this->assert_checkbox_is_checked($wp_list, 'notification.type.report_post_closed_notification.method.webpush'); - $this->set_acp_option('webpush_method_enables', 0); + $this->set_acp_option('webpush_method_default_enable', 0); $crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options');