mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
Removed archived tiers from content api (#14329)
closes https://github.com/TryGhost/Team/issues/1426 When fetching tiers using the content API, we incorrectly returned all tiers including archived ones unless the active:true filter is passed. Correct behaviour is to always hide archived tiers, so this filter should not be required. - forces `active:true` filter for tiers content api browse - updates test to check for archived test removal in tiers content api
This commit is contained in:
parent
e630967c7a
commit
18b59d2c01
4 changed files with 49 additions and 2 deletions
|
@ -1,3 +1,13 @@
|
||||||
|
const localUtils = require('../../index');
|
||||||
|
|
||||||
|
const forceActiveFilter = (frame) => {
|
||||||
|
if (frame.options.filter) {
|
||||||
|
frame.options.filter = `(${frame.options.filter})+active:true`;
|
||||||
|
} else {
|
||||||
|
frame.options.filter = 'active:true';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
all(_apiConfig, frame) {
|
all(_apiConfig, frame) {
|
||||||
if (!frame.options.withRelated) {
|
if (!frame.options.withRelated) {
|
||||||
|
@ -18,6 +28,13 @@ module.exports = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
browse(_apiConfig, frame) {
|
||||||
|
if (localUtils.isContentAPI(frame)) {
|
||||||
|
// CASE: content api can only has active tiers
|
||||||
|
forceActiveFilter(frame);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
add(_apiConfig, frame) {
|
add(_apiConfig, frame) {
|
||||||
if (frame.data.products) {
|
if (frame.data.products) {
|
||||||
frame.data = frame.data.products[0];
|
frame.data = frame.data.products[0];
|
||||||
|
|
|
@ -5,11 +5,11 @@ describe('Tiers Content API', function () {
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
agent = await agentProvider.getContentAPIAgent();
|
agent = await agentProvider.getContentAPIAgent();
|
||||||
await fixtureManager.init('members', 'api_keys');
|
await fixtureManager.init('members', 'api_keys', 'tiers:archived');
|
||||||
agent.authenticate();
|
agent.authenticate();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can request tiers', async function () {
|
it('Can request only active tiers', async function () {
|
||||||
await agent.get('/tiers/')
|
await agent.get('/tiers/')
|
||||||
.expectStatus(200)
|
.expectStatus(200)
|
||||||
.matchHeaderSnapshot({
|
.matchHeaderSnapshot({
|
||||||
|
|
|
@ -457,6 +457,14 @@ const fixtures = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
insertArchivedTiers: function insertArchivedTiers() {
|
||||||
|
let archivedProduct = DataGenerator.forKnex.createProduct({
|
||||||
|
active: false
|
||||||
|
});
|
||||||
|
|
||||||
|
return models.Product.add(archivedProduct, context.internal);
|
||||||
|
},
|
||||||
|
|
||||||
insertMembersAndLabelsAndProducts: function insertMembersAndLabelsAndProducts() {
|
insertMembersAndLabelsAndProducts: function insertMembersAndLabelsAndProducts() {
|
||||||
return Promise.map(DataGenerator.forKnex.labels, function (label) {
|
return Promise.map(DataGenerator.forKnex.labels, function (label) {
|
||||||
return models.Label.add(label, context.internal);
|
return models.Label.add(label, context.internal);
|
||||||
|
@ -693,6 +701,9 @@ const toDoList = {
|
||||||
},
|
},
|
||||||
custom_theme_settings: function insertCustomThemeSettings() {
|
custom_theme_settings: function insertCustomThemeSettings() {
|
||||||
return fixtures.insertCustomThemeSettings();
|
return fixtures.insertCustomThemeSettings();
|
||||||
|
},
|
||||||
|
'tiers:archived': function insertArchivedTiers() {
|
||||||
|
return fixtures.insertArchivedTiers();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -911,6 +911,24 @@ DataGenerator.forKnex = (function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createProduct(overrides) {
|
||||||
|
const newObj = _.cloneDeep(overrides);
|
||||||
|
|
||||||
|
return _.defaults(newObj, {
|
||||||
|
id: ObjectId().toHexString(),
|
||||||
|
name: 'product',
|
||||||
|
slug: 'gold',
|
||||||
|
active: true,
|
||||||
|
type: 'paid',
|
||||||
|
visibility: 'public',
|
||||||
|
benefits: [],
|
||||||
|
created_by: DataGenerator.Content.users[0].id,
|
||||||
|
created_at: new Date(),
|
||||||
|
updated_by: DataGenerator.Content.users[0].id,
|
||||||
|
updated_at: new Date()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function createMembersLabels(member_id, label_id, sort_order = 0) {
|
function createMembersLabels(member_id, label_id, sort_order = 0) {
|
||||||
return {
|
return {
|
||||||
id: ObjectId().toHexString(),
|
id: ObjectId().toHexString(),
|
||||||
|
@ -1337,6 +1355,7 @@ DataGenerator.forKnex = (function () {
|
||||||
createIntegration,
|
createIntegration,
|
||||||
createEmail,
|
createEmail,
|
||||||
createCustomThemeSetting: createBasic,
|
createCustomThemeSetting: createBasic,
|
||||||
|
createProduct,
|
||||||
|
|
||||||
invites,
|
invites,
|
||||||
posts,
|
posts,
|
||||||
|
|
Loading…
Add table
Reference in a new issue