Merge branch 'endpoints' into develop
This commit is contained in:
commit
f7686371c5
1 changed files with 8 additions and 4 deletions
|
|
@ -63,22 +63,26 @@ module.exports = createCoreController(noteUid, ({strapi}) => ({
|
||||||
async update(ctx) {
|
async update(ctx) {
|
||||||
const noteId = getNoteIdFromUrl(ctx.request.url)
|
const noteId = getNoteIdFromUrl(ctx.request.url)
|
||||||
const userId = ctx.state.user.id;
|
const userId = ctx.state.user.id;
|
||||||
const requestBody = ctx.request.body;
|
const requestBody = JSON.parse(ctx.request.body);
|
||||||
|
console.log(JSON.stringify(requestBody, null, 2))
|
||||||
const entry = await strapi.entityService.findOne(noteUid, noteId, {
|
const entry = await strapi.entityService.findOne(noteUid, noteId, {
|
||||||
populate: ['owners'],
|
populate: ['owners'],
|
||||||
});
|
});
|
||||||
const authorized = entry.owners.some(owner => owner.id === userId)
|
const authorized = entry.owners.some(owner => owner.id === userId)
|
||||||
let allPreviousOwnersKept = false;
|
let allPreviousOwnersKept = true;
|
||||||
if (requestBody.data.hasOwnProperty("owners")) {
|
if (requestBody.data.hasOwnProperty("owners")) {
|
||||||
allPreviousOwnersKept = entry.owners.every(owner => requestBody.data.owners.includes(owner));
|
allPreviousOwnersKept = entry.owners.every(owner => requestBody.data.owners.includes(owner));
|
||||||
}
|
}
|
||||||
|
console.log({
|
||||||
|
"auth": authorized,
|
||||||
|
"allprev": allPreviousOwnersKept,
|
||||||
|
})
|
||||||
if (!authorized) {
|
if (!authorized) {
|
||||||
ctx.response.status = 403;
|
ctx.response.status = 403;
|
||||||
} else if (!allPreviousOwnersKept) {
|
} else if (!allPreviousOwnersKept) {
|
||||||
ctx.response.status = 400;
|
ctx.response.status = 400;
|
||||||
} else {
|
|
||||||
return super.update(ctx);
|
|
||||||
}
|
}
|
||||||
|
return await strapi.entityService.update(noteUid, noteId, requestBody);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Creates a new note, automatically sets owners to the user making the request and lastViewed
|
* Creates a new note, automatically sets owners to the user making the request and lastViewed
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue