Skip to content

Commit 69742fb

Browse files
committed
[#1405] Removed cms related booleans from siteconfiguration
1 parent 8f12f2c commit 69742fb

File tree

15 files changed

+93
-345
lines changed

15 files changed

+93
-345
lines changed

src/open_inwoner/accounts/views/actions.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
from django.views.generic.detail import SingleObjectMixin
1313
from django.views.generic.edit import DeletionMixin, UpdateView
1414

15+
from aldryn_apphooks_config.mixins import AppConfigMixin
16+
from aldryn_apphooks_config.utils import get_app_instance
17+
from cms.models import Page
1518
from privates.views import PrivateMediaView
1619
from view_breadcrumbs import BaseBreadcrumbMixin
1720

21+
from open_inwoner.cms.collaborate.cms_apps import CollaborateApphook
1822
from open_inwoner.components.utils import RenderableTag
19-
from open_inwoner.configurations.models import SiteConfiguration
2023
from open_inwoner.htmx.views import HtmxTemplateTagModelFormView
2124
from open_inwoner.utils.logentry import get_verbose_change_message
2225
from open_inwoner.utils.mixins import ExportMixin
@@ -26,11 +29,14 @@
2629
from ..models import Action
2730

2831

29-
class ActionsEnabledMixin:
32+
class ActionsEnabledMixin(AppConfigMixin):
3033
def dispatch(self, request, *args, **kwargs):
31-
config = SiteConfiguration.get_solo()
32-
if not config.show_actions:
34+
self.namespace, self.config = get_app_instance(request)
35+
request.current_app = self.namespace
36+
37+
if self.config and not self.config.actions:
3338
raise Http404("actions not enabled")
39+
3440
return super().dispatch(request, *args, **kwargs)
3541

3642

@@ -89,6 +95,12 @@ def get_context_data(self, **kwargs):
8995
context["page_obj"] = page
9096
context["is_paginated"] = is_paginated
9197
context["actions"] = queryset
98+
context["show_plans"] = (
99+
Page.objects.published()
100+
.filter(application_namespace=CollaborateApphook.app_name)
101+
.exists()
102+
)
103+
92104
return context
93105

94106

src/open_inwoner/components/templates/components/Header/Header.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,6 @@
144144
{% endrender_form %}
145145
</nav>
146146

147-
{% primary_navigation categories=categories request=request has_general_faq_questions=has_general_faq_questions show_plans=show_plans %}
147+
{% primary_navigation categories=categories request=request has_general_faq_questions=has_general_faq_questions %}
148148
</div>
149149
</header>

src/open_inwoner/configurations/admin.py

-5
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ class SiteConfigurarionAdmin(OrderedInlineModelAdminMixin, SingletonModelAdmin):
3939
"name",
4040
"login_show",
4141
"login_allow_registration",
42-
"show_cases",
43-
"show_product_finder",
44-
"show_plans",
45-
"show_actions",
4642
)
4743
},
4844
),
@@ -69,7 +65,6 @@ class SiteConfigurarionAdmin(OrderedInlineModelAdminMixin, SingletonModelAdmin):
6965
"footer_logo_url",
7066
"hero_image_login",
7167
"favicon",
72-
"plans_banner",
7368
)
7469
},
7570
),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Generated by Django 3.2.15 on 2023-05-03 12:17
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("configurations", "0039_alter_siteconfiguration_hero_image_login"),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name="siteconfiguration",
15+
name="plans_banner",
16+
),
17+
migrations.RemoveField(
18+
model_name="siteconfiguration",
19+
name="show_actions",
20+
),
21+
migrations.RemoveField(
22+
model_name="siteconfiguration",
23+
name="show_cases",
24+
),
25+
migrations.RemoveField(
26+
model_name="siteconfiguration",
27+
name="show_plans",
28+
),
29+
migrations.RemoveField(
30+
model_name="siteconfiguration",
31+
name="show_product_finder",
32+
),
33+
]

src/open_inwoner/configurations/models.py

