Skip to content

Commit 5e2c993

Browse files
authored
Merge pull request #1 from JiscSD/UKDSB-687-Add-cookie-banner-to-CKAN
UKDSB-687 add cookie banner to ckan
2 parents d8c2da3 + 9844dec commit 5e2c993

File tree

21 files changed

+544
-2
lines changed

21 files changed

+544
-2
lines changed

.coveragerc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[report]
2+
omit =
3+
*/site-packages/*
4+
*/python?.?/*
5+
ckan/*

.github/workflows/test.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Tests
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
container:
7+
# The CKAN version tag of the Solr and Postgres containers should match
8+
# the one of the container the tests run on.
9+
# You can switch this base image with a custom image tailored to your project
10+
image: ckan/ckan-dev:2.11
11+
options: --user root
12+
services:
13+
solr:
14+
image: ckan/ckan-solr:2.11-solr9
15+
postgres:
16+
image: ckan/ckan-postgres-dev:2.11
17+
env:
18+
POSTGRES_USER: postgres
19+
POSTGRES_PASSWORD: postgres
20+
POSTGRES_DB: postgres
21+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
22+
redis:
23+
image: redis:3
24+
25+
env:
26+
CKAN_SQLALCHEMY_URL: postgresql://ckan_default:pass@postgres/ckan_test
27+
CKAN_DATASTORE_WRITE_URL: postgresql://datastore_write:pass@postgres/datastore_test
28+
CKAN_DATASTORE_READ_URL: postgresql://datastore_read:pass@postgres/datastore_test
29+
CKAN_SOLR_URL: http://solr:8983/solr/ckan
30+
CKAN_REDIS_URL: redis://redis:6379/1
31+
32+
steps:
33+
- uses: actions/checkout@v3
34+
- name: Install requirements
35+
# Install any extra requirements your extension has here (dev requirements, other extensions etc.)
36+
run: |
37+
pip install -r dev-requirements.txt
38+
pip install -e .
39+
- name: Setup extension
40+
# Extra initialization steps
41+
run: |
42+
# Replace default path to CKAN core config file with the one on the container
43+
sed -i -e 's/use = config:.*/use = config:\/srv\/app\/src\/ckan\/test-core.ini/' test.ini
44+
45+
ckan -c test.ini db init
46+
- name: Run tests
47+
run: pytest --ckan-ini=test.ini --cov=ckanext.cookie_banner --disable-warnings ckanext/cookie_banner

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/.venv
2+
3+
/.idea
4+
5+
/.vscode

MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include README.rst
2+
include LICENSE
3+
include requirements.txt
4+
recursive-include ckanext/cookie_banner *.html *.json *.js *.less *.css *.mo *.yml
5+
recursive-include ckanext/cookie_banner/migration *.ini *.py *.mako

README.md

