strapi-plugin-oidc 1.0.5 → 1.0.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.
@@ -5,8 +5,8 @@ import { useState, useCallback, useEffect, memo } from "react";
5
5
  import { Typography, Flex, Box, MultiSelect, MultiSelectOption, Field, Button, Divider, Thead, Tr, Th, Tbody, Td, Dialog, IconButton, Pagination, PreviousLink, PageLink, NextLink, Table, Alert } from "@strapi/design-system";
6
6
  import { Plus, Trash, WarningCircle } from "@strapi/icons";
7
7
  import { useIntl } from "react-intl";
8
- import { p as pluginId } from "./index-D3AvxXlB.mjs";
9
- import en from "./en-f0TxVfx7.mjs";
8
+ import { p as pluginId } from "./index-Cz9Q6j4e.mjs";
9
+ import en from "./en-DInn-mdh.mjs";
10
10
  import styled from "styled-components";
11
11
  function getTrad(id) {
12
12
  const pluginIdWithId = `${pluginId}.${id}`;
@@ -85,199 +85,177 @@ function Whitelist({
85
85
  }, [email]);
86
86
  return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Box, { children: [
87
87
  /* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textColor: "neutral600", marginBottom: 4, children: formatMessage(getTrad("whitelist.description")) }),
88
- /* @__PURE__ */ jsxs(Flex, { gap: 4, marginTop: 5, marginBottom: 5, alignItems: "flex-start", children: [
89
- /* @__PURE__ */ jsx(Box, { style: { flex: 1 }, children: /* @__PURE__ */ jsx(Field.Root, { children: /* @__PURE__ */ jsx(
90
- Field.Input,
91
- {
92
- type: "text",
93
- disabled: loading,
94
- value: email,
95
- hasError: Boolean(email && !isValidEmail()),
96
- onChange: (e) => setEmail(e.currentTarget.value),
97
- placeholder: formatMessage(getTrad("whitelist.email.placeholder"))
98
- }
99
- ) }) }),
100
- /* @__PURE__ */ jsx(Box, { style: { flex: 1 }, children: /* @__PURE__ */ jsx(Field.Root, { children: /* @__PURE__ */ jsx(
101
- MultiSelect,
102
- {
103
- withTags: true,
104
- placeholder: formatMessage(getTrad("whitelist.roles.placeholder")),
105
- value: selectedRoles,
106
- onChange: (value) => {
107
- setSelectedRoles(value || []);
108
- },
109
- children: roles.map((role) => /* @__PURE__ */ jsx(MultiSelectOption, { value: role.id.toString(), children: role.name }, role.id))
110
- }
111
- ) }) }),
112
- /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
113
- Button,
114
- {
115
- size: "L",
116
- startIcon: /* @__PURE__ */ jsx(Plus, {}),
117
- disabled: loading || email.trim() === "" || !isValidEmail(),
118
- loading,
119
- onClick: onSaveEmail,
120
- children: formatMessage(getTrad("page.add"))
121
- }
122
- ) })
123
- ] }),
124
- /* @__PURE__ */ jsx(Divider, {}),
125
- /* @__PURE__ */ jsxs(CustomTable, { colCount: 5, rowCount: users.length, children: [
126
- /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
127
- /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("whitelist.table.no")) }),
128
- /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("whitelist.table.email")) }),
129
- /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("whitelist.table.roles")) }),
130
- /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("whitelist.table.created")) }),
131
- /* @__PURE__ */ jsx(Th, { style: { paddingRight: 0 }, children: " " })
132
- ] }) }),
133
- /* @__PURE__ */ jsx(Tbody, { children: users.length === 0 ? /* @__PURE__ */ jsx(Tr, { children: /* @__PURE__ */ jsx(Td, { colSpan: 5, children: /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage(getTrad("whitelist.table.empty")) }) }) }) }) : paginatedUsers.map((user, index) => {
134
- const getRoleNames = (roleIds) => roleIds.map((roleId) => {
135
- const r = roles.find((ro) => String(ro.id) === String(roleId));
136
- return r ? r.name : roleId;
137
- }).join(", ");
138
- let userRolesNames = getRoleNames(user.roles || []);
139
- if (!userRolesNames) {
140
- const defaultRolesIds = oidcRoles.reduce((acc, oidc) => {
141
- if (oidc.role) acc.push(...oidc.role);
142
- return acc;
143
- }, []);
144
- userRolesNames = getRoleNames(defaultRolesIds);
145
- }
146
- return /* @__PURE__ */ jsxs(Tr, { children: [
147
- /* @__PURE__ */ jsx(Td, { children: index + 1 + (page - 1) * PAGE_SIZE }),
148
- /* @__PURE__ */ jsx(Td, { children: user.email }),
149
- /* @__PURE__ */ jsx(Td, { children: userRolesNames || "-" }),
150
- /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(LocalizedDate, { date: user.createdAt }) }),
151
- /* @__PURE__ */ jsx(Td, { style: { paddingRight: 0 }, children: /* @__PURE__ */ jsx(
152
- Flex,
153
- {
154
- justifyContent: "flex-end",
155
- onClick: (e) => e.stopPropagation(),
156
- style: { width: "100%" },
157
- children: /* @__PURE__ */ jsxs(Dialog.Root, { children: [
158
- /* @__PURE__ */ jsx(Dialog.Trigger, { children: /* @__PURE__ */ jsx(
159
- IconButton,
160
- {
161
- label: formatMessage(getTrad("whitelist.delete.label")),
162
- withTooltip: false,
163
- children: /* @__PURE__ */ jsx(Trash, {})
164
- }
165
- ) }),
166
- /* @__PURE__ */ jsxs(Dialog.Content, { children: [
167
- /* @__PURE__ */ jsx(Dialog.Header, { children: formatMessage(getTrad("whitelist.delete.title")) }),
168
- /* @__PURE__ */ jsx(Dialog.Body, { icon: /* @__PURE__ */ jsx(WarningCircle, { fill: "danger600" }), children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "center", gap: 2, children: [
169
- /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(Typography, { id: "confirm-description", children: formatMessage(getTrad("whitelist.delete.description")) }) }),
170
- /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", children: user.email }) }),
171
- /* @__PURE__ */ jsx(Flex, { justifyContent: "center", marginTop: 2, children: /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: formatMessage(getTrad("whitelist.delete.note")) }) })
172
- ] }) }),
173
- /* @__PURE__ */ jsxs(Dialog.Footer, { children: [
174
- /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { fullWidth: true, variant: "tertiary", children: formatMessage(getTrad("page.cancel")) }) }),
175
- /* @__PURE__ */ jsx(Dialog.Action, { children: /* @__PURE__ */ jsx(
176
- Button,
177
- {
178
- fullWidth: true,
179
- variant: "danger-light",
180
- onClick: () => onDelete(user.email),
181
- children: formatMessage(getTrad("page.ok"))
182
- }
183
- ) })
88
+ useWhitelist && /* @__PURE__ */ jsxs(Fragment, { children: [
89
+ /* @__PURE__ */ jsxs(Flex, { gap: 4, marginTop: 5, marginBottom: 5, alignItems: "flex-start", children: [
90
+ /* @__PURE__ */ jsx(Box, { style: { flex: 1 }, children: /* @__PURE__ */ jsx(Field.Root, { children: /* @__PURE__ */ jsx(
91
+ Field.Input,
92
+ {
93
+ type: "text",
94
+ disabled: loading,
95
+ value: email,
96
+ hasError: Boolean(email && !isValidEmail()),
97
+ onChange: (e) => setEmail(e.currentTarget.value),
98
+ placeholder: formatMessage(getTrad("whitelist.email.placeholder"))
99
+ }
100
+ ) }) }),
101
+ /* @__PURE__ */ jsx(Box, { style: { flex: 1 }, children: /* @__PURE__ */ jsx(Field.Root, { children: /* @__PURE__ */ jsx(
102
+ MultiSelect,
103
+ {
104
+ withTags: true,
105
+ placeholder: formatMessage(getTrad("whitelist.roles.placeholder")),
106
+ value: selectedRoles,
107
+ onChange: (value) => {
108
+ setSelectedRoles(value || []);
109
+ },
110
+ children: roles.map((role) => /* @__PURE__ */ jsx(MultiSelectOption, { value: role.id.toString(), children: role.name }, role.id))
111
+ }
112
+ ) }) }),
113
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
114
+ Button,
115
+ {
116
+ size: "L",
117
+ startIcon: /* @__PURE__ */ jsx(Plus, {}),
118
+ disabled: loading || email.trim() === "" || !isValidEmail(),
119
+ loading,
120
+ onClick: onSaveEmail,
121
+ children: formatMessage(getTrad("page.add"))
122
+ }
123
+ ) })
124
+ ] }),
125
+ /* @__PURE__ */ jsx(Divider, {}),
126
+ /* @__PURE__ */ jsxs(CustomTable, { colCount: 5, rowCount: users.length, children: [
127
+ /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
128
+ /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("whitelist.table.no")) }),
129
+ /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("whitelist.table.email")) }),
130
+ /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("whitelist.table.roles")) }),
131
+ /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("whitelist.table.created")) }),
132
+ /* @__PURE__ */ jsx(Th, { style: { paddingRight: 0 }, children: " " })
133
+ ] }) }),
134
+ /* @__PURE__ */ jsx(Tbody, { children: users.length === 0 ? /* @__PURE__ */ jsx(Tr, { children: /* @__PURE__ */ jsx(Td, { colSpan: 5, children: /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage(getTrad("whitelist.table.empty")) }) }) }) }) : paginatedUsers.map((user, index) => {
135
+ const getRoleNames = (roleIds) => roleIds.map((roleId) => {
136
+ const r = roles.find((ro) => String(ro.id) === String(roleId));
137
+ return r ? r.name : roleId;
138
+ }).join(", ");
139
+ let userRolesNames = getRoleNames(user.roles || []);
140
+ if (!userRolesNames) {
141
+ const defaultRolesIds = oidcRoles.reduce((acc, oidc) => {
142
+ if (oidc.role) acc.push(...oidc.role);
143
+ return acc;
144
+ }, []);
145
+ userRolesNames = getRoleNames(defaultRolesIds);
146
+ }
147
+ return /* @__PURE__ */ jsxs(Tr, { children: [
148
+ /* @__PURE__ */ jsx(Td, { children: index + 1 + (page - 1) * PAGE_SIZE }),
149
+ /* @__PURE__ */ jsx(Td, { children: user.email }),
150
+ /* @__PURE__ */ jsx(Td, { children: userRolesNames || "-" }),
151
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(LocalizedDate, { date: user.createdAt }) }),
152
+ /* @__PURE__ */ jsx(Td, { style: { paddingRight: 0 }, children: /* @__PURE__ */ jsx(
153
+ Flex,
154
+ {
155
+ justifyContent: "flex-end",
156
+ onClick: (e) => e.stopPropagation(),
157
+ style: { width: "100%" },
158
+ children: /* @__PURE__ */ jsxs(Dialog.Root, { children: [
159
+ /* @__PURE__ */ jsx(Dialog.Trigger, { children: /* @__PURE__ */ jsx(
160
+ IconButton,
161
+ {
162
+ label: formatMessage(getTrad("whitelist.delete.label")),
163
+ withTooltip: false,
164
+ children: /* @__PURE__ */ jsx(Trash, {})
165
+ }
166
+ ) }),
167
+ /* @__PURE__ */ jsxs(Dialog.Content, { children: [
168
+ /* @__PURE__ */ jsx(Dialog.Header, { children: formatMessage(getTrad("whitelist.delete.title")) }),
169
+ /* @__PURE__ */ jsx(Dialog.Body, { icon: /* @__PURE__ */ jsx(WarningCircle, { fill: "danger600" }), children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "center", gap: 2, children: [
170
+ /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(Typography, { id: "confirm-description", children: formatMessage(getTrad("whitelist.delete.description")) }) }),
171
+ /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", children: user.email }) }),
172
+ /* @__PURE__ */ jsx(Flex, { justifyContent: "center", marginTop: 2, children: /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: formatMessage(getTrad("whitelist.delete.note")) }) })
173
+ ] }) }),
174
+ /* @__PURE__ */ jsxs(Dialog.Footer, { children: [
175
+ /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { fullWidth: true, variant: "tertiary", children: formatMessage(getTrad("page.cancel")) }) }),
176
+ /* @__PURE__ */ jsx(Dialog.Action, { children: /* @__PURE__ */ jsx(
177
+ Button,
178
+ {
179
+ fullWidth: true,
180
+ variant: "danger-light",
181
+ onClick: () => onDelete(user.email),
182
+ children: formatMessage(getTrad("page.ok"))
183
+ }
184
+ ) })
185
+ ] })
184
186
  ] })
185
187
  ] })
