/
githubmirror
/
strapi
Обзор
Документация
Войти
/
githubmirror
/
strapi
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/plugins/i18n/server/src/services/permissions/sections-builder.ts
53 строки
2 KB
mathildeleg
fix(admin): restore default locale in permissions when adding i18n to ct (#26548)
29 июн 2026, 10:22
Не верифицирован
29 июн 2026, 10:22
cbbac85
Код
Авторство
О чём код?
import { isEmpty } from 'lodash/fp'; import { getService } from '../../utils'; /** * Handler for the permissions layout (sections builder) * Adds the locales property to the subjects * @param {Action} action * @param {ContentTypesSection} section * @return {Promise<void>} */ const localesPropertyHandler = async ({ action, section }: any) => { const { actionProvider } = strapi.service('admin::permission'); const localesService = getService('locales'); const locales = await localesService.setIsDefault(await localesService.find()); // Do not add the locales property if there is none registered if (isEmpty(locales)) { return; } for (const subject of section.subjects) { const applies = await actionProvider.appliesToProperty('locales', action.actionId, subject.uid); const hasLocalesProperty = subject.properties.some( (property: any) => property.value === 'locales' ); if (applies && !hasLocalesProperty) { subject.properties.push({ label: 'Locales', value: 'locales', children: locales.map(({ name, code, isDefault }: any) => ({ label: name || code, value: code, isDefault, })), }); } } }; const registerLocalesPropertyHandler = () => { const { sectionsBuilder } = strapi.service('admin::permission'); sectionsBuilder.addHandler('singleTypes', localesPropertyHandler); sectionsBuilder.addHandler('collectionTypes', localesPropertyHandler); }; export default { localesPropertyHandler, registerLocalesPropertyHandler, };