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

[#911] Added configuration options and logic to hide unused functionality #371

Merged
merged 4 commits into from
Dec 12, 2022
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
8 changes: 7 additions & 1 deletion src/open_inwoner/accounts/tests/test_profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from open_inwoner.accounts.choices import StatusChoices
from open_inwoner.pdc.tests.factories import CategoryFactory

from ...questionnaire.tests.factories import QuestionnaireStepFactory
from ..choices import LoginTypeChoices
from .factories import ActionFactory, DocumentFactory, UserFactory

Expand All @@ -30,17 +31,21 @@ def test_login_required(self):

def test_get_empty_profile_page(self):
response = self.app.get(self.url, user=self.user)

self.assertEquals(response.status_code, 200)
self.assertContains(response, _("U heeft geen intressegebieden aangegeven."))
self.assertContains(response, _("U heeft nog geen contacten."))
self.assertContains(response, "0 acties staan open.")
self.assertNotContains(response, reverse("questionnaire:questionnaire_list"))

def test_get_filled_profile_page(self):
action = ActionFactory(created_by=self.user)
ActionFactory(created_by=self.user)
contact = UserFactory()
self.user.user_contacts.add(contact)
category = CategoryFactory()
self.user.selected_themes.add(category)
QuestionnaireStepFactory(published=True)

response = self.app.get(self.url, user=self.user)
self.assertEquals(response.status_code, 200)
self.assertContains(response, category.name)
Expand All @@ -49,6 +54,7 @@ def test_get_filled_profile_page(self):
f"{contact.first_name} ({contact.get_contact_type_display()})",
)
self.assertContains(response, "1 acties staan open.")
self.assertContains(response, reverse("questionnaire:questionnaire_list"))

def test_only_open_actions(self):
action = ActionFactory(created_by=self.user, status=StatusChoices.closed)
Expand Down
48 changes: 39 additions & 9 deletions src/open_inwoner/accounts/views/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Q
from django.http.response import HttpResponseRedirect
from django.http.response import Http404, HttpResponseRedirect
from django.urls.base import reverse, reverse_lazy
from django.utils.functional import cached_property
from django.utils.translation import gettext as _
Expand All @@ -16,6 +16,7 @@
from view_breadcrumbs import BaseBreadcrumbMixin

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_change_message
from open_inwoner.utils.mixins import ExportMixin
Expand All @@ -25,6 +26,14 @@
from ..models import Action


class ActionsEnabledMixin:
def dispatch(self, request, *args, **kwargs):
config = SiteConfiguration.get_solo()
if not config.show_actions:
raise Http404("actions not enabled")
return super().dispatch(request, *args, **kwargs)


