[terms] allow users to view wiki pages before accepting the terms that are written in the wiki

This commit is contained in:
Shish 2024-06-07 15:10:37 +01:00 committed by Shish
parent 978d0d629b
commit 51a4e753e4
2 changed files with 26 additions and 2 deletions

View file

@ -29,8 +29,15 @@ class Terms extends Extension
$page->set_mode(PageMode::REDIRECT); $page->set_mode(PageMode::REDIRECT);
$page->set_redirect(make_link(explode('/', $event->path, 2)[1])); $page->set_redirect(make_link(explode('/', $event->path, 2)[1]));
} else { } else {
// run on all pages unless logged in or cookie exists // run on all pages unless any of:
if ($user->is_anonymous() && !isset($_COOKIE[$config->get_string('cookie_prefix', 'shm') . '_' . 'accepted_terms'])) { // - 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); $sitename = $config->get_string(SetupConfig::TITLE);
$body = format_text($config->get_string("terms_message")); $body = format_text($config->get_string("terms_message"));
$this->theme->display_page($page, $sitename, $event->path, $body); $this->theme->display_page($page, $sitename, $event->path, $body);

View file

@ -24,4 +24,21 @@ class TermsTest extends ShimmiePHPUnitTestCase
$this->request('GET', 'post/list', cookies: ['shm_accepted_terms' => 'true']); $this->request('GET', 'post/list', cookies: ['shm_accepted_terms' => 'true']);
$this->assert_no_text("terms-modal-enter"); $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(''));
}
} }