Lines changed: 138 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,138 @@
1-
# ckanext-cookie-banner
2-
Cookie Banner Plugin for CKAN
1+
[![Tests](https://github.com/JiscSD/ckanext-ukdstheme/workflows/Tests/badge.svg?branch=main)](https://github.com/JiscSD/ckanext-ukdstheme/actions)
2+
3+
# Cookie Banner Plugin for CKAN
4+
5+
This is the cookie banner plugin for UKDS CKAN instance.
6+
It includes the necessary JavaScript files to apply the civic cookie banner.
7+
8+
## Features included
9+
1. Cookie Banner Displayed
10+
2. Configured correct text
11+
3. Link to the UKDS Privacy Policy
12+
4. Ability to change appearance and behaviour of the cookie banner
13+
14+
15+
## Requirements
16+
17+
This plugin is developed and tested on CKAN version 2.9 & 2.11
18+
19+
Compatibility with core CKAN versions:
20+
21+
| CKAN version | Compatible? |
22+
|-----------------|-------------|
23+
| 2.9 | yes |
24+
| 2.10 | not tested |
25+
| 2.11 | yes |
26+
27+
28+
## Installation
29+
30+
To install ckanext-cookie_banner:
31+
32+
1. Activate your CKAN virtual environment, for example:
33+
```
34+
. /usr/lib/ckan/default/bin/activate
35+
```
36+
2. Clone the source and install it on the virtualenv
37+
```
38+
cd /usr/lib/ckan/default/src
39+
python3 -m pip install -e git+https://github.com/JiscSD/ckanext-cookie-banner.git#egg=ckanext-cookie-banner
40+
41+
then reset the permissions for the new ckanext-cookie-banner directory to 'ckan'
42+
```
43+
3. Add `cookie_banner` to the `ckan.plugins` setting in your CKAN
44+
config file (by default the config file is located at
45+
`/etc/ckan/default/ckan.ini`).
46+
47+
4. Restart CKAN. For example if you've deployed CKAN with Apache on Ubuntu:
48+
```
49+
sudo service apache2 reload
50+
```
51+
or if the server is on AWS, called
52+
```
53+
sudo systemctl restart nginx
54+
```
55+
56+
## Updating to a new version
57+
58+
To update ckanext-cookie_banner:
59+
60+
1. Activate your CKAN virtual environment, for example:
61+
```
62+
. /usr/lib/ckan/default/bin/activate
63+
```
64+
2. pull the latest version then install it on the virtualenv
65+
```
66+
cd /usr/lib/ckan/default/src/ckanext-cookie-banner
67+
git pull
68+
pip install -e .
69+
70+
then reset the permissions for the ckanext-cookie-banner directory to 'ckan'
71+
```
72+
73+
3. Restart CKAN. For example if you've deployed CKAN with Apache on Ubuntu:
74+
```
75+
sudo service apache2 reload
76+
```
77+
or if the server is on AWS, called
78+
```
79+
sudo reboot now
80+
```
81+
82+
## Config settings
83+
84+
None at present
85+
86+
## Developer installation
87+
88+
To install ckanext-cookie_banner for development, activate your CKAN virtualenv and
89+
do:
90+
91+
python3 -m pip install -e git+https://github.com/JiscSD/ckanext-cookie-banner.git#egg=ckanext-cookie-banner
92+
cd ckanext-cookie-banner
93+
python3 setup.py develop
94+
python3 -m pip install -r dev-requirements.txt
95+
96+
97+
## Tests
98+
99+
To run the tests, do:
100+
101+
pytest --ckan-ini=test.ini
102+
103+
104+
## Releasing a new version of ckanext-cookie_banner
105+
106+
If ckanext-cookie_banner should be available on PyPI you can follow these steps to publish a new version:
107+
108+
1. Update the version number in the `setup.py` file. See [PEP 440](http://legacy.python.org/dev/peps/pep-0440/#public-version-identifiers) for how to choose version numbers.
109+
110+
2. Make sure you have the latest version of necessary packages:
111+
112+
pip install --upgrade setuptools wheel twine
113+
114+
3. Create a source and binary distributions of the new version:
115+
116+
python setup.py sdist bdist_wheel && twine check dist/*
117+
118+
Fix any errors you get.
119+
120+
4. Upload the source distribution to PyPI:
121+
122+
twine upload dist/*
123+
124+
5. Commit any outstanding changes:
125+
126+
git commit -a
127+
git push
128+
129+
6. Tag the new release of the project on GitHub with the version number from
130+
the `setup.py` file. For example if the version number in `setup.py` is
131+
0.0.1 then do:
132+
133+
git tag 0.0.1
134+
git push --tags
135+
136+
## License
137+
138+
[Unlicense](https://unlicense.org/)

ckanext/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# encoding: utf-8
2+
3+
# this is a namespace package
4+
try:
5+
import pkg_resources
6+
pkg_resources.declare_namespace(__name__)
7+
except ImportError:
8+
import pkgutil
9+
__path__ = pkgutil.extend_path(__path__, __name__)

ckanext/cookie_banner/__init__.py

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
document.addEventListener("DOMContentLoaded", function(event) {
2+
3+
var cookies_config = {
4+
apiKey: cookieControlSettings.apiKey,
5+
product: cookieControlSettings.product,
6+
encodeCookie: true, // some libraries break if the cookie has unencoded characters e.g. "
7+
consentCookieExpiry: 90,
8+
subDomains: false,
9+
10+
// configuration, List of cookies
11+
necessaryCookies: NECESSARY_COOKIES,
12+
statement: COOKIES_PRIVACY_STATEMENT,
13+
text: CIVIC_CONTROL_TEXT,
14+
15+
// Layout and designing
16+
position: "right",
17+
theme:"dark",
18+
toggleType: "slider",
19+
20+
branding: CIVIC_BRANDING
21+
22+
};
23+
24+
CookieControl.load( cookies_config );
25+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const cookieControlSettings = {
2+
"apiKey":"4ac1eab025f2e0aaaa4857824739d485944e6657",
3+
"product":"CUSTOM",
4+
"domain":"statistics.ukdataservice.ac.uk"
5+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Privacy statement to be displayed in the cookie consent banner
2+
const COOKIES_PRIVACY_STATEMENT = {
3+
description:
4+
"For more information, check the ",
5+
name: "privacy policy",
6+
url: "https://ukdataservice.ac.uk/privacy-policy/",
7+
updated: "10/04/2024",
8+
};
9+
10+
const CIVIC_CONTROL_TEXT = {
11+
title: "This site uses cookies to store information on your computer.",
12+
intro:
13+
"All of these cookies are essential for the application to run properly. We do use some analytics cookies but these use anonymised analytical data which is allowed under GDPR.",
14+
15+
closeLabel: "Close Cookie Control",
16+
cornerButton: "Set cookie preferences",
17+
on: "On",
18+
off: "Off",
19+
thirdPartyTitle: "Some cookies require your attention",
20+
thirdPartyDescription:
21+
"Consent for the following cookies could not be " +
22+
"automatically revoked. Please follow the link(s) " +
23+
"below to opt out manually.",
24+
// notification panels (only accessible for pro licences)
25+
notifyTitle: "Your choice regarding cookies on this site",
26+
notifyDescription:
27+
"We use cookies to optimise site functionality and " +
28+
"give you the best possible experience.",
29+
30+
settings: "Settings",
31+
};
32+
33+
const CIVIC_BRANDING = {
34+
fontFamily: 'Ne10-simplified,Arial, sans-serif',
35+
fontSizeTitle: '20px',
36+
fontSizeHeaders: '20px',
37+
fontSize: '16px',
38+
fontColor: '#000000',
39+
backgroundColor: '#f2f2f2',
40+
alertText: '#fff',
41+
alertBackground: '#111125',
42+
acceptText: '#fff',
43+
acceptBackground: '#B823E2',
44+
rejectText: '#fff',
45+
rejectBackground: '#08C5CC',
46+
toggleText: '#fff',
47+
toggleBackground: '#2d856e',
48+
toggleColor: '#9de3dd',
49+
buttonIcon: null,
50+
buttonIconWidth: 64,
51+
buttonIconHeight: 64,
52+
removeIcon: false,
53+
removeAbout: false,
54+
};

0 commit comments

Comments
 (0)