-46
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,6 @@ class SiteConfiguration(SingletonModel):
196196
verbose_name=_("Edit goal message"),
197197
help_text=_("The message when a user edits a goal."),
198198
)
199-
plans_banner = FilerImageField(
200-
verbose_name=_("Plans banner"),
201-
null=True,
202-
blank=True,
203-
on_delete=models.SET_NULL,
204-
related_name="plans_banner",
205-
help_text=_("Banner of the plans"),
206-
)
207-
208199
footer_visiting_title = models.CharField(
209200
max_length=255,
210201
default="",
@@ -382,36 +373,6 @@ class SiteConfiguration(SingletonModel):
382373
"The xxxxx part is the ID."
383374
),
384375
)
385-
386-
show_cases = models.BooleanField(
387-
verbose_name=_("Show cases"),
388-
default=False,
389-
help_text=_(
390-
"By default the cases are not shown. If the OpenZaak integration is configured this needs to be set to True."
391-
),
392-
)
393-
show_product_finder = models.BooleanField(
394-
verbose_name=_("Laat productzoeker zien op de homepagina."),
395-
blank=True,
396-
default=False,
397-
help_text=_(
398-
"Als dit is aangevinkt en er zijn product condities gemaakt, dan wordt op de homepagina de productzoeker weergegeven."
399-
),
400-
)
401-
show_plans = models.BooleanField(
402-
verbose_name=_("Laat samenwerken zien op de homepage en menu"),
403-
default=True,
404-
help_text=_(
405-
"Als dit is aangevinkt, dan wordt op de homepagina en het gebruikers profiel de samenwerken feature weergegeven."
406-
),
407-
)
408-
show_actions = models.BooleanField(
409-
verbose_name=_("Laat acties zien op de profiel pagina"),
410-
default=True,
411-
help_text=_(
412-
"Als dit is aangevinkt, dan worded op de gebruikers profiel pagina de acties weergegeven."
413-
),
414-
)
415376
openid_connect_logo = FilerImageField(
416377
verbose_name=_("Openid Connect Logo"),
417378
null=True,
@@ -435,13 +396,6 @@ class Meta:
435396
def __str__(self):
436397
return str(_("Site Configuration"))
437398

438-
def clean(self):
439-
super().clean()
440-
441-
if self.show_plans and not self.show_actions:
442-
msg = _("Als Samenwerken actief is moeten Acties ook actief zijn")
443-
raise ValidationError({"show_actions": msg, "show_plans": msg})
444-
445399
@property
446400
def get_primary_color(self):
447401
return hex_to_hsl(self.primary_color)

src/open_inwoner/configurations/tests/test_show_actions.py

+11-44
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from django.core.exceptions import ValidationError
21
from django.test import override_settings
32
from django.urls import reverse
43

@@ -8,71 +7,39 @@
87
from open_inwoner.accounts.tests.factories import ActionFactory, UserFactory
98
from open_inwoner.cms.profile.cms_appconfig import ProfileConfig
109

11-
from ..models import SiteConfiguration
12-
1310

1411
@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls")
1512
class TestShowActions(WebTest):
1613
def setUp(self):
1714
self.user = UserFactory()
18-
self.config = SiteConfiguration.get_solo()
19-
2015
self.action = ActionFactory(created_by=self.user)
21-
2216
self.profile_url = reverse("profile:detail")
2317
self.actions_list_url = reverse("profile:action_list")
2418

25-
def test_default_enabled(self):
26-
self.assertTrue(self.config.show_actions)
27-
28-
def test_show_plans_requires_show_actions(self):
29-
config = SiteConfiguration.get_solo()
30-
31-
# fine
32-
config.show_plans = False
33-
config.show_actions = False
34-
config.clean()
35-
36-
# fine
37-
config.show_plans = True
38-
config.show_actions = True
39-
config.clean()
40-
41-
# fine
42-
config.show_plans = False
43-
config.show_actions = True
44-
config.clean()
45-
46-
# not fine
47-
config.show_plans = True
48-
config.show_actions = False
49-
with self.assertRaises(ValidationError) as e:
50-
config.clean()
51-
52-
self.assertEqual(
53-
set(e.exception.error_dict.keys()), {"show_actions", "show_plans"}
54-
)
55-
56-
def test_when_enabled_and_user_is_logged_in(self):
5719
# cms profile apphook configuration
58-
profile_app = ProfileConfig.objects.create(namespace="profile")
20+
self.profile_config = ProfileConfig.objects.create(namespace="profile")
5921
api.create_page(
6022
"profile",
6123
"INHERIT",
6224
"nl",
6325
published=True,
6426
apphook="ProfileApphook",
65-
apphook_namespace=profile_app.namespace,
27+
apphook_namespace=self.profile_config.namespace,
6628
)
29+
30+
def test_default_enabled(self):
31+
self.assertTrue(self.profile_config.actions)
32+
33+
def test_when_enabled_and_user_is_logged_in(self):
6734
response = self.app.get(self.profile_url, user=self.user)
6835

6936
links = response.pyquery(".personal-overview")
7037
self.assertNotEqual(links.find(".personal-overview__actions"), [])
7138
self.assertNotEqual(links.find(f'a[href="{self.actions_list_url}"]'), [])
7239

7340
def test_when_disabled_and_user_is_logged_in(self):
74-
self.config.show_actions = False
75-
self.config.save()
41+
self.profile_config.actions = False
42+
self.profile_config.save()
7643
response = self.app.get(self.profile_url, user=self.user)
7744

7845
links = response.pyquery(".personal-overview")
@@ -92,8 +59,8 @@ def test_action_pages_show_404_when_disabled(self):
9259
]
9360

9461
# test disabled raises http 404
95-
self.config.show_actions = False
96-
self.config.save()
62+
self.profile_config.actions = False
63+
self.profile_config.save()
9764

9865
for url in urls:
9966
with self.subTest(f"{url}"):

src/open_inwoner/configurations/tests/test_show_cases.py

-68
This file was deleted.

0 commit comments

Comments
 (0)