diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 48bb7be21c..ea9ddbaf3c 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -3168,7 +3168,7 @@ function display_ban_options($mode) { $banned_options[] = [ 'value' => $ban_row['ban_id'], - 'label' => $ban_row['ban_item'], + 'label' => $ban_row['label'] ?? $ban_row['ban_item'], ]; $time_length = ($ban_row['ban_end']) ? ($ban_row['ban_end'] - $ban_row['ban_start']) / 60 : 0; diff --git a/phpBB/phpbb/ban/manager.php b/phpBB/phpbb/ban/manager.php index feddc56f16..0acfd1e019 100644 --- a/phpBB/phpbb/ban/manager.php +++ b/phpBB/phpbb/ban/manager.php @@ -126,6 +126,7 @@ class manager $insert_array[] = [ 'ban_mode' => $mode, 'ban_item' => $ban_item, + 'ban_userid' => $mode === 'user' ? $ban_item : 0, 'ban_start' => $start->getTimestamp(), 'ban_end' => $end->getTimestamp(), 'ban_reason' => $reason, diff --git a/phpBB/phpbb/ban/type/user.php b/phpBB/phpbb/ban/type/user.php index c803e1b16f..a2b3f9b91b 100644 --- a/phpBB/phpbb/ban/type/user.php +++ b/phpBB/phpbb/ban/type/user.php @@ -84,6 +84,7 @@ class user extends base $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { + $row['label'] = $row['username']; $ban_options[] = $row; } $this->db->sql_freeresult($result); diff --git a/tests/ban/ban_manager_test.php b/tests/ban/ban_manager_test.php index a5f3620217..4906b6781c 100644 --- a/tests/ban/ban_manager_test.php +++ b/tests/ban/ban_manager_test.php @@ -261,8 +261,9 @@ class ban_manager_test extends \phpbb_session_test_case 'ban_mode' => 'user', 'ban_userid' => 4, 'user_id' => '4', - 'username' => '', + 'username' => 'ipv6_user', 'username_clean' => 'ipv6_user', + 'label' => 'ipv6_user', ], ], ], @@ -650,8 +651,9 @@ class ban_manager_test extends \phpbb_session_test_case 'ban_reason_display' => '1', 'ban_mode' => 'user', 'user_id' => '4', - 'username' => '', + 'username' => 'ipv6_user', 'username_clean' => 'ipv6_user', + 'label' => 'ipv6_user', ], ], ], @@ -691,9 +693,73 @@ class ban_manager_test extends \phpbb_session_test_case $ban_type_ip = $this->phpbb_container->get('ban.type.ip'); $base_type_reflection = new \ReflectionClass(\phpbb\ban\type\base::class); $after_unban = $base_type_reflection->getMethod('after_unban'); - $this->assertEquals(['foo'], $after_unban->invoke($ban_type_ip, ['items' => ['foo']])); + $this->assertEquals([], $after_unban->invoke($ban_type_ip, ['items' => ['foo']])); $check = $base_type_reflection->getMethod('check'); $this->assertFalse($check->invoke($ban_type_ip, [], [])); } + + public function data_get_ban_message(): array + { + return [ + [ + [ + 'end' => 0, + ], + 'foobar', + 'http://foo.bar', + 'You have been permanently banned from this board.

Please contact the Board Administrator for more information.

BAN_TRIGGERED_BY_FOOBAR', + ], + [ + [ + 'end' => 1, + ], + 'foobar', + 'http://foo.bar', + 'You have been banned from this board until .

Please contact the Board Administrator for more information.

BAN_TRIGGERED_BY_FOOBAR', + ], + [ + [ + 'end' => 1, + 'reason' => 'just because', + ], + 'foobar', + 'http://foo.bar', + 'You have been banned from this board until .

Please contact the Board Administrator for more information.

Reason given for ban: just because

BAN_TRIGGERED_BY_FOOBAR', + ], + ]; + } + + /** + * @dataProvider data_get_ban_message + */ + public function test_get_ban_message($ban_row, $ban_triggered_by, $contact_link, $expected) + { + $this->assertEquals($expected, $this->ban_manager->get_ban_message($ban_row, $ban_triggered_by, $contact_link)); + } + + public function test_get_ban_options_user() + { + $foo = $this->ban_manager->get_bans('user'); + + $this->assertEquals( + [ + [ + 'ban_id' => 4, + 'ban_userid' => '4', + 'ban_mode' => 'user', + 'ban_item' => '4', + 'ban_start' => '1111', + 'ban_end' => '0', + 'ban_reason' => 'HAHAHA', + 'ban_reason_display' => '1', + 'user_id' => '4', + 'username' => 'ipv6_user', + 'username_clean' => 'ipv6_user', + 'label' => 'ipv6_user', + ], + ], + $foo + ); + } } diff --git a/tests/ban/fixtures/sessions_banlist.xml b/tests/ban/fixtures/sessions_banlist.xml index 39253d2681..c6c882fcf9 100644 --- a/tests/ban/fixtures/sessions_banlist.xml +++ b/tests/ban/fixtures/sessions_banlist.xml @@ -2,6 +2,7 @@ user_id + usernameusername_cleanuser_permissionsuser_sig @@ -11,6 +12,7 @@ 1 anonymous + anonymous @@ -20,6 +22,7 @@ 2 founder + founder admin@foo.bar @@ -29,6 +32,7 @@ 3 normal_user + normal_user normal_user@foo.bar @@ -38,6 +42,7 @@ 4 ipv6_user + ipv6_user normal_user@foo.bar @@ -47,6 +52,7 @@ 5 another_user + another_user bar@example.org