From d405c5985f9940405f741b9629af5599e285a050 Mon Sep 17 00:00:00 2001 From: davwas Date: Thu, 7 Sep 2023 20:51:01 +0200 Subject: [PATCH 1/8] add new translations --- locales/de.json | 2 ++ locales/en.json | 2 ++ locales/es.json | 2 ++ locales/uk.json | 2 ++ 4 files changed, 8 insertions(+) diff --git a/locales/de.json b/locales/de.json index c2fcaf7ca6..c88e30550b 100644 --- a/locales/de.json +++ b/locales/de.json @@ -1770,6 +1770,8 @@ "dataProtectionThr": "Datenschutzhinweise", "dataProtectionFile": "Datenschutzerklärung der Schule", "dataProtectionFileThr": "Datenschutzhinweise der Schule", + "termsOfUse": "Nutzungsordnung", + "termsOfUseFile": "Nutzungsordnung der Schule", "emailDomainBlocked": "Dieser Mailprovider wird nicht mehr unterstützt. Bitte wende dich an deinen Schul-Admin.", "errorChangingFilePermissions": "Problem beim Ändern der Berechtigungen", "errorWhileLoadingPage": "Diese Seite konnte nicht geladen werden", diff --git a/locales/en.json b/locales/en.json index 0b4e8a38c5..09f278f67f 100644 --- a/locales/en.json +++ b/locales/en.json @@ -1770,6 +1770,8 @@ "dataProtectionThr": "Privacy Policy", "dataProtectionFile": "Privacy Policy of School", "dataProtectionFileThr": "Privacy Policy of School", + "termsOfUse": "Terms of Use", + "termsOfUseFile": "Terms of Use of School", "emailDomainBlocked": "This mail provider is no longer supported. Please contact your school administrator.", "errorChangingFilePermissions": "Problem changing permissions", "errorWhileLoadingPage": "This page could not be loaded", diff --git a/locales/es.json b/locales/es.json index c5fcab5a68..b501f4ed66 100644 --- a/locales/es.json +++ b/locales/es.json @@ -1770,6 +1770,8 @@ "dataProtectionThr": "Política de Privacidad", "dataProtectionFile": "Política de Privacidad de la Escuela", "dataProtectionFileThr": "Política de Privacidad de la Escuela", + "termsOfUse": "Condiciones de Uso", + "termsOfUseFile": "Condiciones de Uso de la Escuela", "emailDomainBlocked": "Este proveedor de correo ya no es compatible. Ponte en contacto con el administrador de tu escuela.", "errorChangingFilePermissions": "Hay un problema para cambiar los permisos", "errorWhileLoadingPage": "Esta página no se ha podido cargar", diff --git a/locales/uk.json b/locales/uk.json index ffec1c2f2d..599c947c37 100644 --- a/locales/uk.json +++ b/locales/uk.json @@ -130,6 +130,8 @@ "dataProtectionThr": "Політика конфіденційності", "dataProtectionFile": "Політика конфіденційності школи", "dataProtectionFileThr": "Політика конфіденційності школи", + "termsOfUse": "Умови використання", + "termsOfUseFile": "Умови використання школи", "emailDomainBlocked": "Цей постачальник пошти більше не підтримується. Будь ласка, зв’яжіться з адміністратором школи.", "errorChangingFilePermissions": "Проблема зі зміною дозволів", "fileTooLarge": "Вкладені файли перевищують максимально дозволений розмір — {{ maxFileSizeInGb }} Гб!", From 7e0d465cfb225ec4eb55ea1163f944f55955e46e Mon Sep 17 00:00:00 2001 From: davwas Date: Thu, 7 Sep 2023 20:51:27 +0200 Subject: [PATCH 2/8] add new /termsofuse controller and links --- controllers/dataprivacy.js | 10 ++--- controllers/index.js | 1 + controllers/termsofuse.js | 69 +++++++++++++++++++++++++++++++++++ views/lib/extended_footer.hbs | 2 +- views/lib/footer.hbs | 2 +- 5 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 controllers/termsofuse.js diff --git a/controllers/dataprivacy.js b/controllers/dataprivacy.js index d3d926d8fe..b9ef56daa9 100644 --- a/controllers/dataprivacy.js +++ b/controllers/dataprivacy.js @@ -7,9 +7,7 @@ const { specificFiles } = require('../config/documents'); const router = express.Router(); -const privacyUrl = () => { - return new URL(`${SC_THEME}/${specificFiles.privacyExemplary}`, DOCUMENT_BASE_DIR); -}; +const privacyUrl = () => new URL(`${SC_THEME}/${specificFiles.privacyExemplary}`, DOCUMENT_BASE_DIR); const downloadPolicyPdf = (res, fileData, fileTitle) => { // ERR_INVALID_CHAR will get thrown on ukrainian translation without encoding @@ -39,7 +37,7 @@ router.get('/', async (req, res, next) => { const isAuthenticated = await authHelper.isAuthenticated(req); const qs = { $limit: 1, - consentTypes: 'privacy', + consentTypes: ['privacy'], $sort: { publishedAt: -1, }, @@ -54,7 +52,7 @@ router.get('/', async (req, res, next) => { if (consentVersions.data.length) { const fileId = consentVersions.data[0].consentDataId; if (!fileId) { - res.redirect(privacyUrl()); + res.redirect(privacyUrl().toString()); } const fileTitle = res.locals.theme.name === 'thr' @@ -63,7 +61,7 @@ router.get('/', async (req, res, next) => { await getBase64File(req, res, fileId, fileTitle); } else { - res.redirect(privacyUrl()); + res.redirect(privacyUrl().toString()); } } catch (err) { next(err); diff --git a/controllers/index.js b/controllers/index.js index b608184b85..33a15c0d05 100644 --- a/controllers/index.js +++ b/controllers/index.js @@ -34,6 +34,7 @@ router.use('/community/', require('./community')); router.use('/about/', require('./about')); router.use('/help/', require('./help')); router.use('/datenschutz/', require('./dataprivacy')); +router.use('/termsofuse/', require('./termsofuse')); router.use('/my-material', require('./my-material')); router.use('/base64Files', require('./base64Files')); router.use('/logs', require('./logs')); diff --git a/controllers/termsofuse.js b/controllers/termsofuse.js new file mode 100644 index 0000000000..b48e1ef86e --- /dev/null +++ b/controllers/termsofuse.js @@ -0,0 +1,69 @@ +const express = require('express'); +const { URL } = require('url'); +const api = require('../api'); +const authHelper = require('../helpers/authentication'); +const { DOCUMENT_BASE_DIR, SC_THEME } = require('../config/global'); +const { specificFiles } = require('../config/documents'); + +const router = express.Router(); + +const termsUrl = () => new URL(`${SC_THEME}/${specificFiles.termsOfUseSchool}`, DOCUMENT_BASE_DIR); + +const downloadTermsPdf = (res, fileData, fileTitle) => { + // ERR_INVALID_CHAR will get thrown on ukrainian translation without encoding + const encodedFileTitle = encodeURI(fileTitle); + const download = Buffer.from(fileData, 'base64'); + res.writeHead(200, { + 'Content-Type': 'application/pdf', + 'Content-Disposition': `attachment; filename="${encodedFileTitle}.pdf"`, + }).end(download); +}; + +const getBase64File = async (req, res, fileId, fileTitle) => { + if (fileId) { + const base64File = await api(req).get(`/base64Files/${fileId}`); + if (base64File.data) { + const fileData = base64File.data.replace( + 'data:application/pdf;base64,', + '', + ); + downloadTermsPdf(res, fileData, fileTitle); + } + } +}; + +router.get('/', async (req, res, next) => { + try { + const isAuthenticated = await authHelper.isAuthenticated(req); + const qs = { + $limit: 1, + consentTypes: ['termsOfUse'], + $sort: { + publishedAt: -1, + }, + }; + + if (isAuthenticated && res.locals.currentSchool) { + qs.schoolId = res.locals.currentSchool; + } + + const consentVersions = await api(req).get('/consentVersions', { qs }); + + if (consentVersions.data.length) { + const fileId = consentVersions.data[0].consentDataId; + if (!fileId) { + res.redirect(termsUrl().toString()); + } + + const fileTitle = res.$t('global.text.termsOfUseFile'); + + await getBase64File(req, res, fileId, fileTitle); + } else { + res.redirect(termsUrl().toString()); + } + } catch (err) { + next(err); + } +}); + +module.exports = router; diff --git a/views/lib/extended_footer.hbs b/views/lib/extended_footer.hbs index d64e55f393..9f2ad8050d 100644 --- a/views/lib/extended_footer.hbs +++ b/views/lib/extended_footer.hbs @@ -13,7 +13,7 @@

{{$t "lib.extended_footer.headline.links"}}