From 51a4e753e4e207e5b0a09fa3d6c7217513ab71ae Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 7 Jun 2024 15:10:37 +0100 Subject: [PATCH] [terms] allow users to view wiki pages before accepting the terms that are written in the wiki --- ext/terms/main.php | 11 +++++++++-- ext/terms/test.php | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ext/terms/main.php b/ext/terms/main.php index 14c30bfc..7ce0959a 100644 --- a/ext/terms/main.php +++ b/ext/terms/main.php @@ -29,8 +29,15 @@ class Terms extends Extension $page->set_mode(PageMode::REDIRECT); $page->set_redirect(make_link(explode('/', $event->path, 2)[1])); } else { - // run on all pages unless logged in or cookie exists - if ($user->is_anonymous() && !isset($_COOKIE[$config->get_string('cookie_prefix', 'shm') . '_' . 'accepted_terms'])) { + // run on all pages unless any of: + // - user is logged in + // - cookie exists + // - user is viewing the wiki (because that's where the privacy policy / TOS / etc are) + if ( + $user->is_anonymous() + && !$page->get_cookie('accepted_terms') + && !$event->page_starts_with("wiki") + ) { $sitename = $config->get_string(SetupConfig::TITLE); $body = format_text($config->get_string("terms_message")); $this->theme->display_page($page, $sitename, $event->path, $body); diff --git a/ext/terms/test.php b/ext/terms/test.php index 3b23743e..fd0f01b3 100644 --- a/ext/terms/test.php +++ b/ext/terms/test.php @@ -24,4 +24,21 @@ class TermsTest extends ShimmiePHPUnitTestCase $this->request('GET', 'post/list', cookies: ['shm_accepted_terms' => 'true']); $this->assert_no_text("terms-modal-enter"); } + + public function testWiki(): void + { + $this->request('GET', 'wiki/rules'); + $this->assert_no_text("terms-modal-enter"); + } + + public function testAcceptTerms(): void + { + $page = $this->request('POST', 'accept_terms/post/list'); + $this->assertEquals($page->mode, PageMode::REDIRECT); + $this->assertEquals($page->redirect, make_link('post/list')); + + $page = $this->request('POST', 'accept_terms/'); + $this->assertEquals($page->mode, PageMode::REDIRECT); + $this->assertEquals($page->redirect, make_link('')); + } }