class BaseActionFilter:
"""
For when in the template the action tag is used. This will filter the actions correctly.
Expand All @@ -44,7 +53,11 @@ def get_actions(self, actions):


class ActionListView(
LoginRequiredMixin, BaseBreadcrumbMixin, BaseActionFilter, ListView
ActionsEnabledMixin,
LoginRequiredMixin,
BaseBreadcrumbMixin,
BaseActionFilter,
ListView,
):
template_name = "pages/profile/actions/list.html"
model = Action
Expand Down Expand Up @@ -78,7 +91,9 @@ def get_context_data(self, **kwargs):
return context


class ActionUpdateView(LogMixin, LoginRequiredMixin, BaseBreadcrumbMixin, UpdateView):
class ActionUpdateView(
ActionsEnabledMixin, LogMixin, LoginRequiredMixin, BaseBreadcrumbMixin, UpdateView
):
template_name = "pages/profile/actions/edit.html"
model = Action
slug_field = "uuid"
Expand Down Expand Up @@ -149,7 +164,12 @@ def form_valid(self, form):


class ActionDeleteView(
LogMixin, LoginRequiredMixin, DeletionMixin, SingleObjectMixin, View
ActionsEnabledMixin,
LogMixin,
LoginRequiredMixin,
DeletionMixin,
SingleObjectMixin,
View,
):
model = Action
slug_field = "uuid"
Expand Down Expand Up @@ -183,7 +203,9 @@ def on_delete_action(self, action):
)


class ActionCreateView(LogMixin, LoginRequiredMixin, BaseBreadcrumbMixin, CreateView):
class ActionCreateView(
ActionsEnabledMixin, LogMixin, LoginRequiredMixin, BaseBreadcrumbMixin, CreateView
):
template_name = "pages/profile/actions/edit.html"
model = Action
form_class = ActionForm
Expand Down Expand Up @@ -212,7 +234,9 @@ def form_valid(self, form):
return HttpResponseRedirect(self.get_success_url())


class ActionListExportView(LogMixin, LoginRequiredMixin, ExportMixin, ListView):
class ActionListExportView(
ActionsEnabledMixin, LogMixin, LoginRequiredMixin, ExportMixin, ListView
):
template_name = "export/profile/action_list_export.html"
model = Action

Expand All @@ -228,7 +252,9 @@ def get_queryset(self):
)


class ActionExportView(LogMixin, LoginRequiredMixin, ExportMixin, DetailView):
class ActionExportView(
ActionsEnabledMixin, LogMixin, LoginRequiredMixin, ExportMixin, DetailView
):
template_name = "export/profile/action_export.html"
model = Action
slug_field = "uuid"
Expand All @@ -241,7 +267,9 @@ def get_queryset(self):
)


class ActionPrivateMediaView(LogMixin, LoginRequiredMixin, PrivateMediaView):
class ActionPrivateMediaView(
ActionsEnabledMixin, LogMixin, LoginRequiredMixin, PrivateMediaView
):
model = Action
slug_field = "uuid"
slug_url_kwarg = "uuid"
Expand All @@ -262,7 +290,9 @@ def has_permission(self):
return False


class ActionHistoryView(LoginRequiredMixin, BaseBreadcrumbMixin, DetailView):
class ActionHistoryView(
ActionsEnabledMixin, LoginRequiredMixin, BaseBreadcrumbMixin, DetailView
):
template_name = "pages/history.html"
model = Action
slug_field = "uuid"
Expand Down
6 changes: 5 additions & 1 deletion src/open_inwoner/accounts/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ def get_context_data(self, **kwargs):
] = f"{', '.join(contact_names)}{'...' if contacts.count() > 3 else ''}"
else:
context["contact_text"] = _("U heeft nog geen contacten.")
context["questionnaire_exists"] = QuestionnaireStep.objects.exists()

context["questionnaire_exists"] = QuestionnaireStep.objects.filter(
published=True
).exists()
context["can_change_password"] = user.login_type != LoginTypeChoices.digid

return context

def post(self, request, *args, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
<div class="actions__label">
<div class="table__explain">{% trans "Onderdeel van" %}</div>
{% if action.plan %}
{% link href=action.plan.get_absolute_url text=action.plan.title %}
{% if show_plans %}
{% link href=action.plan.get_absolute_url text=action.plan.title %}
{% else %}
{{ action.plan.title }}
{% endif %}
{% else %}
-
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{% endrender_form %}
</nav>

{% primary_navigation categories=categories request=request has_general_faq_questions=has_general_faq_questions %}
{% primary_navigation categories=categories request=request has_general_faq_questions=has_general_faq_questions show_plans=config.show_plans %}
</div>
</div>

Expand Down Expand Up @@ -78,6 +78,6 @@
{% endrender_form %}
</nav>

{% primary_navigation categories=categories request=request has_general_faq_questions=has_general_faq_questions %}
{% primary_navigation categories=categories request=request has_general_faq_questions=has_general_faq_questions show_plans=config.show_plans %}
</div>
</header>
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
{% link text=_('Mijn aanvragen') href='accounts:my_open_cases' icon="inventory_2" icon_position="before" icon_outlined=True %}
</li>
{% endif %}
{% if show_plans %}
<li class="primary-navigation__list-item">
{% link text=_('Samenwerken') href='plans:plan_list' icon="people" icon_outlined=True icon_position="before" %}
</li>
{% endif %}
{% endif %}
{% if has_general_faq_questions %}
<li class="primary-navigation__list-item">
Expand Down
8 changes: 7 additions & 1 deletion src/open_inwoner/components/templatetags/action_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ def actions(actions, request, action_form, **kwargs):
+ action_form: Form | The form containing the needed filters for the actions.
- form_action: string | A url for something
- plan: Plan | The plan that the actions belong to.
- show_plans: bool | If plan functionality is enabled
"""
kwargs.update(actions=actions, request=request, action_form=action_form)
kwargs.update(
actions=actions,
request=request,
action_form=action_form,
show_plans=kwargs.get("show_plans", True),
)
return kwargs


Expand Down
1 change: 1 addition & 0 deletions src/open_inwoner/components/templatetags/header_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def primary_navigation(categories, request, **kwargs):
+ request: Request | The django request object.
+ questionnaire: QuestionnaireStep | The default QuestionnaireStep, if any.
- has_general_faq_questions: boolean | If the FAQ menu item should be shown.
- show_plans: boolean | If the Plan item should be shown.
"""

return {
Expand Down
2 changes: 2 additions & 0 deletions src/open_inwoner/configurations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class SiteConfigurarionAdmin(OrderedInlineModelAdminMixin, SingletonModelAdmin):
"login_allow_registration",
"show_cases",
"show_product_finder",
"show_plans",
"show_actions",
)
},
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.15 on 2022-12-06 10:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("configurations", "0026_alter_siteconfiguration_select_questionnaire_intro"),
]

operations = [
migrations.AddField(
model_name="siteconfiguration",
name="show_plans",
field=models.BooleanField(
default=True,
help_text="Als dit is aangevinkt, dan wordt op de homepagina en het gebruikers profiel de samenwerken feature weergegeven.",
verbose_name="Laat samenwerken zien op de homepage en menu",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.15 on 2022-12-06 12:34

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("configurations", "0027_siteconfiguration_show_plans"),
]

operations = [
migrations.AddField(
model_name="siteconfiguration",
name="show_actions",
field=models.BooleanField(
default=True,
help_text="Als dit is aangevinkt, dan worded op de gebruikers profiel pagina de acties weergegeven.",
verbose_name="Laat acties zien op de profiel pagina",
),
),
]
22 changes: 22 additions & 0 deletions src/open_inwoner/configurations/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.flatpages.models import FlatPage
from django.core.exceptions import ValidationError
from django.db import models
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
Expand Down Expand Up @@ -331,6 +332,20 @@ class SiteConfiguration(SingletonModel):
"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 @@ -354,6 +369,13 @@ class Meta:
def __str__(self):
return str(_("Site Configuration"))

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

if self.show_plans and not self.show_actions:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Netjes opgelost :)

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 self.hex_to_hsl(self.primary_color)
Expand Down
Loading