Added member API for changing enable_comment_notifications and comments_enabled setting

refs https://github.com/TryGhost/Team/issues/1664

These changes are required for Portal to be able to edit the member notification preferences for comments, and to be able to know whether comments are enabled for the site.
This commit is contained in:
Simon Backx 2022-07-07 14:17:50 +02:00 committed by Simon Backx
parent 6a8c6e9081
commit 96504008c1
5 changed files with 19 additions and 14 deletions

View File

@ -75,7 +75,7 @@ const getMemberNewsletters = async function (req, res) {
return res.end('Email address not found.');
}
const data = _.pick(memberData.toJSON(), 'uuid', 'email', 'name', 'newsletters', 'status');
const data = _.pick(memberData.toJSON(), 'uuid', 'email', 'name', 'newsletters', 'enable_comment_notifications', 'status');
return res.json(data);
} catch (err) {
res.writeHead(400);
@ -91,7 +91,7 @@ const updateMemberNewsletters = async function (req, res) {
return res.end('Invalid member uuid');
}
const data = _.pick(req.body, 'newsletters');
const data = _.pick(req.body, 'newsletters', 'enable_comment_notifications');
const memberData = await membersService.api.members.get({
uuid: memberUuid
});
@ -106,7 +106,7 @@ const updateMemberNewsletters = async function (req, res) {
};
const updatedMember = await membersService.api.members.update(data, options);
const updatedMemberData = _.pick(updatedMember.toJSON(), ['uuid', 'email', 'name', 'newsletters', 'status']);
const updatedMemberData = _.pick(updatedMember.toJSON(), ['uuid', 'email', 'name', 'newsletters', 'enable_comment_notifications', 'status']);
res.json(updatedMemberData);
} catch (err) {
res.writeHead(400);
@ -116,7 +116,7 @@ const updateMemberNewsletters = async function (req, res) {
const updateMemberData = async function (req, res) {
try {
const data = _.pick(req.body, 'name', 'subscribed', 'newsletters');
const data = _.pick(req.body, 'name', 'subscribed', 'newsletters', 'enable_comment_notifications');
const member = await membersService.ssr.getMemberDataFromSession(req, res);
if (member) {
const options = {

View File

@ -16,7 +16,8 @@ module.exports.formattedMemberResponse = function formattedMemberResponse(member
avatar_image: member.avatar_image,
subscribed: !!member.subscribed,
subscriptions: member.subscriptions || [],
paid: member.status !== 'free'
paid: member.status !== 'free',
enable_comment_notifications: member.enable_comment_notifications
};
if (member.newsletters) {
data.newsletters = formatNewsletterResponse(member.newsletters);

View File

@ -85,7 +85,7 @@
"@tryghost/logging": "2.2.3",
"@tryghost/magic-link": "1.0.26",
"@tryghost/member-events": "0.4.6",
"@tryghost/members-api": "8.1.3",
"@tryghost/members-api": "8.2.0",
"@tryghost/members-events-service": "0.4.3",
"@tryghost/members-importer": "0.5.16",
"@tryghost/members-offers": "0.11.6",

View File

@ -22,7 +22,8 @@ describe('Members Service - utils', function () {
avatar_image: 'https://gravatar.com/avatar/7d8efd2c2a781111599a8cae293cf704?s=250&d=blank',
subscribed: true,
status: 'free',
extra: 'property'
extra: 'property',
enable_comment_notifications: true
});
should(member1).deepEqual({
uuid: 'uuid-1',
@ -32,7 +33,8 @@ describe('Members Service - utils', function () {
avatar_image: 'https://gravatar.com/avatar/7d8efd2c2a781111599a8cae293cf704?s=250&d=blank',
subscribed: true,
subscriptions: [],
paid: false
paid: false,
enable_comment_notifications: true
});
});
@ -52,7 +54,8 @@ describe('Members Service - utils', function () {
sender_name: 'Jamie',
sender_email: 'jamie@example.com',
sort_order: 0
}]
}],
enable_comment_notifications: false
});
should(member1).deepEqual({
uuid: 'uuid-1',
@ -68,7 +71,8 @@ describe('Members Service - utils', function () {
name: 'Daily brief',
description: 'One email daily',
sort_order: 0
}]
}],
enable_comment_notifications: false
});
});
});

View File

@ -1909,10 +1909,10 @@
"@tryghost/domain-events" "^0.1.14"
"@tryghost/member-events" "^0.4.6"
"@tryghost/members-api@8.1.3":
version "8.1.3"
resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-8.1.3.tgz#8ddcf3d12e31639969a9678b3eb87fb6e49a7c5c"
integrity sha512-XJLXfwSd4EGbk5D9XJ0qOIF/9QBroT51/MN89Vtufw8MLHMx5OxlbIWfCXezrZHADg9GHWyao0xej3MQjGJqAA==
"@tryghost/members-api@8.2.0":
version "8.2.0"
resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-8.2.0.tgz#11e043a716e740f42c6590be44072ff4d3ef884a"
integrity sha512-MCLgN/ixaQDIhmNbXpofoTF9pBgbbLAUcNsoM/WBIPJkzAO7yYL/Np5xtvg4nVrH+/6SrAzYe/IH8wB0mc5QVA==
dependencies:
"@nexes/nql" "^0.6.0"
"@tryghost/debug" "^0.1.2"