From e35a6f7aa5616e9d3ffe46c22c10bda0f4d3bfb5 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 4 Jun 2024 08:26:21 -0700 Subject: [PATCH] [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} */