From f646fcdefa932c8c3829a6e945782390142d09b5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 13 Jul 2024 23:46:28 +0200 Subject: [PATCH 1/2] [ticket/14454] Handle special case of testing user permissions in ACP modules PHPBB-14454 --- phpBB/includes/functions_module.php | 10 ++- tests/functional/switch_permissions_test.php | 70 ++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 tests/functional/switch_permissions_test.php diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 5b7c558365..53ea967fac 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -480,7 +480,7 @@ class p_master */ function set_active($id = false, $mode = false) { - global $request; + global $auth, $request, $user; $icat = false; $this->active_module = false; @@ -502,6 +502,14 @@ class p_master $id = $this->p_class . '_' . $id; } + // Fallback to acp main page for special restore permission mode + if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) + { + $id = ''; + $mode = ''; + $icat = false; + } + $category = false; foreach ($this->module_ary as $row_id => $item_ary) { diff --git a/tests/functional/switch_permissions_test.php b/tests/functional/switch_permissions_test.php new file mode 100644 index 0000000000..d83d303f5d --- /dev/null +++ b/tests/functional/switch_permissions_test.php @@ -0,0 +1,70 @@ + + * @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_switch_permissions_test extends phpbb_functional_test_case +{ + private const TEST_USER = 'switch-permissions-test'; + + protected function setUp(): void + { + parent::setUp(); + + $this->login(); + $this->admin_login(); + + $this->add_lang(['common', 'ucp']); + } + + public function test_switch_permissions() + { + $user_id = $this->create_user(self::TEST_USER); + + // Open user administration page for new user + $crawler = self::request('GET', "adm/index.php?i=users&mode=overview&u={$user_id}&sid={$this->sid}"); + + // Use permissions + $link = $crawler->selectLink($this->lang('USE_PERMISSIONS'))->link(); + $crawler = self::$client->click($link); + + // Check that we switched permissions to test user + $this->assertStringContainsString( + str_replace('
', '
', $this->lang('PERMISSIONS_TRANSFERRED', self::TEST_USER)), + $crawler->html(), + ); + + // Check that ACP pages get forced to acp main with restore permission info + $this->add_lang('acp/common'); + $crawler = self::request('GET', "adm/index.php?i=users&mode=overview&u={$user_id}&sid={$this->sid}"); + $this->assertStringContainsString( + $this->lang('PERMISSIONS_TRANSFERRED'), + $crawler->text(), + ); + + // Check that restore permissions link exists + $crawler = self::$client->request('GET', '../index.php?sid=' . $this->sid); + $this->assertStringContainsString( + $this->lang('RESTORE_PERMISSIONS'), + $crawler->text(), + ); + + // Check that restore permissions works + $crawler = self::$client->request('GET', 'ucp.php?mode=restore_perm&sid=' . $this->sid); + $this->assertStringContainsString( + $this->lang('PERMISSIONS_RESTORED'), + $crawler->text(), + ); + } +} From 13e6cd5992125624a343b4fcfb2df9dd95e49b3a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 14 Jul 2024 08:17:03 +0200 Subject: [PATCH 2/2] [ticket/14454] Remove extra commas PHPBB-14454 --- tests/functional/switch_permissions_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/functional/switch_permissions_test.php b/tests/functional/switch_permissions_test.php index d83d303f5d..a8c64422f3 100644 --- a/tests/functional/switch_permissions_test.php +++ b/tests/functional/switch_permissions_test.php @@ -42,7 +42,7 @@ class phpbb_functional_switch_permissions_test extends phpbb_functional_test_cas // Check that we switched permissions to test user $this->assertStringContainsString( str_replace('
', '
', $this->lang('PERMISSIONS_TRANSFERRED', self::TEST_USER)), - $crawler->html(), + $crawler->html() ); // Check that ACP pages get forced to acp main with restore permission info @@ -50,21 +50,21 @@ class phpbb_functional_switch_permissions_test extends phpbb_functional_test_cas $crawler = self::request('GET', "adm/index.php?i=users&mode=overview&u={$user_id}&sid={$this->sid}"); $this->assertStringContainsString( $this->lang('PERMISSIONS_TRANSFERRED'), - $crawler->text(), + $crawler->text() ); // Check that restore permissions link exists $crawler = self::$client->request('GET', '../index.php?sid=' . $this->sid); $this->assertStringContainsString( $this->lang('RESTORE_PERMISSIONS'), - $crawler->text(), + $crawler->text() ); // Check that restore permissions works $crawler = self::$client->request('GET', 'ucp.php?mode=restore_perm&sid=' . $this->sid); $this->assertStringContainsString( $this->lang('PERMISSIONS_RESTORED'), - $crawler->text(), + $crawler->text() ); } }