From f26bf8e0610261dc923a582a85703467ad491547 Mon Sep 17 00:00:00 2001 From: joostdecock Date: Fri, 26 May 2023 15:39:22 +0200 Subject: [PATCH] fix(backend): Support cset in patterns and sinup-aea links --- sites/backend/prisma/schema.prisma | 3 +++ sites/backend/src/models/pattern.mjs | 13 ++++++++++--- sites/backend/src/models/user.mjs | 13 ++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/sites/backend/prisma/schema.prisma b/sites/backend/prisma/schema.prisma index 1c4a98e72f4..d4a96653bd2 100644 --- a/sites/backend/prisma/schema.prisma +++ b/sites/backend/prisma/schema.prisma @@ -80,6 +80,8 @@ model Pattern { notes String set Set? @relation(fields: [setId], references: [id]) setId Int? + cset CuratedSet? @relation(fields: [csetId], references: [id]) + csetId Int? public Boolean @default(false) settings String user User @relation(fields: [userId], references: [id]) @@ -126,6 +128,7 @@ model CuratedSet { tagsFr String @default("") tagsNl String @default("") measies String @default("{}") + patterns Pattern[] updatedAt DateTime @updatedAt } diff --git a/sites/backend/src/models/pattern.mjs b/sites/backend/src/models/pattern.mjs index 5e954e1ca59..7a21779f834 100644 --- a/sites/backend/src/models/pattern.mjs +++ b/sites/backend/src/models/pattern.mjs @@ -16,8 +16,11 @@ export function PatternModel(tools) { PatternModel.prototype.guardedCreate = async function ({ body, user }) { if (!this.rbac.user(user)) return this.setResponse(403, 'insufficientAccessLevel') if (Object.keys(body).length < 2) return this.setResponse(400, 'postBodyMissing') - if (!body.set) return this.setResponse(400, 'setMissing') - if (typeof body.set !== 'number') return this.setResponse(400, 'setNotNumeric') + if (!body.set && !body.cset) return this.setResponse(400, 'setOrCsetMissing') + if (typeof body.set !== 'undefined' && typeof body.set !== 'number') + return this.setResponse(400, 'setNotNumeric') + if (typeof body.cset !== 'undefined' && typeof body.cset !== 'number') + return this.setResponse(400, 'csetNotNumeric') if (typeof body.settings !== 'object') return this.setResponse(400, 'settingsNotAnObject') if (body.data && typeof body.data !== 'object') return this.setResponse(400, 'dataNotAnObject') if (!body.design && !body.data?.design) return this.setResponse(400, 'designMissing') @@ -26,9 +29,13 @@ PatternModel.prototype.guardedCreate = async function ({ body, user }) { // Prepare data const data = { design: body.design, - setId: body.set, settings: body.settings, } + if (data.settings.measurements) delete data.settings.measurements + if (body.set) data.setId = body.set + else if (body.cset) data.csetId = body.cset + else return this.setResponse(400, 'setOrCsetMissing') + // Data (will be encrypted, so always set _some_ value) if (typeof body.data === 'object') data.data = body.data else data.data = {} diff --git a/sites/backend/src/models/user.mjs b/sites/backend/src/models/user.mjs index 0e3b8730f68..b2731083d26 100644 --- a/sites/backend/src/models/user.mjs +++ b/sites/backend/src/models/user.mjs @@ -187,6 +187,12 @@ UserModel.prototype.guardedCreate = async function ({ body }) { userId: this.record.id, }) } + // Set th action url based on the account status + let actionUrl = false + if (this.record.status === 0) + actionUrl = i18nUrl(body.language, `/confirm/${type}/${this.Confirmation.record.id}/${check}`) + else if (this.record.status === 1) + actionUrl = i18nUrl(body.language, `/confirm/signin/${this.Confirmation.record.id}/${check}`) // Send email unless it's a test and we don't want to send test emails if (!isTest || this.config.tests.sendEmail) await this.mailer.send({ @@ -194,10 +200,7 @@ UserModel.prototype.guardedCreate = async function ({ body }) { language: body.language, to: this.clear.email, replacements: { - actionUrl: - type === 'signup-aed' - ? false // No actionUrl for disabled accounts - : i18nUrl(body.language, `/confirm/${type}/${this.Confirmation.record.id}/${check}`), + actionUrl, whyUrl: i18nUrl(body.language, `/docs/faq/email/why-${type}`), supportUrl: i18nUrl(body.language, `/patrons/join`), }, @@ -342,7 +345,7 @@ UserModel.prototype.linkSignIn = async function (req) { } // Verify whether Confirmation is of the right type - if (this.Confirmation.record.type !== 'signinlink') { + if (!['signinlink', 'signup-aea'].includes(this.Confirmation.record.type)) { log.warn(`Confirmation mismatch; ${req.params.id} is not a signin id`) return this.setResponse(404) }