Changed webhooks to store safe version

refs: https://github.com/TryGhost/Toolbox/issues/229

- We're getting rid of the concept of api versions inside of Ghost
- Instead of storing the supposed api version a webhook was created with, store the current ghost version
- This way we can determine if anything signicant changes in future and we need to update webhooks or something
This commit is contained in:
Hannah Wolfe 2022-05-06 12:40:55 +01:00
parent d3ea145c19
commit 401fe46380
No known key found for this signature in database
GPG Key ID: AB586C3B5AE5C037
3 changed files with 8 additions and 9 deletions

View File

@ -1,5 +1,6 @@
const Promise = require('bluebird');
const ghostBookshelf = require('./base');
const ghostVersion = require('@tryghost/version');
let Webhook;
let Webhooks;
@ -8,7 +9,7 @@ Webhook = ghostBookshelf.Model.extend({
defaults() {
return {
api_version: 'v4',
api_version: `v${ghostVersion.safe}`,
status: 'available'
};
},

View File

@ -4,7 +4,7 @@ exports[`Webhooks API Can create a webhook 1: [body] 1`] = `
Object {
"webhooks": Array [
Object {
"api_version": "canary",
"api_version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}/,
"event": "test.create",
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
@ -26,7 +26,7 @@ exports[`Webhooks API Can create a webhook 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": "414",
"content-length": "413",
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"vary": "Origin, Accept-Encoding",
@ -48,7 +48,7 @@ exports[`Webhooks API Can edit a webhook 1: [body] 1`] = `
Object {
"webhooks": Array [
Object {
"api_version": "canary",
"api_version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}/,
"event": "subscriber.added",
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
@ -70,7 +70,7 @@ exports[`Webhooks API Can edit a webhook 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": "418",
"content-length": "417",
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"vary": "Origin, Accept-Encoding",

View File

@ -1,9 +1,9 @@
const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
const {anyEtag, anyErrorId, anyObjectId, anyISODate} = matchers;
const API_VERSION = 'canary';
const {anyEtag, anyErrorId, anyObjectId, anyISODate, stringMatching} = matchers;
const webhookMatcher = {
id: anyObjectId,
api_version: stringMatching(/v\d+\.\d+/),
integration_id: anyObjectId,
created_at: anyISODate,
updated_at: anyISODate
@ -25,7 +25,6 @@ describe('Webhooks API', function () {
target_url: 'http://example.com/webhooks/test/extra/1',
name: 'test',
secret: 'thisissecret',
api_version: API_VERSION,
integration_id: fixtureManager.get('integrations', 0).id
};
});
@ -69,7 +68,6 @@ describe('Webhooks API', function () {
target_url: 'http://example.com/webhooks/test/extra/10',
name: 'test',
secret: 'thisissecret',
api_version: API_VERSION,
integration_id: `fake-integration`
}]})
.expectStatus(422)