186
- ] })
187
- }
188
- ) })
189
- ] }, user.email);
190
- }) })
191
- ] }),
192
- pageCount > 1 && /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(Flex, { justifyContent: "flex-end", children: /* @__PURE__ */ jsxs(Pagination, { activePage: page, pageCount, children: [
193
- /* @__PURE__ */ jsx(
194
- PreviousLink,
195
- {
196
- href: "#",
197
- onClick: (e) => {
198
- e.preventDefault();
199
- setPage((p) => Math.max(1, p - 1));
200
- },
201
- children: "Go to previous page"
202
- }
203
- ),
204
- Array.from({ length: pageCount }).map((_, i) => /* @__PURE__ */ jsxs(
205
- PageLink,
206
- {
207
- number: i + 1,
208
- href: "#",
209
- onClick: (e) => {
210
- e.preventDefault();
211
- setPage(i + 1);
212
- },
213
- children: [
214
- "Go to page ",
215
- i + 1
216
- ]
217
- },
218
- i + 1
219
- )),
220
- /* @__PURE__ */ jsx(
221
- NextLink,
222
- {
223
- href: "#",
224
- onClick: (e) => {
225
- e.preventDefault();
226
- setPage((p) => Math.min(pageCount, p + 1));
188
+ }
189
+ ) })
190
+ ] }, user.email);
191
+ }) })
192
+ ] }),
193
+ pageCount > 1 && /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(Flex, { justifyContent: "flex-end", children: /* @__PURE__ */ jsxs(Pagination, { activePage: page, pageCount, children: [
194
+ /* @__PURE__ */ jsx(
195
+ PreviousLink,
196
+ {
197
+ href: "#",
198
+ onClick: (e) => {
199
+ e.preventDefault();
200
+ setPage((p) => Math.max(1, p - 1));
201
+ },
202
+ children: "Go to previous page"
203
+ }
204
+ ),
205
+ Array.from({ length: pageCount }).map((_, i) => /* @__PURE__ */ jsxs(
206
+ PageLink,
207
+ {
208
+ number: i + 1,
209
+ href: "#",
210
+ onClick: (e) => {
211
+ e.preventDefault();
212
+ setPage(i + 1);
213
+ },
214
+ children: [
215
+ "Go to page ",
216
+ i + 1
217
+ ]
227
218
  },
228
- children: "Go to next page"
229
- }
230
- )
231
- ] }) }) })
219
+ i + 1
220
+ )),
221
+ /* @__PURE__ */ jsx(
222
+ NextLink,
223
+ {
224
+ href: "#",
225
+ onClick: (e) => {
226
+ e.preventDefault();
227
+ setPage((p) => Math.min(pageCount, p + 1));
228
+ },
229
+ children: "Go to next page"
230
+ }
231
+ )
232
+ ] }) }) })
233
+ ] })
232
234
  ] }) });
