From 5a06e42a52eac5b01417a577eaf7790012582714 Mon Sep 17 00:00:00 2001 From: agnisa-cap Date: Tue, 2 Apr 2024 11:35:23 +0200 Subject: [PATCH] N21-1836 extends ctl with description, media id and publisher (#253) --- controllers/ctltools.js | 69 +++++++++++++-------------- views/ctltools/forms/add-ctl-tool.hbs | 31 +++++++++--- 2 files changed, 58 insertions(+), 42 deletions(-) diff --git a/controllers/ctltools.js b/controllers/ctltools.js index 9f572d4..ddab619 100644 --- a/controllers/ctltools.js +++ b/controllers/ctltools.js @@ -9,66 +9,62 @@ const { api } = require('../api'); const moment = require('moment'); moment.locale('de'); -const trimWhitespaces = (object) => { +const clearEmptyInputs = (object) => { Object.keys(object).forEach((key) => { const type = typeof object[key]; - if (type === 'object') { - trimWhitespaces(object[key]); - } else if (type === 'string') { - object[key] = object[key].trim(); + + switch (type) { + case 'object': + clearEmptyInputs(object[key]); + + if(JSON.stringify(object[key]) === JSON.stringify({})) { + object[key] = undefined; + } + break; + case 'string': + object[key] = object[key].trim(); + + if(object[key] === "") { + object[key] = undefined; + } + break; + case 'boolean': + case 'number': + break; + default: + console.log('Unsupported type for sanitization'); + break; } }); -}; +} -const sanitizeToolInputs = (id, body) => { +const transformToolInputs = (id, body) => { body.id = id; - body.url = body.url || undefined; - body.logoUrl = body.logoUrl || undefined; + body.openNewTab = !!body.openNewTab; body.isHidden = !!body.isHidden; body.isDeactivated = !!body.isDeactivated; - body.config.baseUrl = body.config.baseUrl || undefined; body.restrictToContexts = [].concat(body.restrictToContexts || []); - switch (body.config.type) { - case 'oauth2': - body.config.clientId = body.config.clientId || undefined; - body.config.clientSecret = body.config.clientSecret || undefined; - body.config.skipConsent = !!body.config.skipConsent; - body.config.redirectUris = body.config.redirectUris.split(';'); - body.config.scope = body.config.scope || undefined; - body.config.frontchannelLogoutUri = body.config.frontchannelLogoutUri || undefined; - break; - case 'lti11': - body.config.secret = body.config.secret || undefined; - break; - case 'basic': - break; - default: - // eslint-disable-next-line no-console - console.log('Config type was not set! Server will crash'); - throw new Error('Unknown tool config type'); + if (body.config.type === 'oauth2') { + body.config.skipConsent = !!body.config.skipConsent; + body.config.redirectUris = body.config.redirectUris.split(';'); } if(body.parameters && Array.isArray(body.parameters)) { body.parameters.forEach((param) => { param.isOptional = !!param.isOptional; param.isProtected = !!param.isProtected; - param.defaultValue = param.defaultValue || undefined; - param.regex = param.regex || undefined; - if (!param.regex) { - param.regexComment = param.regexComment || undefined; - } }); } - trimWhitespaces(body); + clearEmptyInputs(body); return body; }; const getUpdateHandler = (req, res, next) => { - req.body = sanitizeToolInputs(req.params.id, req.body); + req.body = transformToolInputs(req.params.id, req.body); api(req, { version: 'v3' }).post(`/tools/external-tools/${req.params.id}`, { json: req.body @@ -114,7 +110,7 @@ const getDeleteHandler = (req, res, next) => { }; const getCreateHandler = (req, res, next) => { - req.body = sanitizeToolInputs(undefined, req.body); + req.body = transformToolInputs(undefined, req.body); api(req, { version: 'v3' }).post('/tools/external-tools/', { json: req.body @@ -190,6 +186,7 @@ const customParameterTypes = [ { label: 'Context Name', value: 'auto_contextname' }, { label: 'Schul Id', value: 'auto_schoolid' }, { label: 'Offizielle Schulnummer', value: 'auto_schoolnumber' }, + { label: 'Medium Id', value: 'auto_mediumid' }, ]; const customParameterLocations = [ diff --git a/views/ctltools/forms/add-ctl-tool.hbs b/views/ctltools/forms/add-ctl-tool.hbs index 5d0b210..e721f22 100644 --- a/views/ctltools/forms/add-ctl-tool.hbs +++ b/views/ctltools/forms/add-ctl-tool.hbs @@ -4,17 +4,35 @@ +
+ + +
- +

Maximale Dateigröße 300 kByte; Zulässige Formate: jpg, png

+ +

Medium

+
+
+ + +
+
+ + +
+ +

Verfügbarkeit

+
+

Konfiguration

+
@@ -65,7 +85,7 @@

OAuth2

- +
@@ -73,7 +93,7 @@
- +
@@ -137,9 +157,8 @@
+

Custom Parameters


- -

Custom Parameters

- +