@akemona-org/strapi-plugin-i18n 3.7.0 → 3.7.2
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.
- package/admin/src/components/CMEditViewCopyLocale/index.js +4 -4
- package/admin/src/components/CMEditViewCopyLocale/utils/generateOptions.js +2 -2
- package/admin/src/components/CMEditViewCopyLocale/utils/removePasswordAndRelationsFieldFromData.js +2 -2
- package/admin/src/components/CMEditViewInjectedComponents/index.js +1 -1
- package/admin/src/components/CMEditViewLocalePicker/Option.js +2 -2
- package/admin/src/components/CMEditViewLocalePicker/index.js +1 -1
- package/admin/src/components/CheckboxConfirmation/index.js +2 -2
- package/admin/src/components/DeleteModalAdditionalInfos/index.js +1 -1
- package/admin/src/components/LocaleList/index.js +1 -1
- package/admin/src/components/LocaleListCell/LocaleListCell.js +6 -6
- package/admin/src/components/LocaleListCell/tests/LocaleListCell.test.js +2 -2
- package/admin/src/components/LocalePicker/index.js +7 -7
- package/admin/src/components/LocaleRow/index.js +1 -1
- package/admin/src/components/ModalCreate/BaseForm.js +1 -1
- package/admin/src/components/ModalCreate/index.js +2 -2
- package/admin/src/components/ModalEdit/index.js +2 -2
- package/admin/src/containers/SettingsPage/LocaleSettingsPage.js +2 -2
- package/admin/src/containers/SettingsPage/tests/SettingsPage.test.js +2 -2
- package/admin/src/hooks/reducers.js +4 -4
- package/admin/src/hooks/useAddLocale/index.js +1 -1
- package/admin/src/hooks/useContentTypePermissions/index.js +1 -1
- package/admin/src/hooks/useDeleteLocale/index.js +2 -2
- package/admin/src/hooks/useHasI18n/index.js +1 -1
- package/admin/src/hooks/useLocales/index.js +3 -3
- package/admin/src/index.js +3 -3
- package/admin/src/middlewares/addCommonFieldsToInitialDataMiddleware.js +61 -57
- package/admin/src/middlewares/addLocaleColumnToListViewMiddleware.js +27 -23
- package/admin/src/middlewares/addLocaleToCollectionTypesMiddleware.js +22 -18
- package/admin/src/middlewares/addLocaleToSingleTypesMiddleware.js +22 -18
- package/admin/src/middlewares/extendCMEditViewLayoutMiddleware.js +6 -6
- package/admin/src/middlewares/extendCTBAttributeInitialDataMiddleware.js +49 -47
- package/admin/src/middlewares/extendCTBInitialDataMiddleware.js +1 -1
- package/admin/src/middlewares/localePermissionMiddleware.js +2 -2
- package/admin/src/middlewares/tests/addCommonFieldsToInitialDataMiddleware.test.js +3 -3
- package/admin/src/middlewares/tests/localePermissionMiddleware.test.js +7 -7
- package/admin/src/middlewares/utils/addLocaleToLinksSearch.js +1 -1
- package/admin/src/pluginId.js +1 -1
- package/admin/src/selectors/selectCollectionTypesRelatedPermissions.js +1 -1
- package/admin/src/selectors/selectI18nLocales.js +1 -1
- package/admin/src/utils/getDefaultLocale.js +3 -3
- package/admin/src/utils/getInitialLocale.js +2 -2
- package/admin/src/utils/getLocaleFromQuery.js +1 -1
- package/admin/src/utils/getTrad.js +1 -1
- package/admin/src/utils/mutateCTBContentTypeSchema.js +2 -2
- package/config/functions/bootstrap.js +2 -2
- package/config/functions/migrations/content-type/disable/migrate-for-bookshelf.js +3 -6
- package/config/functions/migrations/content-type/disable/migrate-for-mongoose.js +2 -5
- package/config/functions/migrations/content-type/enable/index.js +1 -4
- package/config/functions/migrations/field/migrate-for-bookshelf.js +8 -9
- package/config/functions/migrations/field/migrate.js +2 -2
- package/domain/locale.js +1 -1
- package/middlewares/i18n/index.js +3 -3
- package/package.json +3 -3
- package/services/__tests__/content-types.test.js +115 -112
- package/services/__tests__/entity-service-decorator.test.js +5 -5
- package/services/entity-service-decorator.js +3 -3
- package/services/locales.js +6 -6
- package/services/localizations.js +5 -4
- package/services/permissions/actions.js +4 -4
- package/services/permissions/engine.js +1 -1
- package/services/permissions/sections-builder.js +1 -1
- package/tests/graphql.test.e2e.js +1 -1
- package/tests/locales.test.e2e.js +4 -4
- package/utils/index.js +1 -1
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "3.7.
|
|
6
|
+
"version": "3.7.2",
|
|
7
7
|
"description": "This plugin enables to create, to read and to update content in different languages, both from the Admin Panel and from the API",
|
|
8
8
|
"strapi": {
|
|
9
9
|
"name": "Internationalization",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"required": false
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@akemona-org/strapi-utils": "3.7.
|
|
15
|
+
"@akemona-org/strapi-utils": "3.7.2",
|
|
16
16
|
"lodash": "4.17.21",
|
|
17
17
|
"p-map": "4.0.0",
|
|
18
18
|
"pluralize": "8.0.0"
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"npm": ">=6.0.0"
|
|
28
28
|
},
|
|
29
29
|
"license": "SEE LICENSE IN LICENSE",
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "4ab59dbae5135819558c6ae27b45a556ff27cf55"
|
|
31
31
|
}
|
|
@@ -192,121 +192,124 @@ describe('content-types service', () => {
|
|
|
192
192
|
});
|
|
193
193
|
});
|
|
194
194
|
|
|
195
|
-
describe.each([['singleType'], ['collectionType']])(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const relatedEntityId = 1;
|
|
221
|
-
const relatedEntity = {
|
|
222
|
-
id: relatedEntityId,
|
|
223
|
-
locale: 'en',
|
|
224
|
-
localizations: [],
|
|
225
|
-
};
|
|
226
|
-
const findOne = jest.fn(() => Promise.resolve(relatedEntity));
|
|
227
|
-
const model = 'application::country.country';
|
|
228
|
-
const locale = 'en';
|
|
229
|
-
|
|
230
|
-
global.strapi = {
|
|
231
|
-
query: () => ({
|
|
232
|
-
findOne,
|
|
233
|
-
}),
|
|
234
|
-
getModel: () => ({ kind }),
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
try {
|
|
238
|
-
await getAndValidateRelatedEntity(relatedEntityId, model, locale);
|
|
239
|
-
} catch (e) {
|
|
240
|
-
expect(e.message).toBe('The entity already exists in this locale');
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
expect(findOne).toHaveBeenCalledWith(kind === 'singleType' ? {} : { id: relatedEntityId });
|
|
244
|
-
expect.assertions(2);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
test('Throw if locale already exists (2/2)', async () => {
|
|
248
|
-
const relatedEntityId = 1;
|
|
249
|
-
const relatedEntity = {
|
|
250
|
-
id: relatedEntityId,
|
|
251
|
-
locale: 'fr',
|
|
252
|
-
localizations: [
|
|
253
|
-
{
|
|
254
|
-
id: 2,
|
|
255
|
-
locale: 'en',
|
|
256
|
-
},
|
|
257
|
-
],
|
|
258
|
-
};
|
|
259
|
-
const findOne = jest.fn(() => Promise.resolve(relatedEntity));
|
|
260
|
-
const model = 'application::country.country';
|
|
261
|
-
const locale = 'en';
|
|
262
|
-
|
|
263
|
-
global.strapi = {
|
|
264
|
-
query: () => ({
|
|
265
|
-
findOne,
|
|
266
|
-
}),
|
|
267
|
-
getModel: () => ({ kind }),
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
try {
|
|
271
|
-
await getAndValidateRelatedEntity(relatedEntityId, model, locale);
|
|
272
|
-
} catch (e) {
|
|
273
|
-
expect(e.message).toBe('The entity already exists in this locale');
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
expect(findOne).toHaveBeenCalledWith(kind === 'singleType' ? {} : { id: relatedEntityId });
|
|
277
|
-
expect.assertions(2);
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
test('get related entity', async () => {
|
|
281
|
-
const relatedEntityId = 1;
|
|
282
|
-
const relatedEntity = {
|
|
283
|
-
id: relatedEntityId,
|
|
284
|
-
locale: 'fr',
|
|
285
|
-
localizations: [
|
|
286
|
-
{
|
|
287
|
-
id: 2,
|
|
288
|
-
locale: 'en',
|
|
289
|
-
},
|
|
290
|
-
],
|
|
291
|
-
};
|
|
292
|
-
const findOne = jest.fn(() => Promise.resolve(relatedEntity));
|
|
293
|
-
const model = 'application::country.country';
|
|
294
|
-
const locale = 'it';
|
|
195
|
+
describe.each([['singleType'], ['collectionType']])(
|
|
196
|
+
'getAndValidateRelatedEntity - %s',
|
|
197
|
+
(kind) => {
|
|
198
|
+
test("Throw if relatedEntity is provided but doesn't exist", async () => {
|
|
199
|
+
const findOne = jest.fn(() => Promise.resolve(undefined));
|
|
200
|
+
const relatedEntityId = 1;
|
|
201
|
+
const model = 'application::country.country';
|
|
202
|
+
const locale = 'fr';
|
|
203
|
+
|
|
204
|
+
global.strapi = {
|
|
205
|
+
query: () => ({
|
|
206
|
+
findOne,
|
|
207
|
+
}),
|
|
208
|
+
getModel: () => ({ kind }),
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
try {
|
|
212
|
+
await getAndValidateRelatedEntity(relatedEntityId, model, locale);
|
|
213
|
+
} catch (e) {
|
|
214
|
+
expect(e.message).toBe("The related entity doesn't exist");
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
expect(findOne).toHaveBeenCalledWith(kind === 'singleType' ? {} : { id: relatedEntityId });
|
|
218
|
+
expect.assertions(2);
|
|
219
|
+
});
|
|
295
220
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
221
|
+
test('Throw if locale already exists (1/2)', async () => {
|
|
222
|
+
const relatedEntityId = 1;
|
|
223
|
+
const relatedEntity = {
|
|
224
|
+
id: relatedEntityId,
|
|
225
|
+
locale: 'en',
|
|
226
|
+
localizations: [],
|
|
227
|
+
};
|
|
228
|
+
const findOne = jest.fn(() => Promise.resolve(relatedEntity));
|
|
229
|
+
const model = 'application::country.country';
|
|
230
|
+
const locale = 'en';
|
|
231
|
+
|
|
232
|
+
global.strapi = {
|
|
233
|
+
query: () => ({
|
|
234
|
+
findOne,
|
|
235
|
+
}),
|
|
236
|
+
getModel: () => ({ kind }),
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
try {
|
|
240
|
+
await getAndValidateRelatedEntity(relatedEntityId, model, locale);
|
|
241
|
+
} catch (e) {
|
|
242
|
+
expect(e.message).toBe('The entity already exists in this locale');
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
expect(findOne).toHaveBeenCalledWith(kind === 'singleType' ? {} : { id: relatedEntityId });
|
|
246
|
+
expect.assertions(2);
|
|
247
|
+
});
|
|
302
248
|
|
|
303
|
-
|
|
249
|
+
test('Throw if locale already exists (2/2)', async () => {
|
|
250
|
+
const relatedEntityId = 1;
|
|
251
|
+
const relatedEntity = {
|
|
252
|
+
id: relatedEntityId,
|
|
253
|
+
locale: 'fr',
|
|
254
|
+
localizations: [
|
|
255
|
+
{
|
|
256
|
+
id: 2,
|
|
257
|
+
locale: 'en',
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
};
|
|
261
|
+
const findOne = jest.fn(() => Promise.resolve(relatedEntity));
|
|
262
|
+
const model = 'application::country.country';
|
|
263
|
+
const locale = 'en';
|
|
264
|
+
|
|
265
|
+
global.strapi = {
|
|
266
|
+
query: () => ({
|
|
267
|
+
findOne,
|
|
268
|
+
}),
|
|
269
|
+
getModel: () => ({ kind }),
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
try {
|
|
273
|
+
await getAndValidateRelatedEntity(relatedEntityId, model, locale);
|
|
274
|
+
} catch (e) {
|
|
275
|
+
expect(e.message).toBe('The entity already exists in this locale');
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
expect(findOne).toHaveBeenCalledWith(kind === 'singleType' ? {} : { id: relatedEntityId });
|
|
279
|
+
expect.assertions(2);
|
|
280
|
+
});
|
|
304
281
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
282
|
+
test('get related entity', async () => {
|
|
283
|
+
const relatedEntityId = 1;
|
|
284
|
+
const relatedEntity = {
|
|
285
|
+
id: relatedEntityId,
|
|
286
|
+
locale: 'fr',
|
|
287
|
+
localizations: [
|
|
288
|
+
{
|
|
289
|
+
id: 2,
|
|
290
|
+
locale: 'en',
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
};
|
|
294
|
+
const findOne = jest.fn(() => Promise.resolve(relatedEntity));
|
|
295
|
+
const model = 'application::country.country';
|
|
296
|
+
const locale = 'it';
|
|
297
|
+
|
|
298
|
+
global.strapi = {
|
|
299
|
+
query: () => ({
|
|
300
|
+
findOne,
|
|
301
|
+
}),
|
|
302
|
+
getModel: () => ({ kind }),
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
const foundEntity = await getAndValidateRelatedEntity(relatedEntityId, model, locale);
|
|
306
|
+
|
|
307
|
+
expect(foundEntity).toEqual(relatedEntity);
|
|
308
|
+
expect(findOne).toHaveBeenCalledWith(kind === 'singleType' ? {} : { id: relatedEntityId });
|
|
309
|
+
expect.assertions(2);
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
);
|
|
310
313
|
|
|
311
314
|
describe('getNewLocalizationsFrom', () => {
|
|
312
315
|
test('Can get localizations', async () => {
|
|
@@ -80,7 +80,7 @@ describe('Entity service decorator', () => {
|
|
|
80
80
|
|
|
81
81
|
test('Does not wrap options if model is not localized', async () => {
|
|
82
82
|
const defaultService = {
|
|
83
|
-
wrapOptions: jest.fn(opts => Promise.resolve(opts)),
|
|
83
|
+
wrapOptions: jest.fn((opts) => Promise.resolve(opts)),
|
|
84
84
|
};
|
|
85
85
|
const service = decorator(defaultService);
|
|
86
86
|
|
|
@@ -92,7 +92,7 @@ describe('Entity service decorator', () => {
|
|
|
92
92
|
|
|
93
93
|
test('does not change non params options', async () => {
|
|
94
94
|
const defaultService = {
|
|
95
|
-
wrapOptions: jest.fn(opts => Promise.resolve(opts)),
|
|
95
|
+
wrapOptions: jest.fn((opts) => Promise.resolve(opts)),
|
|
96
96
|
};
|
|
97
97
|
const service = decorator(defaultService);
|
|
98
98
|
|
|
@@ -104,7 +104,7 @@ describe('Entity service decorator', () => {
|
|
|
104
104
|
|
|
105
105
|
test('Adds locale param', async () => {
|
|
106
106
|
const defaultService = {
|
|
107
|
-
wrapOptions: jest.fn(opts => Promise.resolve(opts)),
|
|
107
|
+
wrapOptions: jest.fn((opts) => Promise.resolve(opts)),
|
|
108
108
|
};
|
|
109
109
|
const service = decorator(defaultService);
|
|
110
110
|
|
|
@@ -133,7 +133,7 @@ describe('Entity service decorator', () => {
|
|
|
133
133
|
"Doesn't add locale param when the params contain id or id_in - %s",
|
|
134
134
|
async (action, params) => {
|
|
135
135
|
const defaultService = {
|
|
136
|
-
wrapOptions: jest.fn(opts => Promise.resolve(opts)),
|
|
136
|
+
wrapOptions: jest.fn((opts) => Promise.resolve(opts)),
|
|
137
137
|
};
|
|
138
138
|
const service = decorator(defaultService);
|
|
139
139
|
|
|
@@ -146,7 +146,7 @@ describe('Entity service decorator', () => {
|
|
|
146
146
|
|
|
147
147
|
test('Replaces _locale param', async () => {
|
|
148
148
|
const defaultService = {
|
|
149
|
-
wrapOptions: jest.fn(opts => Promise.resolve(opts)),
|
|
149
|
+
wrapOptions: jest.fn((opts) => Promise.resolve(opts)),
|
|
150
150
|
};
|
|
151
151
|
const service = decorator(defaultService);
|
|
152
152
|
|
|
@@ -13,7 +13,7 @@ const paramsContain = (key, params) => {
|
|
|
13
13
|
return (
|
|
14
14
|
has(key, params) ||
|
|
15
15
|
has(key, params._where) ||
|
|
16
|
-
(isArray(params._where) && params._where.some(clause => has(key, clause)))
|
|
16
|
+
(isArray(params._where) && params._where.some((clause) => has(key, clause)))
|
|
17
17
|
);
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -54,7 +54,7 @@ const wrapParams = async (params = {}, ctx = {}) => {
|
|
|
54
54
|
* Assigns a valid locale or the default one if not define
|
|
55
55
|
* @param {object} data
|
|
56
56
|
*/
|
|
57
|
-
const assignValidLocale = async data => {
|
|
57
|
+
const assignValidLocale = async (data) => {
|
|
58
58
|
const { getValidLocale } = getService('content-types');
|
|
59
59
|
|
|
60
60
|
try {
|
|
@@ -68,7 +68,7 @@ const assignValidLocale = async data => {
|
|
|
68
68
|
* Decorates the entity service with I18N business logic
|
|
69
69
|
* @param {object} service - entity service
|
|
70
70
|
*/
|
|
71
|
-
const decorator = service => ({
|
|
71
|
+
const decorator = (service) => ({
|
|
72
72
|
/**
|
|
73
73
|
* Wraps query options. In particular will add default locale to query params
|
|
74
74
|
* @param {object} opts - Query options object (params, data, files, populate)
|
package/services/locales.js
CHANGED
|
@@ -8,13 +8,13 @@ const { getCoreStore } = require('../utils');
|
|
|
8
8
|
|
|
9
9
|
const find = (...args) => strapi.query('locale', 'i18n').find(...args);
|
|
10
10
|
|
|
11
|
-
const findById = id => strapi.query('locale', 'i18n').findOne({ id });
|
|
11
|
+
const findById = (id) => strapi.query('locale', 'i18n').findOne({ id });
|
|
12
12
|
|
|
13
|
-
const findByCode = code => strapi.query('locale', 'i18n').findOne({ code });
|
|
13
|
+
const findByCode = (code) => strapi.query('locale', 'i18n').findOne({ code });
|
|
14
14
|
|
|
15
|
-
const count = params => strapi.query('locale', 'i18n').count(params);
|
|
15
|
+
const count = (params) => strapi.query('locale', 'i18n').count(params);
|
|
16
16
|
|
|
17
|
-
const create = async locale => {
|
|
17
|
+
const create = async (locale) => {
|
|
18
18
|
const result = await strapi.query('locale', 'i18n').create(locale);
|
|
19
19
|
|
|
20
20
|
getService('metrics').sendDidUpdateI18nLocalesEvent();
|
|
@@ -49,7 +49,7 @@ const setDefaultLocale = ({ code }) => getCoreStore().set({ key: 'default_locale
|
|
|
49
49
|
|
|
50
50
|
const getDefaultLocale = () => getCoreStore().get({ key: 'default_locale' });
|
|
51
51
|
|
|
52
|
-
const setIsDefault = async locales => {
|
|
52
|
+
const setIsDefault = async (locales) => {
|
|
53
53
|
if (isNil(locales)) {
|
|
54
54
|
return locales;
|
|
55
55
|
}
|
|
@@ -57,7 +57,7 @@ const setIsDefault = async locales => {
|
|
|
57
57
|
const actualDefault = await getDefaultLocale();
|
|
58
58
|
|
|
59
59
|
if (Array.isArray(locales)) {
|
|
60
|
-
return locales.map(locale => ({ ...locale, isDefault: actualDefault === locale.code }));
|
|
60
|
+
return locales.map((locale) => ({ ...locale, isDefault: actualDefault === locale.code }));
|
|
61
61
|
} else {
|
|
62
62
|
// single locale
|
|
63
63
|
return { ...locales, isDefault: actualDefault === locales.code };
|
|
@@ -8,7 +8,7 @@ const { getService } = require('../utils');
|
|
|
8
8
|
* Adds the default locale to an object if it isn't defined yet
|
|
9
9
|
* @param {Object} data a data object before being persisted into db
|
|
10
10
|
*/
|
|
11
|
-
const assignDefaultLocale = async data => {
|
|
11
|
+
const assignDefaultLocale = async (data) => {
|
|
12
12
|
const { getDefaultLocale } = getService('locales');
|
|
13
13
|
|
|
14
14
|
if (isNil(data.locale)) {
|
|
@@ -26,8 +26,8 @@ const syncLocalizations = async (entry, { model }) => {
|
|
|
26
26
|
if (Array.isArray(entry.localizations)) {
|
|
27
27
|
const newLocalizations = [entry.id, ...entry.localizations.map(prop('id'))];
|
|
28
28
|
|
|
29
|
-
const updateLocalization = id => {
|
|
30
|
-
const localizations = newLocalizations.filter(localizationId => localizationId !== id);
|
|
29
|
+
const updateLocalization = (id) => {
|
|
30
|
+
const localizations = newLocalizations.filter((localizationId) => localizationId !== id);
|
|
31
31
|
|
|
32
32
|
return strapi.query(model.uid).update({ id }, { localizations });
|
|
33
33
|
};
|
|
@@ -52,7 +52,8 @@ const syncNonLocalizedAttributes = async (entry, { model }) => {
|
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
const updateLocalization = id =>
|
|
55
|
+
const updateLocalization = (id) =>
|
|
56
|
+
strapi.query(model.uid).update({ id }, nonLocalizedAttributes);
|
|
56
57
|
|
|
57
58
|
await Promise.all(entry.localizations.map(({ id }) => updateLocalization(id)));
|
|
58
59
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const { capitalize, isArray, getOr, prop } = require('lodash/fp');
|
|
4
4
|
const { getService } = require('../../utils');
|
|
5
5
|
|
|
6
|
-
const actions = ['create', 'read', 'update', 'delete'].map(uid => ({
|
|
6
|
+
const actions = ['create', 'read', 'update', 'delete'].map((uid) => ({
|
|
7
7
|
section: 'settings',
|
|
8
8
|
category: 'Internationalization',
|
|
9
9
|
subCategory: 'Locales',
|
|
@@ -44,7 +44,7 @@ const shouldApplyLocalesPropertyToSubject = ({ property, subject }) => {
|
|
|
44
44
|
return true;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
const addAllLocalesToPermissions = async permissions => {
|
|
47
|
+
const addAllLocalesToPermissions = async (permissions) => {
|
|
48
48
|
const { actionProvider } = strapi.admin.services.permission;
|
|
49
49
|
const { find: findAllLocales } = getService('locales');
|
|
50
50
|
|
|
@@ -52,7 +52,7 @@ const addAllLocalesToPermissions = async permissions => {
|
|
|
52
52
|
const allLocalesCode = allLocales.map(prop('code'));
|
|
53
53
|
|
|
54
54
|
return Promise.all(
|
|
55
|
-
permissions.map(async permission => {
|
|
55
|
+
permissions.map(async (permission) => {
|
|
56
56
|
const { action, subject } = permission;
|
|
57
57
|
|
|
58
58
|
const appliesToLocalesProperty = await actionProvider.appliesToProperty(
|
|
@@ -112,7 +112,7 @@ const updateActionsProperties = () => {
|
|
|
112
112
|
actionProvider.hooks.willRegister.register(addLocalesPropertyIfNeeded);
|
|
113
113
|
|
|
114
114
|
// Handle already registered actions
|
|
115
|
-
actionProvider.values().forEach(action => addLocalesPropertyIfNeeded({ value: action }));
|
|
115
|
+
actionProvider.values().forEach((action) => addLocalesPropertyIfNeeded({ value: action }));
|
|
116
116
|
};
|
|
117
117
|
|
|
118
118
|
module.exports = {
|
|
@@ -14,7 +14,7 @@ const { getService } = require('../../utils');
|
|
|
14
14
|
* Add the has-locale-access condition if the locales property is defined
|
|
15
15
|
* @param {WillRegisterPermissionContext} context
|
|
16
16
|
*/
|
|
17
|
-
const willRegisterPermission = context => {
|
|
17
|
+
const willRegisterPermission = (context) => {
|
|
18
18
|
const { permission, condition, user } = context;
|
|
19
19
|
const { subject, properties } = permission;
|
|
20
20
|
|
|
@@ -23,7 +23,7 @@ const localesPropertyHandler = async ({ action, section }) => {
|
|
|
23
23
|
|
|
24
24
|
for (const subject of section.subjects) {
|
|
25
25
|
const applies = await actionProvider.appliesToProperty('locales', action.actionId, subject.uid);
|
|
26
|
-
const hasLocalesProperty = subject.properties.find(property => property.value === 'locales');
|
|
26
|
+
const hasLocalesProperty = subject.properties.find((property) => property.value === 'locales');
|
|
27
27
|
|
|
28
28
|
if (applies && !hasLocalesProperty) {
|
|
29
29
|
subject.properties.push({
|
|
@@ -175,8 +175,8 @@ describe('CRUD locales', () => {
|
|
|
175
175
|
});
|
|
176
176
|
|
|
177
177
|
expect(res.statusCode).toBe(200);
|
|
178
|
-
const enLocale = res.body.find(locale => locale.code === 'bas');
|
|
179
|
-
const enUsLocale = res.body.find(locale => locale.code === 'en-US');
|
|
178
|
+
const enLocale = res.body.find((locale) => locale.code === 'bas');
|
|
179
|
+
const enUsLocale = res.body.find((locale) => locale.code === 'en-US');
|
|
180
180
|
expect(enLocale.isDefault).toBe(false);
|
|
181
181
|
expect(enUsLocale.isDefault).toBe(true);
|
|
182
182
|
|
|
@@ -290,8 +290,8 @@ describe('CRUD locales', () => {
|
|
|
290
290
|
});
|
|
291
291
|
|
|
292
292
|
expect(res.statusCode).toBe(200);
|
|
293
|
-
expect(res.body.find(locale => locale.code === data.locales[0].code).isDefault).toBe(false);
|
|
294
|
-
expect(res.body.find(locale => locale.code === data.locales[1].code).isDefault).toBe(true);
|
|
293
|
+
expect(res.body.find((locale) => locale.code === data.locales[0].code).isDefault).toBe(false);
|
|
294
|
+
expect(res.body.find((locale) => locale.code === data.locales[1].code).isDefault).toBe(true);
|
|
295
295
|
});
|
|
296
296
|
|
|
297
297
|
test('Cannot unselect isDefault', async () => {
|