@akemona-org/strapi-plugin-i18n 3.7.0 → 3.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/admin/src/components/CMEditViewCopyLocale/index.js +4 -4
  2. package/admin/src/components/CMEditViewCopyLocale/utils/generateOptions.js +2 -2
  3. package/admin/src/components/CMEditViewCopyLocale/utils/removePasswordAndRelationsFieldFromData.js +2 -2
  4. package/admin/src/components/CMEditViewInjectedComponents/index.js +1 -1
  5. package/admin/src/components/CMEditViewLocalePicker/Option.js +2 -2
  6. package/admin/src/components/CMEditViewLocalePicker/index.js +1 -1
  7. package/admin/src/components/CheckboxConfirmation/index.js +2 -2
  8. package/admin/src/components/DeleteModalAdditionalInfos/index.js +1 -1
  9. package/admin/src/components/LocaleList/index.js +1 -1
  10. package/admin/src/components/LocaleListCell/LocaleListCell.js +6 -6
  11. package/admin/src/components/LocaleListCell/tests/LocaleListCell.test.js +2 -2
  12. package/admin/src/components/LocalePicker/index.js +7 -7
  13. package/admin/src/components/LocaleRow/index.js +1 -1
  14. package/admin/src/components/ModalCreate/BaseForm.js +1 -1
  15. package/admin/src/components/ModalCreate/index.js +2 -2
  16. package/admin/src/components/ModalEdit/index.js +2 -2
  17. package/admin/src/containers/SettingsPage/LocaleSettingsPage.js +2 -2
  18. package/admin/src/containers/SettingsPage/tests/SettingsPage.test.js +2 -2
  19. package/admin/src/hooks/reducers.js +4 -4
  20. package/admin/src/hooks/useAddLocale/index.js +1 -1
  21. package/admin/src/hooks/useContentTypePermissions/index.js +1 -1
  22. package/admin/src/hooks/useDeleteLocale/index.js +2 -2
  23. package/admin/src/hooks/useHasI18n/index.js +1 -1
  24. package/admin/src/hooks/useLocales/index.js +3 -3
  25. package/admin/src/index.js +3 -3
  26. package/admin/src/middlewares/addCommonFieldsToInitialDataMiddleware.js +61 -57
  27. package/admin/src/middlewares/addLocaleColumnToListViewMiddleware.js +27 -23
  28. package/admin/src/middlewares/addLocaleToCollectionTypesMiddleware.js +22 -18
  29. package/admin/src/middlewares/addLocaleToSingleTypesMiddleware.js +22 -18
  30. package/admin/src/middlewares/extendCMEditViewLayoutMiddleware.js +6 -6
  31. package/admin/src/middlewares/extendCTBAttributeInitialDataMiddleware.js +49 -47
  32. package/admin/src/middlewares/extendCTBInitialDataMiddleware.js +1 -1
  33. package/admin/src/middlewares/localePermissionMiddleware.js +2 -2
  34. package/admin/src/middlewares/tests/addCommonFieldsToInitialDataMiddleware.test.js +3 -3
  35. package/admin/src/middlewares/tests/localePermissionMiddleware.test.js +7 -7
  36. package/admin/src/middlewares/utils/addLocaleToLinksSearch.js +1 -1
  37. package/admin/src/pluginId.js +1 -1
  38. package/admin/src/selectors/selectCollectionTypesRelatedPermissions.js +1 -1
  39. package/admin/src/selectors/selectI18nLocales.js +1 -1
  40. package/admin/src/utils/getDefaultLocale.js +3 -3
  41. package/admin/src/utils/getInitialLocale.js +2 -2
  42. package/admin/src/utils/getLocaleFromQuery.js +1 -1
  43. package/admin/src/utils/getTrad.js +1 -1
  44. package/admin/src/utils/mutateCTBContentTypeSchema.js +2 -2
  45. package/config/functions/bootstrap.js +2 -2
  46. package/config/functions/migrations/content-type/disable/migrate-for-bookshelf.js +3 -6
  47. package/config/functions/migrations/content-type/disable/migrate-for-mongoose.js +2 -5
  48. package/config/functions/migrations/content-type/enable/index.js +1 -4
  49. package/config/functions/migrations/field/migrate-for-bookshelf.js +8 -9
  50. package/config/functions/migrations/field/migrate.js +2 -2
  51. package/domain/locale.js +1 -1
  52. package/middlewares/i18n/index.js +3 -3
  53. package/package.json +3 -3
  54. package/services/__tests__/content-types.test.js +115 -112
  55. package/services/__tests__/entity-service-decorator.test.js +5 -5
  56. package/services/entity-service-decorator.js +3 -3
  57. package/services/locales.js +6 -6
  58. package/services/localizations.js +5 -4
  59. package/services/permissions/actions.js +4 -4
  60. package/services/permissions/engine.js +1 -1
  61. package/services/permissions/sections-builder.js +1 -1
  62. package/tests/graphql.test.e2e.js +1 -1
  63. package/tests/locales.test.e2e.js +4 -4
  64. package/utils/index.js +1 -1
