From d86c51f9e3804a5297720674a127822a0e5bad88 Mon Sep 17 00:00:00 2001 From: Christian Schnegelberger Date: Tue, 17 Jan 2023 19:49:07 +0100 Subject: [PATCH] [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']) {