-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #732 from maykinmedia/feature/1657-optional-produc…
…ts-and-search [#1657] add options to hide categories and search from anonymous users
- Loading branch information
Showing
15 changed files
with
382 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from django.test import TestCase | ||
|
||
from pyquery import PyQuery | ||
|
||
from open_inwoner.accounts.tests.factories import UserFactory | ||
from open_inwoner.cms.products.cms_apps import ProductsApphook | ||
from open_inwoner.cms.tests import cms_tools | ||
from open_inwoner.cms.tests.cms_tools import create_apphook_page | ||
from open_inwoner.configurations.models import SiteConfiguration | ||
from open_inwoner.pdc.tests.factories import CategoryFactory | ||
|
||
|
||
class HeaderTest(TestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
cls.user = UserFactory() | ||
cls.user.set_password("12345") | ||
cls.user.email = "[email protected]" | ||
cls.user.save() | ||
|
||
cms_tools.create_homepage() | ||
|
||
# PrimaryNavigation.html requires apphook + categories | ||
create_apphook_page(ProductsApphook) | ||
cls.published1 = CategoryFactory( | ||
path="0001", name="First one", slug="first-one" | ||
) | ||
cls.published2 = CategoryFactory( | ||
path="0002", name="Second one", slug="second-one" | ||
) | ||
|
||
def test_categories_hidden_from_anonymous_users(self): | ||
config = SiteConfiguration.get_solo() | ||
config.hide_categories_from_anonymous_users = True | ||
config.save() | ||
|
||
response = self.client.get("/") | ||
|
||
doc = PyQuery(response.content) | ||
|
||
categories = doc.find("[title='Onderwerpen']") | ||
self.assertEqual(len(categories), 0) | ||
|
||
def test_categories_not_hidden_from_anonymous_users(self): | ||
config = SiteConfiguration.get_solo() | ||
config.hide_categories_from_anonymous_users = False | ||
config.save() | ||
|
||
response = self.client.get("/") | ||
|
||
doc = PyQuery(response.content) | ||
|
||
categories = doc.find("[title='Onderwerpen']") | ||
self.assertEqual(len(categories), 2) | ||
self.assertEqual(categories[0].tag, "a") | ||
self.assertEqual(categories[1].tag, "button") | ||
|
||
def test_search_bar_hidden_from_anonymous_users(self): | ||
config = SiteConfiguration.get_solo() | ||
config.hide_search_from_anonymous_users = True | ||
config.save() | ||
|
||
response = self.client.get("/") | ||
|
||
doc = PyQuery(response.content) | ||
|
||
search_buttons = doc.find("[title='Zoeken']") | ||
|
||
self.assertEqual(len(search_buttons), 0) | ||
|
||
def test_search_bar_not_hidden_from_anonymous_users(self): | ||
config = SiteConfiguration.get_solo() | ||
config.hide_search_from_anonymous_users = False | ||
config.save() | ||
|
||
response = self.client.get("/") | ||
|
||
doc = PyQuery(response.content) | ||
|
||
search_buttons = doc.find("[title='Zoeken']") | ||
|
||
for button in search_buttons: | ||
self.assertEqual(button.tag, "button") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
.../configurations/migrations/0047_siteconfiguration_hide_categories_from_anonymous_users.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 3.2.15 on 2023-08-15 12:53 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("configurations", "0046_siteconfiguration_cookie_consent"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="siteconfiguration", | ||
name="hide_categories_from_anonymous_users", | ||
field=models.BooleanField( | ||
default=False, | ||
help_text="If checked, categories will be hidden from users who are not logged in.", | ||
verbose_name="Hide categories from anonymous users", | ||
), | ||
), | ||
] |
25 changes: 25 additions & 0 deletions
25
src/open_inwoner/configurations/migrations/0048_auto_20230816_1255.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 3.2.20 on 2023-08-16 10:55 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
( | ||
"configurations", | ||
"0047_siteconfiguration_hide_categories_from_anonymous_users", | ||
), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="siteconfiguration", | ||
name="hide_search_from_anonymous_users", | ||
field=models.BooleanField( | ||
default=False, | ||
help_text="If checked, only authenticated users will be able to search the page.", | ||
verbose_name="Hide search from anonymous users", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.