mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 10:23:34 +00:00
Avoid ct and st abbreviation
This commit is contained in:
parent
6729cd1a1a
commit
77e05c260a
@ -7,12 +7,18 @@ export const getInitData = () => ({
|
||||
export const resetInitData = () => ({ type: RESET_INIT_DATA });
|
||||
|
||||
export const setInitData = ({
|
||||
authorizedCtLinks,
|
||||
authorizedStLinks,
|
||||
authorizedCollectionTypeLinks,
|
||||
authorizedSingleTypeLinks,
|
||||
contentTypeSchemas,
|
||||
components,
|
||||
fieldSizes,
|
||||
}) => ({
|
||||
type: SET_INIT_DATA,
|
||||
data: { authorizedCtLinks, authorizedStLinks, components, contentTypeSchemas, fieldSizes },
|
||||
data: {
|
||||
authorizedCollectionTypeLinks,
|
||||
authorizedSingleTypeLinks,
|
||||
components,
|
||||
contentTypeSchemas,
|
||||
fieldSizes,
|
||||
},
|
||||
});
|
||||
|
||||
@ -28,10 +28,10 @@ const mainReducer = (state = initialState, action) =>
|
||||
return initialState;
|
||||
}
|
||||
case SET_INIT_DATA: {
|
||||
draftState.collectionTypeLinks = action.data.authorizedCtLinks.filter(
|
||||
draftState.collectionTypeLinks = action.data.authorizedCollectionTypeLinks.filter(
|
||||
({ isDisplayed }) => isDisplayed
|
||||
);
|
||||
draftState.singleTypeLinks = action.data.authorizedStLinks.filter(
|
||||
draftState.singleTypeLinks = action.data.authorizedSingleTypeLinks.filter(
|
||||
({ isDisplayed }) => isDisplayed
|
||||
);
|
||||
draftState.components = action.data.components;
|
||||
|
||||
@ -2,8 +2,8 @@ import { setInitData } from '../actions';
|
||||
|
||||
describe('Content Manager | App | actions', () => {
|
||||
it('should format the setInitData action', () => {
|
||||
const authorizedCtLinks = [{ title: 'addresses', uid: 'address' }];
|
||||
const authorizedStLinks = [{ title: 'Home page', uid: 'homepage' }];
|
||||
const authorizedCollectionTypeLinks = [{ title: 'addresses', uid: 'address' }];
|
||||
const authorizedSingleTypeLinks = [{ title: 'Home page', uid: 'homepage' }];
|
||||
const contentTypeSchemas = [
|
||||
{ kind: 'singleType', uid: 'homepage' },
|
||||
{ kind: 'collectionType', uid: 'address' },
|
||||
@ -13,15 +13,20 @@ describe('Content Manager | App | actions', () => {
|
||||
const expected = {
|
||||
type: 'ContentManager/App/SET_INIT_DATA',
|
||||
data: {
|
||||
authorizedCtLinks,
|
||||
authorizedStLinks,
|
||||
authorizedCollectionTypeLinks,
|
||||
authorizedSingleTypeLinks,
|
||||
contentTypeSchemas,
|
||||
components,
|
||||
},
|
||||
};
|
||||
|
||||
expect(
|
||||
setInitData({ authorizedCtLinks, authorizedStLinks, contentTypeSchemas, components })
|
||||
setInitData({
|
||||
authorizedCollectionTypeLinks,
|
||||
authorizedSingleTypeLinks,
|
||||
contentTypeSchemas,
|
||||
components,
|
||||
})
|
||||
).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@ -31,7 +31,7 @@ describe('Content Manager | App | reducer', () => {
|
||||
});
|
||||
|
||||
it('should handle the setInitData action correctly', () => {
|
||||
const collectionTypeLinks = [
|
||||
const authorizedCollectionTypeLinks = [
|
||||
{
|
||||
name: 'authorizedCt',
|
||||
isDisplayed: true,
|
||||
@ -41,7 +41,7 @@ describe('Content Manager | App | reducer', () => {
|
||||
isDisplayed: false,
|
||||
},
|
||||
];
|
||||
const singleTypeLinks = [
|
||||
const authorizedSingleTypeLinks = [
|
||||
{
|
||||
name: 'authorizedSt',
|
||||
isDisplayed: false,
|
||||
@ -73,8 +73,8 @@ describe('Content Manager | App | reducer', () => {
|
||||
mainReducer(
|
||||
state,
|
||||
setInitData({
|
||||
authorizedCtLinks: collectionTypeLinks,
|
||||
authorizedStLinks: singleTypeLinks,
|
||||
authorizedCollectionTypeLinks,
|
||||
authorizedSingleTypeLinks,
|
||||
contentTypeSchemas: ['test'],
|
||||
components: ['test'],
|
||||
fieldSizes: {},
|
||||
|
||||
@ -44,24 +44,24 @@ const useContentManagerInitData = () => {
|
||||
})
|
||||
);
|
||||
|
||||
const { authorizedCtLinks, authorizedStLinks } = await getContentTypeLinks(
|
||||
const { authorizedContentTypeLinks, authorizedSingleTypeLinks } = await getContentTypeLinks({
|
||||
models,
|
||||
allPermissions,
|
||||
toggleNotification
|
||||
);
|
||||
userPermissions: allPermissions,
|
||||
toggleNotification,
|
||||
});
|
||||
|
||||
const { ctLinks } = runHookWaterfall(MUTATE_COLLECTION_TYPES_LINKS, {
|
||||
ctLinks: authorizedCtLinks,
|
||||
ctLinks: authorizedContentTypeLinks,
|
||||
models,
|
||||
});
|
||||
const { stLinks } = runHookWaterfall(MUTATE_SINGLE_TYPES_LINKS, {
|
||||
stLinks: authorizedStLinks,
|
||||
stLinks: authorizedSingleTypeLinks,
|
||||
models,
|
||||
});
|
||||
|
||||
const actionToDispatch = setInitData({
|
||||
authorizedCtLinks: ctLinks,
|
||||
authorizedStLinks: stLinks,
|
||||
authorizedCollectionTypeLinks: ctLinks,
|
||||
authorizedSingleTypeLinks: stLinks,
|
||||
contentTypeSchemas: models,
|
||||
components,
|
||||
fieldSizes,
|
||||
|
||||
@ -52,12 +52,12 @@ const generateModelsLinks = (models, modelsConfigurations) => {
|
||||
const [collectionTypes, singleTypes] = sortBy(groupedModels, 'name');
|
||||
|
||||
return {
|
||||
collectionTypesSectionLinks: generateLinks(
|
||||
collectionTypeSectionLinks: generateLinks(
|
||||
collectionTypes?.links || [],
|
||||
'collectionTypes',
|
||||
modelsConfigurations
|
||||
),
|
||||
singleTypesSectionLinks: generateLinks(singleTypes?.links ?? [], 'singleTypes'),
|
||||
singleTypeSectionLinks: generateLinks(singleTypes?.links ?? [], 'singleTypes'),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -3,36 +3,38 @@ import generateModelsLinks from './generateModelsLinks';
|
||||
import checkPermissions from './checkPermissions';
|
||||
import { getRequestUrl } from '../../../utils';
|
||||
|
||||
const getContentTypeLinks = async (models, userPermissions, toggleNotification) => {
|
||||
const getContentTypeLinks = async ({ models, userPermissions, toggleNotification }) => {
|
||||
const { get } = getFetchClient();
|
||||
try {
|
||||
const {
|
||||
data: { data: contentTypeConfigurations },
|
||||
} = await get(getRequestUrl('content-types-settings'));
|
||||
|
||||
const { collectionTypesSectionLinks, singleTypesSectionLinks } = generateModelsLinks(
|
||||
const { collectionTypeSectionLinks, singleTypeSectionLinks } = generateModelsLinks(
|
||||
models,
|
||||
contentTypeConfigurations
|
||||
);
|
||||
|
||||
// Content Types verifications
|
||||
const ctLinksPermissionsPromises = checkPermissions(
|
||||
userPermissions,
|
||||
collectionTypesSectionLinks
|
||||
// Collection Types verifications
|
||||
const collectionTypeLinksPermissions = await Promise.all(
|
||||
checkPermissions(userPermissions, collectionTypeSectionLinks)
|
||||
);
|
||||
const ctLinksPermissions = await Promise.all(ctLinksPermissionsPromises);
|
||||
const authorizedCtLinks = collectionTypesSectionLinks.filter(
|
||||
(_, index) => ctLinksPermissions[index]
|
||||
const authorizedCollectionTypeLinks = collectionTypeSectionLinks.filter(
|
||||
(_, index) => collectionTypeLinksPermissions[index]
|
||||
);
|
||||
|
||||
// Single Types verifications
|
||||
const stLinksPermissionsPromises = checkPermissions(userPermissions, singleTypesSectionLinks);
|
||||
const stLinksPermissions = await Promise.all(stLinksPermissionsPromises);
|
||||
const authorizedStLinks = singleTypesSectionLinks.filter(
|
||||
(_, index) => stLinksPermissions[index]
|
||||
const singleTypeLinksPermissions = await Promise.all(
|
||||
checkPermissions(userPermissions, singleTypeSectionLinks)
|
||||
);
|
||||
const authorizedSingleTypeLinks = singleTypeSectionLinks.filter(
|
||||
(_, index) => singleTypeLinksPermissions[index]
|
||||
);
|
||||
|
||||
return { authorizedCtLinks, authorizedStLinks };
|
||||
return {
|
||||
authorizedCollectionTypeLinks,
|
||||
authorizedSingleTypeLinks,
|
||||
};
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
@ -41,7 +43,7 @@ const getContentTypeLinks = async (models, userPermissions, toggleNotification)
|
||||
message: { id: 'notification.error' },
|
||||
});
|
||||
|
||||
return { authorizedCtLinks: [], authorizedStLinks: [], contentTypes: [] };
|
||||
return { authorizedCollectionTypeLinks: [], authorizedSingleTypeLinks: [] };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -119,7 +119,7 @@ describe('ADMIN | LeftMenu | utils', () => {
|
||||
];
|
||||
|
||||
const expected = {
|
||||
collectionTypesSectionLinks: [
|
||||
collectionTypeSectionLinks: [
|
||||
{
|
||||
isDisplayed: true,
|
||||
search: null,
|
||||
@ -140,7 +140,7 @@ describe('ADMIN | LeftMenu | utils', () => {
|
||||
],
|
||||
},
|
||||
],
|
||||
singleTypesSectionLinks: [
|
||||
singleTypeSectionLinks: [
|
||||
{
|
||||
isDisplayed: true,
|
||||
kind: 'singleType',
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { request, hasPermissions } from '@strapi/helper-plugin';
|
||||
import { getFetchClient, hasPermissions } from '@strapi/helper-plugin';
|
||||
import getContentTypeLinks from '../getContentTypeLinks';
|
||||
|
||||
// FIXME
|
||||
@ -44,24 +44,24 @@ describe('checkPermissions', () => {
|
||||
},
|
||||
];
|
||||
|
||||
const data = [
|
||||
const contentTypes = [
|
||||
{
|
||||
uid: 'api::address.address',
|
||||
isDisplayed: true,
|
||||
apiID: 'address',
|
||||
kind: 'collectionType',
|
||||
info: {
|
||||
label: 'address',
|
||||
displayName: 'Address',
|
||||
},
|
||||
isDisplayed: true,
|
||||
kind: 'collectionType',
|
||||
uid: 'api::address.address',
|
||||
},
|
||||
{
|
||||
uid: 'api::article.article',
|
||||
isDisplayed: true,
|
||||
apiID: 'article',
|
||||
kind: 'collectionType',
|
||||
info: {
|
||||
label: 'article',
|
||||
displayName: 'Article',
|
||||
},
|
||||
isDisplayed: true,
|
||||
kind: 'collectionType',
|
||||
uid: 'api::article.article',
|
||||
pluginOptions: {
|
||||
i18n: {
|
||||
localized: true,
|
||||
@ -70,32 +70,36 @@ describe('checkPermissions', () => {
|
||||
},
|
||||
];
|
||||
|
||||
request.mockImplementation((url) => {
|
||||
if (url === '/content-manager/content-types') {
|
||||
return Promise.resolve({ data });
|
||||
}
|
||||
|
||||
return Promise.resolve({
|
||||
data: [
|
||||
{
|
||||
uid: 'api::address.address',
|
||||
settings: {
|
||||
pageSize: 10,
|
||||
defaultSortBy: 'name',
|
||||
defaultSortOrder: 'ASC',
|
||||
getFetchClient.mockImplementation(() => ({
|
||||
get(url) {
|
||||
if (url === '/content-manager/content-types-settings') {
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
data: [
|
||||
{
|
||||
uid: 'api::address.address',
|
||||
settings: {
|
||||
pageSize: 10,
|
||||
defaultSortBy: 'name',
|
||||
defaultSortOrder: 'ASC',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// To please the linter
|
||||
return Promise.resolve(null);
|
||||
},
|
||||
}));
|
||||
|
||||
const expected = {
|
||||
authorizedCtLinks: [
|
||||
authorizedCollectionTypeLinks: [
|
||||
{
|
||||
destination: '/content-manager/collectionType/api::address.address',
|
||||
icon: 'circle',
|
||||
isDisplayed: true,
|
||||
label: 'address',
|
||||
kind: 'collectionType',
|
||||
name: 'api::address.address',
|
||||
permissions: [
|
||||
{
|
||||
action: 'plugin::content-manager.explorer.create',
|
||||
@ -107,13 +111,14 @@ describe('checkPermissions', () => {
|
||||
},
|
||||
],
|
||||
search: 'page=1&pageSize=10&sort=name:ASC',
|
||||
title: 'Address',
|
||||
to: '/content-manager/collectionType/api::address.address',
|
||||
uid: 'api::address.address',
|
||||
},
|
||||
{
|
||||
destination: '/content-manager/collectionType/api::article.article',
|
||||
icon: 'circle',
|
||||
isDisplayed: true,
|
||||
label: 'article',
|
||||
search: null,
|
||||
kind: 'collectionType',
|
||||
name: 'api::article.article',
|
||||
permissions: [
|
||||
{
|
||||
action: 'plugin::content-manager.explorer.create',
|
||||
@ -124,12 +129,15 @@ describe('checkPermissions', () => {
|
||||
subject: 'api::article.article',
|
||||
},
|
||||
],
|
||||
search: null,
|
||||
title: 'Article',
|
||||
to: '/content-manager/collectionType/api::article.article',
|
||||
uid: 'api::article.article',
|
||||
},
|
||||
],
|
||||
authorizedStLinks: [],
|
||||
contentTypes: data,
|
||||
authorizedSingleTypeLinks: [],
|
||||
};
|
||||
const actual = await getContentTypeLinks(userPermissions);
|
||||
const actual = await getContentTypeLinks({ userPermissions, models: contentTypes });
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
@ -139,11 +147,13 @@ describe('checkPermissions', () => {
|
||||
const toggleNotification = jest.fn();
|
||||
const userPermissions = [];
|
||||
|
||||
request.mockImplementation(() => {
|
||||
throw new Error('Something went wrong');
|
||||
});
|
||||
getFetchClient.mockImplementation(() => ({
|
||||
get() {
|
||||
throw new Error('Something went wrong');
|
||||
},
|
||||
}));
|
||||
|
||||
await getContentTypeLinks(userPermissions, toggleNotification);
|
||||
await getContentTypeLinks({ userPermissions, toggleNotification });
|
||||
expect(toggleNotification).toBeCalled();
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user