233
235
  }
234
236
  const AlertMessage = styled.div`
235
- position: fixed;
236
- left: 50%;
237
- transform: translateX(-50%);
238
- top: 2.875rem;
239
- z-index: 10;
240
- width: 31.25rem;
237
+ position: fixed;
238
+ left: 50%;
239
+ transform: translateX(-50%);
240
+ top: 2.875rem;
241
+ z-index: 10;
242
+ width: 31.25rem;
241
243
  `;
242
244
  function SuccessAlertMessage({ onClose }) {
243
245
  const { formatMessage } = useIntl();
244
- return /* @__PURE__ */ jsx(AlertMessage, { children: /* @__PURE__ */ jsx(
245
- Alert,
246
- {
247
- title: "Success",
248
- variant: "success",
249
- closeLabel: "",
250
- onClose,
251
- children: formatMessage(getTrad("page.save.success"))
252
- }
253
- ) });
246
+ return /* @__PURE__ */ jsx(AlertMessage, { children: /* @__PURE__ */ jsx(Alert, { title: "Success", variant: "success", closeLabel: "", onClose, children: formatMessage(getTrad("page.save.success")) }) });
254
247
  }
255
248
  function ErrorAlertMessage({ onClose }) {
256
249
  const { formatMessage } = useIntl();
257
- return /* @__PURE__ */ jsx(AlertMessage, { children: /* @__PURE__ */ jsx(
258
- Alert,
259
- {
260
- title: "Error",
261
- variant: "danger",
262
- closeLabel: "",
263
- onClose,
264
- children: formatMessage(getTrad("page.save.error"))
265
- }
266
- ) });
250
+ return /* @__PURE__ */ jsx(AlertMessage, { children: /* @__PURE__ */ jsx(Alert, { title: "Error", variant: "danger", closeLabel: "", onClose, children: formatMessage(getTrad("page.save.error")) }) });
267
251
  }
268
- function MatchedUserAlertMessage({ onClose, count }) {
252
+ function MatchedUserAlertMessage({
253
+ onClose,
254
+ count
255
+ }) {
269
256
  const { formatMessage } = useIntl();
270
- const id = count > 1 ? "tab.whitelist.users_exists" : "tab.whitelist.user_exists";
271
- return /* @__PURE__ */ jsx(AlertMessage, { children: /* @__PURE__ */ jsx(
272
- Alert,
273
- {
274
- title: "Info",
275
- variant: "default",
276
- closeLabel: "",
277
- onClose,
278
- children: formatMessage(getTrad(id))
279
- }
280
- ) });
257
+ const id = count > 1 ? "whitelist.users_exists" : "whitelist.user_exists";
258
+ return /* @__PURE__ */ jsx(AlertMessage, { children: /* @__PURE__ */ jsx(Alert, { title: "Info", variant: "default", closeLabel: "", onClose, children: formatMessage(getTrad(id)) }) });
281
259
  }
282
260
  const SwitchContainer = styled.label`
283
261
  position: relative;
@@ -391,10 +369,18 @@ function useOidcSettings() {
391
369
  setUsers([...users, newUser]);
392
370
  };
393
371
  const onDeleteWhitelist = async (email) => {
394
- setUsers(users.filter((u) => u.email !== email));
372
+ const updatedUsers = users.filter((u) => u.email !== email);
373
+ setUsers(updatedUsers);
374
+ if (useWhitelist && updatedUsers.length === 0) {
375
+ setEnforceOIDC(false);
376
+ }
395
377
  };
396
378
  const onToggleWhitelist = (e) => {
397
- setUseWhitelist(e.target.checked);
379
+ const checked = e.target.checked;
380
+ setUseWhitelist(checked);
381
+ if (checked && users.length === 0) {
382
+ setEnforceOIDC(false);
383
+ }
398
384
  };
399
385
  const onToggleEnforce = (e) => {
400
386
  setEnforceOIDC(e.target.checked);
@@ -409,13 +395,13 @@ function useOidcSettings() {
409
395
  role: role.role
410
396
  }))
411
397
  });
398
+ const syncResponse = await put("/strapi-plugin-oidc/whitelist/sync", {
399
+ users: users.map((u) => ({ email: u.email, roles: u.roles }))
400
+ });
412
401
  await put("/strapi-plugin-oidc/whitelist/settings", {
413
402
  useWhitelist,
414
403
  enforceOIDC
415
404
  });
416
- const syncResponse = await put("/strapi-plugin-oidc/whitelist/sync", {
417
- users: users.map((u) => ({ email: u.email, roles: u.roles }))
418
- });
419
405
  setInitialOIDCRoles(JSON.parse(JSON.stringify(oidcRoles)));
420
406
  setInitialUseWhitelist(useWhitelist);
421
407
  setInitialEnforceOIDC(enforceOIDC);
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const index = require("./index-B525UaV3.js");
3
+ const index = require("./index-Bc2bQNhu.js");
4
4
  exports.default = index.index;
@@ -1,4 +1,4 @@
1
- import { i } from "./index-D3AvxXlB.mjs";
1
+ import { i } from "./index-Cz9Q6j4e.mjs";
2
2
  export {
3
3
  i as default
4
4
  };