mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 23:24:03 +00:00
feat: do not compute status on non D&P content types
This commit is contained in:
parent
beccc55fe0
commit
9c51bcfcc5
@ -173,7 +173,7 @@ describe('CM API - Basic', () => {
|
||||
});
|
||||
|
||||
// TODO: Fix document service validations
|
||||
describe.skip('validators', () => {
|
||||
describe('validators', () => {
|
||||
test('Cannot publish a product - minLength', async () => {
|
||||
const product = {
|
||||
name: 'Product 1',
|
||||
@ -188,7 +188,7 @@ describe('CM API - Basic', () => {
|
||||
|
||||
const res = await rq({
|
||||
method: 'POST',
|
||||
url: `/content-manager/collection-types/api::product.product/${creationRes.body.documentId}/actions/publish`,
|
||||
url: `/content-manager/collection-types/api::product.product/${creationRes.body.data.documentId}/actions/publish`,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
@ -223,7 +223,7 @@ describe('CM API - Basic', () => {
|
||||
|
||||
const res = await rq({
|
||||
method: 'POST',
|
||||
url: `/content-manager/collection-types/api::product.product/${creationRes.body.documentId}/actions/publish`,
|
||||
url: `/content-manager/collection-types/api::product.product/${creationRes.body.data.documentId}/actions/publish`,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import type { LoadedStrapi as Strapi, Common } from '@strapi/types';
|
||||
import { groupBy, pick } from 'lodash/fp';
|
||||
|
||||
import { contentTypes } from '@strapi/utils';
|
||||
import type { LoadedStrapi as Strapi, Common } from '@strapi/types';
|
||||
|
||||
import type { DocumentMetadata } from '../../../shared/contracts/collection-types';
|
||||
|
||||
export interface DocumentVersion {
|
||||
@ -119,7 +122,7 @@ export default ({ strapi }: { strapi: Strapi }) => ({
|
||||
* @param documents
|
||||
* @returns
|
||||
*/
|
||||
async getManyAvailableStatus(uid: Common.UID.SingleType, documents: DocumentVersion[]) {
|
||||
async getManyAvailableStatus(uid: Common.UID.ContentType, documents: DocumentVersion[]) {
|
||||
if (!documents.length) return [];
|
||||
|
||||
// The status of all documents should be the same
|
||||
@ -206,14 +209,23 @@ export default ({ strapi }: { strapi: Strapi }) => ({
|
||||
) {
|
||||
if (!document) return document;
|
||||
|
||||
const hasDraftAndPublish = contentTypes.hasDraftAndPublish(strapi.getModel(uid));
|
||||
|
||||
// Ignore available status if the content type does not have draft and publish
|
||||
if (!hasDraftAndPublish) {
|
||||
opts.availableStatus = false;
|
||||
}
|
||||
|
||||
const meta = await this.getMetadata(uid, document, opts);
|
||||
|
||||
// TODO: Sanitize output of metadata
|
||||
return {
|
||||
data: {
|
||||
...document,
|
||||
// Add status to the document
|
||||
status: this.getStatus(document, meta.availableStatus as any),
|
||||
// Add status to the document only if draft and publish is enabled
|
||||
status: hasDraftAndPublish
|
||||
? this.getStatus(document, meta.availableStatus as any)
|
||||
: undefined,
|
||||
},
|
||||
meta,
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user