Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1405] Cleanup 'show_xyz' booleans from siteconfiguration #609

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/open_inwoner/accounts/views/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
from django.views.generic.detail import SingleObjectMixin
from django.views.generic.edit import DeletionMixin, UpdateView

from aldryn_apphooks_config.mixins import AppConfigMixin
from aldryn_apphooks_config.utils import get_app_instance
from cms.models import Page
from privates.views import PrivateMediaView
from view_breadcrumbs import BaseBreadcrumbMixin

from open_inwoner.cms.collaborate.cms_apps import CollaborateApphook
from open_inwoner.components.utils import RenderableTag
from open_inwoner.configurations.models import SiteConfiguration
from open_inwoner.htmx.views import HtmxTemplateTagModelFormView
from open_inwoner.utils.logentry import get_verbose_change_message
from open_inwoner.utils.mixins import ExportMixin
Expand All @@ -26,11 +29,14 @@
from ..models import Action


class ActionsEnabledMixin:
class ActionsEnabledMixin(AppConfigMixin):
def dispatch(self, request, *args, **kwargs):
config = SiteConfiguration.get_solo()
if not config.show_actions:
self.namespace, self.config = get_app_instance(request)
request.current_app = self.namespace

if self.config and not self.config.actions:
raise Http404("actions not enabled")

return super().dispatch(request, *args, **kwargs)


Expand Down Expand Up @@ -89,6 +95,12 @@ def get_context_data(self, **kwargs):
context["page_obj"] = page
context["is_paginated"] = is_paginated
context["actions"] = queryset
context["show_plans"] = (
Page.objects.published()
.filter(application_namespace=CollaborateApphook.app_name)
.exists()
)

return context


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@
{% endrender_form %}
</nav>

{% primary_navigation categories=categories request=request has_general_faq_questions=has_general_faq_questions show_plans=show_plans %}
{% primary_navigation categories=categories request=request has_general_faq_questions=has_general_faq_questions %}
</div>
</header>
5 changes: 0 additions & 5 deletions src/open_inwoner/configurations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ class SiteConfigurarionAdmin(OrderedInlineModelAdminMixin, SingletonModelAdmin):
"name",
"login_show",
"login_allow_registration",
"show_cases",
"show_product_finder",
"show_plans",
"show_actions",
)
},
),
Expand All @@ -69,7 +65,6 @@ class SiteConfigurarionAdmin(OrderedInlineModelAdminMixin, SingletonModelAdmin):
"footer_logo_url",
"hero_image_login",
"favicon",
"plans_banner",
)
},
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.2.15 on 2023-05-03 12:17

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("configurations", "0039_alter_siteconfiguration_hero_image_login"),
]

operations = [
migrations.RemoveField(
model_name="siteconfiguration",
name="plans_banner",
),
migrations.RemoveField(
model_name="siteconfiguration",
name="show_actions",
),
migrations.RemoveField(
model_name="siteconfiguration",
name="show_cases",
),
migrations.RemoveField(
model_name="siteconfiguration",
name="show_plans",
),
migrations.RemoveField(
model_name="siteconfiguration",
name="show_product_finder",
),
]
46 changes: 0 additions & 46 deletions src/open_inwoner/configurations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,6 @@ class SiteConfiguration(SingletonModel):
verbose_name=_("Edit goal message"),
help_text=_("The message when a user edits a goal."),
)
plans_banner = FilerImageField(
verbose_name=_("Plans banner"),
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="plans_banner",
help_text=_("Banner of the plans"),
)

footer_visiting_title = models.CharField(
max_length=255,
default="",
Expand Down Expand Up @@ -382,36 +373,6 @@ class SiteConfiguration(SingletonModel):
"The xxxxx part is the ID."
),
)

show_cases = models.BooleanField(
verbose_name=_("Show cases"),
default=False,
help_text=_(
"By default the cases are not shown. If the OpenZaak integration is configured this needs to be set to True."
),
)
show_product_finder = models.BooleanField(
verbose_name=_("Laat productzoeker zien op de homepagina."),
blank=True,
default=False,
help_text=_(
"Als dit is aangevinkt en er zijn product condities gemaakt, dan wordt op de homepagina de productzoeker weergegeven."
),
)
show_plans = models.BooleanField(
verbose_name=_("Laat samenwerken zien op de homepage en menu"),
default=True,
help_text=_(
"Als dit is aangevinkt, dan wordt op de homepagina en het gebruikers profiel de samenwerken feature weergegeven."
),
)
show_actions = models.BooleanField(
verbose_name=_("Laat acties zien op de profiel pagina"),
default=True,
help_text=_(
"Als dit is aangevinkt, dan worded op de gebruikers profiel pagina de acties weergegeven."
),
)
openid_connect_logo = FilerImageField(
verbose_name=_("Openid Connect Logo"),
null=True,
Expand All @@ -435,13 +396,6 @@ class Meta:
def __str__(self):
return str(_("Site Configuration"))

def clean(self):
super().clean()

if self.show_plans and not self.show_actions:
msg = _("Als Samenwerken actief is moeten Acties ook actief zijn")
raise ValidationError({"show_actions": msg, "show_plans": msg})

@property
def get_primary_color(self):
return hex_to_hsl(self.primary_color)
Expand Down
55 changes: 11 additions & 44 deletions src/open_inwoner/configurations/tests/test_show_actions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from django.core.exceptions import ValidationError
from django.test import override_settings
from django.urls import reverse

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

from ..models import SiteConfiguration


@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls")
class TestShowActions(WebTest):
def setUp(self):
self.user = UserFactory()
self.config = SiteConfiguration.get_solo()

self.action = ActionFactory(created_by=self.user)

self.profile_url = reverse("profile:detail")
self.actions_list_url = reverse("profile:action_list")

def test_default_enabled(self):
self.assertTrue(self.config.show_actions)

def test_show_plans_requires_show_actions(self):
config = SiteConfiguration.get_solo()

# fine
config.show_plans = False
config.show_actions = False
config.clean()

# fine
config.show_plans = True
config.show_actions = True
config.clean()

# fine
config.show_plans = False
config.show_actions = True
config.clean()

# not fine
config.show_plans = True
config.show_actions = False
with self.assertRaises(ValidationError) as e:
config.clean()

self.assertEqual(
set(e.exception.error_dict.keys()), {"show_actions", "show_plans"}
)

def test_when_enabled_and_user_is_logged_in(self):
# cms profile apphook configuration
profile_app = ProfileConfig.objects.create(namespace="profile")
self.profile_config = ProfileConfig.objects.create(namespace="profile")
api.create_page(
"profile",
"INHERIT",
"nl",
published=True,
apphook="ProfileApphook",
apphook_namespace=profile_app.namespace,
apphook_namespace=self.profile_config.namespace,
)

def test_default_enabled(self):
self.assertTrue(self.profile_config.actions)

def test_when_enabled_and_user_is_logged_in(self):
response = self.app.get(self.profile_url, user=self.user)

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

def test_when_disabled_and_user_is_logged_in(self):
self.config.show_actions = False
self.config.save()
self.profile_config.actions = False
self.profile_config.save()
response = self.app.get(self.profile_url, user=self.user)

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

# test disabled raises http 404
self.config.show_actions = False
self.config.save()
self.profile_config.actions = False
self.profile_config.save()

for url in urls:
with self.subTest(f"{url}"):
Expand Down
68 changes: 0 additions & 68 deletions src/open_inwoner/configurations/tests/test_show_cases.py

This file was deleted.

Loading