Skip to content

Commit

Permalink
Move cookieconsent settings to generic settings (#3722)
Browse files Browse the repository at this point in the history
Removes the cookie consent settings from the "public" menu
to "settings" menu and make it site independent setting

This PR also remove the `@register_public_site_settings` as this the
last remain setting in the "public" menu in wagtail

Depends on #3721

---------

Co-authored-by: Fredrik Jonsson <[email protected]>
  • Loading branch information
theskumar and frjo authored Jan 29, 2024
1 parent 0eda946 commit 079e015
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 33 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"makefile.extensionOutputFolder": "./.vscode",
"cSpell.words": [
"Anymail",
"cookieconsent",
"coreutils",
"modelcluster",
"pagedown",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 4.2.9 on 2024-01-11 14:38

from django.db import migrations, models
import wagtail.fields


class Migration(migrations.Migration):
dependencies = [
("cookieconsent", "0001_initial"),
]

operations = [
migrations.RemoveField(
model_name="cookieconsentsettings",
name="site",
),
migrations.AlterField(
model_name="cookieconsentsettings",
name="cookieconsent_active",
field=models.BooleanField(
default=False, verbose_name="Activate cookie consent feature"
),
),
migrations.AlterField(
model_name="cookieconsentsettings",
name="cookieconsent_message",
field=wagtail.fields.RichTextField(
default='<p>This website deploys cookies for basic functionality and to keep it secure. These cookies are strictly necessary. Optional analysis cookies which provide us with statistical information about the use of the website may also be deployed, but only with your consent. Please review our <a href="/data-privacy-policy/">Privacy &amp; Data Policy</a> for more information.</p>',
verbose_name="cookie consent message",
),
),
migrations.AlterField(
model_name="cookieconsentsettings",
name="cookieconsent_title",
field=models.CharField(
default="Your cookie settings",
max_length=255,
verbose_name="cookie consent title",
),
),
]
14 changes: 6 additions & 8 deletions hypha/cookieconsent/models.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
from django.db import models
from wagtail.admin.panels import FieldPanel, MultiFieldPanel
from wagtail.contrib.settings.models import BaseSiteSetting
from wagtail.contrib.settings.models import BaseGenericSetting, register_setting
from wagtail.fields import RichTextField

from hypha.core.wagtail.admin.registry import register_public_site_setting


@register_public_site_setting
class CookieConsentSettings(BaseSiteSetting):
@register_setting
class CookieConsentSettings(BaseGenericSetting):
class Meta:
verbose_name = "Cookie consent settings"

cookieconsent_active = models.BooleanField(
"Activate cookie concent feature",
"Activate cookie consent feature",
default=False,
)

cookieconsent_title = models.CharField(
"cookie concent title",
"cookie consent title",
max_length=255,
default="Your cookie settings",
)

cookieconsent_message = RichTextField(
"cookie concent message",
"cookie consent message",
default='<p>This website deploys cookies for basic functionality and to keep it secure. These cookies are strictly necessary. Optional analysis cookies which provide us with statistical information about the use of the website may also be deployed, but only with your consent. Please review our <a href="/data-privacy-policy/">Privacy &amp; Data Policy</a> for more information.</p>',
)

Expand Down
13 changes: 5 additions & 8 deletions hypha/cookieconsent/templatetags/cookieconsent_tags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django import template
from wagtail.models import Site

from ..models import CookieConsentSettings

Expand All @@ -9,15 +8,13 @@
@register.inclusion_tag("includes/banner.html", takes_context=True)
def cookie_banner(context):
request = context["request"]
site = Site.find_for_request(request)
cookieconsent_settings = CookieConsentSettings.for_site(site=site)
show_banner = (
cookieconsent_settings.cookieconsent_active
and not request.COOKIES.get("cookieconsent")
settings = CookieConsentSettings.load(request_or_site=request)
show_banner = settings.cookieconsent_active and not request.COOKIES.get(
"cookieconsent"
)

return {
"show_banner": show_banner,
"title": cookieconsent_settings.cookieconsent_title,
"message": cookieconsent_settings.cookieconsent_message,
"title": settings.cookieconsent_title,
"message": settings.cookieconsent_message,
}
16 changes: 0 additions & 16 deletions hypha/core/wagtail_hooks.py

This file was deleted.

1 change: 1 addition & 0 deletions hypha/static_src/src/sass/apply/components/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@

&--cookieconsent {
@include button(transparent, $color--white);
display: inline;

&:focus,
&:hover {
Expand Down
2 changes: 1 addition & 1 deletion hypha/static_src/src/sass/apply/components/_wrapper.scss
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,6 @@

&--cookieconsent {
padding: 40px 20px;
z-index: 10;
z-index: 20;
}
}

0 comments on commit 079e015

Please sign in to comment.