From d86c51f9e3804a5297720674a127822a0e5bad88 Mon Sep 17 00:00:00 2001 From: Christian Schnegelberger Date: Tue, 17 Jan 2023 19:49:07 +0100 Subject: [PATCH 01/14] [ticket/17093] Add new board settings option for disable board access PHPBB3-17093 --- phpBB/includes/acp/acp_board.php | 11 +++++++ phpBB/install/schemas/schema_data.sql | 1 + phpBB/language/en/acp/board.php | 5 +++ .../v33x/add_disable_board_access_config.php | 31 +++++++++++++++++++ phpBB/phpbb/user.php | 18 ++++++++++- 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 phpBB/phpbb/db/migration/data/v33x/add_disable_board_access_config.php diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index beccef809d..cb16b7808a 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -79,6 +79,7 @@ class acp_board 'board_index_text' => array('lang' => 'BOARD_INDEX_TEXT', 'validate' => 'string', 'type' => 'text:40:255', 'explain' => true), 'board_disable' => array('lang' => 'DISABLE_BOARD', 'validate' => 'bool', 'type' => 'custom', 'method' => 'board_disable', 'explain' => true), 'board_disable_msg' => false, + 'board_disable_access' => array('lang' => 'DISABLE_BOARD_ACCESS', 'validate' => 'int', 'type' => 'select', 'method' => 'board_disable_access', 'explain' => true), 'default_lang' => array('lang' => 'DEFAULT_LANGUAGE', 'validate' => 'lang', 'type' => 'select', 'method' => 'language_select', 'params' => array('{CONFIG_VALUE}'), 'explain' => false), 'default_dateformat' => array('lang' => 'DEFAULT_DATE_FORMAT', 'validate' => 'string', 'type' => 'custom', 'method' => 'dateformat_select', 'explain' => true), 'board_timezone' => array('lang' => 'SYSTEM_TIMEZONE', 'validate' => 'timezone', 'type' => 'custom', 'method' => 'timezone_select', 'explain' => true), @@ -1047,6 +1048,16 @@ class acp_board return h_radio('config[board_disable]', $radio_ary, $value) . '
'; } + /** + * Board disable access for which group: admins: 0; plus global moderators: 1 and plus all moderators: 2 + */ + function board_disable_access($value, $key ='') + { + global $user; + + return ''; + } + /** * Global quick reply enable/disable setting and button to enable in all forums */ diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 3fd9d5888b..c0d3a8a26a 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -57,6 +57,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_contact', 'c INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_contact_name', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_disable', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_disable_msg', ''); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_disable_access', '2'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_email', 'address@yourdomain.tld'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_email_form', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_email_sig', '{L_CONFIG_BOARD_EMAIL_SIG}'); diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index 1676117e13..65542f8078 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -50,6 +50,11 @@ $lang = array_merge($lang, array( 'DEFAULT_STYLE_EXPLAIN' => 'The default style for new users.', 'DISABLE_BOARD' => 'Disable board', 'DISABLE_BOARD_EXPLAIN' => 'This will make the board unavailable to users who are neither administrators nor moderators. You can also enter a short (255 character) message to display if you wish.', + 'DISABLE_BOARD_ACCESS' => 'Limit access of disabled board', + 'DISABLE_BOARD_ACCESS_EXPLAIN' => 'This setting limits the access to a disable board to only administrators, or administrators plus global moderators or administrators and all moderators', + 'DISABLE_BOARD_ACCESS_ADMIN' => 'Only administrators', + 'DISABLE_BOARD_ACCESS_ADMIN_GLOB_MODS' => 'Only administrators and global moderators', + 'DISABLE_BOARD_ACCESS_ADMIN_ALL_MODS' => 'Only administrators and all moderators', 'DISPLAY_LAST_SUBJECT' => 'Display subject of last added post on forum list', 'DISPLAY_LAST_SUBJECT_EXPLAIN' => 'The subject of the last added post will be displayed in the forum list with a hyperlink to the post. Subjects from password protected forums and forums in which user doesn’t have read access are not shown.', 'DISPLAY_UNAPPROVED_POSTS' => 'Display unapproved posts to the author', diff --git a/phpBB/phpbb/db/migration/data/v33x/add_disable_board_access_config.php b/phpBB/phpbb/db/migration/data/v33x/add_disable_board_access_config.php new file mode 100644 index 0000000000..f7db4a41b0 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v33x/add_disable_board_access_config.php @@ -0,0 +1,31 @@ + +* @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\v33x; + +class add_disable_board_access_config extends \phpbb\db\migration\migration +{ + static public function depends_on() + { + return [ + '\phpbb\db\migration\data\v33x\v339', + ]; + } + + public function update_data() + { + return [ + ['config.add', ['board_disable_access', '2']], + ]; + } +} diff --git a/phpBB/phpbb/user.php b/phpBB/phpbb/user.php index 52427d2915..e5156d8406 100644 --- a/phpBB/phpbb/user.php +++ b/phpBB/phpbb/user.php @@ -372,7 +372,23 @@ class user extends \phpbb\session } // Is board disabled and user not an admin or moderator? - if ($config['board_disable'] && !defined('IN_INSTALL') && !defined('IN_LOGIN') && !defined('SKIP_CHECK_DISABLED') && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) + // Check acp setting who has access: only admins "case: 0", plus global moderators "case: 1" and plus moderators "case: 2" + $disable_board_access = (int) $config['add_disable_board_access_config']; + + switch ($disable_board_access) { + case 0: + $access_disabled_board = $auth->acl_gets('a_'); + break; + case 1: + $access_disabled_board = $auth->acl_gets('a_') && $auth->acl_getf_global('m_'); + break; + default: + case 2: + $access_disabled_board = $auth->acl_gets('a_', 'm_') && $auth->acl_getf_global('m_'); + break; + } + + if ($config['board_disable'] && !defined('IN_INSTALL') && !defined('IN_LOGIN') && !defined('SKIP_CHECK_DISABLED') && !$access_disabled_board) { if ($this->data['is_bot']) { From 31d30ae01dc1d69e2d1d3a6de02853f95d2236c6 Mon Sep 17 00:00:00 2001 From: Christian Schnegelberger Date: Tue, 17 Jan 2023 20:01:57 +0100 Subject: [PATCH 02/14] [ticket/17093] Fixes copy & paste error in acp_board.php PHPBB3-17093 --- phpBB/includes/acp/acp_board.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index cb16b7808a..948cd31d05 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -1055,7 +1055,7 @@ class acp_board { global $user; - return ''; + return ''; } /** From 54f9b95bea9dd3a3a00f874996e4128f292eeb1b Mon Sep 17 00:00:00 2001 From: Christian Schnegelberger Date: Tue, 17 Jan 2023 20:20:57 +0100 Subject: [PATCH 03/14] [ticket/17093] Fix wording, variable name and && => || PHPBB3-17093 --- phpBB/language/en/acp/board.php | 4 ++-- phpBB/phpbb/user.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index 65542f8078..19a97a5298 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -50,8 +50,8 @@ $lang = array_merge($lang, array( 'DEFAULT_STYLE_EXPLAIN' => 'The default style for new users.', 'DISABLE_BOARD' => 'Disable board', 'DISABLE_BOARD_EXPLAIN' => 'This will make the board unavailable to users who are neither administrators nor moderators. You can also enter a short (255 character) message to display if you wish.', - 'DISABLE_BOARD_ACCESS' => 'Limit access of disabled board', - 'DISABLE_BOARD_ACCESS_EXPLAIN' => 'This setting limits the access to a disable board to only administrators, or administrators plus global moderators or administrators and all moderators', + 'DISABLE_BOARD_ACCESS' => 'Limit access to disabled board', + 'DISABLE_BOARD_ACCESS_EXPLAIN' => 'This setting limits the access to a disabled board to only administrators, or administrators plus global moderators or administrators and all moderators.', 'DISABLE_BOARD_ACCESS_ADMIN' => 'Only administrators', 'DISABLE_BOARD_ACCESS_ADMIN_GLOB_MODS' => 'Only administrators and global moderators', 'DISABLE_BOARD_ACCESS_ADMIN_ALL_MODS' => 'Only administrators and all moderators', diff --git a/phpBB/phpbb/user.php b/phpBB/phpbb/user.php index e5156d8406..2c7e5da8bc 100644 --- a/phpBB/phpbb/user.php +++ b/phpBB/phpbb/user.php @@ -373,18 +373,18 @@ class user extends \phpbb\session // Is board disabled and user not an admin or moderator? // Check acp setting who has access: only admins "case: 0", plus global moderators "case: 1" and plus moderators "case: 2" - $disable_board_access = (int) $config['add_disable_board_access_config']; + $board_disable_access = (int) $config['board_disable_access']; - switch ($disable_board_access) { + switch ($board_disable_access) { case 0: $access_disabled_board = $auth->acl_gets('a_'); break; case 1: - $access_disabled_board = $auth->acl_gets('a_') && $auth->acl_getf_global('m_'); + $access_disabled_board = $auth->acl_gets('a_') || $auth->acl_getf_global('m_'); break; default: case 2: - $access_disabled_board = $auth->acl_gets('a_', 'm_') && $auth->acl_getf_global('m_'); + $access_disabled_board = $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'); break; } From e55e2f17d36ac439a49ce093270db70f0bb555b1 Mon Sep 17 00:00:00 2001 From: Christian Schnegelberger Date: Tue, 17 Jan 2023 20:31:38 +0100 Subject: [PATCH 04/14] [ticket/17093] Add space to fix phing sniffer error PHPBB3-17093 --- phpBB/includes/acp/acp_board.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 948cd31d05..ce7b6871b5 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -1051,7 +1051,7 @@ class acp_board /** * Board disable access for which group: admins: 0; plus global moderators: 1 and plus all moderators: 2 */ - function board_disable_access($value, $key ='') + function board_disable_access($value, $key = '') { global $user; From 104e56f56fcfc5cd3531e1bedec6e298bc251e88 Mon Sep 17 00:00:00 2001 From: Christian Schnegelberger Date: Tue, 17 Jan 2023 20:58:22 +0100 Subject: [PATCH 05/14] [ticket/17093] Fix to differ between Global and local moderators PHPBB3-17093 --- phpBB/phpbb/user.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/user.php b/phpBB/phpbb/user.php index 2c7e5da8bc..47fba882bd 100644 --- a/phpBB/phpbb/user.php +++ b/phpBB/phpbb/user.php @@ -375,12 +375,13 @@ class user extends \phpbb\session // Check acp setting who has access: only admins "case: 0", plus global moderators "case: 1" and plus moderators "case: 2" $board_disable_access = (int) $config['board_disable_access']; - switch ($board_disable_access) { + switch ($board_disable_access) + { case 0: $access_disabled_board = $auth->acl_gets('a_'); break; case 1: - $access_disabled_board = $auth->acl_gets('a_') || $auth->acl_getf_global('m_'); + $access_disabled_board = $auth->acl_gets('a_', 'm_'); break; default: case 2: From fd21296a18d629cd593f7766f05389b060d89b3a Mon Sep 17 00:00:00 2001 From: Christian Schnegelberger Date: Tue, 31 Jan 2023 16:42:39 +0100 Subject: [PATCH 06/14] [ticket/17093] Change wording for _ACCESS_EXPLAIN PHPBB3-17093 --- phpBB/language/en/acp/board.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index 19a97a5298..c159cb30e6 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -51,7 +51,7 @@ $lang = array_merge($lang, array( 'DISABLE_BOARD' => 'Disable board', 'DISABLE_BOARD_EXPLAIN' => 'This will make the board unavailable to users who are neither administrators nor moderators. You can also enter a short (255 character) message to display if you wish.', 'DISABLE_BOARD_ACCESS' => 'Limit access to disabled board', - 'DISABLE_BOARD_ACCESS_EXPLAIN' => 'This setting limits the access to a disabled board to only administrators, or administrators plus global moderators or administrators and all moderators.', + 'DISABLE_BOARD_ACCESS_EXPLAIN' => 'This setting limits who can access a disabled board.', 'DISABLE_BOARD_ACCESS_ADMIN' => 'Only administrators', 'DISABLE_BOARD_ACCESS_ADMIN_GLOB_MODS' => 'Only administrators and global moderators', 'DISABLE_BOARD_ACCESS_ADMIN_ALL_MODS' => 'Only administrators and all moderators', From 042feffed86354687c29062d97c699dd9cbb3d47 Mon Sep 17 00:00:00 2001 From: Christian Schnegelberger Date: Thu, 2 Mar 2023 21:14:46 +0100 Subject: [PATCH 07/14] [ticket/17093] Depends_on to v3310 and reformat switch PHPBB3-17093 --- .../data/v33x/add_disable_board_access_config.php | 2 +- phpBB/phpbb/user.php | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v33x/add_disable_board_access_config.php b/phpBB/phpbb/db/migration/data/v33x/add_disable_board_access_config.php index f7db4a41b0..2cb580d532 100644 --- a/phpBB/phpbb/db/migration/data/v33x/add_disable_board_access_config.php +++ b/phpBB/phpbb/db/migration/data/v33x/add_disable_board_access_config.php @@ -18,7 +18,7 @@ class add_disable_board_access_config extends \phpbb\db\migration\migration static public function depends_on() { return [ - '\phpbb\db\migration\data\v33x\v339', + '\phpbb\db\migration\data\v33x\v3310', ]; } diff --git a/phpBB/phpbb/user.php b/phpBB/phpbb/user.php index 47fba882bd..e84cb13afd 100644 --- a/phpBB/phpbb/user.php +++ b/phpBB/phpbb/user.php @@ -379,14 +379,17 @@ class user extends \phpbb\session { case 0: $access_disabled_board = $auth->acl_gets('a_'); - break; + break; + case 1: $access_disabled_board = $auth->acl_gets('a_', 'm_'); - break; - default: + break; + case 2: + default: $access_disabled_board = $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'); - break; + break; + } if ($config['board_disable'] && !defined('IN_INSTALL') && !defined('IN_LOGIN') && !defined('SKIP_CHECK_DISABLED') && !$access_disabled_board) From 73806f934271140508caabf73dd219ee5ac4ef1b Mon Sep 17 00:00:00 2001 From: Christian Schnegelberger Date: Sun, 4 Feb 2024 15:15:22 +0100 Subject: [PATCH 08/14] [ticket/17093] Use acp twig macro for display of acp board setting PHPBB3-17093 --- phpBB/includes/acp/acp_board.php | 23 +++++++++++++++++-- .../add_disable_board_access_config.php | 4 ++-- 2 files changed, 23 insertions(+), 4 deletions(-) rename phpBB/phpbb/db/migration/data/{v33x => v400}/add_disable_board_access_config.php (86%) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index ce7b6871b5..f161c308b7 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -1051,11 +1051,30 @@ class acp_board /** * Board disable access for which group: admins: 0; plus global moderators: 1 and plus all moderators: 2 */ - function board_disable_access($value, $key = '') + public function board_disable_access($value, $key = '') : array { global $user; - return ''; + return [ + [ + 'tag' => 'select', + 'value' => 0, + 'selected' => ($value == 0) ? ' selected="selected"' : '', + 'label' => $user->lang['DISABLE_BOARD_ACCESS_ADMIN'], + ], + [ + 'tag' => 'select', + 'value' => 1, + 'selected' => ($value == 1) ? ' selected="selected"' : '', + 'label' => $user->lang['DISABLE_BOARD_ACCESS_ADMIN_GLOB_MODS'], + ], + [ + 'tag' => 'select', + 'value' => 2, + 'selected' => ($value == 2) ? ' selected="selected"' : '', + 'label' => $user->lang['DISABLE_BOARD_ACCESS_ADMIN_ALL_MODS'], + ] + ]; } /** diff --git a/phpBB/phpbb/db/migration/data/v33x/add_disable_board_access_config.php b/phpBB/phpbb/db/migration/data/v400/add_disable_board_access_config.php similarity index 86% rename from phpBB/phpbb/db/migration/data/v33x/add_disable_board_access_config.php rename to phpBB/phpbb/db/migration/data/v400/add_disable_board_access_config.php index 2cb580d532..d7a7214cae 100644 --- a/phpBB/phpbb/db/migration/data/v33x/add_disable_board_access_config.php +++ b/phpBB/phpbb/db/migration/data/v400/add_disable_board_access_config.php @@ -11,14 +11,14 @@ * */ -namespace phpbb\db\migration\data\v33x; +namespace phpbb\db\migration\data\v400; class add_disable_board_access_config extends \phpbb\db\migration\migration { static public function depends_on() { return [ - '\phpbb\db\migration\data\v33x\v3310', + '\phpbb\db\migration\data\v400\dev', ]; } From ce8b31130c8082e3dfe3687979bd75bb4f670b5d Mon Sep 17 00:00:00 2001 From: Christian Schnegelberger Date: Sun, 4 Feb 2024 16:06:31 +0100 Subject: [PATCH 09/14] [ticket/17093] Fix sniff error in migration PHPBB3-17093 --- .../db/migration/data/v400/add_disable_board_access_config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/db/migration/data/v400/add_disable_board_access_config.php b/phpBB/phpbb/db/migration/data/v400/add_disable_board_access_config.php index d7a7214cae..e534cbdf67 100644 --- a/phpBB/phpbb/db/migration/data/v400/add_disable_board_access_config.php +++ b/phpBB/phpbb/db/migration/data/v400/add_disable_board_access_config.php @@ -15,7 +15,7 @@ namespace phpbb\db\migration\data\v400; class add_disable_board_access_config extends \phpbb\db\migration\migration { - static public function depends_on() + public static function depends_on() { return [ '\phpbb\db\migration\data\v400\dev', From c000089cfdc4d5fb49b0792f73e93e9a9034aa8a Mon Sep 17 00:00:00 2001 From: Christian Schnegelberger Date: Sun, 4 Feb 2024 16:45:04 +0100 Subject: [PATCH 10/14] [ticket/17093] Remove short if in selected PHPBB3-17093 --- phpBB/includes/acp/acp_board.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index f161c308b7..48bb4a84e7 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -1059,19 +1059,19 @@ class acp_board [ 'tag' => 'select', 'value' => 0, - 'selected' => ($value == 0) ? ' selected="selected"' : '', + 'selected' => $value == 0, 'label' => $user->lang['DISABLE_BOARD_ACCESS_ADMIN'], ], [ 'tag' => 'select', 'value' => 1, - 'selected' => ($value == 1) ? ' selected="selected"' : '', + 'selected' => $value == 1, 'label' => $user->lang['DISABLE_BOARD_ACCESS_ADMIN_GLOB_MODS'], ], [ 'tag' => 'select', 'value' => 2, - 'selected' => ($value == 2) ? ' selected="selected"' : '', + 'selected' => $value == 2, 'label' => $user->lang['DISABLE_BOARD_ACCESS_ADMIN_ALL_MODS'], ] ]; From d8608e4ba585c510225ef10b39867b1bebfea13c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 19 Feb 2024 18:49:37 +0100 Subject: [PATCH 11/14] [ticket/17093] Remove not needed values PHPBB3-17093 --- phpBB/includes/acp/acp_board.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 48bb4a84e7..935a773073 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -1057,23 +1057,20 @@ class acp_board return [ [ - 'tag' => 'select', 'value' => 0, 'selected' => $value == 0, 'label' => $user->lang['DISABLE_BOARD_ACCESS_ADMIN'], ], [ - 'tag' => 'select', 'value' => 1, 'selected' => $value == 1, 'label' => $user->lang['DISABLE_BOARD_ACCESS_ADMIN_GLOB_MODS'], ], [ - 'tag' => 'select', 'value' => 2, 'selected' => $value == 2, 'label' => $user->lang['DISABLE_BOARD_ACCESS_ADMIN_ALL_MODS'], - ] + ], ]; } From 232dfa6b208b573766627abef91a5acfa768da10 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 19 Feb 2024 18:54:12 +0100 Subject: [PATCH 12/14] [ticket/17093] Add docblock and use language instead of user PHPBB3-17093 --- phpBB/includes/acp/acp_board.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 935a773073..df7c8bf657 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -1050,26 +1050,28 @@ class acp_board /** * Board disable access for which group: admins: 0; plus global moderators: 1 and plus all moderators: 2 + * + * @param int $value Value from config + * + * @return array Options array for select */ - public function board_disable_access($value, $key = '') : array + public function board_disable_access(int $value) : array { - global $user; - return [ [ 'value' => 0, 'selected' => $value == 0, - 'label' => $user->lang['DISABLE_BOARD_ACCESS_ADMIN'], + 'label' => $this->language->lang('DISABLE_BOARD_ACCESS_ADMIN'), ], [ 'value' => 1, 'selected' => $value == 1, - 'label' => $user->lang['DISABLE_BOARD_ACCESS_ADMIN_GLOB_MODS'], + 'label' => $this->language->lang('DISABLE_BOARD_ACCESS_ADMIN_GLOB_MODS'), ], [ 'value' => 2, 'selected' => $value == 2, - 'label' => $user->lang['DISABLE_BOARD_ACCESS_ADMIN_ALL_MODS'], + 'label' => $this->language->lang('DISABLE_BOARD_ACCESS_ADMIN_ALL_MODS'), ], ]; } From be93efee1dd1a930ff535d102c2d95b409a29d05 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 22 Feb 2024 17:42:06 +0100 Subject: [PATCH 13/14] [ticket/17093] Add test for disabled board behavior PHPBB3-17093 --- tests/functional/browse_disabled_test.php | 164 ++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 tests/functional/browse_disabled_test.php diff --git a/tests/functional/browse_disabled_test.php b/tests/functional/browse_disabled_test.php new file mode 100644 index 0000000000..528f95fc25 --- /dev/null +++ b/tests/functional/browse_disabled_test.php @@ -0,0 +1,164 @@ + +* @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_browse_disabled_test extends phpbb_functional_test_case +{ + public function setUp(): void + { + parent::setUp(); + + $this->login(); + $this->admin_login(); + + // Disable board + $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=settings&sid=' . $this->sid); + $form = $crawler->selectButton('Submit')->form(); + $form->setValues(['config[board_disable]' => 1]); + + $crawler = self::submit($form); + $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('div[class="successbox"] > p')->text()); + + $this->logout(); + } + + public function tearDown(): void + { + $this->login(); + $this->admin_login(); + + // Disable board + $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=settings&sid=' . $this->sid); + $form = $crawler->selectButton('Submit')->form(); + $form->setValues(['config[board_disable]' => 0]); + + $crawler = self::submit($form); + $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('div[class="successbox"] > p')->text()); + + $this->logout(); + + parent::tearDown(); + } + + public function test_disabled_index_admin() + { + $this->login(); + $this->admin_login(); + + // Board should be fully visible for all variations for admins + for ($i = 0; $i <= 2; $i++) + { + $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=settings&sid=' . $this->sid); + $form = $crawler->selectButton('Submit')->form(); + $form->setValues(['config[board_disable_access]' => $i]); + + $crawler = self::submit($form); + $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('div[class="successbox"] > p')->text()); + + $crawler = self::request('GET', 'index.php'); + $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count()); + $this->assertContainsLang('BOARD_DISABLED', $crawler->filter('div[class="rules"]')->text()); + } + + $this->logout(); + } + + public function test_disabled_index_global_moderator() + { + $this->create_user('moderator-disabled-index'); + $this->add_user_group('GLOBAL_MODERATORS', ['moderator-disabled-index']); + + // Board should be fully visible for options 1 & 2 + for ($i = 0; $i <= 2; $i++) + { + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=settings&sid=' . $this->sid); + $form = $crawler->selectButton('Submit')->form(); + $form->setValues(['config[board_disable_access]' => $i]); + + $crawler = self::submit($form); + $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('div[class="successbox"] > p')->text()); + + $this->logout(); + + $this->login('moderator-disabled-index'); + + $crawler = self::request('GET', 'index.php'); + + if ($i == 0) + { + $this->assertEquals(0, $crawler->filter('.topiclist')->count(), 'Board should not be visible for option ' . $i); + $this->assertContainsLang('BOARD_DISABLE', $crawler->filter('div#message')->text()); + } + else + { + $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count(), 'Board should be visible for option ' . $i); + $this->assertContainsLang('BOARD_DISABLED', $crawler->filter('div[class="rules"]')->text()); + } + $this->logout(); + } + } + + public function test_disabled_index_local_moderator() + { + $user_id = $this->create_user('moduser-disabled-index'); + + // Set m_delete to yes for user --> user has moderator permission + $this->add_lang('acp/permissions'); + $this->login(); + $this->admin_login(); + $crawler = self::request('GET', "adm/index.php?i=acp_permissions&icat=16&mode=setting_user_local&user_id[0]=$user_id&forum_id[0]=2&type=m_&sid={$this->sid}"); + var_export($crawler->text()); + $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form(); + $data = array("setting[$user_id][2][m_edit]" => ACL_YES); + $form->setValues($data); + self::submit($form); + $this->logout(); + + // Board should be fully visible for option 2 only + for ($i = 0; $i <= 2; $i++) + { + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=settings&sid=' . $this->sid); + $form = $crawler->selectButton('Submit')->form(); + $form->setValues(['config[board_disable_access]' => $i]); + + $crawler = self::submit($form); + $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('div[class="successbox"] > p')->text()); + + $this->logout(); + + $this->login('moduser-disabled-index'); + + $crawler = self::request('GET', 'index.php'); + + if ($i < 2) + { + $this->assertEquals(0, $crawler->filter('.topiclist')->count(), 'Board should not be visible for option ' . $i); + $this->assertContainsLang('BOARD_DISABLE', $crawler->filter('div#message')->text()); + } + else + { + $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count(), 'Board should be visible for option ' . $i); + $this->assertContainsLang('BOARD_DISABLED', $crawler->filter('div[class="rules"]')->text()); + } + $this->logout(); + } + } +} From 946fb7d9a42a128da7b92e6350d326620d950f5d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 22 Feb 2024 19:06:26 +0100 Subject: [PATCH 14/14] [ticket/17093] Change how login is handled to support disabled boards PHPBB3-17093 --- tests/test_framework/phpbb_functional_test_case.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 18fe2bbf38..c0dd68ab14 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -851,8 +851,9 @@ class phpbb_functional_test_case extends phpbb_test_case { $this->add_lang('ucp'); - $crawler = self::request('GET', 'ucp.php'); - $this->assertStringContainsString($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); + $crawler = self::request('GET', 'ucp.php?mode=login'); + $button = $crawler->selectButton($this->lang('LOGIN')); + $this->assertGreaterThan(0, $button->count(), 'No login button found'); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); if ($autologin)