From 63fe0136062bee22a1a1a7a2b0e979ce197ab877 Mon Sep 17 00:00:00 2001 From: "Fabien \"egg\" O'Carroll" Date: Tue, 1 Nov 2022 11:31:49 +0700 Subject: [PATCH 1/3] Fixed verification trigger usage of Event Repository refs https://github.com/TryGhost/Team/issues/2192 The method signatures of the Event Repository have been updated to take mongo filter objects, but this call-site was not updated. Long term we should really be using NQL filter strings for our filtering API and the mongo filter objects should be an implementation detail, however we don't have time right now to rectify this. --- .../lib/verification-trigger.js | 12 ++++--- .../test/verification-trigger.test.js | 36 ++++++++++--------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/ghost/verification-trigger/lib/verification-trigger.js b/ghost/verification-trigger/lib/verification-trigger.js index cb45ff7040..7d611c1ee1 100644 --- a/ghost/verification-trigger/lib/verification-trigger.js +++ b/ghost/verification-trigger/lib/verification-trigger.js @@ -67,8 +67,10 @@ class VerificationTrigger { const createdAt = new Date(); createdAt.setDate(createdAt.getDate() - 30); const events = await this._eventRepository.getCreatedEvents({}, { - 'data.source': `data.source:'${source}'`, - 'data.created_at': `data.created_at:>'${createdAt.toISOString().replace('T', ' ').substring(0, 19)}'` + source: source, + created_at: { + $gt: createdAt.toISOString().replace('T', ' ').substring(0, 19) + } }); if (events.meta.pagination.total > sourceThreshold) { @@ -100,8 +102,10 @@ class VerificationTrigger { const createdAt = new Date(); createdAt.setDate(createdAt.getDate() - 30); const events = await this._eventRepository.getCreatedEvents({}, { - 'data.source': `data.source:'import'`, - 'data.created_at': `data.created_at:>'${createdAt.toISOString().replace('T', ' ').substring(0, 19)}'` + source: 'import', + created_at: { + $gt: createdAt.toISOString().replace('T', ' ').substring(0, 19) + } }); const membersTotal = await this._membersStats.getTotalMembers(); diff --git a/ghost/verification-trigger/test/verification-trigger.test.js b/ghost/verification-trigger/test/verification-trigger.test.js index d4c4859737..5f44743b69 100644 --- a/ghost/verification-trigger/test/verification-trigger.test.js +++ b/ghost/verification-trigger/test/verification-trigger.test.js @@ -185,10 +185,11 @@ describe('Email verification flow', function () { }, new Date())); eventStub.callCount.should.eql(1); - eventStub.lastCall.lastArg.should.have.property('data.source'); - eventStub.lastCall.lastArg.should.have.property('data.created_at'); - eventStub.lastCall.lastArg['data.source'].should.eql(`data.source:'api'`); - eventStub.lastCall.lastArg['data.created_at'].should.startWith(`data.created_at:>'`); + eventStub.lastCall.lastArg.should.have.property('source'); + eventStub.lastCall.lastArg.source.should.eql('api'); + eventStub.lastCall.lastArg.should.have.property('created_at'); + eventStub.lastCall.lastArg.created_at.should.have.property('$gt'); + eventStub.lastCall.lastArg.created_at.$gt.should.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/); }); it('Triggers when a number of members are imported', async function () { @@ -221,10 +222,11 @@ describe('Email verification flow', function () { await trigger.testImportThreshold(); eventStub.callCount.should.eql(1); - eventStub.lastCall.lastArg.should.have.property('data.source'); - eventStub.lastCall.lastArg.should.have.property('data.created_at'); - eventStub.lastCall.lastArg['data.source'].should.eql(`data.source:'import'`); - eventStub.lastCall.lastArg['data.created_at'].should.startWith(`data.created_at:>'`); + eventStub.lastCall.lastArg.should.have.property('source'); + eventStub.lastCall.lastArg.source.should.eql('import'); + eventStub.lastCall.lastArg.should.have.property('created_at'); + eventStub.lastCall.lastArg.created_at.should.have.property('$gt'); + eventStub.lastCall.lastArg.created_at.$gt.should.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/); emailStub.callCount.should.eql(1); emailStub.lastCall.firstArg.should.eql({ @@ -268,10 +270,11 @@ describe('Email verification flow', function () { }); eventStub.callCount.should.eql(1); - eventStub.lastCall.lastArg.should.have.property('data.source'); - eventStub.lastCall.lastArg.should.have.property('data.created_at'); - eventStub.lastCall.lastArg['data.source'].should.eql(`data.source:'admin'`); - eventStub.lastCall.lastArg['data.created_at'].should.startWith(`data.created_at:>'`); + eventStub.lastCall.lastArg.should.have.property('source'); + eventStub.lastCall.lastArg.source.should.eql('admin'); + eventStub.lastCall.lastArg.should.have.property('created_at'); + eventStub.lastCall.lastArg.created_at.should.have.property('$gt'); + eventStub.lastCall.lastArg.created_at.$gt.should.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/); emailStub.callCount.should.eql(1); emailStub.lastCall.firstArg.should.eql({ @@ -316,10 +319,11 @@ describe('Email verification flow', function () { }); eventStub.callCount.should.eql(1); - eventStub.lastCall.lastArg.should.have.property('data.source'); - eventStub.lastCall.lastArg.should.have.property('data.created_at'); - eventStub.lastCall.lastArg['data.source'].should.eql(`data.source:'api'`); - eventStub.lastCall.lastArg['data.created_at'].should.startWith(`data.created_at:>'`); + eventStub.lastCall.lastArg.should.have.property('source'); + eventStub.lastCall.lastArg.source.should.eql('api'); + eventStub.lastCall.lastArg.should.have.property('created_at'); + eventStub.lastCall.lastArg.created_at.should.have.property('$gt'); + eventStub.lastCall.lastArg.created_at.$gt.should.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/); emailStub.callCount.should.eql(1); emailStub.lastCall.firstArg.should.eql({ From a0ebb9a6f338fd2295a041ad736de758084c1295 Mon Sep 17 00:00:00 2001 From: Fabien 'egg' O'Carroll Date: Tue, 1 Nov 2022 16:25:55 +0700 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20Tier=20description?= =?UTF-8?q?=20not=20being=20set=20=20(#15741)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/TryGhost/Ghost/issues/15740 The validation function for a Tier description was not returning the validated value, which meant we were unable to set the Tier description. --- ghost/core/test/e2e-api/admin/tiers.test.js | 16 ++++++++++++++++ ghost/tiers/lib/Tier.js | 1 + ghost/tiers/test/Tier.test.js | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/ghost/core/test/e2e-api/admin/tiers.test.js b/ghost/core/test/e2e-api/admin/tiers.test.js index f1a97d36ca..080887e5a6 100644 --- a/ghost/core/test/e2e-api/admin/tiers.test.js +++ b/ghost/core/test/e2e-api/admin/tiers.test.js @@ -126,4 +126,20 @@ describe('Tiers API', function () { assert(updatedTier.trial_days === 0, `The trial_days should have been set to 0`); }); + + it('Can edit description', async function () { + const {body: {tiers: [tier]}} = await agent.get('/tiers/?type:paid&limit=1'); + + await agent.put(`/tiers/${tier.id}/`) + .body({ + tiers: [{ + description: 'Updated description' + }] + }) + .expectStatus(200); + + const {body: {tiers: [updatedTier]}} = await agent.get(`/tiers/${tier.id}/`); + + assert.strictEqual('Updated description', updatedTier.description); + }); }); diff --git a/ghost/tiers/lib/Tier.js b/ghost/tiers/lib/Tier.js index 8a40c71655..6b0345c0a6 100644 --- a/ghost/tiers/lib/Tier.js +++ b/ghost/tiers/lib/Tier.js @@ -338,6 +338,7 @@ function validateDescription(value) { message: 'Tier description must be a string with a maximum of 191 characters' }); } + return value; } function validateStatus(value) { diff --git a/ghost/tiers/test/Tier.test.js b/ghost/tiers/test/Tier.test.js index 51ed7286b9..6037de7602 100644 --- a/ghost/tiers/test/Tier.test.js +++ b/ghost/tiers/test/Tier.test.js @@ -251,5 +251,13 @@ describe('Tier', function () { }); }); }); + + it('Can set the description of a Tier', async function () { + const tier = await Tier.create(validInput); + + tier.description = 'Updated description'; + + assert.strictEqual('Updated description', tier.description); + }); }); }); From 3c71d07dfb351d75d3f76eca1152b78bca241eef Mon Sep 17 00:00:00 2001 From: Ghost CI <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 1 Nov 2022 09:28:14 +0000 Subject: [PATCH 3/3] v5.22.2 --- ghost/admin/package.json | 2 +- ghost/core/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ghost/admin/package.json b/ghost/admin/package.json index 43f7fdefb7..a233ca86bf 100644 --- a/ghost/admin/package.json +++ b/ghost/admin/package.json @@ -1,6 +1,6 @@ { "name": "ghost-admin", - "version": "5.22.1", + "version": "5.22.2", "description": "Ember.js admin client for Ghost", "author": "Ghost Foundation", "homepage": "http://ghost.org", diff --git a/ghost/core/package.json b/ghost/core/package.json index a50caa2e27..8e79ee8195 100644 --- a/ghost/core/package.json +++ b/ghost/core/package.json @@ -1,6 +1,6 @@ { "name": "ghost", - "version": "5.22.1", + "version": "5.22.2", "description": "The professional publishing platform", "author": "Ghost Foundation", "homepage": "https://ghost.org",