0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-18 02:21:47 -05:00

Added ability to filter members on signup attribution

refs https://github.com/TryGhost/Team/issues/1831
This commit is contained in:
Fabien "egg" O'Carroll 2022-08-22 14:19:13 -04:00
parent 36d9ae36ae
commit 83f2bf4757
5 changed files with 131 additions and 1 deletions

View file

@ -40,6 +40,9 @@ const Member = ghostBookshelf.Model.extend({
}, {
key: 'newsletters',
replacement: 'newsletters.slug'
}, {
key: 'signup',
replacement: 'signups.attribution_id'
}];
},
@ -74,6 +77,12 @@ const Member = ghostBookshelf.Model.extend({
joinFrom: 'member_id',
joinTo: 'customer_id',
joinToForeign: 'customer_id'
},
signups: {
tableName: 'members_created_events',
tableNameAs: 'signups',
type: 'oneToOne',
joinFrom: 'member_id'
}
};
},

View file

@ -1837,6 +1837,98 @@ Object {
}
`;
exports[`Members API Can filter by signup attribution 1: [body] 1`] = `
Object {
"members": Array [
Object {
"avatar_image": null,
"comped": false,
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"email": "vip-paid@test.com",
"email_count": 0,
"email_open_rate": null,
"email_opened_count": 0,
"geolocation": null,
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"labels": Any<Array>,
"last_seen_at": null,
"name": "Peter Venkman",
"newsletters": Any<Array>,
"note": null,
"status": "paid",
"subscribed": false,
"subscriptions": Any<Array>,
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
},
Object {
"avatar_image": null,
"comped": false,
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"email": "trialing@test.com",
"email_count": 0,
"email_open_rate": null,
"email_opened_count": 0,
"geolocation": null,
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"labels": Any<Array>,
"last_seen_at": null,
"name": "Ray Stantz",
"newsletters": Any<Array>,
"note": null,
"status": "paid",
"subscribed": true,
"subscriptions": Any<Array>,
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
},
Object {
"avatar_image": null,
"comped": false,
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"email": "member1@test.com",
"email_count": 0,
"email_open_rate": null,
"email_opened_count": 0,
"geolocation": null,
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"labels": Any<Array>,
"last_seen_at": null,
"name": "Mr Egg",
"newsletters": Any<Array>,
"note": null,
"status": "free",
"subscribed": true,
"subscriptions": Any<Array>,
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
},
],
"meta": Object {
"pagination": Object {
"limit": 15,
"next": null,
"page": 1,
"pages": 1,
"prev": null,
"total": 3,
},
},
}
`;
exports[`Members API Can filter by signup attribution 2: [headers] 1`] = `
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": "4367",
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"vary": "Origin, Accept-Encoding",
"x-powered-by": "Express",
}
`;
exports[`Members API Can filter on newsletter slug 1: [body] 1`] = `
Object {
"members": Array [

View file

@ -222,6 +222,19 @@ describe('Members API', function () {
});
});
it('Can filter by signup attribution', async function () {
await agent
.get('/members/?filter=signup:' + fixtureManager.get('posts', 0).id)
.expectStatus(200)
.matchBodySnapshot({
members: new Array(3).fill(memberMatcherShallowIncludes)
})
.matchHeaderSnapshot({
etag: anyEtag
});
});
it('Can browse with search', async function () {
await agent
.get('/members/?search=member1')

View file

@ -579,6 +579,10 @@ const fixtures = {
for (const event of DataGenerator.forKnex.members_paid_subscription_events) {
await models.MemberPaidSubscriptionEvent.add(event);
}
}).then(async function () {
for (const event of DataGenerator.forKnex.members_created_events) {
await models.MemberCreatedEvent.add(event);
}
});
},

View file

@ -1531,6 +1531,17 @@ DataGenerator.forKnex = (function () {
createMember(DataGenerator.Content.members[7])
];
const members_created_events = members.map((member, index) => {
return {
id: ObjectId().toHexString(),
member_id: member.id,
source: 'system',
attribution_type: 'post',
attribution_id: DataGenerator.Content.posts[index % 3].id,
attribution_url: '/' + DataGenerator.Content.posts[index % 3].slug
};
});
const newsletters = [
createNewsletter(DataGenerator.Content.newsletters[0]),
createNewsletter(DataGenerator.Content.newsletters[1]),
@ -1672,7 +1683,8 @@ DataGenerator.forKnex = (function () {
custom_theme_settings,
comments,
members_paid_subscription_events
members_paid_subscription_events,
members_created_events
};
}());