|
@@ -196,6 +196,35 @@
|
|
|
|
|
|
return (intersect.length || (await slice.allUserIds).includes(userId + ''))
|
|
|
}
|
|
|
+
|
|
|
+ let wrapSave = instance => {
|
|
|
+ let save = instance.save
|
|
|
+ instance.save = async function(...params){
|
|
|
+ let readSlice = await Slice.findOne({where: {
|
|
|
+ model: model.getTableName(),
|
|
|
+ modelId: instance.id,
|
|
|
+ permission: 'read'
|
|
|
+ }})
|
|
|
+ if (!readSlice) throw ReferenceError('No access to write')
|
|
|
+ if (readSlice.ownerId === userId){
|
|
|
+ console.log('SAVE because owner')
|
|
|
+ return save.apply(instance,params)
|
|
|
+ }
|
|
|
+
|
|
|
+ let writeSlice = await Slice.findOne({where: {
|
|
|
+ model: model.getTableName(),
|
|
|
+ modelId: instance.id,
|
|
|
+ permission: 'write'
|
|
|
+ }})
|
|
|
+ if (await checker(writeSlice)){
|
|
|
+ return save.apply(instance, params)
|
|
|
+ }
|
|
|
+ throw ReferenceError('No access to write')
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
let wrappers = {
|
|
|
async read(...params){
|
|
|
console.log('read wrapper')
|
|
@@ -212,6 +241,7 @@
|
|
|
let instance = result.filter(instance => instance.id === slice.modelId)[0]
|
|
|
|
|
|
if (await checker(slice)) {
|
|
|
+ wrapSave(instance)
|
|
|
filteredResult.push(instance)
|
|
|
continue;
|
|
|
}
|
|
@@ -224,6 +254,7 @@
|
|
|
modelId: result.id,
|
|
|
permission,
|
|
|
}})
|
|
|
+ wrapSave(result)
|
|
|
return (await checker(slice)) ? result : null;
|
|
|
}
|
|
|
},
|
|
@@ -241,6 +272,7 @@
|
|
|
permission: 'read',
|
|
|
slice: createSlice.slice,
|
|
|
})
|
|
|
+ wrapSave(result)
|
|
|
return result
|
|
|
}
|
|
|
}
|
|
@@ -258,14 +290,19 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- let SlicedContent = await sliced(Content)(3)
|
|
|
-
|
|
|
+ let SlicedContent = await sliced(Content)(2)
|
|
|
+ console.log(JSON.stringify(await SlicedContent.findAll({}),null, 4))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ let content = await SlicedContent.findByPk(7)
|
|
|
+ content.data = `SLICED by WRITE permission for groupzzz #1`
|
|
|
+ content.save()
|
|
|
|
|
|
- let newContent = await SlicedContent.create({title: "SLiced", data: "SLICED"})
|
|
|
- console.log(newContent)
|
|
|
|
|
|
- newContent.data = 'sliced2'
|
|
|
- await newContent.save()
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|