@@ -1,25 +1,29 @@
1
1
  import addLocaleToLinksSearch from './utils/addLocaleToLinksSearch';
2
2
 
3
- const addLocaleToCollectionTypesMiddleware = () => ({ getState }) => next => action => {
4
- if (action.type !== 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS') {
5
- return next(action);
6
- }
3
+ const addLocaleToCollectionTypesMiddleware =
4
+ () =>
5
+ ({ getState }) =>
6
+ (next) =>
7
+ (action) => {
8
+ if (action.type !== 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS') {
9
+ return next(action);
10
+ }
7
11
 
8
- if (action.data.authorizedCtLinks.length) {
9
- const store = getState();
10
- const { locales } = store.get('i18n_locales');
11
- const { collectionTypesRelatedPermissions } = store.get('permissionsManager');
12
+ if (action.data.authorizedCtLinks.length) {
13
+ const store = getState();
14
+ const { locales } = store.get('i18n_locales');
15
+ const { collectionTypesRelatedPermissions } = store.get('permissionsManager');
12
16
 
13
- action.data.authorizedCtLinks = addLocaleToLinksSearch(
14
- action.data.authorizedCtLinks,
15
- 'collectionType',
16
- action.data.contentTypeSchemas,
17
- locales,
18
- collectionTypesRelatedPermissions
19
- );
20
- }
17
+ action.data.authorizedCtLinks = addLocaleToLinksSearch(
18
+ action.data.authorizedCtLinks,
19
+ 'collectionType',
20
+ action.data.contentTypeSchemas,
21
+ locales,
22
+ collectionTypesRelatedPermissions
23
+ );
24
+ }
21
25
 
22
- return next(action);
23
- };
26
+ return next(action);
27
+ };
24
28
 
25
29
  export default addLocaleToCollectionTypesMiddleware;
@@ -1,25 +1,29 @@
1
1
  import addLocaleToLinksSearch from './utils/addLocaleToLinksSearch';
2
2
 
3
- const addLocaleToSingleTypesMiddleware = () => ({ getState }) => next => action => {
4
- if (action.type !== 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS') {
5
- return next(action);
6
- }
3
+ const addLocaleToSingleTypesMiddleware =
4
+ () =>
5
+ ({ getState }) =>
6
+ (next) =>
7
+ (action) => {
8
+ if (action.type !== 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS') {
9
+ return next(action);
10
+ }
7
11
 
8
- if (action.data.authorizedStLinks.length) {
9
- const store = getState();
10
- const { locales } = store.get('i18n_locales');
11
- const { collectionTypesRelatedPermissions } = store.get('permissionsManager');
12
+ if (action.data.authorizedStLinks.length) {
13
+ const store = getState();
14
+ const { locales } = store.get('i18n_locales');
15
+ const { collectionTypesRelatedPermissions } = store.get('permissionsManager');
12
16
 
13
- action.data.authorizedStLinks = addLocaleToLinksSearch(
14
- action.data.authorizedStLinks,
15
- 'singleType',
16
- action.data.contentTypeSchemas,
17
- locales,
18
- collectionTypesRelatedPermissions
19
- );
20
- }
17
+ action.data.authorizedStLinks = addLocaleToLinksSearch(
18
+ action.data.authorizedStLinks,
19
+ 'singleType',
20
+ action.data.contentTypeSchemas,
21
+ locales,
22
+ collectionTypesRelatedPermissions
23
+ );
24
+ }
21
25
 
22
- return next(action);
23
- };
26
+ return next(action);
27
+ };
24
28
 
