mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -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 = {
|
||||
all(_apiConfig, frame) {
|
||||
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) {
|
||||
if (frame.data.products) {
|
||||
frame.data = frame.data.products[0];
|
||||
|
|
|
@ -5,11 +5,11 @@ describe('Tiers Content API', function () {
|
|||
|
||||
before(async function () {
|
||||
agent = await agentProvider.getContentAPIAgent();
|
||||
await fixtureManager.init('members', 'api_keys');
|
||||
await fixtureManager.init('members', 'api_keys', 'tiers:archived');
|
||||
agent.authenticate();
|
||||
});
|
||||
|
||||
it('Can request tiers', async function () {
|
||||
it('Can request only active tiers', async function () {
|
||||
await agent.get('/tiers/')
|
||||
.expectStatus(200)
|
||||
.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() {
|
||||
return Promise.map(DataGenerator.forKnex.labels, function (label) {
|
||||
return models.Label.add(label, context.internal);
|
||||
|
@ -693,6 +701,9 @@ const toDoList = {
|
|||
},
|
||||
custom_theme_settings: function 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) {
|
||||
return {
|
||||
id: ObjectId().toHexString(),
|
||||
|
@ -1337,6 +1355,7 @@ DataGenerator.forKnex = (function () {
|
|||
createIntegration,
|
||||
createEmail,
|
||||
createCustomThemeSetting: createBasic,
|
||||
createProduct,
|
||||
|
||||
invites,
|
||||
posts,
|
||||
|
|
Loading…
Add table
Reference in a new issue