diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index c50e0d01ee..1939d0ff78 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -915,7 +915,7 @@ function user_active_flip($mode, $user_id_ary, $reason = INACTIVE_MANUAL) /** * Add a ban or ban exclusion to the banlist. Bans either a user, an IP or an email address * -* @deprecated 3.3.0-a1 (To be removed: 4.0.0) +* @deprecated 4.0.0-a1 (To be removed: 4.1.0) * * @param string $mode Type of ban. One of the following: user, ip, email * @param mixed $ban Banned entity. Either string or array with usernames, ips or email addresses @@ -970,14 +970,12 @@ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_reason, $ban_give_ $end->setTimestamp($ban_end); return $ban_manager->ban($mode, $items, $start, $end, $ban_reason, $ban_give_reason); - - // TODO: logging } /** * Unban User * -* @deprecated 3.3.0-a1 (To be removed: 4.0.0) +* @deprecated 4.0.0-a1 (To be removed: 4.1.0) */ function user_unban($mode, $ban) { @@ -3254,8 +3252,6 @@ function remove_newly_registered($user_id, $user_data = false) /** * Gets user ids of currently banned registered users. * -* @deprecated 3.3.0-a1 (To be removed: 4.0.0) -* * @param array $user_ids Array of users' ids to check for banning, * leave empty to get complete list of banned ids * @param bool|int $ban_end Bool True to get users currently banned @@ -3283,10 +3279,21 @@ function phpbb_get_banned_user_ids($user_ids = array(), $ban_end = true) return $end <= 0 || $end > (int) $ban_end; }); } + else + { + $banned_users = array_filter($banned_users, function ($end) { + return $end <= 0 || $end > time(); + }); + } $result_array = []; foreach ($banned_users as $user_id => $_) { + if (count($user_ids) && !in_array($user_id, $user_ids)) + { + continue; + } + $result_array[$user_id] = $user_id; } diff --git a/phpBB/phpbb/ban/manager.php b/phpBB/phpbb/ban/manager.php index 7455f7635c..7586cb6dde 100644 --- a/phpBB/phpbb/ban/manager.php +++ b/phpBB/phpbb/ban/manager.php @@ -417,9 +417,7 @@ class manager $this->cache->put(self::CACHE_KEY_USERS, $banned_users, self::CACHE_TTL); } - return array_filter($banned_users, function ($end) { - return $end <= 0 || $end > time(); - }); + return $banned_users; } /** diff --git a/tests/ban/ban_manager_test.php b/tests/ban/ban_manager_test.php index 4906b6781c..2eb49686d6 100644 --- a/tests/ban/ban_manager_test.php +++ b/tests/ban/ban_manager_test.php @@ -403,6 +403,7 @@ class ban_manager_test extends \phpbb_session_test_case [ 4 => 0, 5 => 0, + 19 => 1234, 20 => 0, ], $ban_manager->get_banned_users() diff --git a/tests/functions/fixtures/banned_users.xml b/tests/functions/fixtures/banned_users.xml index 4d6a6bfa40..082f210ca3 100644 --- a/tests/functions/fixtures/banned_users.xml +++ b/tests/functions/fixtures/banned_users.xml @@ -2,27 +2,68 @@ ban_userid + ban_modeban_end 2 - 0 + user 0 3 + user 0 4 + user 2 5 - 999999999999999999999 + user + 2147485547 6 + user 3
+ + user_id + username_clean + user_permissions + user_sig + + 2 + admin + + + + + 3 + user3 + + + + + 4 + user4 + + + + + 5 + user5 + + + + + 6 + user6 + + + +
diff --git a/tests/functions/phpbb_get_banned_user_ids.php b/tests/functions/phpbb_get_banned_user_ids.php index 0877a3526e..6aaa5f8641 100644 --- a/tests/functions/phpbb_get_banned_user_ids.php +++ b/tests/functions/phpbb_get_banned_user_ids.php @@ -20,6 +20,47 @@ class phpbb_get_banned_user_ids_test extends phpbb_database_test_case return $this->createXMLDataSet(__DIR__ . '/fixtures/banned_users.xml'); } + protected function setUp(): void + { + global $db, $phpbb_container, $phpbb_root_path, $phpEx; + + $db = $this->new_dbal(); + + parent::setUp(); + + $phpbb_container = new phpbb_mock_container_builder(); + $config = new \phpbb\config\config([]); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $language = new phpbb\language\language(new phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); + $user = new phpbb\user($language, '\phpbb\datetime'); + $user->data['user_email'] = ''; + + $cache = new \phpbb\cache\service( + new \phpbb\cache\driver\dummy(), + $config, + $db, + $phpbb_dispatcher, + $phpbb_root_path, + $phpEx + ); + $cache->get_driver()->purge(); + + $ban_type_email = new \phpbb\ban\type\email($db, 'phpbb_bans', 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys'); + $ban_type_user = new \phpbb\ban\type\user($db, 'phpbb_bans', 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys'); + $ban_type_ip = new \phpbb\ban\type\ip($db, 'phpbb_bans', 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys'); + $phpbb_container->set('ban.type.email', $ban_type_email); + $phpbb_container->set('ban.type.user', $ban_type_user); + $phpbb_container->set('ban.type.ip', $ban_type_ip); + $collection = new \phpbb\di\service_collection($phpbb_container); + $collection->add('ban.type.email'); + $collection->add('ban.type.user'); + $collection->add('ban.type.ip'); + $phpbb_log = new \phpbb\log\dummy(); + + $ban_manager = new \phpbb\ban\manager($collection, $cache->get_driver(), $db, $language, $phpbb_log, $user, 'phpbb_bans', 'phpbb_users'); + $phpbb_container->set('ban.manager', $ban_manager); + } + public function phpbb_get_banned_user_ids_data() { return array( @@ -35,6 +76,11 @@ class phpbb_get_banned_user_ids_test extends phpbb_database_test_case array(array(1, 2, 4, 5, 6), false), array(2 => 2), ), + array( + // True to get users currently banned, but should only return passed user IDs + array(array(5, 6, 7), true), + array(5 => 5), + ), array( // Unix timestamp to get users banned until that time array(array(1, 2, 4, 5, 6), 2), @@ -43,15 +89,6 @@ class phpbb_get_banned_user_ids_test extends phpbb_database_test_case ); } - protected function setUp(): void - { - global $db; - - $db = $this->new_dbal(); - - parent::setUp(); - } - /** * @dataProvider phpbb_get_banned_user_ids_data */