Skip to content

Commit

Permalink
🐛 Fixed malformed unsubscribe_url in members api response (#21437)
Browse files Browse the repository at this point in the history
no ref
  • Loading branch information
9larsons committed Oct 28, 2024
1 parent 2b29812 commit 00bd31a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
10 changes: 5 additions & 5 deletions ghost/core/test/e2e-api/admin/__snapshots__/members.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ exports[`Members API - member attribution Can read member attributed to a page 2
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "1082",
"content-length": "1094",
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
Expand Down Expand Up @@ -129,7 +129,7 @@ exports[`Members API - member attribution Can read member attributed to a post 2
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "1065",
"content-length": "1077",
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
Expand Down Expand Up @@ -198,7 +198,7 @@ exports[`Members API - member attribution Can read member attributed to a tag 2:
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "1071",
"content-length": "1083",
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
Expand Down Expand Up @@ -267,7 +267,7 @@ exports[`Members API - member attribution Can read member attributed to an autho
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "1053",
"content-length": "1065",
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
Expand Down Expand Up @@ -336,7 +336,7 @@ exports[`Members API - member attribution Can read member attributed to an url 2
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "1049",
"content-length": "1061",
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
Expand Down
4 changes: 2 additions & 2 deletions ghost/members-api/lib/services/MemberBREADService.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ module.exports = class MemberBREADService {
info: suppressionData.info
};

const unsubscribeUrl = this.settingsHelpers.createUnsubscribeUrl(member.id);
const unsubscribeUrl = this.settingsHelpers.createUnsubscribeUrl(member.uuid);
member.unsubscribe_url = unsubscribeUrl;

return member;
Expand Down Expand Up @@ -432,7 +432,7 @@ module.exports = class MemberBREADService {
suppressed: bulkSuppressionData[index].suppressed || !!model.get('email_disabled'),
info: bulkSuppressionData[index].info
};
member.unsubscribe_url = this.settingsHelpers.createUnsubscribeUrl(member.id);
member.unsubscribe_url = this.settingsHelpers.createUnsubscribeUrl(member.uuid);
return member;
});

Expand Down
6 changes: 4 additions & 2 deletions ghost/members-api/test/unit/lib/services/member-bread.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const moment = require('moment');
describe('MemberBreadService', function () {
describe('read', function () {
const MEMBER_ID = 123;
const MEMBER_UUID = 'abcd-efgh';
const DEFAULT_RELATIONS = [
'labels',
'stripeSubscriptions',
Expand All @@ -27,7 +28,7 @@ describe('MemberBreadService', function () {
const getService = () => {
return new MemberBreadService({
settingsHelpers: {
createUnsubscribeUrl: sinon.stub().returns('https://example.com/unsubscribe/?uuid=123&key=456')
createUnsubscribeUrl: sinon.stub().callsFake(uuid => `https://example.com/unsubscribe/?uuid=${uuid}&key=456`)
},
memberRepository: memberRepositoryStub,
memberAttributionService: memberAttributionServiceStub,
Expand All @@ -38,6 +39,7 @@ describe('MemberBreadService', function () {
beforeEach(function () {
memberModelJSON = {
id: MEMBER_ID,
uuid: MEMBER_UUID,
name: 'foo bar',
email: '[email protected]',
subscriptions: []
Expand Down Expand Up @@ -294,7 +296,7 @@ describe('MemberBreadService', function () {
const memberBreadService = getService();
const member = await memberBreadService.read({id: MEMBER_ID});

assert.equal(member.unsubscribe_url, 'https://example.com/unsubscribe/?uuid=123&key=456');
assert.equal(member.unsubscribe_url, `https://example.com/unsubscribe/?uuid=${MEMBER_UUID}&key=456`);
});
});
});

0 comments on commit 00bd31a

Please sign in to comment.