{"version":3,"file":"sections-builder.mjs","sources":["../../../../server/src/services/permissions/sections-builder.ts"],"sourcesContent":["import { isEmpty } from 'lodash/fp';\n\nimport { getService } from '../../utils';\n\n/**\n * Handler for the permissions layout (sections builder)\n * Adds the locales property to the subjects\n * @param {Action} action\n * @param {ContentTypesSection} section\n * @return {Promise}\n */\nconst localesPropertyHandler = async ({ action, section }: any) => {\n const { actionProvider } = strapi.service('admin::permission');\n\n const localesService = getService('locales');\n const locales = await localesService.setIsDefault(await localesService.find());\n\n // Do not add the locales property if there is none registered\n if (isEmpty(locales)) {\n return;\n }\n\n for (const subject of section.subjects) {\n const applies = await actionProvider.appliesToProperty('locales', action.actionId, subject.uid);\n const hasLocalesProperty = subject.properties.some(\n (property: any) => property.value === 'locales'\n );\n\n if (applies && !hasLocalesProperty) {\n subject.properties.push({\n label: 'Locales',\n value: 'locales',\n children: locales.map(({ name, code, isDefault }: any) => ({\n label: name || code,\n value: code,\n isDefault,\n })),\n });\n }\n }\n};\n\nconst registerLocalesPropertyHandler = () => {\n const { sectionsBuilder } = strapi.service('admin::permission');\n\n sectionsBuilder.addHandler('singleTypes', localesPropertyHandler);\n sectionsBuilder.addHandler('collectionTypes', localesPropertyHandler);\n};\n\nexport default {\n localesPropertyHandler,\n registerLocalesPropertyHandler,\n};\n"],"names":["localesPropertyHandler","action","section","actionProvider","strapi","service","localesService","getService","locales","setIsDefault","find","isEmpty","subject","subjects","applies","appliesToProperty","actionId","uid","hasLocalesProperty","properties","some","property","value","push","label","children","map","name","code","isDefault","registerLocalesPropertyHandler","sectionsBuilder","addHandler"],"mappings":";;;AAIA;;;;;;AAMC,IACD,MAAMA,sBAAAA,GAAyB,OAAO,EAAEC,MAAM,EAAEC,OAAO,EAAO,GAAA;AAC5D,IAAA,MAAM,EAAEC,cAAc,EAAE,GAAGC,MAAAA,CAAOC,OAAO,CAAC,mBAAA,CAAA;AAE1C,IAAA,MAAMC,iBAAiBC,UAAAA,CAAW,SAAA,CAAA;AAClC,IAA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