Skip to content

Commit

Permalink
Merge pull request #30 from bouvet-apps/release/1.1.0
Browse files Browse the repository at this point in the history
Release/1.1.0
  • Loading branch information
Roeland-Bouvet authored Jun 28, 2024
2 parents f572ab1 + 6536f01 commit f91acd9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 124 deletions.
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,6 @@ other apps that they now can render their content.
## Customizing
You can add CSS styling in your own applications to make the panels fit any design you want.

## Controlling
You can control various aspects of Cookie Panel in the frontend.
These are dependent on the panel code being included in the render. There is only 3 ways to include the code for the panel in the render:
- `no.bouvet.app.cookiepanel-cookie-control` cookie is not set to `true`(means the user has not made a choice in the panel)
- Add `cookie_settings=true` as param to URL
- The header `X-Cookiepanel` with value `include` is added to the response object by your app code.
```
return {
body,
headers: { "x-cookiepanel": "include" }
};
```

### Open settings panel from a link or button
There are 2 ways to add buttons that directly open the cookie settings panel.

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ group = no.bouvet
projectName = app-cookie-panel
vendorName = Bouvet
vendorUrl = https://www.bouvet.no
version = 1.0.1
version = 1.1.0
xpVersion = 7.9.0
41 changes: 0 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"eslint-plugin-jest": "27.6.0",
"eslint-plugin-jsx-a11y": "6.8.0",
"eslint-plugin-react": "7.33.2",
"fibers": "5.0.3",
"npm-run-all": "4.1.5",
"replace": "1.2.2"
},
Expand Down
39 changes: 12 additions & 27 deletions src/frontend/scripts/cookie-panel.es6
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,6 @@
document.cookie = `${name}=${value || ""}; Expires=${date.toUTCString()}; Max-Age=${365 * 24 * 60 * 60}; Path=/`;
};

// -- Temporary fix for broken cookie handling in XP
const deleteCookie = (name) => {
const pathname = window.location.pathname;
const path = pathname.substring(0, pathname.lastIndexOf("/"));
const cookie = `${name}=""; Expires=${new Date(0).toUTCString()}; Path=${path}`;
document.cookie = cookie;
};

const resetCookiePaths = () => {
forceArray(config.categories).forEach((category) => {
forceArray(category.cookies).forEach((cookie) => {
const value = getCookieValue(cookie["cookie-name"]);
deleteCookie(cookie["cookie-name"]);
setCookie(cookie["cookie-name"], value);
});
});
};
// -- END OF Temporary fix for broken cookie handling in XP

const reloadOnSave = (forceReload) => {
if (config.page.reloadOnSave || forceReload) {
if (/[?&]cookie_settings=/.test(document.location.search)) {
Expand Down Expand Up @@ -192,18 +173,21 @@

// ---
const renderBanner = () => {
// Only show the reject all button if the label has been set
const rejectLabelHtml = config.rejectLabel ? `<button id="cookie-panel-banner-reject-button">${config.rejectLabel}</button>` : "";

const html = `<div class="cookie-panel-banner ${config.theme}" id="cookie-panel-banner">
<div class="cookie-panel-banner__inner">
${config.title ? `<h2 class="cookie-panel-banner__title">${config.title}</h2>` : ""}
${config.description ? `<p class="cookie-panel-banner__description">${config.description}</p>` : ""}
<div class="cookie-panel-banner__buttons">
${config.buttonOrder === "accept-left"
? `<button id="cookie-panel-banner-accept-button">${config.acceptLabel}</button>
<button id="cookie-panel-banner-reject-button">${config.rejectLabel}</button>
${rejectLabelHtml}
<button id="cookie-panel-banner-settings-button">${config.settingsLabel}</button>`
: `<button id="cookie-panel-banner-settings-button">${config.settingsLabel}</button>
<button id="cookie-panel-banner-accept-button">${config.acceptLabel}</button>
<button id="cookie-panel-banner-reject-button">${config.rejectLabel}</button>`}
${rejectLabelHtml}`}
</div>
</div>
</div>`;
Expand All @@ -223,10 +207,12 @@
showCookiePanelSettings();
});

document.getElementById("cookie-panel-banner-reject-button").addEventListener("click", () => {
document.getElementById("cookie-panel-banner").style.display = "none";
rejectAllCookies();
});
if (config.rejectLabel) {
document.getElementById("cookie-panel-banner-reject-button").addEventListener("click", () => {
document.getElementById("cookie-panel-banner").style.display = "none";
rejectAllCookies();
});
}

return banner;
};
Expand All @@ -248,8 +234,7 @@
config = getData("config");
config.page = getData("page-config");

if (!config.accepted) {
resetCookiePaths(); // -- Temporary fix for broken cookie handling in XP
if (getCookieValue(config.controlCookie) !== "true") {
bannerContainer = renderBanner();
}

Expand Down
41 changes: 0 additions & 41 deletions src/main/resources/site/processors/cookie-panel.es6
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,6 @@ const libs = {
util: require("/lib/util")
};

const HEADER_NAME = "X-Cookiepanel";
const HEADER_VALUE_INCLUDE = "include";

/**
* Set up cookies with rejected values
* @param categories Cookie categories
* @param res Response object
*/
const getRejectedCookies = (categories, res) => {
const cookies = res.cookies || {};
libs.util.forceArray(categories).forEach((category) => {
libs.util.forceArray(category.cookies).forEach((cookie) => {
cookies[cookie["cookie-name"]] = {
value: cookie["cookie-value-rejected"],
path: "/",
secure: false,
httpOnly: false,
maxAge: 31556926
};
});
});
return cookies;
};

/**
* Render JSON page contribution
* @param model Model to render
Expand All @@ -41,21 +17,13 @@ exports.responseProcessor = (req, res) => {
return res;
}

if (req.cookies[controlCookieName] === "true"
&& !req.params.cookie_settings
&& !(res.headers[HEADER_NAME] === HEADER_VALUE_INCLUDE || res.headers[HEADER_NAME.toLowerCase()] === HEADER_VALUE_INCLUDE)) {
return res;
}

const siteConfig = libs.portal.getSiteConfig();
const categories = libs.util.getCookieCategories(siteConfig);

const model = {
controlCookie: controlCookieName,
url: libs.portal.serviceUrl({ service: "cookie-info" }),
showSettings: req.params.cookie_settings === "true",
// passive: res.headers[HEADER_NAME] === HEADER_VALUE_INCLUDE,
accepted: req.cookies[controlCookieName] === "true",
theme: siteConfig["cookie-panel-theme"] === "none" ? "" : `theme ${siteConfig["cookie-panel-theme"]}`,
buttonOrder: siteConfig["cookie-panel-button-order"],
title: siteConfig["cookie-panel-text-title"],
Expand All @@ -82,14 +50,5 @@ exports.responseProcessor = (req, res) => {
const html = render(model);
res.pageContributions.bodyEnd.push(html);

// If no control cookie is set, reject all cookies by default to achieve opt-in functionality
if (!req.cookies[controlCookieName]) {
res.cookies = getRejectedCookies(siteConfig["cookie-panel-categories"], res);
}

// if (!res.headers) res.headers = {};
// res.headers["Set-Cookie"] = "test=hei; Path=/; Max-Age=31556926";

// log.info(JSON.stringify(res, null, 4));
return res;
};

0 comments on commit f91acd9

Please sign in to comment.