[terms] allow users to view wiki pages before accepting the terms that are written in the wiki
This commit is contained in:
parent
978d0d629b
commit
51a4e753e4
2 changed files with 26 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -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(''));
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue