feat(content-releases): add publish webhook (#19515)

* feat(content-releases): add publish webhook

* apply Marks feedback
This commit is contained in:
Fernando Chávez 2024-02-20 14:38:27 +01:00 committed by GitHub
parent 8d3598965d
commit 4af8963f68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 675 additions and 597 deletions

View File

@ -1 +1,5 @@
module.exports = ({ env }) => ({}); module.exports = ({ env }) => ({
future: {
contentReleasesScheduling: env('STRAPI_FUTURE_CONTENT_RELEASES_SCHEDULING', false),
},
});

View File

@ -1,11 +1,21 @@
import { Events } from '../../../../../../../../admin/src/pages/Settings/pages/Webhooks/components/Events'; import { Events } from '../../../../../../../../admin/src/pages/Settings/pages/Webhooks/components/Events';
const events = { const eeTables = {
'review-workflows': ['review-workflows.updateEntryStage'], 'review-workflows': {
'review-workflows': ['review-workflows.updateEntryStage'],
},
releases: {
releases: ['releases.publish'],
},
}; };
const getHeaders = () => { const getHeaders = (table: keyof typeof eeTables) => {
return [{ id: 'review-workflows.updateEntryStage', defaultMessage: 'Stage Change' }]; switch (table) {
case 'review-workflows':
return () => [{ id: 'review-workflows.updateEntryStage', defaultMessage: 'Stage Change' }];
case 'releases':
return () => [{ id: 'releases.publish', defaultMessage: 'Publish' }];
}
}; };
const EventsTableEE = () => { const EventsTableEE = () => {
@ -13,8 +23,12 @@ const EventsTableEE = () => {
<Events.Root> <Events.Root>
<Events.Headers /> <Events.Headers />
<Events.Body /> <Events.Body />
<Events.Headers getHeaders={getHeaders} /> {(Object.keys(eeTables) as Array<keyof typeof eeTables>).map((table) => (
<Events.Body providedEvents={events} /> <>
<Events.Headers getHeaders={getHeaders(table)} />
<Events.Body providedEvents={eeTables[table]} />
</>
))}
</Events.Root> </Events.Root>
); );
}; };

View File

@ -84,6 +84,9 @@ describe('bootstrap', () => {
log: { log: {
error: jest.fn(), error: jest.fn(),
}, },
webhookStore: {
addAllowedEvent: jest.fn(),
},
}; };
beforeEach(() => { beforeEach(() => {

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-var-requires */ /* eslint-disable @typescript-eslint/no-var-requires */
import type { LoadedStrapi, Entity as StrapiEntity } from '@strapi/types'; import type { LoadedStrapi, Entity as StrapiEntity } from '@strapi/types';
import { RELEASE_ACTION_MODEL_UID } from './constants'; import { ALLOWED_WEBHOOK_EVENTS, RELEASE_ACTION_MODEL_UID } from './constants';
import { getService } from './utils'; import { getService } from './utils';
const { features } = require('@strapi/strapi/dist/utils/ee'); const { features } = require('@strapi/strapi/dist/utils/ee');
@ -69,6 +69,10 @@ export const bootstrap = async ({ strapi }: { strapi: LoadedStrapi }) => {
throw err; throw err;
}); });
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
strapi.webhookStore.addAllowedEvent(key, value);
});
} }
} }
}; };

View File

@ -45,3 +45,7 @@ export const ACTIONS = [
pluginName: 'content-releases', pluginName: 'content-releases',
}, },
]; ];
export const ALLOWED_WEBHOOK_EVENTS = {
RELEASES_PUBLISH: 'releases.publish',
};

View File

@ -26,6 +26,9 @@ const baseStrapiMock = {
isEnabled: jest.fn().mockReturnValue(true), isEnabled: jest.fn().mockReturnValue(true),
}, },
}, },
eventHub: {
emit: jest.fn(),
},
telemetry: { telemetry: {
send: jest.fn().mockReturnValue(true), send: jest.fn().mockReturnValue(true),
}, },

File diff suppressed because it is too large Load Diff