[ticket/17333] Suggested code improvements

PHPBB-17333

Signed-off-by: Matt Friedman <maf675@gmail.com>
This commit is contained in:
Matt Friedman 2024-06-06 19:37:36 -07:00
parent 36527a97b8
commit ca918f893e
No known key found for this signature in database
7 changed files with 15 additions and 17 deletions

View file

@ -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',
],

View file

@ -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));
}
}
}

View file

@ -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);

View file

@ -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.<br><em><strong>Caution:</strong> Modifying the VAPID public key will automatically render all Web Push subscriptions invalid.</em>',
'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 <strong>must</strong> form a valid public-private key pair alongside the VAPID public key.<br><em><strong>Caution:</strong> Modifying the VAPID private key will automatically render all Web Push subscriptions invalid.</em>',
'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.<br><br>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.<br><br>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

View file

@ -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']],
];
}

View file

@ -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'];
}
/**

View file

@ -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');