fix(backend): Support cset in patterns and sinup-aea links
This commit is contained in:
parent
fecb894ecb
commit
f26bf8e061
3 changed files with 21 additions and 8 deletions
|
@ -80,6 +80,8 @@ model Pattern {
|
||||||
notes String
|
notes String
|
||||||
set Set? @relation(fields: [setId], references: [id])
|
set Set? @relation(fields: [setId], references: [id])
|
||||||
setId Int?
|
setId Int?
|
||||||
|
cset CuratedSet? @relation(fields: [csetId], references: [id])
|
||||||
|
csetId Int?
|
||||||
public Boolean @default(false)
|
public Boolean @default(false)
|
||||||
settings String
|
settings String
|
||||||
user User @relation(fields: [userId], references: [id])
|
user User @relation(fields: [userId], references: [id])
|
||||||
|
@ -126,6 +128,7 @@ model CuratedSet {
|
||||||
tagsFr String @default("")
|
tagsFr String @default("")
|
||||||
tagsNl String @default("")
|
tagsNl String @default("")
|
||||||
measies String @default("{}")
|
measies String @default("{}")
|
||||||
|
patterns Pattern[]
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,11 @@ export function PatternModel(tools) {
|
||||||
PatternModel.prototype.guardedCreate = async function ({ body, user }) {
|
PatternModel.prototype.guardedCreate = async function ({ body, user }) {
|
||||||
if (!this.rbac.user(user)) return this.setResponse(403, 'insufficientAccessLevel')
|
if (!this.rbac.user(user)) return this.setResponse(403, 'insufficientAccessLevel')
|
||||||
if (Object.keys(body).length < 2) return this.setResponse(400, 'postBodyMissing')
|
if (Object.keys(body).length < 2) return this.setResponse(400, 'postBodyMissing')
|
||||||
if (!body.set) return this.setResponse(400, 'setMissing')
|
if (!body.set && !body.cset) return this.setResponse(400, 'setOrCsetMissing')
|
||||||
if (typeof body.set !== 'number') return this.setResponse(400, 'setNotNumeric')
|
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 (typeof body.settings !== 'object') return this.setResponse(400, 'settingsNotAnObject')
|
||||||
if (body.data && typeof body.data !== 'object') return this.setResponse(400, 'dataNotAnObject')
|
if (body.data && typeof body.data !== 'object') return this.setResponse(400, 'dataNotAnObject')
|
||||||
if (!body.design && !body.data?.design) return this.setResponse(400, 'designMissing')
|
if (!body.design && !body.data?.design) return this.setResponse(400, 'designMissing')
|
||||||
|
@ -26,9 +29,13 @@ PatternModel.prototype.guardedCreate = async function ({ body, user }) {
|
||||||
// Prepare data
|
// Prepare data
|
||||||
const data = {
|
const data = {
|
||||||
design: body.design,
|
design: body.design,
|
||||||
setId: body.set,
|
|
||||||
settings: body.settings,
|
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)
|
// Data (will be encrypted, so always set _some_ value)
|
||||||
if (typeof body.data === 'object') data.data = body.data
|
if (typeof body.data === 'object') data.data = body.data
|
||||||
else data.data = {}
|
else data.data = {}
|
||||||
|
|
|
@ -187,6 +187,12 @@ UserModel.prototype.guardedCreate = async function ({ body }) {
|
||||||
userId: this.record.id,
|
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
|
// Send email unless it's a test and we don't want to send test emails
|
||||||
if (!isTest || this.config.tests.sendEmail)
|
if (!isTest || this.config.tests.sendEmail)
|
||||||
await this.mailer.send({
|
await this.mailer.send({
|
||||||
|
@ -194,10 +200,7 @@ UserModel.prototype.guardedCreate = async function ({ body }) {
|
||||||
language: body.language,
|
language: body.language,
|
||||||
to: this.clear.email,
|
to: this.clear.email,
|
||||||
replacements: {
|
replacements: {
|
||||||
actionUrl:
|
actionUrl,
|
||||||
type === 'signup-aed'
|
|
||||||
? false // No actionUrl for disabled accounts
|
|
||||||
: i18nUrl(body.language, `/confirm/${type}/${this.Confirmation.record.id}/${check}`),
|
|
||||||
whyUrl: i18nUrl(body.language, `/docs/faq/email/why-${type}`),
|
whyUrl: i18nUrl(body.language, `/docs/faq/email/why-${type}`),
|
||||||
supportUrl: i18nUrl(body.language, `/patrons/join`),
|
supportUrl: i18nUrl(body.language, `/patrons/join`),
|
||||||
},
|
},
|
||||||
|
@ -342,7 +345,7 @@ UserModel.prototype.linkSignIn = async function (req) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify whether Confirmation is of the right type
|
// 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`)
|
log.warn(`Confirmation mismatch; ${req.params.id} is not a signin id`)
|
||||||
return this.setResponse(404)
|
return this.setResponse(404)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue