@strapi/plugin-users-permissions 5.0.0-beta.6 → 5.0.0-beta.7

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 (144) hide show
  1. package/admin/src/components/BoundRoute/index.jsx +2 -2
  2. package/admin/src/components/FormModal/Input/index.jsx +32 -31
  3. package/admin/src/components/Permissions/PermissionRow/CheckboxWrapper.jsx +1 -1
  4. package/admin/src/components/Permissions/PermissionRow/SubCategory.jsx +2 -2
  5. package/admin/src/components/Policies/index.jsx +2 -2
  6. package/admin/src/components/UsersPermissions/index.jsx +2 -2
  7. package/admin/src/pages/AdvancedSettings/index.jsx +6 -16
  8. package/admin/src/pages/EmailTemplates/components/EmailForm.jsx +2 -1
  9. package/admin/src/pages/EmailTemplates/index.jsx +5 -4
  10. package/admin/src/pages/Providers/index.jsx +6 -9
  11. package/admin/src/pages/Roles/pages/CreatePage.jsx +29 -24
  12. package/admin/src/pages/Roles/pages/EditPage.jsx +33 -24
  13. package/admin/src/pages/Roles/pages/ListPage/components/TableBody.jsx +1 -1
  14. package/admin/src/pages/Roles/pages/ListPage/index.jsx +8 -11
  15. package/dist/_chunks/ar-BguGUqwK.js +44 -0
  16. package/dist/_chunks/ar-BguGUqwK.js.map +1 -0
  17. package/dist/_chunks/ar-CK8BRRXB.mjs +44 -0
  18. package/dist/_chunks/ar-CK8BRRXB.mjs.map +1 -0
  19. package/dist/_chunks/cs-BVigMk0l.mjs +50 -0
  20. package/dist/_chunks/cs-BVigMk0l.mjs.map +1 -0
  21. package/dist/_chunks/cs-BW8-K_GY.js +50 -0
  22. package/dist/_chunks/cs-BW8-K_GY.js.map +1 -0
  23. package/dist/_chunks/de-BKUdRFI4.mjs +62 -0
  24. package/dist/_chunks/de-BKUdRFI4.mjs.map +1 -0
  25. package/dist/_chunks/de-owXpVluI.js +62 -0
  26. package/dist/_chunks/de-owXpVluI.js.map +1 -0
  27. package/dist/_chunks/dk-BQiTK50l.mjs +86 -0
  28. package/dist/_chunks/dk-BQiTK50l.mjs.map +1 -0
  29. package/dist/_chunks/dk-LXAnbuBk.js +86 -0
  30. package/dist/_chunks/dk-LXAnbuBk.js.map +1 -0
  31. package/dist/_chunks/en-DOHtPf-2.mjs +86 -0
  32. package/dist/_chunks/en-DOHtPf-2.mjs.map +1 -0
  33. package/dist/_chunks/en-MHo5mcsU.js +86 -0
  34. package/dist/_chunks/en-MHo5mcsU.js.map +1 -0
  35. package/dist/_chunks/es-BwLCLXAQ.js +86 -0
  36. package/dist/_chunks/es-BwLCLXAQ.js.map +1 -0
  37. package/dist/_chunks/es-DNgOVMjD.mjs +86 -0
  38. package/dist/_chunks/es-DNgOVMjD.mjs.map +1 -0
  39. package/dist/_chunks/fr-DkgRugiU.mjs +50 -0
  40. package/dist/_chunks/fr-DkgRugiU.mjs.map +1 -0
  41. package/dist/_chunks/fr-DkhpSjjm.js +50 -0
  42. package/dist/_chunks/fr-DkhpSjjm.js.map +1 -0
  43. package/dist/_chunks/id-BTemOeTZ.js +62 -0
  44. package/dist/_chunks/id-BTemOeTZ.js.map +1 -0
  45. package/dist/_chunks/id-BdEsvnaF.mjs +62 -0
  46. package/dist/_chunks/id-BdEsvnaF.mjs.map +1 -0
  47. package/dist/_chunks/index--VHJr8__-Cx-PmaTb.mjs +10577 -0
  48. package/dist/_chunks/index--VHJr8__-Cx-PmaTb.mjs.map +1 -0
  49. package/dist/_chunks/index--VHJr8__-a6vFdIyj.js +10601 -0
  50. package/dist/_chunks/index--VHJr8__-a6vFdIyj.js.map +1 -0
  51. package/dist/_chunks/index-B-kWBHFg.mjs +1153 -0
  52. package/dist/_chunks/index-B-kWBHFg.mjs.map +1 -0
  53. package/dist/_chunks/index-B0IECp2U.js +272 -0
  54. package/dist/_chunks/index-B0IECp2U.js.map +1 -0
  55. package/dist/_chunks/index-BEhglMSg.mjs +249 -0
  56. package/dist/_chunks/index-BEhglMSg.mjs.map +1 -0
  57. package/dist/_chunks/index-BRZCpa1U.mjs +335 -0
  58. package/dist/_chunks/index-BRZCpa1U.mjs.map +1 -0
  59. package/dist/_chunks/index-CYVy1i0_.mjs +253 -0
  60. package/dist/_chunks/index-CYVy1i0_.mjs.map +1 -0
  61. package/dist/_chunks/index-CvBfU3H9.js +634 -0
  62. package/dist/_chunks/index-CvBfU3H9.js.map +1 -0
  63. package/dist/_chunks/index-D6s_GV1d.js +357 -0
  64. package/dist/_chunks/index-D6s_GV1d.js.map +1 -0
  65. package/dist/_chunks/index-Du8DLJcX.mjs +611 -0
  66. package/dist/_chunks/index-Du8DLJcX.mjs.map +1 -0
  67. package/dist/_chunks/index-QrGtUO_1.js +248 -0
  68. package/dist/_chunks/index-QrGtUO_1.js.map +1 -0
  69. package/dist/_chunks/index-lnrC9bmZ.js +1183 -0
  70. package/dist/_chunks/index-lnrC9bmZ.js.map +1 -0
  71. package/dist/_chunks/it-B-rv0E24.mjs +62 -0
  72. package/dist/_chunks/it-B-rv0E24.mjs.map +1 -0
  73. package/dist/_chunks/it-D1rH6V6_.js +62 -0
  74. package/dist/_chunks/it-D1rH6V6_.js.map +1 -0
  75. package/dist/_chunks/ja-C8K-VBPD.mjs +48 -0
  76. package/dist/_chunks/ja-C8K-VBPD.mjs.map +1 -0
  77. package/dist/_chunks/ja-DqShgTMf.js +48 -0
  78. package/dist/_chunks/ja-DqShgTMf.js.map +1 -0
  79. package/dist/_chunks/ko-B9DGEPWH.js +86 -0
  80. package/dist/_chunks/ko-B9DGEPWH.js.map +1 -0
  81. package/dist/_chunks/ko-Busb0wIY.mjs +86 -0
  82. package/dist/_chunks/ko-Busb0wIY.mjs.map +1 -0
  83. package/dist/_chunks/ms-ByvsQjRt.mjs +49 -0
  84. package/dist/_chunks/ms-ByvsQjRt.mjs.map +1 -0
  85. package/dist/_chunks/ms-CPBU3LWf.js +49 -0
  86. package/dist/_chunks/ms-CPBU3LWf.js.map +1 -0
  87. package/dist/_chunks/nl-5qO8Rpcy.mjs +48 -0
  88. package/dist/_chunks/nl-5qO8Rpcy.mjs.map +1 -0
  89. package/dist/_chunks/nl-CwNB6YoO.js +48 -0
  90. package/dist/_chunks/nl-CwNB6YoO.js.map +1 -0
  91. package/dist/_chunks/pl-BdIzifBE.mjs +86 -0
  92. package/dist/_chunks/pl-BdIzifBE.mjs.map +1 -0
  93. package/dist/_chunks/pl-Do9UD69f.js +86 -0
  94. package/dist/_chunks/pl-Do9UD69f.js.map +1 -0
  95. package/dist/_chunks/pt-BIO24ioG.mjs +48 -0
  96. package/dist/_chunks/pt-BIO24ioG.mjs.map +1 -0
  97. package/dist/_chunks/pt-BR-D7dZhxuP.js +44 -0
  98. package/dist/_chunks/pt-BR-D7dZhxuP.js.map +1 -0
  99. package/dist/_chunks/pt-BR-f0p23AQZ.mjs +44 -0
  100. package/dist/_chunks/pt-BR-f0p23AQZ.mjs.map +1 -0
  101. package/dist/_chunks/pt-fdvyOnUp.js +48 -0
  102. package/dist/_chunks/pt-fdvyOnUp.js.map +1 -0
  103. package/dist/_chunks/ru-C94rjPGA.js +86 -0
  104. package/dist/_chunks/ru-C94rjPGA.js.map +1 -0
  105. package/dist/_chunks/ru-VWy-IB7K.mjs +86 -0
  106. package/dist/_chunks/ru-VWy-IB7K.mjs.map +1 -0
  107. package/dist/_chunks/sk-BABEhykl.js +50 -0
  108. package/dist/_chunks/sk-BABEhykl.js.map +1 -0
  109. package/dist/_chunks/sk-B_LIcepm.mjs +50 -0
  110. package/dist/_chunks/sk-B_LIcepm.mjs.map +1 -0
  111. package/dist/_chunks/sv-ABLKOokl.mjs +86 -0
  112. package/dist/_chunks/sv-ABLKOokl.mjs.map +1 -0
  113. package/dist/_chunks/sv-Be43LhA9.js +86 -0
  114. package/dist/_chunks/sv-Be43LhA9.js.map +1 -0
  115. package/dist/_chunks/th-DKyP7ueR.mjs +60 -0
  116. package/dist/_chunks/th-DKyP7ueR.mjs.map +1 -0
  117. package/dist/_chunks/th-DgVhVLhL.js +60 -0
  118. package/dist/_chunks/th-DgVhVLhL.js.map +1 -0
  119. package/dist/_chunks/tr-B_idhkEs.js +85 -0
  120. package/dist/_chunks/tr-B_idhkEs.js.map +1 -0
  121. package/dist/_chunks/tr-qa1Q5UjC.mjs +85 -0
  122. package/dist/_chunks/tr-qa1Q5UjC.mjs.map +1 -0
  123. package/dist/_chunks/uk-BmRqbeQc.mjs +49 -0
  124. package/dist/_chunks/uk-BmRqbeQc.mjs.map +1 -0
  125. package/dist/_chunks/uk-LHOivnhP.js +49 -0
  126. package/dist/_chunks/uk-LHOivnhP.js.map +1 -0
  127. package/dist/_chunks/vi-CdVRdKDw.js +50 -0
  128. package/dist/_chunks/vi-CdVRdKDw.js.map +1 -0
  129. package/dist/_chunks/vi-HW-EdMea.mjs +50 -0
  130. package/dist/_chunks/vi-HW-EdMea.mjs.map +1 -0
  131. package/dist/_chunks/zh-5hKkVPA4.mjs +86 -0
  132. package/dist/_chunks/zh-5hKkVPA4.mjs.map +1 -0
  133. package/dist/_chunks/zh-Cuq8gMnF.js +86 -0
  134. package/dist/_chunks/zh-Cuq8gMnF.js.map +1 -0
  135. package/dist/_chunks/zh-Hans-BHilK-yc.mjs +86 -0
  136. package/dist/_chunks/zh-Hans-BHilK-yc.mjs.map +1 -0
  137. package/dist/_chunks/zh-Hans-GQDMKtY4.js +86 -0
  138. package/dist/_chunks/zh-Hans-GQDMKtY4.js.map +1 -0
  139. package/dist/admin/index.js +4 -0
  140. package/dist/admin/index.js.map +1 -0
  141. package/dist/admin/index.mjs +5 -0
  142. package/dist/admin/index.mjs.map +1 -0
  143. package/package.json +8 -8
  144. package/server/utils/sanitize/visitors/remove-user-relation-from-role-entities.js +2 -2
@@ -0,0 +1,1183 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
5
+ const admin = require("@strapi/strapi/admin");
6
+ const reactRouterDom = require("react-router-dom");
7
+ const index = require("./index-QrGtUO_1.js");
8
+ const designSystem = require("@strapi/design-system");
9
+ const icons = require("@strapi/icons");
10
+ const formik = require("formik");
11
+ const reactIntl = require("react-intl");
12
+ const reactQuery = require("react-query");
13
+ const PropTypes = require("prop-types");
14
+ const upperFirst = require("lodash/upperFirst");
15
+ const sortBy = require("lodash/sortBy");
16
+ const get = require("lodash/get");
17
+ const styledComponents = require("styled-components");
18
+ const createNextState2 = require("immer");
19
+ const isEmpty = require("lodash/isEmpty");
20
+ const without = require("lodash/without");
21
+ const map = require("lodash/map");
22
+ const tail = require("lodash/tail");
23
+ const set = require("lodash/set");
24
+ const take = require("lodash/take");
25
+ const yup = require("yup");
26
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
27
+ function _interopNamespace(e) {
28
+ if (e && e.__esModule)
29
+ return e;
30
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
31
+ if (e) {
32
+ for (const k in e) {
33
+ if (k !== "default") {
34
+ const d = Object.getOwnPropertyDescriptor(e, k);
35
+ Object.defineProperty(n, k, d.get ? d : {
36
+ enumerable: true,
37
+ get: () => e[k]
38
+ });
39
+ }
40
+ }
41
+ }
42
+ n.default = e;
43
+ return Object.freeze(n);
44
+ }
45
+ const React__namespace = /* @__PURE__ */ _interopNamespace(React);
46
+ const PropTypes__default = /* @__PURE__ */ _interopDefault(PropTypes);
47
+ const upperFirst__default = /* @__PURE__ */ _interopDefault(upperFirst);
48
+ const sortBy__default = /* @__PURE__ */ _interopDefault(sortBy);
49
+ const get__default = /* @__PURE__ */ _interopDefault(get);
50
+ const isEmpty__default = /* @__PURE__ */ _interopDefault(isEmpty);
51
+ const without__default = /* @__PURE__ */ _interopDefault(without);
52
+ const map__default = /* @__PURE__ */ _interopDefault(map);
53
+ const tail__default = /* @__PURE__ */ _interopDefault(tail);
54
+ const set__default = /* @__PURE__ */ _interopDefault(set);
55
+ const take__default = /* @__PURE__ */ _interopDefault(take);
56
+ const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
57
+ const UsersPermissions$2 = React.createContext({});
58
+ const UsersPermissionsProvider = ({ children, value }) => {
59
+ return /* @__PURE__ */ jsxRuntime.jsx(UsersPermissions$2.Provider, { value, children });
60
+ };
61
+ const useUsersPermissions = () => React.useContext(UsersPermissions$2);
62
+ UsersPermissionsProvider.propTypes = {
63
+ children: PropTypes__default.default.node.isRequired,
64
+ value: PropTypes__default.default.object.isRequired
65
+ };
66
+ function formatPluginName(pluginSlug) {
67
+ switch (pluginSlug) {
68
+ case "application":
69
+ return "Application";
70
+ case "plugin::content-manager":
71
+ return "Content manager";
72
+ case "plugin::content-type-builder":
73
+ return "Content types builder";
74
+ case "plugin::documentation":
75
+ return "Documentation";
76
+ case "plugin::email":
77
+ return "Email";
78
+ case "plugin::i18n":
79
+ return "i18n";
80
+ case "plugin::upload":
81
+ return "Upload";
82
+ case "plugin::users-permissions":
83
+ return "Users-permissions";
84
+ default:
85
+ return upperFirst__default.default(pluginSlug.replace("api::", "").replace("plugin::", ""));
86
+ }
87
+ }
88
+ const init$1 = (initialState2, permissions) => {
89
+ const collapses = Object.keys(permissions).sort().map((name) => ({ name, isOpen: false }));
90
+ return { ...initialState2, collapses };
91
+ };
92
+ const activeCheckboxWrapperStyles = styledComponents.css`
93
+ background: ${(props) => props.theme.colors.primary100};
94
+ svg {
95
+ opacity: 1;
96
+ }
97
+ `;
98
+ const CheckboxWrapper = styledComponents.styled(designSystem.Box)`
99
+ display: flex;
100
+ justify-content: space-between;
101
+ align-items: center;
102
+
103
+ svg {
104
+ opacity: 0;
105
+ path {
106
+ fill: ${(props) => props.theme.colors.primary600};
107
+ }
108
+ }
109
+
110
+ /* Show active style both on hover and when the action is selected */
111
+ ${(props) => props.isActive && activeCheckboxWrapperStyles}
112
+ &:hover {
113
+ ${activeCheckboxWrapperStyles}
114
+ }
115
+ `;
116
+ const Border = styledComponents.styled.div`
117
+ flex: 1;
118
+ align-self: center;
119
+ border-top: 1px solid ${({ theme }) => theme.colors.neutral150};
120
+ `;
121
+ const SubCategory = ({ subCategory }) => {
122
+ const { formatMessage } = reactIntl.useIntl();
123
+ const { onChange, onChangeSelectAll, onSelectedAction, selectedAction, modifiedData } = useUsersPermissions();
124
+ const currentScopedModifiedData = React.useMemo(() => {
125
+ return get__default.default(modifiedData, subCategory.name, {});
126
+ }, [modifiedData, subCategory]);
127
+ const hasAllActionsSelected = React.useMemo(() => {
128
+ return Object.values(currentScopedModifiedData).every((action) => action.enabled === true);
129
+ }, [currentScopedModifiedData]);
130
+ const hasSomeActionsSelected = React.useMemo(() => {
131
+ return Object.values(currentScopedModifiedData).some((action) => action.enabled === true) && !hasAllActionsSelected;
132
+ }, [currentScopedModifiedData, hasAllActionsSelected]);
133
+ const handleChangeSelectAll = React.useCallback(
134
+ ({ target: { name } }) => {
135
+ onChangeSelectAll({ target: { name, value: !hasAllActionsSelected } });
136
+ },
137
+ [hasAllActionsSelected, onChangeSelectAll]
138
+ );
139
+ const isActionSelected = React.useCallback(
140
+ (actionName) => {
141
+ return selectedAction === actionName;
142
+ },
143
+ [selectedAction]
144
+ );
145
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
146
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", children: [
147
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingRight: 4, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: subCategory.label }) }),
148
+ /* @__PURE__ */ jsxRuntime.jsx(Border, {}),
149
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingLeft: 4, children: /* @__PURE__ */ jsxRuntime.jsx(
150
+ designSystem.Checkbox,
151
+ {
152
+ name: subCategory.name,
153
+ value: hasAllActionsSelected,
154
+ onValueChange: (value) => handleChangeSelectAll({ target: { name: subCategory.name, value } }),
155
+ indeterminate: hasSomeActionsSelected,
156
+ children: formatMessage({ id: "app.utils.select-all", defaultMessage: "Select all" })
157
+ }
158
+ ) })
159
+ ] }),
160
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { paddingTop: 6, paddingBottom: 6, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid, { gap: 2, style: { flex: 1 }, children: subCategory.actions.map((action) => {
161
+ const name = `${action.name}.enabled`;
162
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.GridItem, { col: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(CheckboxWrapper, { isActive: isActionSelected(action.name), padding: 2, hasRadius: true, children: [
163
+ /* @__PURE__ */ jsxRuntime.jsx(
164
+ designSystem.Checkbox,
165
+ {
166
+ value: get__default.default(modifiedData, name, false),
167
+ name,
168
+ onValueChange: (value) => onChange({ target: { name, value } }),
169
+ children: action.label
170
+ }
171
+ ),
172
+ /* @__PURE__ */ jsxRuntime.jsxs(
173
+ "button",
174
+ {
175
+ type: "button",
176
+ onClick: () => onSelectedAction(action.name),
177
+ style: { display: "inline-flex", alignItems: "center" },
178
+ children: [
179
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { tag: "span", children: formatMessage(
180
+ {
181
+ id: "app.utils.show-bound-route",
182
+ defaultMessage: "Show bound route for {route}"
183
+ },
184
+ {
185
+ route: action.name
186
+ }
187
+ ) }),
188
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Cog, {})
189
+ ]
190
+ }
191
+ )
192
+ ] }) }, action.name);
193
+ }) }) })
194
+ ] });
195
+ };
196
+ SubCategory.propTypes = {
197
+ subCategory: PropTypes__default.default.object.isRequired
198
+ };
199
+ const PermissionRow = ({ name, permissions }) => {
200
+ const subCategories = React.useMemo(() => {
201
+ return sortBy__default.default(
202
+ Object.values(permissions.controllers).reduce((acc, curr, index2) => {
203
+ const currentName = `${name}.controllers.${Object.keys(permissions.controllers)[index2]}`;
204
+ const actions = sortBy__default.default(
205
+ Object.keys(curr).reduce((acc2, current) => {
206
+ return [
207
+ ...acc2,
208
+ {
209
+ ...curr[current],
210
+ label: current,
211
+ name: `${currentName}.${current}`
212
+ }
213
+ ];
214
+ }, []),
215
+ "label"
216
+ );
217
+ return [
218
+ ...acc,
219
+ {
220
+ actions,
221
+ label: Object.keys(permissions.controllers)[index2],
222
+ name: currentName
223
+ }
224
+ ];
225
+ }, []),
226
+ "label"
227
+ );
228
+ }, [name, permissions]);
229
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 6, children: subCategories.map((subCategory) => /* @__PURE__ */ jsxRuntime.jsx(SubCategory, { subCategory }, subCategory.name)) });
230
+ };
231
+ PermissionRow.propTypes = {
232
+ name: PropTypes__default.default.string.isRequired,
233
+ permissions: PropTypes__default.default.object.isRequired
234
+ };
235
+ const initialState$1 = {
236
+ collapses: []
237
+ };
238
+ const reducer$1 = (state, action) => (
239
+ // eslint-disable-next-line consistent-return
240
+ createNextState2.produce(state, (draftState) => {
241
+ switch (action.type) {
242
+ case "TOGGLE_COLLAPSE": {
243
+ draftState.collapses = state.collapses.map((collapse, index2) => {
244
+ if (index2 === action.index) {
245
+ return { ...collapse, isOpen: !collapse.isOpen };
246
+ }
247
+ return { ...collapse, isOpen: false };
248
+ });
249
+ break;
250
+ }
251
+ default:
252
+ return draftState;
253
+ }
254
+ })
255
+ );
256
+ const Permissions = () => {
257
+ const { modifiedData } = useUsersPermissions();
258
+ const { formatMessage } = reactIntl.useIntl();
259
+ const [{ collapses }, dispatch] = React.useReducer(
260
+ reducer$1,
261
+ initialState$1,
262
+ (state) => init$1(state, modifiedData)
263
+ );
264
+ const handleToggle = (index2) => dispatch({
265
+ type: "TOGGLE_COLLAPSE",
266
+ index: index2
267
+ });
268
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 1, children: collapses.map((collapse, index2) => /* @__PURE__ */ jsxRuntime.jsxs(
269
+ designSystem.Accordion,
270
+ {
271
+ expanded: collapse.isOpen,
272
+ onToggle: () => handleToggle(index2),
273
+ variant: index2 % 2 === 0 ? "secondary" : void 0,
274
+ children: [
275
+ /* @__PURE__ */ jsxRuntime.jsx(
276
+ designSystem.AccordionToggle,
277
+ {
278
+ title: formatPluginName(collapse.name),
279
+ description: formatMessage(
280
+ {
281
+ id: "users-permissions.Plugin.permissions.plugins.description",
282
+ defaultMessage: "Define all allowed actions for the {name} plugin."
283
+ },
284
+ { name: collapse.name }
285
+ ),
286
+ variant: index2 % 2 ? "primary" : "secondary"
287
+ }
288
+ ),
289
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.AccordionContent, { children: /* @__PURE__ */ jsxRuntime.jsx(PermissionRow, { permissions: modifiedData[collapse.name], name: collapse.name }) })
290
+ ]
291
+ },
292
+ collapse.name
293
+ )) });
294
+ };
295
+ const getMethodColor = (verb) => {
296
+ switch (verb) {
297
+ case "POST": {
298
+ return {
299
+ text: "success600",
300
+ border: "success200",
301
+ background: "success100"
302
+ };
303
+ }
304
+ case "GET": {
305
+ return {
306
+ text: "secondary600",
307
+ border: "secondary200",
308
+ background: "secondary100"
309
+ };
310
+ }
311
+ case "PUT": {
312
+ return {
313
+ text: "warning600",
314
+ border: "warning200",
315
+ background: "warning100"
316
+ };
317
+ }
318
+ case "DELETE": {
319
+ return {
320
+ text: "danger600",
321
+ border: "danger200",
322
+ background: "danger100"
323
+ };
324
+ }
325
+ default: {
326
+ return {
327
+ text: "neutral600",
328
+ border: "neutral200",
329
+ background: "neutral100"
330
+ };
331
+ }
332
+ }
333
+ };
334
+ const MethodBox = styledComponents.styled(designSystem.Box)`
335
+ margin: -1px;
336
+ border-radius: ${({ theme }) => theme.spaces[1]} 0 0 ${({ theme }) => theme.spaces[1]};
337
+ `;
338
+ function BoundRoute({ route }) {
339
+ const { formatMessage } = reactIntl.useIntl();
340
+ const { method, handler: title, path } = route;
341
+ const formattedRoute = path ? tail__default.default(path.split("/")) : [];
342
+ const [controller = "", action = ""] = title ? title.split(".") : [];
343
+ const colors = getMethodColor(route.method);
344
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
345
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "delta", tag: "h3", children: [
346
+ formatMessage({
347
+ id: "users-permissions.BoundRoute.title",
348
+ defaultMessage: "Bound route to"
349
+ }),
350
+ " ",
351
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: controller }),
352
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "delta", textColor: "primary600", children: [
353
+ ".",
354
+ action
355
+ ] })
356
+ ] }),
357
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { hasRadius: true, background: "neutral0", borderColor: "neutral200", gap: 0, children: [
358
+ /* @__PURE__ */ jsxRuntime.jsx(MethodBox, { background: colors.background, borderColor: colors.border, padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "bold", textColor: colors.text, children: method }) }),
359
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingLeft: 2, paddingRight: 2, children: map__default.default(formattedRoute, (value) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { textColor: value.includes(":") ? "neutral600" : "neutral900", children: [
360
+ "/",
361
+ value
362
+ ] }, value)) })
363
+ ] })
364
+ ] });
365
+ }
366
+ BoundRoute.defaultProps = {
367
+ route: {
368
+ handler: "Nocontroller.error",
369
+ method: "GET",
370
+ path: "/there-is-no-path"
371
+ }
372
+ };
373
+ BoundRoute.propTypes = {
374
+ route: PropTypes__default.default.shape({
375
+ handler: PropTypes__default.default.string,
376
+ method: PropTypes__default.default.string,
377
+ path: PropTypes__default.default.string
378
+ })
379
+ };
380
+ const Policies = () => {
381
+ const { formatMessage } = reactIntl.useIntl();
382
+ const { selectedAction, routes } = useUsersPermissions();
383
+ const path = without__default.default(selectedAction.split("."), "controllers");
384
+ const controllerRoutes = get__default.default(routes, path[0]);
385
+ const pathResolved = path.slice(1).join(".");
386
+ const displayedRoutes = isEmpty__default.default(controllerRoutes) ? [] : controllerRoutes.filter((o) => o.handler.endsWith(pathResolved));
387
+ return /* @__PURE__ */ jsxRuntime.jsx(
388
+ designSystem.GridItem,
389
+ {
390
+ col: 5,
391
+ background: "neutral150",
392
+ paddingTop: 6,
393
+ paddingBottom: 6,
394
+ paddingLeft: 7,
395
+ paddingRight: 7,
396
+ style: { minHeight: "100%" },
397
+ children: selectedAction ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: displayedRoutes.map((route, key) => (
398
+ // eslint-disable-next-line react/no-array-index-key
399
+ /* @__PURE__ */ jsxRuntime.jsx(BoundRoute, { route }, key)
400
+ )) }) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
401
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", tag: "h3", children: formatMessage({
402
+ id: "users-permissions.Policies.header.title",
403
+ defaultMessage: "Advanced settings"
404
+ }) }),
405
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", textColor: "neutral600", children: formatMessage({
406
+ id: "users-permissions.Policies.header.hint",
407
+ defaultMessage: "Select the application's actions or the plugin's actions and click on the cog icon to display the bound route"
408
+ }) })
409
+ ] })
410
+ }
411
+ );
412
+ };
413
+ const init = (state, permissions, routes) => {
414
+ return {
415
+ ...state,
416
+ initialData: permissions,
417
+ modifiedData: permissions,
418
+ routes
419
+ };
420
+ };
421
+ const initialState = {
422
+ initialData: {},
423
+ modifiedData: {},
424
+ routes: {},
425
+ selectedAction: "",
426
+ policies: []
427
+ };
428
+ const reducer = (state, action) => createNextState2.produce(state, (draftState) => {
429
+ switch (action.type) {
430
+ case "ON_CHANGE": {
431
+ const keysLength = action.keys.length;
432
+ const isChangingCheckbox = action.keys[keysLength - 1] === "enabled";
433
+ if (action.value && isChangingCheckbox) {
434
+ const selectedAction = take__default.default(action.keys, keysLength - 1).join(".");
435
+ draftState.selectedAction = selectedAction;
436
+ }
437
+ set__default.default(draftState, ["modifiedData", ...action.keys], action.value);
438
+ break;
439
+ }
440
+ case "ON_CHANGE_SELECT_ALL": {
441
+ const pathToValue = ["modifiedData", ...action.keys];
442
+ const oldValues = get__default.default(state, pathToValue, {});
443
+ const updatedValues = Object.keys(oldValues).reduce((acc, current) => {
444
+ acc[current] = { ...oldValues[current], enabled: action.value };
445
+ return acc;
446
+ }, {});
447
+ set__default.default(draftState, pathToValue, updatedValues);
448
+ break;
449
+ }
450
+ case "ON_RESET": {
451
+ draftState.modifiedData = state.initialData;
452
+ break;
453
+ }
454
+ case "ON_SUBMIT_SUCCEEDED": {
455
+ draftState.initialData = state.modifiedData;
456
+ break;
457
+ }
458
+ case "SELECT_ACTION": {
459
+ const { actionToSelect } = action;
460
+ draftState.selectedAction = actionToSelect === state.selectedAction ? "" : actionToSelect;
461
+ break;
462
+ }
463
+ default:
464
+ return draftState;
465
+ }
466
+ });
467
+ const UsersPermissions = React.forwardRef(({ permissions, routes }, ref) => {
468
+ const { formatMessage } = reactIntl.useIntl();
469
+ const [state, dispatch] = React.useReducer(
470
+ reducer,
471
+ initialState,
472
+ (state2) => init(state2, permissions, routes)
473
+ );
474
+ React.useImperativeHandle(ref, () => ({
475
+ getPermissions() {
476
+ return {
477
+ permissions: state.modifiedData
478
+ };
479
+ },
480
+ resetForm() {
481
+ dispatch({ type: "ON_RESET" });
482
+ },
483
+ setFormAfterSubmit() {
484
+ dispatch({ type: "ON_SUBMIT_SUCCEEDED" });
485
+ }
486
+ }));
487
+ const handleChange = ({ target: { name, value } }) => dispatch({
488
+ type: "ON_CHANGE",
489
+ keys: name.split("."),
490
+ value: value === "empty__string_value" ? "" : value
491
+ });
492
+ const handleChangeSelectAll = ({ target: { name, value } }) => dispatch({
493
+ type: "ON_CHANGE_SELECT_ALL",
494
+ keys: name.split("."),
495
+ value
496
+ });
497
+ const handleSelectedAction = (actionToSelect) => dispatch({
498
+ type: "SELECT_ACTION",
499
+ actionToSelect
500
+ });
501
+ const providerValue = {
502
+ ...state,
503
+ onChange: handleChange,
504
+ onChangeSelectAll: handleChangeSelectAll,
505
+ onSelectedAction: handleSelectedAction
506
+ };
507
+ return /* @__PURE__ */ jsxRuntime.jsx(UsersPermissionsProvider, { value: providerValue, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid, { gap: 0, shadow: "filterShadow", hasRadius: true, background: "neutral0", children: [
508
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.GridItem, { col: 7, paddingTop: 6, paddingBottom: 6, paddingLeft: 7, paddingRight: 7, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
509
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
510
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", tag: "h2", children: formatMessage({
511
+ id: index.getTrad("Plugins.header.title"),
512
+ defaultMessage: "Permissions"
513
+ }) }),
514
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", textColor: "neutral600", children: formatMessage({
515
+ id: index.getTrad("Plugins.header.description"),
516
+ defaultMessage: "Only actions bound by a route are listed below."
517
+ }) })
518
+ ] }),
519
+ /* @__PURE__ */ jsxRuntime.jsx(Permissions, {})
520
+ ] }) }),
521
+ /* @__PURE__ */ jsxRuntime.jsx(Policies, {})
522
+ ] }) });
523
+ });
524
+ UsersPermissions.propTypes = {
525
+ permissions: PropTypes__default.default.object.isRequired,
526
+ routes: PropTypes__default.default.object.isRequired
527
+ };
528
+ const UsersPermissions$1 = React.memo(UsersPermissions);
529
+ const createRoleSchema = yup__namespace.object().shape({
530
+ name: yup__namespace.string().required(admin.translatedErrors.required.id),
531
+ description: yup__namespace.string().required(admin.translatedErrors.required.id)
532
+ });
533
+ const cleanPermissions = (permissions) => Object.keys(permissions).reduce((acc, current) => {
534
+ const currentPermission = permissions[current].controllers;
535
+ const cleanedControllers = Object.keys(currentPermission).reduce((acc2, curr) => {
536
+ if (isEmpty__default.default(currentPermission[curr])) {
537
+ return acc2;
538
+ }
539
+ acc2[curr] = currentPermission[curr];
540
+ return acc2;
541
+ }, {});
542
+ if (isEmpty__default.default(cleanedControllers)) {
543
+ return acc;
544
+ }
545
+ acc[current] = { controllers: cleanedControllers };
546
+ return acc;
547
+ }, {});
548
+ const usePlugins = () => {
549
+ const { toggleNotification } = admin.useNotification();
550
+ const { get: get2 } = admin.useFetchClient();
551
+ const { formatAPIError } = admin.useAPIErrorHandler(index.getTrad);
552
+ const [
553
+ {
554
+ data: permissions,
555
+ isLoading: isLoadingPermissions,
556
+ error: permissionsError,
557
+ refetch: refetchPermissions
558
+ },
559
+ { data: routes, isLoading: isLoadingRoutes, error: routesError, refetch: refetchRoutes }
560
+ ] = reactQuery.useQueries([
561
+ {
562
+ queryKey: ["users-permissions", "permissions"],
563
+ async queryFn() {
564
+ const {
565
+ data: { permissions: permissions2 }
566
+ } = await get2(`/users-permissions/permissions`);
567
+ return permissions2;
568
+ }
569
+ },
570
+ {
571
+ queryKey: ["users-permissions", "routes"],
572
+ async queryFn() {
573
+ const {
574
+ data: { routes: routes2 }
575
+ } = await get2(`/users-permissions/routes`);
576
+ return routes2;
577
+ }
578
+ }
579
+ ]);
580
+ const refetchQueries = async () => {
581
+ await Promise.all([refetchPermissions(), refetchRoutes()]);
582
+ };
583
+ React.useEffect(() => {
584
+ if (permissionsError) {
585
+ toggleNotification({
586
+ type: "danger",
587
+ message: formatAPIError(permissionsError)
588
+ });
589
+ }
590
+ }, [toggleNotification, permissionsError, formatAPIError]);
591
+ React.useEffect(() => {
592
+ if (routesError) {
593
+ toggleNotification({
594
+ type: "danger",
595
+ message: formatAPIError(routesError)
596
+ });
597
+ }
598
+ }, [toggleNotification, routesError, formatAPIError]);
599
+ const isLoading = isLoadingPermissions || isLoadingRoutes;
600
+ return {
601
+ // TODO: these return values need to be memoized, otherwise
602
+ // they will create infinite rendering loops when used as
603
+ // effect dependencies
604
+ permissions: permissions ? cleanPermissions(permissions) : {},
605
+ routes: routes ?? {},
606
+ getData: refetchQueries,
607
+ isLoading
608
+ };
609
+ };
610
+ const CreatePage = () => {
611
+ const { formatMessage } = reactIntl.useIntl();
612
+ const { toggleNotification } = admin.useNotification();
613
+ const navigate = reactRouterDom.useNavigate();
614
+ const { isLoading: isLoadingPlugins, permissions, routes } = usePlugins();
615
+ const { trackUsage } = admin.useTracking();
616
+ const permissionsRef = React__namespace.useRef();
617
+ const { post } = admin.useFetchClient();
618
+ const mutation = reactQuery.useMutation((body) => post(`/users-permissions/roles`, body), {
619
+ onError() {
620
+ toggleNotification({
621
+ type: "danger",
622
+ message: formatMessage({
623
+ id: "notification.error",
624
+ defaultMessage: "An error occurred"
625
+ })
626
+ });
627
+ },
628
+ onSuccess() {
629
+ trackUsage("didCreateRole");
630
+ toggleNotification({
631
+ type: "success",
632
+ message: formatMessage({
633
+ id: index.getTrad("Settings.roles.created"),
634
+ defaultMessage: "Role created"
635
+ })
636
+ });
637
+ navigate(-1);
638
+ }
639
+ });
640
+ const handleCreateRoleSubmit = async (data) => {
641
+ const permissions2 = permissionsRef.current.getPermissions();
642
+ await mutation.mutate({ ...data, ...permissions2, users: [] });
643
+ };
644
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
645
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Title, { children: formatMessage(
646
+ { id: "Settings.PageTitle", defaultMessage: "Settings - {name}" },
647
+ { name: "Roles" }
648
+ ) }),
649
+ /* @__PURE__ */ jsxRuntime.jsx(
650
+ formik.Formik,
651
+ {
652
+ enableReinitialize: true,
653
+ initialValues: { name: "", description: "" },
654
+ onSubmit: handleCreateRoleSubmit,
655
+ validationSchema: createRoleSchema,
656
+ children: ({ handleSubmit, values, handleChange, errors }) => /* @__PURE__ */ jsxRuntime.jsxs(formik.Form, { noValidate: true, onSubmit: handleSubmit, children: [
657
+ /* @__PURE__ */ jsxRuntime.jsx(
658
+ admin.Layouts.Header,
659
+ {
660
+ primaryAction: !isLoadingPlugins && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { type: "submit", loading: mutation.isLoading, startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}), children: formatMessage({
661
+ id: "global.save",
662
+ defaultMessage: "Save"
663
+ }) }),
664
+ title: formatMessage({
665
+ id: "Settings.roles.create.title",
666
+ defaultMessage: "Create a role"
667
+ }),
668
+ subtitle: formatMessage({
669
+ id: "Settings.roles.create.description",
670
+ defaultMessage: "Define the rights given to the role"
671
+ })
672
+ }
673
+ ),
674
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsxs(
675
+ designSystem.Flex,
676
+ {
677
+ background: "neutral0",
678
+ direction: "column",
679
+ alignItems: "stretch",
680
+ gap: 7,
681
+ hasRadius: true,
682
+ paddingTop: 6,
683
+ paddingBottom: 6,
684
+ paddingLeft: 7,
685
+ paddingRight: 7,
686
+ shadow: "filterShadow",
687
+ children: [
688
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", children: [
689
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", tag: "h2", children: formatMessage({
690
+ id: index.getTrad("EditPage.form.roles"),
691
+ defaultMessage: "Role details"
692
+ }) }),
693
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid, { gap: 4, children: [
694
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.GridItem, { col: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(
695
+ designSystem.Field.Root,
696
+ {
697
+ name: "name",
698
+ error: errors?.name ? formatMessage({ id: errors.name, defaultMessage: "Name is required" }) : false,
699
+ required: true,
700
+ children: [
701
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage({
702
+ id: "global.name",
703
+ defaultMessage: "Name"
704
+ }) }),
705
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.TextInput, { value: values.name || "", onChange: handleChange }),
706
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
707
+ ]
708
+ }
709
+ ) }),
710
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.GridItem, { col: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(
711
+ designSystem.Field.Root,
712
+ {
713
+ name: "description",
714
+ error: errors?.description ? formatMessage({
715
+ id: errors.description,
716
+ defaultMessage: "Description is required"
717
+ }) : false,
718
+ required: true,
719
+ children: [
720
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage({
721
+ id: "global.description",
722
+ defaultMessage: "Description"
723
+ }) }),
724
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Textarea, { value: values.description || "", onChange: handleChange }),
725
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
726
+ ]
727
+ }
728
+ ) })
729
+ ] })
730
+ ] }),
731
+ !isLoadingPlugins && /* @__PURE__ */ jsxRuntime.jsx(
732
+ UsersPermissions$1,
733
+ {
734
+ ref: permissionsRef,
735
+ permissions,
736
+ routes
737
+ }
738
+ )
739
+ ]
740
+ }
741
+ ) })
742
+ ] })
743
+ }
744
+ )
745
+ ] });
746
+ };
747
+ const ProtectedRolesCreatePage = () => /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions: index.PERMISSIONS.createRole, children: /* @__PURE__ */ jsxRuntime.jsx(CreatePage, {}) });
748
+ const EditPage = () => {
749
+ const { formatMessage } = reactIntl.useIntl();
750
+ const { toggleNotification } = admin.useNotification();
751
+ const {
752
+ params: { id }
753
+ } = reactRouterDom.useMatch(`/settings/users-permissions/roles/:id`);
754
+ const { get: get2 } = admin.useFetchClient();
755
+ const { isLoading: isLoadingPlugins, routes } = usePlugins();
756
+ const {
757
+ data: role,
758
+ isLoading: isLoadingRole,
759
+ refetch: refetchRole
760
+ } = reactQuery.useQuery(["users-permissions", "role", id], async () => {
761
+ const {
762
+ data: { role: role2 }
763
+ } = await get2(`/users-permissions/roles/${id}`);
764
+ return role2;
765
+ });
766
+ const permissionsRef = React__namespace.useRef();
767
+ const { put } = admin.useFetchClient();
768
+ const { formatAPIError } = admin.useAPIErrorHandler();
769
+ const mutation = reactQuery.useMutation((body) => put(`/users-permissions/roles/${id}`, body), {
770
+ onError(error) {
771
+ toggleNotification({
772
+ type: "danger",
773
+ message: formatAPIError(error)
774
+ });
775
+ },
776
+ async onSuccess() {
777
+ toggleNotification({
778
+ type: "success",
779
+ message: formatMessage({
780
+ id: index.getTrad("Settings.roles.created"),
781
+ defaultMessage: "Role edited"
782
+ })
783
+ });
784
+ await refetchRole();
785
+ }
786
+ });
787
+ const handleEditRoleSubmit = async (data) => {
788
+ const permissions = permissionsRef.current.getPermissions();
789
+ await mutation.mutate({ ...data, ...permissions, users: [] });
790
+ };
791
+ if (isLoadingRole) {
792
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Loading, {});
793
+ }
794
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
795
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Title, { children: formatMessage(
796
+ { id: "Settings.PageTitle", defaultMessage: "Settings - {name}" },
797
+ { name: "Roles" }
798
+ ) }),
799
+ /* @__PURE__ */ jsxRuntime.jsx(
800
+ formik.Formik,
801
+ {
802
+ enableReinitialize: true,
803
+ initialValues: { name: role.name, description: role.description },
804
+ onSubmit: handleEditRoleSubmit,
805
+ validationSchema: createRoleSchema,
806
+ children: ({ handleSubmit, values, handleChange, errors }) => /* @__PURE__ */ jsxRuntime.jsxs(formik.Form, { noValidate: true, onSubmit: handleSubmit, children: [
807
+ /* @__PURE__ */ jsxRuntime.jsx(
808
+ admin.Layouts.Header,
809
+ {
810
+ primaryAction: !isLoadingPlugins ? /* @__PURE__ */ jsxRuntime.jsx(
811
+ designSystem.Button,
812
+ {
813
+ disabled: role.code === "strapi-super-admin",
814
+ type: "submit",
815
+ loading: mutation.isLoading,
816
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}),
817
+ children: formatMessage({
818
+ id: "global.save",
819
+ defaultMessage: "Save"
820
+ })
821
+ }
822
+ ) : null,
823
+ title: role.name,
824
+ subtitle: role.description,
825
+ navigationAction: /* @__PURE__ */ jsxRuntime.jsx(admin.BackButton, {})
826
+ }
827
+ ),
828
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsxs(
829
+ designSystem.Flex,
830
+ {
831
+ background: "neutral0",
832
+ direction: "column",
833
+ alignItems: "stretch",
834
+ gap: 7,
835
+ hasRadius: true,
836
+ paddingTop: 6,
837
+ paddingBottom: 6,
838
+ paddingLeft: 7,
839
+ paddingRight: 7,
840
+ shadow: "filterShadow",
841
+ children: [
842
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
843
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", tag: "h2", children: formatMessage({
844
+ id: index.getTrad("EditPage.form.roles"),
845
+ defaultMessage: "Role details"
846
+ }) }),
847
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid, { gap: 4, children: [
848
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.GridItem, { col: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(
849
+ designSystem.Field.Root,
850
+ {
851
+ name: "name",
852
+ error: errors?.name ? formatMessage({
853
+ id: errors.name,
854
+ defaultMessage: "Name is required"
855
+ }) : false,
856
+ required: true,
857
+ children: [
858
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage({
859
+ id: "global.name",
860
+ defaultMessage: "Name"
861
+ }) }),
862
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.TextInput, { value: values.name || "", onChange: handleChange }),
863
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
864
+ ]
865
+ }
866
+ ) }),
867
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.GridItem, { col: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(
868
+ designSystem.Field.Root,
869
+ {
870
+ name: "description",
871
+ error: errors?.description ? formatMessage({
872
+ id: errors.description,
873
+ defaultMessage: "Description is required"
874
+ }) : false,
875
+ required: true,
876
+ children: [
877
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage({
878
+ id: "global.description",
879
+ defaultMessage: "Description"
880
+ }) }),
881
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Textarea, { value: values.description || "", onChange: handleChange }),
882
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
883
+ ]
884
+ }
885
+ ) })
886
+ ] })
887
+ ] }),
888
+ !isLoadingPlugins && /* @__PURE__ */ jsxRuntime.jsx(
889
+ UsersPermissions$1,
890
+ {
891
+ ref: permissionsRef,
892
+ permissions: role.permissions,
893
+ routes
894
+ }
895
+ )
896
+ ]
897
+ }
898
+ ) })
899
+ ] })
900
+ }
901
+ )
902
+ ] });
903
+ };
904
+ const ProtectedRolesEditPage = () => /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions: index.PERMISSIONS.updateRole, children: /* @__PURE__ */ jsxRuntime.jsx(EditPage, {}) });
905
+ const EditLink = styledComponents.styled(designSystem.Link)`
906
+ align-items: center;
907
+ height: 3.2rem;
908
+ display: flex;
909
+ justify-content: center;
910
+ padding: ${({ theme }) => `${theme.spaces[2]}}`};
911
+ width: 3.2rem;
912
+
913
+ svg {
914
+ height: 1.2rem;
915
+ width: 1.2rem;
916
+
917
+ path {
918
+ fill: ${({ theme }) => theme.colors.neutral500};
919
+ }
920
+ }
921
+
922
+ &:hover,
923
+ &:focus {
924
+ svg {
925
+ path {
926
+ fill: ${({ theme }) => theme.colors.neutral800};
927
+ }
928
+ }
929
+ }
930
+ `;
931
+ const TableBody = ({ sortedRoles, canDelete, canUpdate, setRoleToDelete, onDelete }) => {
932
+ const { formatMessage } = reactIntl.useIntl();
933
+ const navigate = reactRouterDom.useNavigate();
934
+ const [showConfirmDelete, setShowConfirmDelete] = onDelete;
935
+ const checkCanDeleteRole = (role) => canDelete && !["public", "authenticated"].includes(role.type);
936
+ const handleClickDelete = (id) => {
937
+ setRoleToDelete(id);
938
+ setShowConfirmDelete(!showConfirmDelete);
939
+ };
940
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: sortedRoles?.map((role) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { onClick: () => navigate(role.id.toString()), children: [
941
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { width: "20%", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: role.name }) }),
942
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { width: "50%", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: role.description }) }),
943
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { width: "30%", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: formatMessage(
944
+ {
945
+ id: "Roles.RoleRow.user-count",
946
+ defaultMessage: "{number, plural, =0 {# user} one {# user} other {# users}}"
947
+ },
948
+ { number: role.nb_users }
949
+ ) }) }),
950
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "end", onClick: (e) => e.stopPropagation(), children: [
951
+ canUpdate ? /* @__PURE__ */ jsxRuntime.jsx(
952
+ EditLink,
953
+ {
954
+ to: role.id.toString(),
955
+ "aria-label": formatMessage(
956
+ { id: "app.component.table.edit", defaultMessage: "Edit {target}" },
957
+ { target: `${role.name}` }
958
+ ),
959
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.Pencil, {})
960
+ }
961
+ ) : null,
962
+ checkCanDeleteRole(role) && /* @__PURE__ */ jsxRuntime.jsx(
963
+ designSystem.IconButton,
964
+ {
965
+ onClick: () => handleClickDelete(role.id.toString()),
966
+ noBorder: true,
967
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
968
+ label: formatMessage(
969
+ { id: "global.delete-target", defaultMessage: "Delete {target}" },
970
+ { target: `${role.name}` }
971
+ )
972
+ }
973
+ )
974
+ ] }) })
975
+ ] }, role.name)) });
976
+ };
977
+ TableBody.defaultProps = {
978
+ canDelete: false,
979
+ canUpdate: false
980
+ };
981
+ TableBody.propTypes = {
982
+ onDelete: PropTypes__default.default.array.isRequired,
983
+ permissions: PropTypes__default.default.object.isRequired,
984
+ setRoleToDelete: PropTypes__default.default.func.isRequired,
985
+ sortedRoles: PropTypes__default.default.array.isRequired,
986
+ canDelete: PropTypes__default.default.bool,
987
+ canUpdate: PropTypes__default.default.bool
988
+ };
989
+ const RolesListPage = () => {
990
+ const { trackUsage } = admin.useTracking();
991
+ const { formatMessage, locale } = reactIntl.useIntl();
992
+ const { toggleNotification } = admin.useNotification();
993
+ const { notifyStatus } = designSystem.useNotifyAT();
994
+ const [{ query }] = admin.useQueryParams();
995
+ const _q = query?._q || "";
996
+ const [showConfirmDelete, setShowConfirmDelete] = React.useState(false);
997
+ const [roleToDelete, setRoleToDelete] = React.useState();
998
+ const { del, get: get2 } = admin.useFetchClient();
999
+ const {
1000
+ isLoading: isLoadingForPermissions,
1001
+ allowedActions: { canRead, canDelete, canCreate, canUpdate }
1002
+ } = admin.useRBAC({
1003
+ create: index.PERMISSIONS.createRole,
1004
+ read: index.PERMISSIONS.readRoles,
1005
+ update: index.PERMISSIONS.updateRole,
1006
+ delete: index.PERMISSIONS.deleteRole
1007
+ });
1008
+ const {
1009
+ isLoading: isLoadingForData,
1010
+ data: { roles },
1011
+ isFetching,
1012
+ refetch
1013
+ } = reactQuery.useQuery("get-roles", () => fetchData(toggleNotification, formatMessage, notifyStatus), {
1014
+ initialData: {},
1015
+ enabled: canRead
1016
+ });
1017
+ const { contains } = designSystem.useFilter(locale, {
1018
+ sensitivity: "base"
1019
+ });
1020
+ const formatter = designSystem.useCollator(locale, {
1021
+ sensitivity: "base"
1022
+ });
1023
+ const isLoading = isLoadingForData || isFetching || isLoadingForPermissions;
1024
+ const handleShowConfirmDelete = () => {
1025
+ setShowConfirmDelete(!showConfirmDelete);
1026
+ };
1027
+ const deleteData = async (id, formatMessage2, toggleNotification2) => {
1028
+ try {
1029
+ await del(`/users-permissions/roles/${id}`);
1030
+ } catch (error) {
1031
+ toggleNotification2({
1032
+ type: "danger",
1033
+ message: formatMessage2({ id: "notification.error", defaultMessage: "An error occured" })
1034
+ });
1035
+ }
1036
+ };
1037
+ const fetchData = async (toggleNotification2, formatMessage2, notifyStatus2) => {
1038
+ try {
1039
+ const { data } = await get2("/users-permissions/roles");
1040
+ notifyStatus2("The roles have loaded successfully");
1041
+ return data;
1042
+ } catch (err) {
1043
+ toggleNotification2({
1044
+ type: "danger",
1045
+ message: formatMessage2({ id: "notification.error", defaultMessage: "An error occurred" })
1046
+ });
1047
+ throw new Error(err);
1048
+ }
1049
+ };
1050
+ const emptyLayout = {
1051
+ roles: {
1052
+ id: index.getTrad("Roles.empty"),
1053
+ defaultMessage: "You don't have any roles yet."
1054
+ },
1055
+ search: {
1056
+ id: index.getTrad("Roles.empty.search"),
1057
+ defaultMessage: "No roles match the search."
1058
+ }
1059
+ };
1060
+ const pageTitle = formatMessage({
1061
+ id: "global.roles",
1062
+ defaultMessage: "Roles"
1063
+ });
1064
+ const deleteMutation = reactQuery.useMutation((id) => deleteData(id, formatMessage, toggleNotification), {
1065
+ async onSuccess() {
1066
+ await refetch();
1067
+ }
1068
+ });
1069
+ const handleConfirmDelete = async () => {
1070
+ await deleteMutation.mutateAsync(roleToDelete);
1071
+ setShowConfirmDelete(!showConfirmDelete);
1072
+ };
1073
+ const sortedRoles = (roles || []).filter((role) => contains(role.name, _q) || contains(role.description, _q)).sort(
1074
+ (a, b) => formatter.compare(a.name, b.name) || formatter.compare(a.description, b.description)
1075
+ );
1076
+ const emptyContent = _q && !sortedRoles.length ? "search" : "roles";
1077
+ const colCount = 4;
1078
+ const rowCount = (roles?.length || 0) + 1;
1079
+ if (isLoading) {
1080
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Loading, {});
1081
+ }
1082
+ return /* @__PURE__ */ jsxRuntime.jsxs(admin.Layouts.Root, { children: [
1083
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Title, { children: formatMessage(
1084
+ { id: "Settings.PageTitle", defaultMessage: "Settings - {name}" },
1085
+ { name: pageTitle }
1086
+ ) }),
1087
+ /* @__PURE__ */ jsxRuntime.jsxs(admin.Page.Main, { children: [
1088
+ /* @__PURE__ */ jsxRuntime.jsx(
1089
+ admin.Layouts.Header,
1090
+ {
1091
+ title: formatMessage({
1092
+ id: "global.roles",
1093
+ defaultMessage: "Roles"
1094
+ }),
1095
+ subtitle: formatMessage({
1096
+ id: "Settings.roles.list.description",
1097
+ defaultMessage: "List of roles"
1098
+ }),
1099
+ primaryAction: canCreate ? /* @__PURE__ */ jsxRuntime.jsx(
1100
+ designSystem.LinkButton,
1101
+ {
1102
+ to: "new",
1103
+ tag: reactRouterDom.NavLink,
1104
+ onClick: () => trackUsage("willCreateRole"),
1105
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
1106
+ size: "S",
1107
+ children: formatMessage({
1108
+ id: index.getTrad("List.button.roles"),
1109
+ defaultMessage: "Add new role"
1110
+ })
1111
+ }
1112
+ ) : null,
1113
+ navigationAction: /* @__PURE__ */ jsxRuntime.jsx(admin.BackButton, {})
1114
+ }
1115
+ ),
1116
+ /* @__PURE__ */ jsxRuntime.jsx(
1117
+ admin.Layouts.Action,
1118
+ {
1119
+ startActions: /* @__PURE__ */ jsxRuntime.jsx(
1120
+ admin.SearchInput,
1121
+ {
1122
+ label: formatMessage({
1123
+ id: "app.component.search.label",
1124
+ defaultMessage: "Search"
1125
+ })
1126
+ }
1127
+ )
1128
+ }
1129
+ ),
1130
+ /* @__PURE__ */ jsxRuntime.jsxs(admin.Layouts.Content, { children: [
1131
+ !canRead && /* @__PURE__ */ jsxRuntime.jsx(admin.Page.NoPermissions, {}),
1132
+ canRead && sortedRoles && sortedRoles?.length ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Table, { colCount, rowCount, children: [
1133
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Thead, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
1134
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({ id: "global.name", defaultMessage: "Name" }) }) }),
1135
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
1136
+ id: "global.description",
1137
+ defaultMessage: "Description"
1138
+ }) }) }),
1139
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({
1140
+ id: "global.users",
1141
+ defaultMessage: "Users"
1142
+ }) }) }),
1143
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { children: formatMessage({
1144
+ id: "global.actions",
1145
+ defaultMessage: "Actions"
1146
+ }) }) })
1147
+ ] }) }),
1148
+ /* @__PURE__ */ jsxRuntime.jsx(
1149
+ TableBody,
1150
+ {
1151
+ sortedRoles,
1152
+ canDelete,
1153
+ canUpdate,
1154
+ permissions: index.PERMISSIONS,
1155
+ setRoleToDelete,
1156
+ onDelete: [showConfirmDelete, setShowConfirmDelete]
1157
+ }
1158
+ )
1159
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.EmptyStateLayout, { content: formatMessage(emptyLayout[emptyContent]) })
1160
+ ] }),
1161
+ /* @__PURE__ */ jsxRuntime.jsx(
1162
+ admin.ConfirmDialog,
1163
+ {
1164
+ onConfirm: handleConfirmDelete,
1165
+ onClose: handleShowConfirmDelete,
1166
+ isOpen: showConfirmDelete
1167
+ }
1168
+ )
1169
+ ] })
1170
+ ] });
1171
+ };
1172
+ const ProtectedRolesListPage = () => {
1173
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions: index.PERMISSIONS.accessRoles, children: /* @__PURE__ */ jsxRuntime.jsx(RolesListPage, {}) });
1174
+ };
1175
+ const Roles = () => {
1176
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions: index.PERMISSIONS.accessRoles, children: /* @__PURE__ */ jsxRuntime.jsxs(reactRouterDom.Routes, { children: [
1177
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { index: true, element: /* @__PURE__ */ jsxRuntime.jsx(ProtectedRolesListPage, {}) }),
1178
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "new", element: /* @__PURE__ */ jsxRuntime.jsx(ProtectedRolesCreatePage, {}) }),
1179
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: ":id", element: /* @__PURE__ */ jsxRuntime.jsx(ProtectedRolesEditPage, {}) })
1180
+ ] }) });
1181
+ };
1182
+ exports.default = Roles;
1183
+ //# sourceMappingURL=index-lnrC9bmZ.js.map