25
29
  export default addLocaleToSingleTypesMiddleware;
@@ -4,7 +4,7 @@ import { Globe, GlobeCrossed } from '@buffetjs/icons';
4
4
  import { getTrad } from '../utils';
5
5
 
6
6
  const enhanceRelationLayout = (layout, locale) =>
7
- layout.map(current => {
7
+ layout.map((current) => {
8
8
  const labelIcon = {
9
9
  title: {
10
10
  id: getTrad('Field.localized'),
@@ -25,8 +25,8 @@ const enhanceRelationLayout = (layout, locale) =>
25
25
  return { ...current, labelIcon, queryInfos };
26
26
  });
27
27
 
28
- const enhanceEditLayout = layout =>
29
- layout.map(row => {
28
+ const enhanceEditLayout = (layout) =>
29
+ layout.map((row) => {
30
30
  const enhancedRow = row.reduce((acc, field) => {
31
31
  const type = get(field, ['fieldSchema', 'type'], null);
32
32
  const hasI18nEnabled = get(
@@ -72,7 +72,7 @@ const enhanceComponentsLayout = (components, locale) => {
72
72
  };
73
73
 
74
74
  const enhanceComponentLayoutForRelations = (layout, locale) =>
75
- layout.map(row => {
75
+ layout.map((row) => {
76
76
  const enhancedRow = row.reduce((acc, field) => {
77
77
  if (
78
78
  get(field, ['fieldSchema', 'type']) === 'relation' &&
@@ -97,7 +97,7 @@ const enhanceComponentLayoutForRelations = (layout, locale) =>
97
97
  return enhancedRow;
98
98
  });
99
99
 
100
- const extendCMEditViewLayoutMiddleware = () => () => next => action => {
100
+ const extendCMEditViewLayoutMiddleware = () => () => (next) => (action) => {
101
101
  if (action.type !== 'ContentManager/EditViewLayoutManager/SET_LAYOUT') {
102
102
  return next(action);
103
103
  }
@@ -148,7 +148,7 @@ const extendCMEditViewLayoutMiddleware = () => () => next => action => {
148
148
  return next(enhancedAction);
149
149
  };
150
150
 
151
- const getPathToContentType = pathArray => ['layout', 'contentType', ...pathArray];
151
+ const getPathToContentType = (pathArray) => ['layout', 'contentType', ...pathArray];
152
152
 
153
153
  export default extendCMEditViewLayoutMiddleware;
154
154
  export {
@@ -1,58 +1,60 @@
1
1
  const extendCTBAttributeInitialDataMiddleware = () => {
2
- return ({ getState }) => next => action => {
3
- const enhanceAction = () => {
4
- // the block here is to catch the error when trying to access the state
5
- // of the ctb when the plugin is not mounted
6
- try {
7
- const hasi18nEnabled = getState().getIn([
8
- 'content-type-builder_dataManagerProvider',
9
- 'modifiedData',
10
- 'contentType',
11
- 'schema',
12
- 'pluginOptions',
13
- 'i18n',
14
- 'localized',
15
- ]);
2
+ return ({ getState }) =>
3
+ (next) =>
4
+ (action) => {
5
+ const enhanceAction = () => {
6
+ // the block here is to catch the error when trying to access the state
7
+ // of the ctb when the plugin is not mounted
8
+ try {
9
+ const hasi18nEnabled = getState().getIn([
10
+ 'content-type-builder_dataManagerProvider',
11
+ 'modifiedData',
12
+ 'contentType',
13
+ 'schema',
14
+ 'pluginOptions',
15
+ 'i18n',
16
+ 'localized',
17
+ ]);
16
18
 
17
- if (hasi18nEnabled) {
18
- const pluginOptions = action.options
19
- ? { ...action.options.pluginOptions, i18n: { localized: true } }
20
- : { i18n: { localized: true } };
19
+ if (hasi18nEnabled) {
20
+ const pluginOptions = action.options
21
+ ? { ...action.options.pluginOptions, i18n: { localized: true } }
22
+ : { i18n: { localized: true } };
21
23
 
22
- return next({
23
- ...action,
24
- options: {
25
- pluginOptions,
26
- },
27
- });
24
+ return next({
25
+ ...action,
26
+ options: {
27
+ pluginOptions,
28
+ },
29
+ });
30
+ }
31
+
32
+ return next(action);
33
+ } catch (err) {
34
+ return next(action);
28
35
  }
36
+ };
29
37
 
30
- return next(action);
31
- } catch (err) {
32
- return next(action);
38
+ if (
39
+ action.type === 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA' &&
40
+ action.forTarget === 'contentType' &&
41
+ !['relation', 'component'].includes(action.attributeType) &&
42
+ !action.isEditing
43
+ ) {
44
+ return enhanceAction();
33
45
  }
34
- };
35
-
36
- if (
37
- action.type === 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA' &&
38
- action.forTarget === 'contentType' &&
39
- !['relation', 'component'].includes(action.attributeType) &&
40
- !action.isEditing
41
- ) {
42
- return enhanceAction();
43
- }
44
46
 
45
- if (
46
- (action.type ===
47
- 'ContentTypeBuilder/FormModal/RESET_PROPS_AND_SET_FORM_FOR_ADDING_AN_EXISTING_COMPO' ||
48
- action.type === 'ContentTypeBuilder/FormModal/RESET_PROPS_AND_SAVE_CURRENT_DATA') &&
49
- action.forTarget === 'contentType'
50
- ) {
51
- return enhanceAction();
52
- }
47
+ if (
48
+ (action.type ===
49
+ 'ContentTypeBuilder/FormModal/RESET_PROPS_AND_SET_FORM_FOR_ADDING_AN_EXISTING_COMPO' ||
50
+ action.type === 'ContentTypeBuilder/FormModal/RESET_PROPS_AND_SAVE_CURRENT_DATA') &&
51
+ action.forTarget === 'contentType'
52
+ ) {
53
+ return enhanceAction();
54
+ }
53
55
 
54
- return next(action);
55
- };
56
+ return next(action);
57
+ };
56
58
  };
57
59
 
58
60
  export default extendCTBAttributeInitialDataMiddleware;
@@ -1,7 +1,7 @@
1
1
  import { has } from 'lodash';
2
2
 
3
3
  const extendCTBInitialDataMiddleware = () => {
4
- return () => next => action => {
4
+ return () => (next) => (action) => {
5
5
  if (
6
6
  action.type === 'ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT' &&
7
7
  action.modalType === 'contentType'
@@ -1,9 +1,9 @@
1
1
  import get from 'lodash/get';
2
2
 
3
- const filterPermissionWithLocale = locale => permission =>
3
+ const filterPermissionWithLocale = (locale) => (permission) =>
4
4
  get(permission, 'properties.locales', []).indexOf(locale) !== -1;
5
5
 
6
- const localePermissionMiddleware = () => () => next => action => {
6
+ const localePermissionMiddleware = () => () => (next) => (action) => {
7
7
  if (action.type !== 'ContentManager/RBACManager/SET_PERMISSIONS') {
8
8
  return next(action);
9
9
  }
@@ -5,8 +5,8 @@ jest.mock('strapi-helper-plugin', () => ({
5
5
  nonLocalizedFields: { common: 'test' },
6
6
  localizations: ['test'],
7
7
  }),
8
- formatComponentData: data => data,
9
- contentManagementUtilRemoveFieldsFromData: data => data,
8
+ formatComponentData: (data) => data,
9
+ contentManagementUtilRemoveFieldsFromData: (data) => data,
10
10
  }));
11
11
 
12
12
  describe('i18n | middlewares | addCommonFieldsToInitialDataMiddleware', () => {
@@ -77,7 +77,7 @@ describe('i18n | middlewares | addCommonFieldsToInitialDataMiddleware', () => {
77
77
  rawQuery: '?plugins[i18n][relatedEntityId]=1',
78
78
  };
79
79
 
80
- const next = jest.fn(x => x);
80
+ const next = jest.fn((x) => x);
81
81
  const middleware = addCommonFieldsToInitialDataMiddleware()({ getState, dispatch });
82
82
 
83
83
  const nextAction = await middleware(next)(action);
@@ -2,7 +2,7 @@ import localePermissionMiddleware from '../localePermissionMiddleware';
2
2
 
3
3
  describe('localePermissionMiddleware', () => {
4
4
  it('does not modify the action when the type is not "ContentManager/RBACManager/SET_PERMISSIONS"', () => {
5
- const nextFn = jest.fn(x => x);
5
+ const nextFn = jest.fn((x) => x);
6
6
  const action = {
7
7
  type: 'UNKNOWN_TYPE',
8
8
  };
@@ -13,7 +13,7 @@ describe('localePermissionMiddleware', () => {
13
13
  });
14
14
 
15
15
  it('does not modify the action when it the __meta__ key is not set', () => {
16
- const nextFn = jest.fn(x => x);
16
+ const nextFn = jest.fn((x) => x);
17
17
  const action = {
18
18
  type: 'ContentManager/RBACManager/SET_PERMISSIONS',
19
19
  __meta__: undefined,
@@ -25,7 +25,7 @@ describe('localePermissionMiddleware', () => {
25
25
  });
26
26
 
27
27
  it('does not modify the action when it the __meta__.containerName is not "listView"', () => {
28
- const nextFn = jest.fn(x => x);
28
+ const nextFn = jest.fn((x) => x);
29
29
  const action = {
30
30
  type: 'ContentManager/RBACManager/SET_PERMISSIONS',
31
31
  __meta__: { containerName: undefined },
@@ -37,7 +37,7 @@ describe('localePermissionMiddleware', () => {
37
37
  });
38
38
 
39
39
  it('does not modify the action when it the __meta__.plugins is not set', () => {
40
- const nextFn = jest.fn(x => x);
40
+ const nextFn = jest.fn((x) => x);
41
41
  const action = {
42
42
  type: 'ContentManager/RBACManager/SET_PERMISSIONS',
43
43
  __meta__: { containerName: 'listView' },
@@ -49,7 +49,7 @@ describe('localePermissionMiddleware', () => {
49
49
  });
50
50
 
51
51
  it('does not modify the action when it the __meta__.plugins.i18n.locale is not set', () => {
52
- const nextFn = jest.fn(x => x);
52
+ const nextFn = jest.fn((x) => x);
53
53
  const action = {
54
54
  type: 'ContentManager/RBACManager/SET_PERMISSIONS',
55
55
  __meta__: {
@@ -64,7 +64,7 @@ describe('localePermissionMiddleware', () => {
64
64
  });
65
65
 
66
66
  it('creates an empty permissions object from an empty array', () => {
67
- const nextFn = jest.fn(x => x);
67
+ const nextFn = jest.fn((x) => x);
68
68
  const action = {
69
69
  type: 'ContentManager/RBACManager/SET_PERMISSIONS',
70
70
  __meta__: {
@@ -88,7 +88,7 @@ describe('localePermissionMiddleware', () => {
88
88
  });
89
89
 
90
90
  it('creates a valid permissions object from a filled array', () => {
91
- const nextFn = jest.fn(x => x);
91
+ const nextFn = jest.fn((x) => x);
92
92
  const action = {
93
93
  type: 'ContentManager/RBACManager/SET_PERMISSIONS',
94
94
  __meta__: {
@@ -3,7 +3,7 @@ import { stringify, parse } from 'qs';
3
3
  import getDefaultLocale from '../../utils/getDefaultLocale';
4
4
 
5
5
  const addLocaleToLinksSearch = (links, kind, contentTypeSchemas, locales, permissions) => {
6
- return links.map(link => {
6
+ return links.map((link) => {
7
7
  const contentTypeUID = link.destination.split(`/${kind}/`)[1];
8
8
 
9
9
  const contentTypeSchema = contentTypeSchemas.find(({ uid }) => uid === contentTypeUID);
@@ -1,5 +1,5 @@
1
1
  import pluginPkg from '../../package.json';
2
2
 
3
- const pluginId = pluginPkg.name.replace(/^strapi-plugin-/i, '');
3
+ const pluginId = pluginPkg.name.replace(/^@akemona-org\/strapi-plugin-/i, '');
4
4
 
5
5
  export default pluginId;
@@ -1,4 +1,4 @@
1
- const selectCollectionTypesRelatedPermissions = state =>
1
+ const selectCollectionTypesRelatedPermissions = (state) =>
2
2
  state.get('permissionsManager').collectionTypesRelatedPermissions;
3
3
 
4
4
  export default selectCollectionTypesRelatedPermissions;
@@ -1,3 +1,3 @@
1
- const selectI18NLocales = state => state.get('i18n_locales').locales;
1
+ const selectI18NLocales = (state) => state.get('i18n_locales').locales;
2
2
 
3
3
  export default selectI18NLocales;
@@ -2,7 +2,7 @@ import get from 'lodash/get';
2
2
 
3
3
  const hasLocalePermission = (permissions, localeCode) => {
4
4
  if (permissions) {
5
- const hasPermission = permissions.some(permission =>
5
+ const hasPermission = permissions.some((permission) =>
6
6
  get(permission, 'properties.locales', []).includes(localeCode)
7
7
  );
8
8
 
@@ -14,7 +14,7 @@ const hasLocalePermission = (permissions, localeCode) => {
14
14
  return false;
15
15
  };
16
16
 
17
- const getFirstLocale = permissions => {
17
+ const getFirstLocale = (permissions) => {
18
18
  if (permissions && permissions.length > 0) {
19
19
  const firstAuthorizedNonDefaultLocale = get(permissions, [0, 'properties', 'locales', 0], null);
20
20
 
@@ -30,7 +30,7 @@ const getFirstLocale = permissions => {
30
30
  * Entry point of the module
31
31
  */
32
32
  const getDefaultLocale = (ctPermissions, locales = []) => {
33
- const defaultLocale = locales.find(locale => locale.isDefault);
33
+ const defaultLocale = locales.find((locale) => locale.isDefault);
34
34
 
35
35
  if (!defaultLocale) {
36
36
  return null;
@@ -4,11 +4,11 @@ const getInitialLocale = (query, locales = []) => {
4
4
  const localeFromQuery = getLocaleFromQuery(query);
5
5
 
6
6
  if (localeFromQuery) {
7
- return locales.find(locale => locale.code === localeFromQuery);
7
+ return locales.find((locale) => locale.code === localeFromQuery);
8
8
  }
9
9
 
10
10
  // Returns the default locale when nothing is in the query
11
- return locales.find(locale => locale.isDefault);
11
+ return locales.find((locale) => locale.isDefault);
12
12
  };
13
13
 
14
14
  export default getInitialLocale;
@@ -1,6 +1,6 @@
1
1
  import get from 'lodash/get';
2
2
 
3
- const getLocaleFromQuery = query => {
3
+ const getLocaleFromQuery = (query) => {
4
4
  return get(query, 'plugins.i18n.locale', undefined);
5
5
  };
6
6
 
@@ -1,5 +1,5 @@
1
1
  import pluginId from '../pluginId';
2
2
 
3
- const getTrad = id => `${pluginId}.${id}`;
3
+ const getTrad = (id) => `${pluginId}.${id}`;
4
4
 
5
5
  export default getTrad;
@@ -3,7 +3,7 @@ import LOCALIZED_FIELDS from './localizedFields';
3
3
 
4
4
  const localizedPath = ['pluginOptions', 'i18n', 'localized'];
5
5
 
6
- const addLocalisationToFields = attributes =>
6
+ const addLocalisationToFields = (attributes) =>
7
7
  Object.keys(attributes).reduce((acc, current) => {
8
8
  const currentAttribute = attributes[current];
9
9
 
@@ -24,7 +24,7 @@ const addLocalisationToFields = attributes =>
24
24
  return acc;
25
25
  }, {});
26
26
 
27
- const disableAttributesLocalisation = attributes =>
27
+ const disableAttributesLocalisation = (attributes) =>
28
28
  Object.keys(attributes).reduce((acc, current) => {
29
29
  acc[current] = omit(attributes[current], 'pluginOptions.i18n');
30
30
 
@@ -33,8 +33,8 @@ module.exports = async () => {
33
33
 
34
34
  const registerModelsHooks = () => {
35
35
  Object.values(strapi.models)
36
- .filter(model => getService('content-types').isLocalizedContentType(model))
37
- .forEach(model => {
36
+ .filter((model) => getService('content-types').isLocalizedContentType(model))
37
+ .forEach((model) => {
38
38
  strapi.db.lifecycles.register({
39
39
  model: model.uid,
40
40
  async beforeCreate(data) {
@@ -23,7 +23,7 @@ const migrateForBookshelf = async (
23
23
  .limit(BATCH_SIZE);
24
24
  offset += BATCH_SIZE;
25
25
 
26
- await pmap(batch, entry => model.deleteRelations(entry.id, { transacting: trx }), {
26
+ await pmap(batch, (entry) => model.deleteRelations(entry.id, { transacting: trx }), {
27
27
  concurrency: 100,
28
28
  stopOnError: true,
29
29
  });
@@ -32,10 +32,7 @@ const migrateForBookshelf = async (
32
32
  break;
33
33
  }
34
34
  }
35
- await trx
36
- .from(model.collectionName)
37
- .del()
38
- .whereNot('locale', defaultLocale);
35
+ await trx.from(model.collectionName).del().whereNot('locale', defaultLocale);
39
36
  await trx.commit();
40
37
  } catch (e) {
41
38
  await trx.rollback();
@@ -47,7 +44,7 @@ const migrateForBookshelf = async (
47
44
  // Need to recreate the table
48
45
  context.recreateSqliteTable = true;
49
46
  } else {
50
- await ORM.knex.schema.table(definition.collectionName, t => {
47
+ await ORM.knex.schema.table(definition.collectionName, (t) => {
51
48
  t.dropColumn('locale');
52
49
  });
53
50
  }
@@ -14,16 +14,13 @@ const migrateForMongoose = async ({ model, defaultLocale }) => {
14
14
  findParams._id = { $gt: lastId };
15
15
  }
16
16
 
17
- const batch = await model
18
- .find(findParams, ['id'])
19
- .sort({ _id: 1 })
20
- .limit(BATCH_SIZE);
17
+ const batch = await model.find(findParams, ['id']).sort({ _id: 1 }).limit(BATCH_SIZE);
21
18
 
22
19
  if (batch.length > 0) {
23
20
  lastId = batch[batch.length - 1]._id;
24
21
  }
25
22
 
26
- await pmap(batch, entry => model.deleteRelations(entry), {
23
+ await pmap(batch, (entry) => model.deleteRelations(entry), {
27
24
  concurrency: 100,
28
25
  stopOnError: true,
29
26
  });
@@ -5,10 +5,7 @@ const { getDefaultLocale } = require('../utils');
5
5
 
6
6
  const updateLocale = (model, ORM, locale) => {
7
7
  if (model.orm === 'bookshelf') {
8
- return ORM.knex
9
- .update({ locale })
10
- .from(model.collectionName)
11
- .where({ locale: null });
8
+ return ORM.knex.update({ locale }).from(model.collectionName).where({ locale: null });
12
9
  }
13
10
 
14
11
  if (model.orm === 'mongoose') {
@@ -8,7 +8,7 @@ const TMP_TABLE_NAME = '__tmp__i18n_field_migration';
8
8
  const batchInsertInTmpTable = async ({ updatesInfo }, { transacting: trx }) => {
9
9
  const tmpEntries = [];
10
10
  updatesInfo.forEach(({ entriesIdsToUpdate, attributesValues }) => {
11
- entriesIdsToUpdate.forEach(id => {
11
+ entriesIdsToUpdate.forEach((id) => {
12
12
  tmpEntries.push({ id, ...attributesValues });
13
13
  });
14
14
  });
@@ -20,14 +20,16 @@ const updateFromTmpTable = async ({ model, attributesToMigrate }, { transacting:
20
20
  if (model.client === 'pg') {
21
21
  const substitutes = attributesToMigrate.map(() => '?? = ??.??').join(',');
22
22
  const bindings = [collectionName];
23
- attributesToMigrate.forEach(attr => bindings.push(attr, TMP_TABLE_NAME, attr));
23
+ attributesToMigrate.forEach((attr) => bindings.push(attr, TMP_TABLE_NAME, attr));
24
24
  bindings.push(TMP_TABLE_NAME, collectionName, TMP_TABLE_NAME);
25
25
 
26
26
  await trx.raw(`UPDATE ?? SET ${substitutes} FROM ?? WHERE ??.id = ??.id;`, bindings);
27
27
  } else if (model.client === 'mysql') {
28
28
  const substitutes = attributesToMigrate.map(() => '??.?? = ??.??').join(',');
29
29
  const bindings = [collectionName, TMP_TABLE_NAME, collectionName, TMP_TABLE_NAME];
30
- attributesToMigrate.forEach(attr => bindings.push(collectionName, attr, TMP_TABLE_NAME, attr));
30
+ attributesToMigrate.forEach((attr) =>
31
+ bindings.push(collectionName, attr, TMP_TABLE_NAME, attr)
32
+ );
31
33
 
32
34
  await trx.raw(`UPDATE ?? JOIN ?? ON ??.id = ??.id SET ${substitutes};`, bindings);
33
35
  }
@@ -38,10 +40,7 @@ const createTmpTable = async ({ ORM, attributesToMigrate, model }) => {
38
40
  await deleteTmpTable({ ORM });
39
41
  await ORM.knex.raw(`CREATE TABLE ?? AS ??`, [
40
42
  TMP_TABLE_NAME,
41
- ORM.knex
42
- .select(columnsToCopy)
43
- .from(model.collectionName)
44
- .whereRaw('?', 0),
43
+ ORM.knex.select(columnsToCopy).from(model.collectionName).whereRaw('?', 0),
45
44
  ]);
46
45
  };
47
46
 
@@ -54,7 +53,7 @@ const migrateForBookshelf = async ({ ORM, model, attributesToMigrate }) => {
54
53
  if (onlyScalarAttrs && ['pg', 'mysql'].includes(model.client)) {
55
54
  // create table outside of the transaction because mysql doesn't accept the creation inside
56
55
  await createTmpTable({ ORM, attributesToMigrate, model });
57
- await ORM.knex.transaction(async transacting => {
56
+ await ORM.knex.transaction(async (transacting) => {
58
57
  await migrate(
59
58
  { model, attributesToMigrate },
60
59
  { migrateFn: batchInsertInTmpTable, transacting }
@@ -63,7 +62,7 @@ const migrateForBookshelf = async ({ ORM, model, attributesToMigrate }) => {
63
62
  });
64
63
  await deleteTmpTable({ ORM });
65
64
  } else {
66
- await ORM.knex.transaction(async transacting => {
65
+ await ORM.knex.transaction(async (transacting) => {
67
66
  await migrate({ model, attributesToMigrate }, { transacting });
68
67
  });
69
68
  }
@@ -9,11 +9,11 @@ const BATCH_SIZE = 1000;
9
9
  const migrateBatch = async (entries, { model, attributesToMigrate }, { transacting }) => {
10
10
  const { copyNonLocalizedAttributes } = getService('content-types');
11
11
 
12
- const updatePromises = entries.map(entity => {
12
+ const updatePromises = entries.map((entity) => {
13
13
  const updateValues = pick(attributesToMigrate, copyNonLocalizedAttributes(model, entity));
14
14
  const entriesIdsToUpdate = entity.localizations.map(prop('id'));
15
15
  return Promise.all(
16
- entriesIdsToUpdate.map(id =>
16
+ entriesIdsToUpdate.map((id) =>
17
17
  strapi.query(model.uid).update({ id }, updateValues, { transacting })
18
18
  )
19
19
  );
package/domain/locale.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const formatLocale = locale => {
3
+ const formatLocale = (locale) => {
4
4
  return {
5
5
  ...locale,
6
6
  name: locale.name || null,
@@ -3,7 +3,7 @@
3
3
  const { getOr, get, isMatch } = require('lodash/fp');
4
4
  const _ = require('lodash');
5
5
 
6
- module.exports = strapi => {
6
+ module.exports = (strapi) => {
7
7
  return {
8
8
  beforeInitialize() {
9
9
  strapi.config.middleware.load.before.unshift('i18n');
@@ -12,12 +12,12 @@ module.exports = strapi => {
12
12
  initialize() {
13
13
  const routes = get('plugins.content-manager.config.routes', strapi);
14
14
  const routesToAddPolicyTo = routes.filter(
15
- route =>
15
+ (route) =>
16
16
  isMatch({ method: 'POST', path: '/collection-types/:model' }, route) ||
17
17
  isMatch({ method: 'PUT', path: '/single-types/:model' }, route)
18
18
  );
19
19
 
20
- routesToAddPolicyTo.forEach(route => {
20
+ routesToAddPolicyTo.forEach((route) => {
21
21
  const policies = getOr([], 'config.policies', route).concat(
22
22
  'plugins::i18n.validateLocaleCreation'
23
23
  );