mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Updated comments.add to use member id from cookie
refs https://github.com/TryGhost/Team/issues/1664 - make sure we only create comments for the currently logged in member
This commit is contained in:
parent
3e1e5b6760
commit
d4c8660323
1 changed files with 14 additions and 5 deletions
|
@ -2,11 +2,13 @@ const Promise = require('bluebird');
|
||||||
const tpl = require('@tryghost/tpl');
|
const tpl = require('@tryghost/tpl');
|
||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
const models = require('../../models');
|
const models = require('../../models');
|
||||||
|
const {identity} = require('lodash');
|
||||||
const ALLOWED_INCLUDES = ['post', 'member'];
|
const ALLOWED_INCLUDES = ['post', 'member'];
|
||||||
const UNSAFE_ATTRS = ['status'];
|
const UNSAFE_ATTRS = ['status'];
|
||||||
|
|
||||||
const messages = {
|
const messages = {
|
||||||
commentNotFound: 'Comment could not be found'
|
commentNotFound: 'Comment could not be found',
|
||||||
|
memberNotFound: 'Unable to find member'
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -103,9 +105,6 @@ module.exports = {
|
||||||
include: ALLOWED_INCLUDES
|
include: ALLOWED_INCLUDES
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
member_id: {
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
post_id: {
|
post_id: {
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
|
@ -115,7 +114,17 @@ module.exports = {
|
||||||
unsafeAttrs: UNSAFE_ATTRS
|
unsafeAttrs: UNSAFE_ATTRS
|
||||||
},
|
},
|
||||||
query(frame) {
|
query(frame) {
|
||||||
return models.Comment.add(frame.data.comments[0], frame.options);
|
// TODO: move to comment service
|
||||||
|
const data = frame.data.comments[0];
|
||||||
|
|
||||||
|
if (frame.options?.context?.member?.id) {
|
||||||
|
data.member_id = frame.options.context.member.id;
|
||||||
|
return models.Comment.add(data, frame.options);
|
||||||
|
} else {
|
||||||
|
return Promise.reject(new errors.NotFoundError({
|
||||||
|
message: tpl(messages.memberNotFound)
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue