🔧 (validate document) add script to generate the validate function
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
import IAccount from '@/models/IAccount'
|
||||
import ITransaction from '@/models/ITransaction'
|
||||
import IExchange from '@/models/IExchange'
|
||||
|
||||
type Doc = IAccount | ITransaction | IExchange
|
||||
|
||||
interface IUserContext {
|
||||
db: string
|
||||
name: string | null
|
||||
roles: string[]
|
||||
}
|
||||
|
||||
export default {
|
||||
validate_doc_update(newDoc: Doc, oldDoc: Doc, userCtx: IUserContext) {
|
||||
if (newDoc.doctype === 'account' && oldDoc.doctype === 'account') {
|
||||
if (newDoc.userIds.indexOf(userCtx.name || '') < 0) {
|
||||
throw { forbidden: 'You do not have rights to update this account' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/scripts/validate-doc-update.ts
Normal file
31
src/scripts/validate-doc-update.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import IAccount from '@/models/IAccount'
|
||||
import ITransaction from '@/models/ITransaction'
|
||||
import IExchange from '@/models/IExchange'
|
||||
|
||||
type Doc = IAccount | ITransaction | IExchange
|
||||
|
||||
interface IUserContext {
|
||||
db: string
|
||||
name: string | null
|
||||
roles: string[]
|
||||
}
|
||||
|
||||
// tslint:disable-next-line: variable-name only-arrow-functions
|
||||
const validate_doc_update = function(
|
||||
newDoc: Doc,
|
||||
oldDoc: Doc,
|
||||
userCtx: IUserContext
|
||||
) {
|
||||
if (!userCtx.name) {
|
||||
throw { forbidden: 'You need to be logged in to update accounts' }
|
||||
}
|
||||
|
||||
if (newDoc.doctype === 'account' && oldDoc.doctype === 'account') {
|
||||
if (true) {
|
||||
throw { forbidden: 'You do not have rights to update this account' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:no-console
|
||||
console.info(validate_doc_update.toString().replace(/\n/g, ''))
|
||||
Reference in New Issue
Block a user