1
0
Fork 0

fix(backend): Support cset in patterns and sinup-aea links

This commit is contained in:
joostdecock 2023-05-26 15:39:22 +02:00
parent fecb894ecb
commit f26bf8e061
3 changed files with 21 additions and 8 deletions

View file

@ -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
}

View file

@ -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 = {}

View file

@ -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)
}