strapi-plugin-magic-sessionmanager 4.21.0 → 4.22.1
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/CHANGELOG.md +97 -0
- package/README.md +92 -47
- package/dist/admin/{Analytics-BqdZIBV4.js → Analytics-B7BAjApz.js} +1 -1
- package/dist/admin/{Analytics-C-OLLzoB.mjs → Analytics-CIHgaURb.mjs} +1 -1
- package/dist/admin/{App-BswHmNQT.mjs → App-CPE-CQGz.mjs} +1309 -2564
- package/dist/admin/{App-Cx9v6n_7.js → App-DJkJC06E.js} +1336 -2591
- package/dist/admin/{OnlineUsersWidget-BRmQPPp9.js → OnlineUsersWidget-CcjNfzzf.js} +1 -1
- package/dist/admin/{OnlineUsersWidget-Dusgjc1d.mjs → OnlineUsersWidget-Dou2hxGY.mjs} +1 -1
- package/dist/admin/{Settings-DWGuf_Z3.js → Settings--eEiHv_a.js} +104 -81
- package/dist/admin/{Settings-DZyQheUS.mjs → Settings-h_exWUiI.mjs} +62 -39
- package/dist/admin/dashboardModel-DNT_l-Bk.js +169 -0
- package/dist/admin/dashboardModel-fApbKGay.mjs +170 -0
- package/dist/admin/{de-DUnrmFWk.mjs → de-Wz5Emtrb.mjs} +79 -7
- package/dist/admin/{de-24TPqzG6.js → de-oBmcAcXj.js} +79 -7
- package/dist/admin/{en-8mBSkWOF.js → en-B1TN5F62.js} +80 -8
- package/dist/admin/{en-D8J__tyF.mjs → en-B_1Ka64U.mjs} +80 -8
- package/dist/admin/{es-ChUKey-Q.js → es-Bb515J0p.js} +79 -7
- package/dist/admin/{es-BgpgWdk0.mjs → es-CVgw4zsj.mjs} +79 -7
- package/dist/admin/{fr-k1MHYKJo.mjs → fr-0AgMxTFc.mjs} +79 -7
- package/dist/admin/{fr-DE_CWmgq.js → fr-yDdwunmg.js} +79 -7
- package/dist/admin/index-DVQ7tdTC.mjs +4746 -0
- package/dist/admin/index-qtN2dOm4.js +4747 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/{pt-BjqU5ioB.js → pt-BAB07LY-.js} +79 -7
- package/dist/admin/{pt-DPO4DmDc.mjs → pt-DtM74ffN.mjs} +79 -7
- package/dist/server/index.js +1487 -438
- package/dist/server/index.mjs +1487 -438
- package/package.json +4 -3
- package/dist/admin/index-Ceh3Q1Ki.js +0 -2308
- package/dist/admin/index-meLDPPwt.mjs +0 -2307
- package/dist/admin/settingsTabs-C1q5iMMw.mjs +0 -437
- package/dist/admin/settingsTabs-CfquZuKH.js +0 -436
|
@@ -0,0 +1,4747 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const react = require("react");
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const icons = require("@strapi/icons");
|
|
5
|
+
const reactIntl = require("react-intl");
|
|
6
|
+
const reactRouterDom = require("react-router-dom");
|
|
7
|
+
const designSystem = require("@strapi/design-system");
|
|
8
|
+
const StrapiAdmin = require("@strapi/strapi/admin");
|
|
9
|
+
const styled = require("styled-components");
|
|
10
|
+
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
11
|
+
const styled__default = /* @__PURE__ */ _interopDefault(styled);
|
|
12
|
+
const strapi = { "name": "magic-sessionmanager", "displayName": "Magic Sessionmanager" };
|
|
13
|
+
const pluginPkg = {
|
|
14
|
+
strapi
|
|
15
|
+
};
|
|
16
|
+
const pluginId$1 = "magic-sessionmanager";
|
|
17
|
+
const PLUGIN_ID = pluginId$1;
|
|
18
|
+
const Initializer = ({ setPlugin }) => {
|
|
19
|
+
const ref = react.useRef(setPlugin);
|
|
20
|
+
react.useEffect(() => {
|
|
21
|
+
if (ref.current) {
|
|
22
|
+
ref.current(pluginId$1);
|
|
23
|
+
}
|
|
24
|
+
}, []);
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
27
|
+
const PluginIcon = (props) => /* @__PURE__ */ jsxRuntime.jsx(icons.Monitor, { "aria-hidden": true, focusable: false, ...props });
|
|
28
|
+
const TONES = {
|
|
29
|
+
danger: { background: "danger100", border: "danger200", icon: "danger700" },
|
|
30
|
+
success: { background: "success100", border: "success200", icon: "success700" },
|
|
31
|
+
warning: { background: "warning100", border: "warning200", icon: "warning700" },
|
|
32
|
+
default: { background: "primary100", border: "primary200", icon: "primary700" },
|
|
33
|
+
neutral: { background: "neutral0", border: "neutral200", icon: "neutral600" }
|
|
34
|
+
};
|
|
35
|
+
const AlertBody = styled__default.default(designSystem.Typography)`
|
|
36
|
+
min-width: 0;
|
|
37
|
+
|
|
38
|
+
& > * {
|
|
39
|
+
display: inline;
|
|
40
|
+
max-width: none;
|
|
41
|
+
margin: 0;
|
|
42
|
+
font-size: inherit;
|
|
43
|
+
font-weight: inherit;
|
|
44
|
+
line-height: inherit;
|
|
45
|
+
color: inherit;
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
const PersistentAlert = react.forwardRef(function PersistentAlert2({
|
|
49
|
+
variant = "default",
|
|
50
|
+
title,
|
|
51
|
+
titleAs = "p",
|
|
52
|
+
stacked = false,
|
|
53
|
+
action,
|
|
54
|
+
closeLabel: _closeLabel,
|
|
55
|
+
onClose: _onClose,
|
|
56
|
+
children,
|
|
57
|
+
...rest
|
|
58
|
+
}, ref) {
|
|
59
|
+
const tone = TONES[variant] || TONES.default;
|
|
60
|
+
const Icon = variant === "success" ? icons.CheckCircle : variant === "danger" || variant === "warning" ? icons.WarningCircle : icons.Information;
|
|
61
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
62
|
+
designSystem.Flex,
|
|
63
|
+
{
|
|
64
|
+
ref,
|
|
65
|
+
alignItems: "flex-start",
|
|
66
|
+
background: tone.background,
|
|
67
|
+
borderColor: tone.border,
|
|
68
|
+
shadow: "filterShadow",
|
|
69
|
+
gap: 3,
|
|
70
|
+
hasRadius: true,
|
|
71
|
+
padding: 5,
|
|
72
|
+
paddingRight: 6,
|
|
73
|
+
"data-persistent-alert": "",
|
|
74
|
+
...rest,
|
|
75
|
+
children: [
|
|
76
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { shrink: 0, width: "2rem", height: "2rem", children: /* @__PURE__ */ jsxRuntime.jsx(Icon, { "aria-hidden": true, focusable: "false", width: "2rem", height: "2rem", fill: tone.icon }) }),
|
|
77
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
78
|
+
designSystem.Flex,
|
|
79
|
+
{
|
|
80
|
+
direction: stacked ? "column" : "row",
|
|
81
|
+
alignItems: stacked ? "stretch" : "start",
|
|
82
|
+
gap: action || stacked ? 2 : 1,
|
|
83
|
+
wrap: stacked ? "nowrap" : "wrap",
|
|
84
|
+
role: variant === "danger" ? "alert" : "status",
|
|
85
|
+
width: "100%",
|
|
86
|
+
minWidth: 0,
|
|
87
|
+
children: [
|
|
88
|
+
title ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "bold", textColor: "neutral800", tag: titleAs, children: title }) : null,
|
|
89
|
+
/* @__PURE__ */ jsxRuntime.jsx(AlertBody, { tag: "div", variant: "omega", textColor: "neutral800", children }),
|
|
90
|
+
action ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { children: action }) : null
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
const paragraphRhythm = styled.css`
|
|
99
|
+
p {
|
|
100
|
+
max-width: 72ch;
|
|
101
|
+
margin-block: 0;
|
|
102
|
+
line-height: 1.6;
|
|
103
|
+
text-wrap: pretty;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
p + p {
|
|
107
|
+
margin-block-start: ${({ theme }) => theme.spaces[3]};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
li {
|
|
111
|
+
max-width: 72ch;
|
|
112
|
+
line-height: 1.6;
|
|
113
|
+
text-wrap: pretty;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
li + li {
|
|
117
|
+
margin-block-start: ${({ theme }) => theme.spaces[2]};
|
|
118
|
+
}
|
|
119
|
+
`;
|
|
120
|
+
const ReadableText = styled__default.default(designSystem.Typography)`
|
|
121
|
+
display: block;
|
|
122
|
+
width: 100%;
|
|
123
|
+
min-width: 0;
|
|
124
|
+
max-width: 72ch;
|
|
125
|
+
margin: 0;
|
|
126
|
+
line-height: 1.6;
|
|
127
|
+
text-wrap: pretty;
|
|
128
|
+
|
|
129
|
+
& + & {
|
|
130
|
+
margin-block-start: ${({ theme }) => theme.spaces[3]};
|
|
131
|
+
}
|
|
132
|
+
`;
|
|
133
|
+
const ParagraphGroup = styled__default.default.div`
|
|
134
|
+
display: block;
|
|
135
|
+
width: 100%;
|
|
136
|
+
min-width: 0;
|
|
137
|
+
`;
|
|
138
|
+
const InlineParagraphGroup = styled__default.default.span`
|
|
139
|
+
display: block;
|
|
140
|
+
width: 100%;
|
|
141
|
+
min-width: 0;
|
|
142
|
+
`;
|
|
143
|
+
const ReadableParagraphs = ({ id, text, ...typographyProps }) => {
|
|
144
|
+
const ParagraphContainer = typographyProps.tag === "span" ? InlineParagraphGroup : ParagraphGroup;
|
|
145
|
+
const paragraphs = String(text ?? "").split(/\n\s*\n/).map((paragraph) => paragraph.trim()).filter(Boolean);
|
|
146
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ParagraphContainer, { id, "data-readable-paragraphs": "", children: paragraphs.map((paragraph, index2) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
147
|
+
ReadableText,
|
|
148
|
+
{
|
|
149
|
+
...typographyProps,
|
|
150
|
+
tag: typographyProps.tag || "p",
|
|
151
|
+
children: paragraph
|
|
152
|
+
},
|
|
153
|
+
`${id || "readable-paragraph"}-${index2}`
|
|
154
|
+
)) });
|
|
155
|
+
};
|
|
156
|
+
const PageContent = styled__default.default(designSystem.Flex)`
|
|
157
|
+
width: 100%;
|
|
158
|
+
min-width: 0;
|
|
159
|
+
|
|
160
|
+
${paragraphRhythm}
|
|
161
|
+
`;
|
|
162
|
+
const PageShell = ({
|
|
163
|
+
headingId,
|
|
164
|
+
title,
|
|
165
|
+
documentTitle,
|
|
166
|
+
subtitle,
|
|
167
|
+
primaryAction,
|
|
168
|
+
secondaryAction,
|
|
169
|
+
navigationAction,
|
|
170
|
+
startActions,
|
|
171
|
+
endActions,
|
|
172
|
+
children
|
|
173
|
+
}) => {
|
|
174
|
+
const generatedId = react.useId();
|
|
175
|
+
const titleId = headingId || `page-title-${generatedId.replace(/:/g, "")}`;
|
|
176
|
+
const hasActionBar = Boolean(startActions || endActions);
|
|
177
|
+
const tabTitle = documentTitle || (typeof title === "string" ? title : "");
|
|
178
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(StrapiAdmin.Page.Main, { "aria-labelledby": titleId, children: [
|
|
179
|
+
tabTitle ? /* @__PURE__ */ jsxRuntime.jsx(StrapiAdmin.Page.Title, { children: tabTitle }) : null,
|
|
180
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
181
|
+
StrapiAdmin.Layouts.Header,
|
|
182
|
+
{
|
|
183
|
+
id: titleId,
|
|
184
|
+
title,
|
|
185
|
+
subtitle,
|
|
186
|
+
primaryAction,
|
|
187
|
+
secondaryAction,
|
|
188
|
+
navigationAction
|
|
189
|
+
}
|
|
190
|
+
),
|
|
191
|
+
hasActionBar ? /* @__PURE__ */ jsxRuntime.jsx(StrapiAdmin.Layouts.Action, { startActions, endActions }) : null,
|
|
192
|
+
/* @__PURE__ */ jsxRuntime.jsx(StrapiAdmin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
193
|
+
PageContent,
|
|
194
|
+
{
|
|
195
|
+
direction: "column",
|
|
196
|
+
alignItems: "stretch",
|
|
197
|
+
gap: 6,
|
|
198
|
+
paddingBottom: 8,
|
|
199
|
+
"data-text-rhythm": "page",
|
|
200
|
+
"data-page-shell": "",
|
|
201
|
+
children
|
|
202
|
+
}
|
|
203
|
+
) })
|
|
204
|
+
] });
|
|
205
|
+
};
|
|
206
|
+
const ALLOWED_COLUMNS = /* @__PURE__ */ new Set([1, 2, 3, 4, 6]);
|
|
207
|
+
function getGridItemSpans(columns, stackBelow = "medium") {
|
|
208
|
+
const count = ALLOWED_COLUMNS.has(columns) ? columns : 2;
|
|
209
|
+
const col = 12 / count;
|
|
210
|
+
const twoUp = count >= 2 ? 6 : 12;
|
|
211
|
+
if (stackBelow === "small") {
|
|
212
|
+
return { xs: 12, s: twoUp, m: twoUp, col };
|
|
213
|
+
}
|
|
214
|
+
return { xs: 12, s: 12, m: twoUp, col };
|
|
215
|
+
}
|
|
216
|
+
const EqualGrid = ({ columns = 2, stackBelow = "medium", gap = 6, label, children }) => {
|
|
217
|
+
const spans = getGridItemSpans(columns, stackBelow);
|
|
218
|
+
const items = react.Children.toArray(children).filter(Boolean);
|
|
219
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
220
|
+
designSystem.Grid.Root,
|
|
221
|
+
{
|
|
222
|
+
gap,
|
|
223
|
+
role: label ? "group" : void 0,
|
|
224
|
+
"aria-label": label,
|
|
225
|
+
"data-equal-grid": columns,
|
|
226
|
+
children: items.map((child, index2) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
227
|
+
designSystem.Grid.Item,
|
|
228
|
+
{
|
|
229
|
+
col: spans.col,
|
|
230
|
+
m: spans.m,
|
|
231
|
+
s: spans.s,
|
|
232
|
+
xs: spans.xs,
|
|
233
|
+
direction: "column",
|
|
234
|
+
alignItems: "stretch",
|
|
235
|
+
minWidth: 0,
|
|
236
|
+
children: child
|
|
237
|
+
},
|
|
238
|
+
child.key ?? index2
|
|
239
|
+
))
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
};
|
|
243
|
+
const STAT_GRID_FOLD_REM = (4 * 200 + 3 * 16) / 10;
|
|
244
|
+
const DS_SMALL_REM = 52;
|
|
245
|
+
const StatGridFrame = styled__default.default.div`
|
|
246
|
+
container-type: inline-size;
|
|
247
|
+
min-width: 0;
|
|
248
|
+
|
|
249
|
+
@container (min-width: ${DS_SMALL_REM}rem) and (max-width: ${STAT_GRID_FOLD_REM - 0.01}rem) {
|
|
250
|
+
[data-equal-grid='4'] > * {
|
|
251
|
+
grid-column: span 6;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/* Rows without secondary lines: pin every value to the card bottom, so a
|
|
256
|
+
label that wraps onto two lines does not push its value off the row's line. */
|
|
257
|
+
&[data-align-values] [data-stat-body] {
|
|
258
|
+
flex: 1 1 auto;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
&[data-align-values] [data-stat-text] {
|
|
262
|
+
justify-content: space-between;
|
|
263
|
+
}
|
|
264
|
+
`;
|
|
265
|
+
const StatGrid = ({ columns = 4, label, alignValues = false, children }) => /* @__PURE__ */ jsxRuntime.jsx(StatGridFrame, { "data-stat-grid": "", "data-align-values": alignValues ? "" : void 0, children: /* @__PURE__ */ jsxRuntime.jsx(EqualGrid, { columns, stackBelow: "small", gap: 4, label, children }) });
|
|
266
|
+
const IconTile = styled__default.default(designSystem.Flex)`
|
|
267
|
+
align-self: flex-start;
|
|
268
|
+
|
|
269
|
+
svg {
|
|
270
|
+
width: ${({ theme }) => theme.spaces[5]};
|
|
271
|
+
height: ${({ theme }) => theme.spaces[5]};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
svg path {
|
|
275
|
+
fill: ${({ theme, $tone }) => theme.colors[`${$tone}600`]};
|
|
276
|
+
}
|
|
277
|
+
`;
|
|
278
|
+
const STAT_TONES = /* @__PURE__ */ new Set([
|
|
279
|
+
"primary",
|
|
280
|
+
"success",
|
|
281
|
+
"warning",
|
|
282
|
+
"danger",
|
|
283
|
+
"neutral",
|
|
284
|
+
"secondary",
|
|
285
|
+
"alternative"
|
|
286
|
+
]);
|
|
287
|
+
const CardButton = styled__default.default(designSystem.Box)`
|
|
288
|
+
appearance: none;
|
|
289
|
+
font: inherit;
|
|
290
|
+
color: inherit;
|
|
291
|
+
text-align: start;
|
|
292
|
+
cursor: pointer;
|
|
293
|
+
width: 100%;
|
|
294
|
+
|
|
295
|
+
&:hover {
|
|
296
|
+
background: ${({ theme }) => theme.colors.primary100};
|
|
297
|
+
}
|
|
298
|
+
`;
|
|
299
|
+
const StatCard = ({
|
|
300
|
+
label,
|
|
301
|
+
value,
|
|
302
|
+
icon: Icon,
|
|
303
|
+
tone = "neutral",
|
|
304
|
+
description,
|
|
305
|
+
onClick,
|
|
306
|
+
pressed,
|
|
307
|
+
actionLabel
|
|
308
|
+
}) => {
|
|
309
|
+
const safeTone = STAT_TONES.has(tone) ? tone : "neutral";
|
|
310
|
+
const clickable = typeof onClick === "function";
|
|
311
|
+
const buttonProps = clickable ? {
|
|
312
|
+
tag: "button",
|
|
313
|
+
type: "button",
|
|
314
|
+
onClick,
|
|
315
|
+
"aria-pressed": Boolean(pressed),
|
|
316
|
+
"aria-label": actionLabel
|
|
317
|
+
} : {};
|
|
318
|
+
const Card = clickable ? CardButton : designSystem.Box;
|
|
319
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
320
|
+
Card,
|
|
321
|
+
{
|
|
322
|
+
...buttonProps,
|
|
323
|
+
background: "neutral0",
|
|
324
|
+
hasRadius: true,
|
|
325
|
+
shadow: "tableShadow",
|
|
326
|
+
borderColor: clickable ? pressed ? "primary600" : "neutral150" : void 0,
|
|
327
|
+
padding: 4,
|
|
328
|
+
flex: "1 1 auto",
|
|
329
|
+
minWidth: 0,
|
|
330
|
+
"data-stat-card": safeTone,
|
|
331
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, height: "100%", children: [
|
|
332
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, alignItems: "stretch", minWidth: 0, "data-stat-body": "", children: [
|
|
333
|
+
Icon ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
334
|
+
IconTile,
|
|
335
|
+
{
|
|
336
|
+
$tone: safeTone,
|
|
337
|
+
background: `${safeTone}100`,
|
|
338
|
+
hasRadius: true,
|
|
339
|
+
padding: 2,
|
|
340
|
+
shrink: 0,
|
|
341
|
+
justifyContent: "center",
|
|
342
|
+
alignItems: "center",
|
|
343
|
+
"aria-hidden": true,
|
|
344
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Icon, { "aria-hidden": true, focusable: false })
|
|
345
|
+
}
|
|
346
|
+
) : null,
|
|
347
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
348
|
+
designSystem.Flex,
|
|
349
|
+
{
|
|
350
|
+
direction: "column",
|
|
351
|
+
alignItems: "flex-start",
|
|
352
|
+
gap: 1,
|
|
353
|
+
minWidth: 0,
|
|
354
|
+
flex: "1 1 auto",
|
|
355
|
+
"data-stat-text": "",
|
|
356
|
+
children: [
|
|
357
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", tag: "span", children: label }),
|
|
358
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "beta", textColor: "neutral800", tag: "span", children: value })
|
|
359
|
+
]
|
|
360
|
+
}
|
|
361
|
+
)
|
|
362
|
+
] }),
|
|
363
|
+
description ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", tag: "span", children: description }) : null
|
|
364
|
+
] })
|
|
365
|
+
}
|
|
366
|
+
);
|
|
367
|
+
};
|
|
368
|
+
const MISSING_VALUE_GLYPH = "—";
|
|
369
|
+
const MISSING_VALUE_MESSAGE = Object.freeze({
|
|
370
|
+
messageId: "common.value.missing",
|
|
371
|
+
defaultMessage: "Not available"
|
|
372
|
+
});
|
|
373
|
+
function isMissingValue(value) {
|
|
374
|
+
if (value === null || value === void 0) return true;
|
|
375
|
+
if (typeof value === "number") return !Number.isFinite(value);
|
|
376
|
+
if (value instanceof Date) return !Number.isFinite(value.getTime());
|
|
377
|
+
if (typeof value === "string") {
|
|
378
|
+
const trimmed = value.trim();
|
|
379
|
+
return trimmed === "" || trimmed.toLowerCase() === "unknown";
|
|
380
|
+
}
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
function presentText(value) {
|
|
384
|
+
if (isMissingValue(value)) return "";
|
|
385
|
+
return String(value).trim();
|
|
386
|
+
}
|
|
387
|
+
const getTranslation = (id) => `${PLUGIN_ID}.${id}`;
|
|
388
|
+
const MissingValue = ({ textColor = "neutral600", variant }) => {
|
|
389
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
390
|
+
const label = formatMessage({
|
|
391
|
+
id: getTranslation(MISSING_VALUE_MESSAGE.messageId),
|
|
392
|
+
defaultMessage: MISSING_VALUE_MESSAGE.defaultMessage
|
|
393
|
+
});
|
|
394
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { textColor, variant, "data-missing-value": "", children: [
|
|
395
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: MISSING_VALUE_GLYPH }),
|
|
396
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { children: label })
|
|
397
|
+
] });
|
|
398
|
+
};
|
|
399
|
+
const ValueOrMissing = ({ value, children, textColor, variant }) => {
|
|
400
|
+
if (isMissingValue(value)) return /* @__PURE__ */ jsxRuntime.jsx(MissingValue, { textColor, variant });
|
|
401
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children ?? String(value) });
|
|
402
|
+
};
|
|
403
|
+
const List = styled__default.default.dl`
|
|
404
|
+
display: grid;
|
|
405
|
+
grid-template-columns: minmax(0, 1fr);
|
|
406
|
+
gap: ${({ theme }) => theme.spaces[4]};
|
|
407
|
+
column-gap: ${({ theme, $columnGap }) => theme.spaces[$columnGap ?? 4]};
|
|
408
|
+
margin: 0;
|
|
409
|
+
min-width: 0;
|
|
410
|
+
|
|
411
|
+
${({ theme }) => theme.breakpoints.small} {
|
|
412
|
+
grid-template-columns: repeat(${({ $columns }) => $columns}, minmax(0, 1fr));
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
& > div {
|
|
416
|
+
display: flex;
|
|
417
|
+
flex-direction: column;
|
|
418
|
+
gap: ${({ theme }) => theme.spaces[1]};
|
|
419
|
+
min-width: 0;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
& > div[data-span='full'] {
|
|
423
|
+
grid-column: 1 / -1;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
dt,
|
|
427
|
+
dd {
|
|
428
|
+
margin: 0;
|
|
429
|
+
min-width: 0;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
dd {
|
|
433
|
+
overflow-wrap: break-word;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
dd[data-wrap='anywhere'] {
|
|
437
|
+
overflow-wrap: anywhere;
|
|
438
|
+
}
|
|
439
|
+
`;
|
|
440
|
+
const PropertyList = ({ items = [], columns = 2, label, columnGap }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
441
|
+
List,
|
|
442
|
+
{
|
|
443
|
+
$columns: columns === 1 ? 1 : 2,
|
|
444
|
+
$columnGap: columnGap,
|
|
445
|
+
"aria-label": label,
|
|
446
|
+
"data-property-list": "",
|
|
447
|
+
children: items.filter(Boolean).map((item) => {
|
|
448
|
+
const wrapsAnywhere = item.kind === "id" || item.kind === "email";
|
|
449
|
+
const missing = item.render === void 0 && isMissingValue(item.value);
|
|
450
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-span": item.fullWidth ? "full" : void 0, children: [
|
|
451
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: item.label }) }),
|
|
452
|
+
/* @__PURE__ */ jsxRuntime.jsx("dd", { "data-wrap": wrapsAnywhere ? "anywhere" : void 0, children: missing ? /* @__PURE__ */ jsxRuntime.jsx(MissingValue, { variant: "omega" }) : item.render ?? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", textColor: "neutral800", children: String(item.value) }) })
|
|
453
|
+
] }, item.id);
|
|
454
|
+
})
|
|
455
|
+
}
|
|
456
|
+
);
|
|
457
|
+
const DEFAULT_DATE_OPTIONS = Object.freeze({ dateStyle: "medium", timeStyle: "short" });
|
|
458
|
+
const RELATIVE_UNITS = [
|
|
459
|
+
["year", 365 * 24 * 60 * 60],
|
|
460
|
+
["month", 30 * 24 * 60 * 60],
|
|
461
|
+
["week", 7 * 24 * 60 * 60],
|
|
462
|
+
["day", 24 * 60 * 60],
|
|
463
|
+
["hour", 60 * 60],
|
|
464
|
+
["minute", 60],
|
|
465
|
+
["second", 1]
|
|
466
|
+
];
|
|
467
|
+
function toValidDate(value) {
|
|
468
|
+
if (value === null || value === void 0 || value === "") return null;
|
|
469
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
470
|
+
return Number.isFinite(date.getTime()) ? date : null;
|
|
471
|
+
}
|
|
472
|
+
function formatSessionDate(value, locale, fallback = "", options = DEFAULT_DATE_OPTIONS) {
|
|
473
|
+
const date = toValidDate(value);
|
|
474
|
+
if (!date) return fallback;
|
|
475
|
+
try {
|
|
476
|
+
return new Intl.DateTimeFormat(locale || "en", options).format(date);
|
|
477
|
+
} catch {
|
|
478
|
+
return new Intl.DateTimeFormat("en", options).format(date);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
function getRelativeTimeParts(value, now = Date.now()) {
|
|
482
|
+
const date = toValidDate(value);
|
|
483
|
+
const reference = toValidDate(now);
|
|
484
|
+
if (!date || !reference) return null;
|
|
485
|
+
const diffSeconds = Math.round((date.getTime() - reference.getTime()) / 1e3);
|
|
486
|
+
const absolute = Math.abs(diffSeconds);
|
|
487
|
+
if (absolute < 45) return { value: 0, unit: "second" };
|
|
488
|
+
for (const [unit, seconds] of RELATIVE_UNITS) {
|
|
489
|
+
if (absolute >= seconds) {
|
|
490
|
+
const amount = Math.round(diffSeconds / seconds);
|
|
491
|
+
return { value: amount === 0 ? Math.sign(diffSeconds) : amount, unit };
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
return { value: 0, unit: "second" };
|
|
495
|
+
}
|
|
496
|
+
function formatRelative(value, locale, { now = Date.now(), fallback = "" } = {}) {
|
|
497
|
+
const parts = getRelativeTimeParts(value, now);
|
|
498
|
+
if (!parts) return fallback;
|
|
499
|
+
const options = { numeric: "auto" };
|
|
500
|
+
try {
|
|
501
|
+
return new Intl.RelativeTimeFormat(locale || "en", options).format(parts.value, parts.unit);
|
|
502
|
+
} catch {
|
|
503
|
+
return new Intl.RelativeTimeFormat("en", options).format(parts.value, parts.unit);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
const API_CLIENTS = [
|
|
507
|
+
["curl/", "cURL"],
|
|
508
|
+
["postman", "Postman"],
|
|
509
|
+
["insomnia", "Insomnia"],
|
|
510
|
+
["okhttp", "OkHttp"],
|
|
511
|
+
["python-requests", "Python Requests"],
|
|
512
|
+
["axios/", "Axios"],
|
|
513
|
+
["node-fetch", "node-fetch"],
|
|
514
|
+
["undici", "undici"],
|
|
515
|
+
["go-http-client", "Go HTTP client"],
|
|
516
|
+
["cfnetwork/", "CFNetwork"],
|
|
517
|
+
["dart/", "Dart"],
|
|
518
|
+
["java/", "Java"],
|
|
519
|
+
["wget/", "Wget"],
|
|
520
|
+
["httpie/", "HTTPie"]
|
|
521
|
+
];
|
|
522
|
+
const RUNTIME_AGENTS = Object.freeze({ node: "Node.js", deno: "Deno", bun: "Bun" });
|
|
523
|
+
const BOT_PATTERN = /bot\b|crawler|spider|slurp|headlesschrome/i;
|
|
524
|
+
const TABLET_PATTERN = /(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i;
|
|
525
|
+
const MOBILE_PATTERN = /Mobile|Android|iP(?:hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(?:hpw|web)OS|Opera M(?:obi|ini)/;
|
|
526
|
+
const LEGACY_DEVICE_LABELS = Object.freeze({
|
|
527
|
+
desktop: "Desktop",
|
|
528
|
+
mobile: "Mobile",
|
|
529
|
+
tablet: "Tablet",
|
|
530
|
+
api: "API Client",
|
|
531
|
+
bot: "Bot",
|
|
532
|
+
"": ""
|
|
533
|
+
});
|
|
534
|
+
const detectBrowser = (ua) => {
|
|
535
|
+
if (ua.includes("edg/") || ua.includes("edga/") || ua.includes("edgios/")) return "Edge";
|
|
536
|
+
if (ua.includes("opr/") || ua.includes("opera")) return "Opera";
|
|
537
|
+
if (ua.includes("firefox/") || ua.includes("fxios/")) return "Firefox";
|
|
538
|
+
if (ua.includes("chrome/") || ua.includes("crios/")) return "Chrome";
|
|
539
|
+
if (ua.includes("safari/")) return "Safari";
|
|
540
|
+
return "";
|
|
541
|
+
};
|
|
542
|
+
const detectOs = (ua) => {
|
|
543
|
+
if (ua.includes("android")) return "Android";
|
|
544
|
+
if (ua.includes("iphone") || ua.includes("ipad") || ua.includes("ipod")) return "iOS";
|
|
545
|
+
if (ua.includes("windows")) return "Windows";
|
|
546
|
+
if (ua.includes("cros")) return "ChromeOS";
|
|
547
|
+
if (ua.includes("mac os x") || ua.includes("macintosh")) return "macOS";
|
|
548
|
+
if (ua.includes("linux") || ua.includes("x11")) return "Linux";
|
|
549
|
+
return "";
|
|
550
|
+
};
|
|
551
|
+
const DESKTOP_OPERATING_SYSTEMS = /* @__PURE__ */ new Set(["Windows", "macOS", "Linux", "ChromeOS"]);
|
|
552
|
+
function parseUserAgent(userAgent) {
|
|
553
|
+
const raw = typeof userAgent === "string" ? userAgent.trim() : "";
|
|
554
|
+
if (!raw || raw.toLowerCase() === "unknown") {
|
|
555
|
+
return { deviceType: "", device: "", deviceIcon: "unknown", browser: "", os: "" };
|
|
556
|
+
}
|
|
557
|
+
const ua = raw.toLowerCase();
|
|
558
|
+
const runtime = RUNTIME_AGENTS[ua.split("/")[0]];
|
|
559
|
+
if (runtime && !ua.includes(" ")) {
|
|
560
|
+
return {
|
|
561
|
+
deviceType: "api",
|
|
562
|
+
device: LEGACY_DEVICE_LABELS.api,
|
|
563
|
+
deviceIcon: "api",
|
|
564
|
+
browser: runtime,
|
|
565
|
+
os: ""
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
const apiClient = API_CLIENTS.find(([needle]) => ua.includes(needle));
|
|
569
|
+
if (apiClient) {
|
|
570
|
+
return {
|
|
571
|
+
deviceType: "api",
|
|
572
|
+
device: LEGACY_DEVICE_LABELS.api,
|
|
573
|
+
deviceIcon: "api",
|
|
574
|
+
browser: apiClient[1],
|
|
575
|
+
os: detectOs(ua)
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
const browser = detectBrowser(ua);
|
|
579
|
+
const os = detectOs(ua);
|
|
580
|
+
let deviceType = "";
|
|
581
|
+
if (BOT_PATTERN.test(raw)) deviceType = "bot";
|
|
582
|
+
else if (TABLET_PATTERN.test(raw)) deviceType = "tablet";
|
|
583
|
+
else if (MOBILE_PATTERN.test(raw)) deviceType = "mobile";
|
|
584
|
+
else if (DESKTOP_OPERATING_SYSTEMS.has(os)) deviceType = "desktop";
|
|
585
|
+
return {
|
|
586
|
+
deviceType,
|
|
587
|
+
device: LEGACY_DEVICE_LABELS[deviceType],
|
|
588
|
+
deviceIcon: deviceType || "unknown",
|
|
589
|
+
browser,
|
|
590
|
+
os
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
const BROWSER_VERSION_PATTERNS = [
|
|
594
|
+
/\bEdg(?:A|iOS)?\/([\d.]+)/i,
|
|
595
|
+
/\bOPR\/([\d.]+)/i,
|
|
596
|
+
/\b(?:Chrome|CriOS)\/([\d.]+)/i,
|
|
597
|
+
/\bFirefox\/([\d.]+)/i,
|
|
598
|
+
/\bVersion\/([\d.]+).*Safari/i
|
|
599
|
+
];
|
|
600
|
+
function getBrowserVersionFromUserAgent(userAgent) {
|
|
601
|
+
if (typeof userAgent !== "string" || !userAgent.trim() || userAgent.trim().toLowerCase() === "unknown") {
|
|
602
|
+
return "";
|
|
603
|
+
}
|
|
604
|
+
for (const pattern of BROWSER_VERSION_PATTERNS) {
|
|
605
|
+
const match = userAgent.match(pattern);
|
|
606
|
+
if (match?.[1]) return match[1];
|
|
607
|
+
}
|
|
608
|
+
return "";
|
|
609
|
+
}
|
|
610
|
+
const DEVICE_TYPE_MESSAGES = Object.freeze({
|
|
611
|
+
desktop: Object.freeze({ messageId: "common.device.type.desktop", defaultMessage: "Desktop" }),
|
|
612
|
+
mobile: Object.freeze({ messageId: "common.device.type.mobile", defaultMessage: "Mobile" }),
|
|
613
|
+
tablet: Object.freeze({ messageId: "common.device.type.tablet", defaultMessage: "Tablet" }),
|
|
614
|
+
api: Object.freeze({ messageId: "common.device.type.api", defaultMessage: "API client" }),
|
|
615
|
+
bot: Object.freeze({ messageId: "common.device.type.bot", defaultMessage: "Bot" }),
|
|
616
|
+
unknown: Object.freeze({
|
|
617
|
+
messageId: "common.device.type.unknown",
|
|
618
|
+
defaultMessage: "Unknown device"
|
|
619
|
+
})
|
|
620
|
+
});
|
|
621
|
+
const DEVICE_SUMMARY_MESSAGE = Object.freeze({
|
|
622
|
+
messageId: "common.device.summary",
|
|
623
|
+
defaultMessage: "{browser} · {os}"
|
|
624
|
+
});
|
|
625
|
+
const DEVICE_TYPE_ALIASES = Object.freeze({
|
|
626
|
+
desktop: "desktop",
|
|
627
|
+
laptop: "desktop",
|
|
628
|
+
pc: "desktop",
|
|
629
|
+
computer: "desktop",
|
|
630
|
+
mobile: "mobile",
|
|
631
|
+
phone: "mobile",
|
|
632
|
+
smartphone: "mobile",
|
|
633
|
+
tablet: "tablet",
|
|
634
|
+
"api client": "api",
|
|
635
|
+
api: "api",
|
|
636
|
+
apiclient: "api",
|
|
637
|
+
bot: "bot",
|
|
638
|
+
crawler: "bot"
|
|
639
|
+
});
|
|
640
|
+
function normalizeDeviceType(value) {
|
|
641
|
+
if (typeof value !== "string") return "";
|
|
642
|
+
const key = value.trim().toLowerCase().replace(/[\s_-]+/g, " ");
|
|
643
|
+
return DEVICE_TYPE_ALIASES[key] || DEVICE_TYPE_ALIASES[key.replace(/ /g, "")] || "";
|
|
644
|
+
}
|
|
645
|
+
function getDeviceTypeMessage(deviceType) {
|
|
646
|
+
return DEVICE_TYPE_MESSAGES[deviceType] || DEVICE_TYPE_MESSAGES.unknown;
|
|
647
|
+
}
|
|
648
|
+
const TRAILING_VERSION = /\s+v?\d[\w./-]*$/i;
|
|
649
|
+
function splitNameAndVersion(value) {
|
|
650
|
+
let name2 = presentText(value);
|
|
651
|
+
const versions = [];
|
|
652
|
+
while (TRAILING_VERSION.test(name2)) {
|
|
653
|
+
const match = name2.match(TRAILING_VERSION);
|
|
654
|
+
versions.unshift(match[0].trim());
|
|
655
|
+
name2 = name2.slice(0, match.index).trim();
|
|
656
|
+
}
|
|
657
|
+
return { name: presentText(name2), version: versions.join(" ") };
|
|
658
|
+
}
|
|
659
|
+
function getDevicePresentation(session = {}) {
|
|
660
|
+
const row = session || {};
|
|
661
|
+
const userAgent = presentText(row.userAgent);
|
|
662
|
+
const parsed = userAgent ? parseUserAgent(userAgent) : null;
|
|
663
|
+
const storedBrowser = splitNameAndVersion(row.browserName);
|
|
664
|
+
const storedOs = splitNameAndVersion(row.osName);
|
|
665
|
+
const deviceType = parsed ? parsed.deviceType : normalizeDeviceType(row.deviceType);
|
|
666
|
+
const browser = parsed?.browser || storedBrowser.name;
|
|
667
|
+
const os = parsed?.os || storedOs.name;
|
|
668
|
+
const browserVersion = userAgent && getBrowserVersionFromUserAgent(userAgent) || presentText(row.browserVersion) || storedBrowser.version;
|
|
669
|
+
let summary = { text: "" };
|
|
670
|
+
if (browser && os) {
|
|
671
|
+
summary = { ...DEVICE_SUMMARY_MESSAGE, values: { browser, os } };
|
|
672
|
+
} else if (browser || os) {
|
|
673
|
+
summary = { text: browser || os };
|
|
674
|
+
}
|
|
675
|
+
return {
|
|
676
|
+
deviceType,
|
|
677
|
+
hasDeviceType: Boolean(deviceType),
|
|
678
|
+
icon: deviceType || "unknown",
|
|
679
|
+
deviceTypeMessage: getDeviceTypeMessage(deviceType),
|
|
680
|
+
browser,
|
|
681
|
+
browserVersion,
|
|
682
|
+
browserLabel: browser,
|
|
683
|
+
os,
|
|
684
|
+
hasSummary: Boolean(browser || os),
|
|
685
|
+
summary
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
const SESSION_STATES = Object.freeze(["active", "idle", "ended"]);
|
|
689
|
+
const SESSION_END_REASONS = Object.freeze([
|
|
690
|
+
"logout",
|
|
691
|
+
"idle",
|
|
692
|
+
"expired",
|
|
693
|
+
"manual",
|
|
694
|
+
"blocked",
|
|
695
|
+
"unrecorded"
|
|
696
|
+
]);
|
|
697
|
+
const RECORDED_END_REASONS = /* @__PURE__ */ new Set(["logout", "idle", "expired", "manual", "blocked"]);
|
|
698
|
+
const ACTIVE_DEFINITION = Object.freeze({
|
|
699
|
+
messageId: "common.status.active.definition",
|
|
700
|
+
defaultMessage: "Open and used within the inactivity timeout."
|
|
701
|
+
});
|
|
702
|
+
const SESSION_STATUS_PRESENTATION = Object.freeze({
|
|
703
|
+
active: Object.freeze({
|
|
704
|
+
tone: "success",
|
|
705
|
+
messageId: "common.status.active",
|
|
706
|
+
defaultMessage: "Active",
|
|
707
|
+
// B.3 tooltip and A.3 definition are the same sentence: one message.
|
|
708
|
+
help: ACTIVE_DEFINITION,
|
|
709
|
+
definition: ACTIVE_DEFINITION
|
|
710
|
+
}),
|
|
711
|
+
idle: Object.freeze({
|
|
712
|
+
tone: "warning",
|
|
713
|
+
messageId: "common.status.idle",
|
|
714
|
+
defaultMessage: "Idle",
|
|
715
|
+
help: Object.freeze({
|
|
716
|
+
messageId: "common.status.idle.help",
|
|
717
|
+
defaultMessage: "Still open. It ends on its next request or at the next idle check. A token refresh makes it active again."
|
|
718
|
+
}),
|
|
719
|
+
definition: Object.freeze({
|
|
720
|
+
messageId: "common.status.idle.definition",
|
|
721
|
+
defaultMessage: "Open, but not used for longer than the inactivity timeout. It ends on its next request or at the next idle check. A token refresh makes it active again."
|
|
722
|
+
})
|
|
723
|
+
}),
|
|
724
|
+
ended: Object.freeze({
|
|
725
|
+
tone: "neutral",
|
|
726
|
+
messageId: "common.status.ended",
|
|
727
|
+
defaultMessage: "Ended",
|
|
728
|
+
help: null,
|
|
729
|
+
definition: Object.freeze({
|
|
730
|
+
messageId: "common.status.ended.definition",
|
|
731
|
+
defaultMessage: "The session can no longer be used. The user has to sign in again on this device."
|
|
732
|
+
})
|
|
733
|
+
})
|
|
734
|
+
});
|
|
735
|
+
const SESSION_END_REASON_PRESENTATION = Object.freeze({
|
|
736
|
+
logout: Object.freeze({
|
|
737
|
+
messageId: "common.endReason.logout",
|
|
738
|
+
defaultMessage: "Logged out",
|
|
739
|
+
description: Object.freeze({
|
|
740
|
+
messageId: "common.endReason.logout.description",
|
|
741
|
+
defaultMessage: "The user signed out."
|
|
742
|
+
})
|
|
743
|
+
}),
|
|
744
|
+
idle: Object.freeze({
|
|
745
|
+
messageId: "common.endReason.idle",
|
|
746
|
+
defaultMessage: "Timed out",
|
|
747
|
+
description: Object.freeze({
|
|
748
|
+
messageId: "common.endReason.idle.description",
|
|
749
|
+
defaultMessage: "Not used for longer than the inactivity timeout."
|
|
750
|
+
})
|
|
751
|
+
}),
|
|
752
|
+
expired: Object.freeze({
|
|
753
|
+
messageId: "common.endReason.expired",
|
|
754
|
+
defaultMessage: "Expired",
|
|
755
|
+
description: Object.freeze({
|
|
756
|
+
messageId: "common.endReason.expired.description",
|
|
757
|
+
defaultMessage: "Reached the maximum session age."
|
|
758
|
+
})
|
|
759
|
+
}),
|
|
760
|
+
manual: Object.freeze({
|
|
761
|
+
messageId: "common.endReason.manual",
|
|
762
|
+
defaultMessage: "Ended manually",
|
|
763
|
+
description: Object.freeze({
|
|
764
|
+
messageId: "common.endReason.manual.description",
|
|
765
|
+
defaultMessage: "Ended from the Strapi admin, or by the user from another of their devices."
|
|
766
|
+
})
|
|
767
|
+
}),
|
|
768
|
+
blocked: Object.freeze({
|
|
769
|
+
messageId: "common.endReason.blocked",
|
|
770
|
+
defaultMessage: "User blocked",
|
|
771
|
+
description: Object.freeze({
|
|
772
|
+
messageId: "common.endReason.blocked.description",
|
|
773
|
+
defaultMessage: "Ended because the user account was blocked."
|
|
774
|
+
})
|
|
775
|
+
}),
|
|
776
|
+
unrecorded: Object.freeze({
|
|
777
|
+
messageId: "common.endReason.unrecorded",
|
|
778
|
+
defaultMessage: "Reason not recorded",
|
|
779
|
+
description: Object.freeze({
|
|
780
|
+
messageId: "common.endReason.unrecorded.description",
|
|
781
|
+
defaultMessage: "No end reason was stored, for example because the session ended in Strapi’s own session store or was recorded by an older plugin version."
|
|
782
|
+
})
|
|
783
|
+
})
|
|
784
|
+
});
|
|
785
|
+
function getSessionState(session = {}) {
|
|
786
|
+
const row = session || {};
|
|
787
|
+
if (row.isActive === true) return row.isTrulyActive ? "active" : "idle";
|
|
788
|
+
return "ended";
|
|
789
|
+
}
|
|
790
|
+
function getSessionStatus(session = {}) {
|
|
791
|
+
return getSessionState(session);
|
|
792
|
+
}
|
|
793
|
+
function getSessionEndReason(session = {}) {
|
|
794
|
+
const row = session || {};
|
|
795
|
+
if (row.isActive === true) return null;
|
|
796
|
+
const reason = typeof row.terminationReason === "string" ? row.terminationReason.trim().toLowerCase() : "";
|
|
797
|
+
return RECORDED_END_REASONS.has(reason) ? (
|
|
798
|
+
/** @type {any} */
|
|
799
|
+
reason
|
|
800
|
+
) : "unrecorded";
|
|
801
|
+
}
|
|
802
|
+
function isNativeOnlySession(session) {
|
|
803
|
+
const id = session?.id;
|
|
804
|
+
return typeof id === "string" && id.startsWith("native_");
|
|
805
|
+
}
|
|
806
|
+
function isSessionStatus(status) {
|
|
807
|
+
return SESSION_STATES.includes(
|
|
808
|
+
/** @type {any} */
|
|
809
|
+
status
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
function isSessionEndReason(reason) {
|
|
813
|
+
return SESSION_END_REASONS.includes(
|
|
814
|
+
/** @type {any} */
|
|
815
|
+
reason
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
function getSessionStatusPresentation(statusOrSession) {
|
|
819
|
+
const status = typeof statusOrSession === "string" ? statusOrSession : getSessionState(statusOrSession);
|
|
820
|
+
const key = isSessionStatus(status) ? status : "ended";
|
|
821
|
+
return { status: key, ...SESSION_STATUS_PRESENTATION[key] };
|
|
822
|
+
}
|
|
823
|
+
function getEndReasonPresentation(reason) {
|
|
824
|
+
const key = isSessionEndReason(reason) ? reason : "unrecorded";
|
|
825
|
+
return { reason: key, ...SESSION_END_REASON_PRESENTATION[key] };
|
|
826
|
+
}
|
|
827
|
+
function getSessionEndReasonPresentation(session) {
|
|
828
|
+
const reason = getSessionEndReason(session);
|
|
829
|
+
return reason ? getEndReasonPresentation(reason) : null;
|
|
830
|
+
}
|
|
831
|
+
function useSessionFormatters() {
|
|
832
|
+
const { formatMessage, locale } = reactIntl.useIntl();
|
|
833
|
+
const translate = react.useCallback(
|
|
834
|
+
(descriptor, values) => formatMessage(
|
|
835
|
+
{ id: getTranslation(descriptor.messageId), defaultMessage: descriptor.defaultMessage },
|
|
836
|
+
values
|
|
837
|
+
),
|
|
838
|
+
[formatMessage]
|
|
839
|
+
);
|
|
840
|
+
return react.useMemo(() => {
|
|
841
|
+
const formatDate = (value, options) => formatSessionDate(value, locale, MISSING_VALUE_GLYPH, options);
|
|
842
|
+
const formatRelativeTime = (value, now) => formatRelative(value, locale, { now: now ?? Date.now(), fallback: MISSING_VALUE_GLYPH });
|
|
843
|
+
const statusLabel = (statusOrSession) => translate(getSessionStatusPresentation(statusOrSession));
|
|
844
|
+
const endReasonLabel = (sessionOrReason) => {
|
|
845
|
+
const reason = typeof sessionOrReason === "string" ? getEndReasonPresentation(sessionOrReason) : getSessionEndReasonPresentation(sessionOrReason);
|
|
846
|
+
return reason ? translate(reason) : "";
|
|
847
|
+
};
|
|
848
|
+
const deviceTypeLabel = (session) => translate(getDevicePresentation(session).deviceTypeMessage);
|
|
849
|
+
const deviceSummary = (session) => {
|
|
850
|
+
const { summary } = getDevicePresentation(session);
|
|
851
|
+
return summary.text ?? translate(summary, summary.values);
|
|
852
|
+
};
|
|
853
|
+
return {
|
|
854
|
+
locale,
|
|
855
|
+
formatDate,
|
|
856
|
+
formatRelativeTime,
|
|
857
|
+
translate,
|
|
858
|
+
statusLabel,
|
|
859
|
+
endReasonLabel,
|
|
860
|
+
deviceTypeLabel,
|
|
861
|
+
deviceSummary
|
|
862
|
+
};
|
|
863
|
+
}, [locale, translate]);
|
|
864
|
+
}
|
|
865
|
+
const NoWrap$1 = styled__default.default.span`
|
|
866
|
+
white-space: nowrap;
|
|
867
|
+
`;
|
|
868
|
+
const StatusDetail = ({ session, status }) => {
|
|
869
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
870
|
+
const { formatDate, formatRelativeTime, endReasonLabel } = useSessionFormatters();
|
|
871
|
+
const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
|
|
872
|
+
let text;
|
|
873
|
+
if (status === "ended") {
|
|
874
|
+
const endedAt = toValidDate(session.logoutTime);
|
|
875
|
+
text = t("common.status.ended.detail", "{reason} · {endedAt}", {
|
|
876
|
+
reason: /* @__PURE__ */ jsxRuntime.jsx(NoWrap$1, { children: endReasonLabel(session) }, "reason"),
|
|
877
|
+
endedAt: endedAt ? /* @__PURE__ */ jsxRuntime.jsx(NoWrap$1, { children: formatDate(endedAt) }, "ended-at") : /* @__PURE__ */ jsxRuntime.jsx(MissingValue, { variant: "pi" }, "ended-at")
|
|
878
|
+
});
|
|
879
|
+
} else {
|
|
880
|
+
const minutes = Number(session.minutesSinceActive);
|
|
881
|
+
const hasMinutes = session.minutesSinceActive !== null && session.minutesSinceActive !== void 0 && Number.isFinite(minutes);
|
|
882
|
+
text = status === "idle" && hasMinutes ? t("common.status.idle.detail", "Not used for {minutes} min", { minutes }) : t("common.status.active.detail", "Last active {time}", {
|
|
883
|
+
time: formatRelativeTime(session.lastActive || session.loginTime)
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", "data-status-detail": "", children: text });
|
|
887
|
+
};
|
|
888
|
+
const getBadgeColors = (tone) => tone === "warning" ? { backgroundColor: "warning200", textColor: "neutral800" } : { variant: tone };
|
|
889
|
+
const StatusBadge = ({ status, session, detail = false, showEndReason = false, size = "M" }) => {
|
|
890
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
891
|
+
const presentation = getSessionStatusPresentation(status || session || {});
|
|
892
|
+
const translate = (descriptor) => formatMessage({
|
|
893
|
+
id: getTranslation(descriptor.messageId),
|
|
894
|
+
defaultMessage: descriptor.defaultMessage
|
|
895
|
+
});
|
|
896
|
+
const label = translate(presentation);
|
|
897
|
+
const badge = /* @__PURE__ */ jsxRuntime.jsx(
|
|
898
|
+
designSystem.Badge,
|
|
899
|
+
{
|
|
900
|
+
...getBadgeColors(presentation.tone),
|
|
901
|
+
size,
|
|
902
|
+
"data-session-status": presentation.status,
|
|
903
|
+
children: label
|
|
904
|
+
}
|
|
905
|
+
);
|
|
906
|
+
if (!(detail || showEndReason) || !session) return badge;
|
|
907
|
+
const reason = presentation.status === "ended" ? getSessionEndReasonPresentation(session) : null;
|
|
908
|
+
const help = reason ? reason.description : presentation.help;
|
|
909
|
+
const native = isNativeOnlySession(session);
|
|
910
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 1, minWidth: 0, children: [
|
|
911
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, alignItems: "center", wrap: "wrap", children: [
|
|
912
|
+
help ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tooltip, { label: translate(help), children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: badge }) }) : badge,
|
|
913
|
+
native ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
914
|
+
designSystem.Tooltip,
|
|
915
|
+
{
|
|
916
|
+
label: formatMessage({
|
|
917
|
+
id: getTranslation("common.status.nativeSession.help"),
|
|
918
|
+
defaultMessage: "Created by Strapi’s own session store. No device or location details were recorded."
|
|
919
|
+
}),
|
|
920
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { variant: "neutral", size, "data-native-session": "", children: formatMessage({
|
|
921
|
+
id: getTranslation("common.status.nativeSession"),
|
|
922
|
+
defaultMessage: "Strapi session"
|
|
923
|
+
}) }) })
|
|
924
|
+
}
|
|
925
|
+
) : null
|
|
926
|
+
] }),
|
|
927
|
+
/* @__PURE__ */ jsxRuntime.jsx(StatusDetail, { session, status: presentation.status })
|
|
928
|
+
] });
|
|
929
|
+
};
|
|
930
|
+
const canTakeFocus = (element) => Boolean(
|
|
931
|
+
element?.isConnected && typeof element.focus === "function" && !element.disabled && element.getAttribute?.("aria-disabled") !== "true"
|
|
932
|
+
);
|
|
933
|
+
function pickFocusTarget(opener, fallback) {
|
|
934
|
+
if (canTakeFocus(opener)) return opener;
|
|
935
|
+
return canTakeFocus(fallback) ? fallback : null;
|
|
936
|
+
}
|
|
937
|
+
function restoreDialogFocus(event, opener, fallback) {
|
|
938
|
+
const target = pickFocusTarget(opener, fallback);
|
|
939
|
+
if (!target) return;
|
|
940
|
+
event.preventDefault();
|
|
941
|
+
target.focus();
|
|
942
|
+
}
|
|
943
|
+
function refocusIfLost(opener, fallback, doc = typeof document === "undefined" ? void 0 : document) {
|
|
944
|
+
if (!doc) return;
|
|
945
|
+
const active = doc.activeElement;
|
|
946
|
+
if (active && active !== doc.body) return;
|
|
947
|
+
pickFocusTarget(opener, fallback)?.focus();
|
|
948
|
+
}
|
|
949
|
+
const ConfirmAction = ({
|
|
950
|
+
trigger,
|
|
951
|
+
title,
|
|
952
|
+
body,
|
|
953
|
+
confirmLabel,
|
|
954
|
+
onConfirm,
|
|
955
|
+
variant = "danger",
|
|
956
|
+
disabled = false,
|
|
957
|
+
fallbackFocusRef,
|
|
958
|
+
isOpen,
|
|
959
|
+
onOpenChange,
|
|
960
|
+
returnFocusRef
|
|
961
|
+
}) => {
|
|
962
|
+
const [internalOpen, setInternalOpen] = react.useState(false);
|
|
963
|
+
const [busy, setBusy] = react.useState(false);
|
|
964
|
+
const triggerRef = react.useRef(null);
|
|
965
|
+
const controlled = !trigger;
|
|
966
|
+
const open = controlled ? Boolean(isOpen) : internalOpen;
|
|
967
|
+
const restoreFocus = () => {
|
|
968
|
+
if (typeof window === "undefined") return;
|
|
969
|
+
window.requestAnimationFrame(() => {
|
|
970
|
+
const active = document.activeElement;
|
|
971
|
+
if (active && active !== document.body) return;
|
|
972
|
+
const ownTrigger = controlled ? returnFocusRef?.current : triggerRef.current;
|
|
973
|
+
const target = pickFocusTarget(ownTrigger, fallbackFocusRef?.current);
|
|
974
|
+
if (target) target.focus();
|
|
975
|
+
});
|
|
976
|
+
};
|
|
977
|
+
const setOpen = (next) => {
|
|
978
|
+
if (controlled) onOpenChange?.(next);
|
|
979
|
+
else setInternalOpen(next);
|
|
980
|
+
};
|
|
981
|
+
const handleOpenChange = (next) => {
|
|
982
|
+
if (busy) return;
|
|
983
|
+
setOpen(next);
|
|
984
|
+
if (!next) restoreFocus();
|
|
985
|
+
};
|
|
986
|
+
const handleConfirm = async (event) => {
|
|
987
|
+
event?.preventDefault?.();
|
|
988
|
+
setBusy(true);
|
|
989
|
+
try {
|
|
990
|
+
await onConfirm();
|
|
991
|
+
setOpen(false);
|
|
992
|
+
restoreFocus();
|
|
993
|
+
} catch {
|
|
994
|
+
} finally {
|
|
995
|
+
setBusy(false);
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Root, { open, onOpenChange: handleOpenChange, children: [
|
|
999
|
+
trigger ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Trigger, { ref: triggerRef, disabled, children: trigger }) : null,
|
|
1000
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1001
|
+
StrapiAdmin.ConfirmDialog,
|
|
1002
|
+
{
|
|
1003
|
+
title,
|
|
1004
|
+
variant,
|
|
1005
|
+
endAction: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1006
|
+
designSystem.Button,
|
|
1007
|
+
{
|
|
1008
|
+
fullWidth: true,
|
|
1009
|
+
variant,
|
|
1010
|
+
onClick: handleConfirm,
|
|
1011
|
+
loading: busy,
|
|
1012
|
+
disabled: busy,
|
|
1013
|
+
children: confirmLabel
|
|
1014
|
+
}
|
|
1015
|
+
),
|
|
1016
|
+
children: body
|
|
1017
|
+
}
|
|
1018
|
+
)
|
|
1019
|
+
] });
|
|
1020
|
+
};
|
|
1021
|
+
const DEVICE_ICONS = {
|
|
1022
|
+
desktop: icons.Monitor,
|
|
1023
|
+
mobile: icons.Phone,
|
|
1024
|
+
tablet: icons.Phone,
|
|
1025
|
+
api: icons.Code,
|
|
1026
|
+
bot: icons.Server,
|
|
1027
|
+
unknown: icons.Information
|
|
1028
|
+
};
|
|
1029
|
+
const DeviceIcon = ({ icon }) => {
|
|
1030
|
+
const Icon = DEVICE_ICONS[icon] || icons.Information;
|
|
1031
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Icon, { "aria-hidden": true, focusable: false });
|
|
1032
|
+
};
|
|
1033
|
+
const TargetLink = styled__default.default(designSystem.Link)`
|
|
1034
|
+
min-height: 3.2rem;
|
|
1035
|
+
display: inline-flex;
|
|
1036
|
+
align-items: center;
|
|
1037
|
+
align-self: flex-start;
|
|
1038
|
+
`;
|
|
1039
|
+
const ActionStack = styled__default.default.div`
|
|
1040
|
+
display: grid;
|
|
1041
|
+
grid-template-columns: minmax(0, 1fr);
|
|
1042
|
+
grid-auto-rows: 1fr;
|
|
1043
|
+
gap: ${({ theme }) => theme.spaces[2]};
|
|
1044
|
+
min-width: 0;
|
|
1045
|
+
|
|
1046
|
+
/* The buttons are the plugin's own children; wrapped labels centre
|
|
1047
|
+
through inheritance, not through a selector into the DS button. */
|
|
1048
|
+
& > button {
|
|
1049
|
+
height: auto;
|
|
1050
|
+
min-height: 3.2rem;
|
|
1051
|
+
padding-block: ${({ theme }) => theme.spaces[1]};
|
|
1052
|
+
text-align: center;
|
|
1053
|
+
}
|
|
1054
|
+
`;
|
|
1055
|
+
const pluginPermissions = {
|
|
1056
|
+
access: [{ action: `plugin::${pluginId$1}.access`, subject: null }],
|
|
1057
|
+
/** Strapi admin panel sessions (view). The server also requires `access`. */
|
|
1058
|
+
adminSessionsRead: [{ action: `plugin::${pluginId$1}.admin-sessions.read`, subject: null }],
|
|
1059
|
+
/** Signing admins out. The server also requires `access` and `admin-sessions.read`. */
|
|
1060
|
+
adminSessionsRevoke: [{ action: `plugin::${pluginId$1}.admin-sessions.revoke`, subject: null }],
|
|
1061
|
+
/** Admin sign-in history and Content Manager activity. The server also requires `access` and `admin-sessions.read`. */
|
|
1062
|
+
adminActivityRead: [{ action: `plugin::${pluginId$1}.admin-activity.read`, subject: null }],
|
|
1063
|
+
/**
|
|
1064
|
+
* Protected settings (4.17): location lookup, webhooks and the security log.
|
|
1065
|
+
* The server also requires `access` (and `admin-activity.read` for the log).
|
|
1066
|
+
*/
|
|
1067
|
+
settingsUpdate: [{ action: `plugin::${pluginId$1}.settings.update`, subject: null }],
|
|
1068
|
+
/**
|
|
1069
|
+
* App-user security activity (4.22): failed sign-ins, lockouts, new devices,
|
|
1070
|
+
* impersonations ... of Users & Permissions accounts, and its export. The
|
|
1071
|
+
* server also requires `access`.
|
|
1072
|
+
*/
|
|
1073
|
+
userActivityRead: [{ action: `plugin::${pluginId$1}.user-activity.read`, subject: null }],
|
|
1074
|
+
/** Lifting a sign-in lock. The server also requires `access`. */
|
|
1075
|
+
lockoutsUnlock: [{ action: `plugin::${pluginId$1}.lockouts.unlock`, subject: null }],
|
|
1076
|
+
/**
|
|
1077
|
+
* Impersonating app users (4.20): start, list and end. The server also
|
|
1078
|
+
* requires `access` and the Impersonation switch.
|
|
1079
|
+
*/
|
|
1080
|
+
impersonateUsers: [{ action: `plugin::${pluginId$1}.impersonate.users`, subject: null }],
|
|
1081
|
+
/**
|
|
1082
|
+
* "View as admin" (4.20): the read-only permission preview of another
|
|
1083
|
+
* admin. The server also requires `access`, the switch and the
|
|
1084
|
+
* anti-escalation rules.
|
|
1085
|
+
*/
|
|
1086
|
+
impersonateAdmins: [{ action: `plugin::${pluginId$1}.impersonate.admins`, subject: null }]
|
|
1087
|
+
};
|
|
1088
|
+
const SAFE_SCOPE = /^[A-Za-z0-9_.:-]{1,48}$/;
|
|
1089
|
+
const CANCEL_NAMES = /* @__PURE__ */ new Set(["AbortError", "TimeoutError", "CanceledError"]);
|
|
1090
|
+
function safeGet(value, key) {
|
|
1091
|
+
try {
|
|
1092
|
+
return value && typeof value === "object" ? value[key] : void 0;
|
|
1093
|
+
} catch {
|
|
1094
|
+
return void 0;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
function isCancelledRequest(error) {
|
|
1098
|
+
const name2 = safeGet(error, "name");
|
|
1099
|
+
return typeof name2 === "string" && CANCEL_NAMES.has(name2);
|
|
1100
|
+
}
|
|
1101
|
+
function logSafeAdminError(scope, error) {
|
|
1102
|
+
if (isCancelledRequest(error)) return;
|
|
1103
|
+
const safeScope = typeof scope === "string" && SAFE_SCOPE.test(scope) ? scope : "admin";
|
|
1104
|
+
const directStatus = safeGet(error, "status");
|
|
1105
|
+
const status = Number.isInteger(directStatus) ? directStatus : safeGet(safeGet(error, "response"), "status");
|
|
1106
|
+
const statusSuffix = Number.isInteger(status) && status >= 400 && status <= 599 ? ` (HTTP ${status})` : "";
|
|
1107
|
+
console.warn(`[${safeScope}] Request failed${statusSuffix}`);
|
|
1108
|
+
}
|
|
1109
|
+
function useSettingsTranslate() {
|
|
1110
|
+
const { formatMessage, locale } = reactIntl.useIntl();
|
|
1111
|
+
const t = react.useCallback(
|
|
1112
|
+
(id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values),
|
|
1113
|
+
[formatMessage]
|
|
1114
|
+
);
|
|
1115
|
+
const tError = react.useCallback(
|
|
1116
|
+
(descriptor) => descriptor ? t(descriptor.messageId, descriptor.defaultMessage, descriptor.values) : void 0,
|
|
1117
|
+
[t]
|
|
1118
|
+
);
|
|
1119
|
+
return { t, tError, locale };
|
|
1120
|
+
}
|
|
1121
|
+
async function copyText(value, clipboard = globalThis.navigator?.clipboard) {
|
|
1122
|
+
if (typeof value !== "string") {
|
|
1123
|
+
throw new TypeError("clipboard_value_must_be_text");
|
|
1124
|
+
}
|
|
1125
|
+
if (!clipboard || typeof clipboard.writeText !== "function") {
|
|
1126
|
+
throw new Error("clipboard_unavailable");
|
|
1127
|
+
}
|
|
1128
|
+
await clipboard.writeText(value);
|
|
1129
|
+
}
|
|
1130
|
+
const USER_IMPERSONATION_DURATIONS = Object.freeze([15, 30, 60]);
|
|
1131
|
+
const DEFAULT_IMPERSONATION_MINUTES = 15;
|
|
1132
|
+
const REASON_MIN = 3;
|
|
1133
|
+
const REASON_MAX = 255;
|
|
1134
|
+
function validateReason(value) {
|
|
1135
|
+
const clean = typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "";
|
|
1136
|
+
if (clean.length < REASON_MIN) {
|
|
1137
|
+
return {
|
|
1138
|
+
messageId: "impersonation.reason.tooShort",
|
|
1139
|
+
defaultMessage: "Enter a reason of at least {min} characters.",
|
|
1140
|
+
values: { min: REASON_MIN }
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
if (clean.length > REASON_MAX) {
|
|
1144
|
+
return {
|
|
1145
|
+
messageId: "impersonation.reason.tooLong",
|
|
1146
|
+
defaultMessage: "Use at most {max} characters.",
|
|
1147
|
+
values: { max: REASON_MAX }
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
return null;
|
|
1151
|
+
}
|
|
1152
|
+
function secondsUntil(iso, now = Date.now()) {
|
|
1153
|
+
const end = Date.parse(String(iso ?? ""));
|
|
1154
|
+
if (!Number.isFinite(end)) return 0;
|
|
1155
|
+
return Math.max(0, Math.floor((end - now) / 1e3));
|
|
1156
|
+
}
|
|
1157
|
+
function formatClock(seconds) {
|
|
1158
|
+
const total = Math.max(0, Math.floor(Number(seconds) || 0));
|
|
1159
|
+
const hours = Math.floor(total / 3600);
|
|
1160
|
+
const minutes = Math.floor(total % 3600 / 60);
|
|
1161
|
+
const rest = String(total % 60).padStart(2, "0");
|
|
1162
|
+
return hours > 0 ? `${hours}:${String(minutes).padStart(2, "0")}:${rest}` : `${minutes}:${rest}`;
|
|
1163
|
+
}
|
|
1164
|
+
function submitFrontendHandoff(doc, handoff) {
|
|
1165
|
+
if (!doc || !handoff || typeof handoff.url !== "string" || typeof handoff.code !== "string") {
|
|
1166
|
+
return false;
|
|
1167
|
+
}
|
|
1168
|
+
let url;
|
|
1169
|
+
try {
|
|
1170
|
+
url = new URL(handoff.url);
|
|
1171
|
+
} catch {
|
|
1172
|
+
return false;
|
|
1173
|
+
}
|
|
1174
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") return false;
|
|
1175
|
+
const form = doc.createElement("form");
|
|
1176
|
+
form.method = "POST";
|
|
1177
|
+
form.action = url.toString();
|
|
1178
|
+
form.target = "_blank";
|
|
1179
|
+
form.rel = "noopener noreferrer";
|
|
1180
|
+
form.style.display = "none";
|
|
1181
|
+
const input = doc.createElement("input");
|
|
1182
|
+
input.type = "hidden";
|
|
1183
|
+
input.name = typeof handoff.field === "string" && handoff.field ? handoff.field : "code";
|
|
1184
|
+
input.value = handoff.code;
|
|
1185
|
+
form.appendChild(input);
|
|
1186
|
+
doc.body.appendChild(form);
|
|
1187
|
+
try {
|
|
1188
|
+
form.submit();
|
|
1189
|
+
} finally {
|
|
1190
|
+
form.remove();
|
|
1191
|
+
}
|
|
1192
|
+
return true;
|
|
1193
|
+
}
|
|
1194
|
+
const dialogs = /* @__PURE__ */ new Map();
|
|
1195
|
+
const mounted = /* @__PURE__ */ new Map();
|
|
1196
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1197
|
+
const notify = () => {
|
|
1198
|
+
for (const listener of listeners) listener();
|
|
1199
|
+
};
|
|
1200
|
+
function subscribeImpersonationDialogs(listener) {
|
|
1201
|
+
listeners.add(listener);
|
|
1202
|
+
return () => listeners.delete(listener);
|
|
1203
|
+
}
|
|
1204
|
+
function getImpersonationDialog(key) {
|
|
1205
|
+
return dialogs.get(key) || null;
|
|
1206
|
+
}
|
|
1207
|
+
function registerImpersonationPanel(key, instance) {
|
|
1208
|
+
const list = [...mounted.get(key) || [], instance];
|
|
1209
|
+
mounted.set(key, list);
|
|
1210
|
+
const dialog = dialogs.get(key);
|
|
1211
|
+
if (dialog && (!dialog.owner || !list.includes(dialog.owner))) {
|
|
1212
|
+
dialogs.set(key, { ...dialog, owner: instance });
|
|
1213
|
+
notify();
|
|
1214
|
+
}
|
|
1215
|
+
return () => {
|
|
1216
|
+
const rest = (mounted.get(key) || []).filter((id) => id !== instance);
|
|
1217
|
+
if (rest.length) mounted.set(key, rest);
|
|
1218
|
+
else mounted.delete(key);
|
|
1219
|
+
const current = dialogs.get(key);
|
|
1220
|
+
if (current && current.owner === instance) {
|
|
1221
|
+
dialogs.set(key, { ...current, owner: rest[rest.length - 1] || null });
|
|
1222
|
+
notify();
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
function openImpersonationDialog(key, instance) {
|
|
1227
|
+
dialogs.set(key, { open: true, owner: instance, draft: {} });
|
|
1228
|
+
notify();
|
|
1229
|
+
}
|
|
1230
|
+
function saveImpersonationDraft(key, draft) {
|
|
1231
|
+
const current = dialogs.get(key);
|
|
1232
|
+
if (current) dialogs.set(key, { ...current, draft });
|
|
1233
|
+
}
|
|
1234
|
+
function closeImpersonationDialog(key) {
|
|
1235
|
+
if (dialogs.delete(key)) notify();
|
|
1236
|
+
}
|
|
1237
|
+
const REFUSALS = Object.freeze({
|
|
1238
|
+
disabled: ["impersonation.error.disabled", "Impersonation is turned off in the settings."],
|
|
1239
|
+
"already-active": [
|
|
1240
|
+
"impersonation.error.alreadyActive",
|
|
1241
|
+
"An impersonation of this user is already running. End it first."
|
|
1242
|
+
],
|
|
1243
|
+
blocked: ["impersonation.error.blocked", "Blocked accounts cannot be impersonated."],
|
|
1244
|
+
"api-token": ["impersonation.error.apiToken", "API tokens cannot impersonate."]
|
|
1245
|
+
});
|
|
1246
|
+
function useSecondsLeft(expiresAt) {
|
|
1247
|
+
const [now, setNow] = react.useState(() => Date.now());
|
|
1248
|
+
react.useEffect(() => {
|
|
1249
|
+
if (!expiresAt) return void 0;
|
|
1250
|
+
const timer = window.setInterval(() => setNow(Date.now()), 1e3);
|
|
1251
|
+
return () => window.clearInterval(timer);
|
|
1252
|
+
}, [expiresAt]);
|
|
1253
|
+
return secondsUntil(expiresAt, now);
|
|
1254
|
+
}
|
|
1255
|
+
const SecretField = ({ label, value, name: name2 }) => {
|
|
1256
|
+
const { t } = useSettingsTranslate();
|
|
1257
|
+
const { toggleNotification } = StrapiAdmin.useNotification();
|
|
1258
|
+
const copy = async () => {
|
|
1259
|
+
try {
|
|
1260
|
+
await copyText(value);
|
|
1261
|
+
toggleNotification({
|
|
1262
|
+
type: "success",
|
|
1263
|
+
message: t("impersonation.result.copied", "Copied to the clipboard.")
|
|
1264
|
+
});
|
|
1265
|
+
} catch {
|
|
1266
|
+
toggleNotification({
|
|
1267
|
+
type: "warning",
|
|
1268
|
+
message: t(
|
|
1269
|
+
"impersonation.result.copyFailed",
|
|
1270
|
+
"Copying failed. Select the text and copy it yourself."
|
|
1271
|
+
)
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
};
|
|
1275
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: name2, children: [
|
|
1276
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: label }),
|
|
1277
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1278
|
+
designSystem.TextInput,
|
|
1279
|
+
{
|
|
1280
|
+
value,
|
|
1281
|
+
readOnly: true,
|
|
1282
|
+
onFocus: (event) => event.target.select(),
|
|
1283
|
+
endAction: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1284
|
+
designSystem.Field.Action,
|
|
1285
|
+
{
|
|
1286
|
+
label: t("impersonation.result.copy", "Copy {name}", { name: label }),
|
|
1287
|
+
onClick: copy,
|
|
1288
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.Duplicate, {})
|
|
1289
|
+
}
|
|
1290
|
+
)
|
|
1291
|
+
}
|
|
1292
|
+
)
|
|
1293
|
+
] });
|
|
1294
|
+
};
|
|
1295
|
+
const ImpersonateUserModal = ({
|
|
1296
|
+
open,
|
|
1297
|
+
onOpenChange,
|
|
1298
|
+
onCloseAutoFocus,
|
|
1299
|
+
user,
|
|
1300
|
+
status,
|
|
1301
|
+
onChanged
|
|
1302
|
+
}) => {
|
|
1303
|
+
const { t, tError } = useSettingsTranslate();
|
|
1304
|
+
const { post } = StrapiAdmin.useFetchClient();
|
|
1305
|
+
const { toggleNotification } = StrapiAdmin.useNotification();
|
|
1306
|
+
const notifyHintId = react.useId();
|
|
1307
|
+
const [saved] = react.useState(() => getImpersonationDialog(user.documentId)?.draft || {});
|
|
1308
|
+
const [reason, setReason] = react.useState(saved.reason ?? "");
|
|
1309
|
+
const [minutes, setMinutes] = react.useState(saved.minutes ?? DEFAULT_IMPERSONATION_MINUTES);
|
|
1310
|
+
const [notifyUser, setNotifyUser] = react.useState(saved.notifyUser === true);
|
|
1311
|
+
const [touched, setTouched] = react.useState(false);
|
|
1312
|
+
const [pending, setPending] = react.useState(null);
|
|
1313
|
+
const [failure, setFailure] = react.useState(null);
|
|
1314
|
+
const [result, setResult] = react.useState(saved.result ?? null);
|
|
1315
|
+
react.useEffect(() => {
|
|
1316
|
+
if (!open) return;
|
|
1317
|
+
saveImpersonationDraft(user.documentId, { reason, minutes, notifyUser, result });
|
|
1318
|
+
}, [open, user.documentId, reason, minutes, notifyUser, result]);
|
|
1319
|
+
const secondsLeft = useSecondsLeft(result?.impersonation?.expiresAt || null);
|
|
1320
|
+
const durations = Array.isArray(status?.durations) ? status.durations : USER_IMPERSONATION_DURATIONS;
|
|
1321
|
+
const reasonError = validateReason(reason);
|
|
1322
|
+
const showReasonError = touched && reasonError;
|
|
1323
|
+
const start = async () => {
|
|
1324
|
+
setTouched(true);
|
|
1325
|
+
if (reasonError) return;
|
|
1326
|
+
setPending("start");
|
|
1327
|
+
setFailure(null);
|
|
1328
|
+
try {
|
|
1329
|
+
const { data } = await post(
|
|
1330
|
+
`/${pluginId$1}/impersonation/users/${encodeURIComponent(user.documentId)}`,
|
|
1331
|
+
{ reason: reason.trim(), durationMinutes: minutes, notifyUser }
|
|
1332
|
+
);
|
|
1333
|
+
setResult(data?.data || null);
|
|
1334
|
+
onChanged?.();
|
|
1335
|
+
} catch (err) {
|
|
1336
|
+
if (isCancelledRequest(err)) return;
|
|
1337
|
+
const response = err?.response;
|
|
1338
|
+
const reasonCode = response?.data?.error?.details?.reason;
|
|
1339
|
+
if (response?.status === 429) {
|
|
1340
|
+
setFailure(
|
|
1341
|
+
t(
|
|
1342
|
+
"impersonation.error.rateLimited",
|
|
1343
|
+
"Too many impersonations were started. Try again in a few minutes."
|
|
1344
|
+
)
|
|
1345
|
+
);
|
|
1346
|
+
} else if (REFUSALS[reasonCode]) {
|
|
1347
|
+
setFailure(t(...REFUSALS[reasonCode]));
|
|
1348
|
+
} else {
|
|
1349
|
+
logSafeAdminError("impersonation.start", err);
|
|
1350
|
+
setFailure(t("impersonation.error.start", "The impersonation could not be started."));
|
|
1351
|
+
}
|
|
1352
|
+
} finally {
|
|
1353
|
+
setPending(null);
|
|
1354
|
+
}
|
|
1355
|
+
};
|
|
1356
|
+
const end = async () => {
|
|
1357
|
+
if (!result?.impersonation?.id) return;
|
|
1358
|
+
setPending("end");
|
|
1359
|
+
try {
|
|
1360
|
+
await post(`/${pluginId$1}/impersonation/${result.impersonation.id}/end`, {});
|
|
1361
|
+
toggleNotification({
|
|
1362
|
+
type: "success",
|
|
1363
|
+
message: t("impersonation.ended", "Impersonation ended.")
|
|
1364
|
+
});
|
|
1365
|
+
onChanged?.();
|
|
1366
|
+
onOpenChange(false);
|
|
1367
|
+
} catch (err) {
|
|
1368
|
+
logSafeAdminError("impersonation.end", err);
|
|
1369
|
+
toggleNotification({
|
|
1370
|
+
type: "danger",
|
|
1371
|
+
message: t("impersonation.error.end", "The impersonation could not be ended.")
|
|
1372
|
+
});
|
|
1373
|
+
} finally {
|
|
1374
|
+
setPending(null);
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
const openFrontend = () => {
|
|
1378
|
+
setFailure(null);
|
|
1379
|
+
const onViolation = (event) => {
|
|
1380
|
+
if (String(event?.violatedDirective || "").startsWith("form-action")) {
|
|
1381
|
+
setFailure(
|
|
1382
|
+
t(
|
|
1383
|
+
"impersonation.error.csp",
|
|
1384
|
+
"Your Strapi security settings block sending the sign-in to {origin}. Add this origin to form-action of the Content-Security-Policy (see the README), then start again.",
|
|
1385
|
+
{ origin: status?.frontendOrigin || "" }
|
|
1386
|
+
)
|
|
1387
|
+
);
|
|
1388
|
+
}
|
|
1389
|
+
};
|
|
1390
|
+
document.addEventListener("securitypolicyviolation", onViolation);
|
|
1391
|
+
window.setTimeout(
|
|
1392
|
+
() => document.removeEventListener("securitypolicyviolation", onViolation),
|
|
1393
|
+
3e3
|
|
1394
|
+
);
|
|
1395
|
+
if (!submitFrontendHandoff(document, result?.handoff)) {
|
|
1396
|
+
setFailure(t("impersonation.error.frontend", "The frontend could not be opened."));
|
|
1397
|
+
}
|
|
1398
|
+
};
|
|
1399
|
+
const handoff = result?.handoff;
|
|
1400
|
+
const clock = formatClock(secondsLeft);
|
|
1401
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Root, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Content, { onCloseAutoFocus, "aria-describedby": void 0, children: [
|
|
1402
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Header, { closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Title, { children: result ? t("impersonation.result.title", "Impersonating {user}", { user: user.label }) : t("impersonation.modal.title", "Impersonate {user}", { user: user.label }) }) }),
|
|
1403
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
|
|
1404
|
+
failure ? /* @__PURE__ */ jsxRuntime.jsx(PersistentAlert, { variant: "danger", closeLabel: t("common.close", "Close"), children: failure }) : null,
|
|
1405
|
+
!result ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1406
|
+
/* @__PURE__ */ jsxRuntime.jsx(ReadableText, { variant: "omega", textColor: "neutral800", tag: "p", children: t(
|
|
1407
|
+
"impersonation.modal.intro",
|
|
1408
|
+
"You get a short-lived sign-in as this user to reproduce a problem. Password, email address, account and sessions cannot be changed with it. It is recorded in the security log."
|
|
1409
|
+
) }),
|
|
1410
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1411
|
+
designSystem.Field.Root,
|
|
1412
|
+
{
|
|
1413
|
+
name: "reason",
|
|
1414
|
+
required: true,
|
|
1415
|
+
error: showReasonError ? tError(reasonError) : void 0,
|
|
1416
|
+
hint: t(
|
|
1417
|
+
"impersonation.reason.hint",
|
|
1418
|
+
"Stored in the security log for admins. The user sees it only in the optional email; their data export says only that an administrator opened the account."
|
|
1419
|
+
),
|
|
1420
|
+
children: [
|
|
1421
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("impersonation.reason.label", "Reason") }),
|
|
1422
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1423
|
+
designSystem.Textarea,
|
|
1424
|
+
{
|
|
1425
|
+
value: reason,
|
|
1426
|
+
maxLength: REASON_MAX,
|
|
1427
|
+
placeholder: t("impersonation.reason.placeholder", "For example: ticket 4711"),
|
|
1428
|
+
onChange: (event) => setReason(event.target.value),
|
|
1429
|
+
onBlur: () => setTouched(true)
|
|
1430
|
+
}
|
|
1431
|
+
),
|
|
1432
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}),
|
|
1433
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
1434
|
+
]
|
|
1435
|
+
}
|
|
1436
|
+
),
|
|
1437
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "durationMinutes", children: [
|
|
1438
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: t("impersonation.duration.label", "Duration") }),
|
|
1439
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1440
|
+
designSystem.SingleSelect,
|
|
1441
|
+
{
|
|
1442
|
+
value: String(minutes),
|
|
1443
|
+
onChange: (value) => setMinutes(Number(value)),
|
|
1444
|
+
children: durations.map((value) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: String(value), children: t(
|
|
1445
|
+
"impersonation.duration.minutes",
|
|
1446
|
+
"{count, plural, one {# minute} other {# minutes}}",
|
|
1447
|
+
{
|
|
1448
|
+
count: value
|
|
1449
|
+
}
|
|
1450
|
+
) }, value))
|
|
1451
|
+
}
|
|
1452
|
+
)
|
|
1453
|
+
] }),
|
|
1454
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
|
|
1455
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1456
|
+
designSystem.Checkbox,
|
|
1457
|
+
{
|
|
1458
|
+
checked: notifyUser,
|
|
1459
|
+
"aria-describedby": notifyHintId,
|
|
1460
|
+
onCheckedChange: (checked) => setNotifyUser(checked === true),
|
|
1461
|
+
children: t(
|
|
1462
|
+
"impersonation.notify.label",
|
|
1463
|
+
"Email the user that their account was opened"
|
|
1464
|
+
)
|
|
1465
|
+
}
|
|
1466
|
+
),
|
|
1467
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { id: notifyHintId, variant: "pi", textColor: "neutral600", children: t(
|
|
1468
|
+
"impersonation.notify.hint",
|
|
1469
|
+
"Sent through Strapi’s email plugin, with the reason and the duration."
|
|
1470
|
+
) })
|
|
1471
|
+
] })
|
|
1472
|
+
] }) : null,
|
|
1473
|
+
handoff?.type === "frontend" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1474
|
+
/* @__PURE__ */ jsxRuntime.jsx(PersistentAlert, { variant: "default", closeLabel: t("common.close", "Close"), children: t(
|
|
1475
|
+
"impersonation.result.frontendBody",
|
|
1476
|
+
"Open {origin} within one minute. The sign-in link works once and is sent without appearing in the address bar.",
|
|
1477
|
+
{ origin: status?.frontendOrigin || "" }
|
|
1478
|
+
) }),
|
|
1479
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ExternalLink, {}), onClick: openFrontend, children: t("impersonation.result.openFrontend", "Open frontend") }) })
|
|
1480
|
+
] }) : null,
|
|
1481
|
+
handoff?.type === "token" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1482
|
+
/* @__PURE__ */ jsxRuntime.jsx(PersistentAlert, { variant: "warning", closeLabel: t("common.close", "Close"), children: t(
|
|
1483
|
+
"impersonation.result.tokenBody",
|
|
1484
|
+
"Shown only once. Anyone who has this token acts as {user} until it ends. Do not store or share it.",
|
|
1485
|
+
{ user: user.label }
|
|
1486
|
+
) }),
|
|
1487
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1488
|
+
SecretField,
|
|
1489
|
+
{
|
|
1490
|
+
name: "jwt",
|
|
1491
|
+
label: t("impersonation.result.accessToken", "Access token"),
|
|
1492
|
+
value: handoff.jwt
|
|
1493
|
+
}
|
|
1494
|
+
),
|
|
1495
|
+
handoff.refreshToken ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1496
|
+
SecretField,
|
|
1497
|
+
{
|
|
1498
|
+
name: "refreshToken",
|
|
1499
|
+
label: t("impersonation.result.refreshToken", "Refresh token"),
|
|
1500
|
+
value: handoff.refreshToken
|
|
1501
|
+
}
|
|
1502
|
+
) : null
|
|
1503
|
+
] }) : null,
|
|
1504
|
+
result ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", textColor: "neutral800", tag: "p", "aria-live": "polite", children: t("impersonation.result.endsIn", "Ends in {time}.", { time: clock }) }) : null
|
|
1505
|
+
] }) }),
|
|
1506
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Footer, { children: result ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1507
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "danger-light", onClick: end, loading: pending === "end", children: t("impersonation.end", "End impersonation") }),
|
|
1508
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Close, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: t("impersonation.result.done", "Done") }) })
|
|
1509
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1510
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Close, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: t("common.cancel", "Cancel") }) }),
|
|
1511
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: start, loading: pending === "start", children: t("impersonation.start", "Start impersonation") })
|
|
1512
|
+
] }) })
|
|
1513
|
+
] }) });
|
|
1514
|
+
};
|
|
1515
|
+
const focusVisibleTrigger = (documentId, fallback) => {
|
|
1516
|
+
const candidates = [
|
|
1517
|
+
...document.querySelectorAll(
|
|
1518
|
+
`[data-impersonation-trigger="${globalThis.CSS?.escape ? globalThis.CSS.escape(documentId) : documentId}"]`
|
|
1519
|
+
)
|
|
1520
|
+
];
|
|
1521
|
+
const visible = candidates.find((node) => node.getClientRects().length > 0);
|
|
1522
|
+
(visible || fallback)?.focus?.();
|
|
1523
|
+
};
|
|
1524
|
+
const ImpersonationPanelSection = ({ documentId, userLabel }) => {
|
|
1525
|
+
const { t } = useSettingsTranslate();
|
|
1526
|
+
const { get, post } = StrapiAdmin.useFetchClient();
|
|
1527
|
+
const { toggleNotification } = StrapiAdmin.useNotification();
|
|
1528
|
+
const { formatDate } = useSessionFormatters();
|
|
1529
|
+
const {
|
|
1530
|
+
isLoading,
|
|
1531
|
+
allowedActions: { canUsers }
|
|
1532
|
+
} = StrapiAdmin.useRBAC(pluginPermissions.impersonateUsers);
|
|
1533
|
+
const [status, setStatus] = react.useState(null);
|
|
1534
|
+
const [active, setActive] = react.useState(null);
|
|
1535
|
+
const instance = react.useId();
|
|
1536
|
+
const dialog = react.useSyncExternalStore(
|
|
1537
|
+
subscribeImpersonationDialogs,
|
|
1538
|
+
() => getImpersonationDialog(documentId)
|
|
1539
|
+
);
|
|
1540
|
+
const open = dialog?.open === true && dialog.owner === instance;
|
|
1541
|
+
react.useEffect(() => registerImpersonationPanel(documentId, instance), [documentId, instance]);
|
|
1542
|
+
const triggerRef = react.useRef(null);
|
|
1543
|
+
const endTriggerRef = react.useRef(null);
|
|
1544
|
+
const requestRef = react.useRef(0);
|
|
1545
|
+
const apply = react.useCallback(
|
|
1546
|
+
async (request, pending) => {
|
|
1547
|
+
try {
|
|
1548
|
+
const [statusResponse, listResponse] = await pending;
|
|
1549
|
+
if (request !== requestRef.current) return;
|
|
1550
|
+
setStatus(statusResponse?.data?.data || null);
|
|
1551
|
+
const rows = Array.isArray(listResponse?.data?.data) ? listResponse.data.data : [];
|
|
1552
|
+
setActive(
|
|
1553
|
+
rows.find((row) => row.targetType === "user" && row.targetId === documentId) || null
|
|
1554
|
+
);
|
|
1555
|
+
} catch (err) {
|
|
1556
|
+
if (isCancelledRequest(err) || request !== requestRef.current) return;
|
|
1557
|
+
logSafeAdminError("impersonation.panel", err);
|
|
1558
|
+
setStatus(null);
|
|
1559
|
+
}
|
|
1560
|
+
},
|
|
1561
|
+
[documentId]
|
|
1562
|
+
);
|
|
1563
|
+
const fetchState = react.useCallback(
|
|
1564
|
+
() => Promise.all([
|
|
1565
|
+
get(`/${pluginId$1}/impersonation/status`),
|
|
1566
|
+
get(`/${pluginId$1}/impersonation/active`)
|
|
1567
|
+
]),
|
|
1568
|
+
[get]
|
|
1569
|
+
);
|
|
1570
|
+
const load = react.useCallback(() => apply(++requestRef.current, fetchState()), [apply, fetchState]);
|
|
1571
|
+
react.useEffect(() => {
|
|
1572
|
+
if (isLoading || !canUsers || !documentId) return;
|
|
1573
|
+
apply(++requestRef.current, fetchState());
|
|
1574
|
+
}, [apply, canUsers, documentId, fetchState, isLoading]);
|
|
1575
|
+
if (isLoading || !canUsers || !status?.enabled) return null;
|
|
1576
|
+
const end = async () => {
|
|
1577
|
+
try {
|
|
1578
|
+
await post(`/${pluginId$1}/impersonation/${active.id}/end`, {});
|
|
1579
|
+
toggleNotification({
|
|
1580
|
+
type: "success",
|
|
1581
|
+
message: t("impersonation.ended", "Impersonation ended.")
|
|
1582
|
+
});
|
|
1583
|
+
} catch (err) {
|
|
1584
|
+
logSafeAdminError("impersonation.end", err);
|
|
1585
|
+
toggleNotification({
|
|
1586
|
+
type: "danger",
|
|
1587
|
+
message: t("impersonation.error.end", "The impersonation could not be ended.")
|
|
1588
|
+
});
|
|
1589
|
+
throw err;
|
|
1590
|
+
} finally {
|
|
1591
|
+
await load();
|
|
1592
|
+
}
|
|
1593
|
+
};
|
|
1594
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-panel-impersonation": "", children: [
|
|
1595
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", tag: "h3", children: t("impersonation.panel.title", "Impersonation") }),
|
|
1596
|
+
active ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1597
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral800", tag: "p", children: t("impersonation.panel.running", "Running until {time}.", {
|
|
1598
|
+
time: formatDate(active.expiresAt, { hour: "2-digit", minute: "2-digit" })
|
|
1599
|
+
}) }),
|
|
1600
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1601
|
+
ConfirmAction,
|
|
1602
|
+
{
|
|
1603
|
+
title: t("impersonation.confirm.title", "End the impersonation of {user}?", {
|
|
1604
|
+
user: userLabel
|
|
1605
|
+
}),
|
|
1606
|
+
body: t(
|
|
1607
|
+
"impersonation.confirm.body",
|
|
1608
|
+
"The short-lived sign-in stops working at once. This is recorded in the security log."
|
|
1609
|
+
),
|
|
1610
|
+
confirmLabel: t("impersonation.end", "End impersonation"),
|
|
1611
|
+
onConfirm: end,
|
|
1612
|
+
fallbackFocusRef: triggerRef,
|
|
1613
|
+
trigger: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1614
|
+
designSystem.Button,
|
|
1615
|
+
{
|
|
1616
|
+
ref: endTriggerRef,
|
|
1617
|
+
"data-impersonation-trigger": documentId,
|
|
1618
|
+
fullWidth: true,
|
|
1619
|
+
size: "S",
|
|
1620
|
+
variant: "danger-light",
|
|
1621
|
+
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.SignOut, { "aria-hidden": true, focusable: false }),
|
|
1622
|
+
type: "button",
|
|
1623
|
+
children: t("impersonation.end", "End impersonation")
|
|
1624
|
+
}
|
|
1625
|
+
)
|
|
1626
|
+
}
|
|
1627
|
+
)
|
|
1628
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1629
|
+
designSystem.Button,
|
|
1630
|
+
{
|
|
1631
|
+
ref: triggerRef,
|
|
1632
|
+
"data-impersonation-trigger": documentId,
|
|
1633
|
+
fullWidth: true,
|
|
1634
|
+
size: "S",
|
|
1635
|
+
variant: "secondary",
|
|
1636
|
+
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.User, { "aria-hidden": true, focusable: false }),
|
|
1637
|
+
onClick: () => openImpersonationDialog(documentId, instance),
|
|
1638
|
+
type: "button",
|
|
1639
|
+
children: t("impersonation.panel.start", "Impersonate…")
|
|
1640
|
+
}
|
|
1641
|
+
),
|
|
1642
|
+
open ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1643
|
+
ImpersonateUserModal,
|
|
1644
|
+
{
|
|
1645
|
+
open: true,
|
|
1646
|
+
onOpenChange: (next) => {
|
|
1647
|
+
if (!next) {
|
|
1648
|
+
closeImpersonationDialog(documentId);
|
|
1649
|
+
load();
|
|
1650
|
+
window.setTimeout(
|
|
1651
|
+
() => focusVisibleTrigger(documentId, triggerRef.current || endTriggerRef.current),
|
|
1652
|
+
0
|
|
1653
|
+
);
|
|
1654
|
+
}
|
|
1655
|
+
},
|
|
1656
|
+
onCloseAutoFocus: (event) => {
|
|
1657
|
+
event.preventDefault();
|
|
1658
|
+
focusVisibleTrigger(documentId, triggerRef.current || endTriggerRef.current);
|
|
1659
|
+
},
|
|
1660
|
+
user: { documentId, label: userLabel },
|
|
1661
|
+
status,
|
|
1662
|
+
onChanged: load
|
|
1663
|
+
}
|
|
1664
|
+
) : null
|
|
1665
|
+
] });
|
|
1666
|
+
};
|
|
1667
|
+
function useElementWidth() {
|
|
1668
|
+
const [width, setWidth] = react.useState(0);
|
|
1669
|
+
const observerRef = react.useRef(null);
|
|
1670
|
+
const ref = react.useCallback((node) => {
|
|
1671
|
+
observerRef.current?.disconnect();
|
|
1672
|
+
observerRef.current = null;
|
|
1673
|
+
if (!node || typeof ResizeObserver === "undefined") return;
|
|
1674
|
+
const observer = new ResizeObserver((entries) => {
|
|
1675
|
+
const next = Math.round(entries[0]?.contentRect?.width || 0);
|
|
1676
|
+
setWidth((previous) => previous === next ? previous : next);
|
|
1677
|
+
});
|
|
1678
|
+
observer.observe(node);
|
|
1679
|
+
observerRef.current = observer;
|
|
1680
|
+
}, []);
|
|
1681
|
+
react.useEffect(() => () => observerRef.current?.disconnect(), []);
|
|
1682
|
+
return [ref, width];
|
|
1683
|
+
}
|
|
1684
|
+
const CSV_HEADERS = Object.freeze([
|
|
1685
|
+
"ID",
|
|
1686
|
+
"Status",
|
|
1687
|
+
"User Email",
|
|
1688
|
+
"Username",
|
|
1689
|
+
"Device",
|
|
1690
|
+
"Browser",
|
|
1691
|
+
"OS",
|
|
1692
|
+
"IP Address",
|
|
1693
|
+
"Login Time",
|
|
1694
|
+
"Last Active",
|
|
1695
|
+
"Logout Time",
|
|
1696
|
+
"Minutes Idle",
|
|
1697
|
+
"End Reason"
|
|
1698
|
+
]);
|
|
1699
|
+
const FORMULA_START = /^[\s\u00ad\u061c\u180e\u200b-\u200f\u2060-\u2064\ufeff]*[=+\-@\uff1d\uff0b\uff0d\uff20\t\r\n]/;
|
|
1700
|
+
const escapeCsvValue = (value) => {
|
|
1701
|
+
const text = String(value ?? "");
|
|
1702
|
+
const safe = typeof value === "string" && FORMULA_START.test(text) ? `'${text}` : text;
|
|
1703
|
+
return `"${safe.replace(/"/g, '""')}"`;
|
|
1704
|
+
};
|
|
1705
|
+
function toIsoTimestamp(value) {
|
|
1706
|
+
if (value === null || value === void 0 || value === "") return "";
|
|
1707
|
+
const date = value instanceof Date ? value : new Date(
|
|
1708
|
+
/** @type {any} */
|
|
1709
|
+
value
|
|
1710
|
+
);
|
|
1711
|
+
return Number.isFinite(date.getTime()) ? date.toISOString() : "";
|
|
1712
|
+
}
|
|
1713
|
+
function buildSessionCsv(sessions, {
|
|
1714
|
+
unavailableValue,
|
|
1715
|
+
getDeviceInfo,
|
|
1716
|
+
getSessionStatus: getSessionStatus2,
|
|
1717
|
+
getSessionEndReason: getSessionEndReason$1 = getSessionEndReason
|
|
1718
|
+
}) {
|
|
1719
|
+
const rows = Array.isArray(sessions) ? sessions : [];
|
|
1720
|
+
const csvRows = rows.map((session) => {
|
|
1721
|
+
const deviceInfo = getDeviceInfo(session, unavailableValue);
|
|
1722
|
+
const minutesIdle = Number.isFinite(session.minutesSinceActive) ? session.minutesSinceActive : "";
|
|
1723
|
+
return [
|
|
1724
|
+
session.id,
|
|
1725
|
+
getSessionStatus2(session),
|
|
1726
|
+
session.user?.email || "",
|
|
1727
|
+
session.user?.username || "",
|
|
1728
|
+
deviceInfo.device,
|
|
1729
|
+
deviceInfo.browser,
|
|
1730
|
+
deviceInfo.os,
|
|
1731
|
+
session.ipAddress || unavailableValue,
|
|
1732
|
+
toIsoTimestamp(session.loginTime),
|
|
1733
|
+
toIsoTimestamp(session.lastActive || session.loginTime),
|
|
1734
|
+
toIsoTimestamp(session.logoutTime),
|
|
1735
|
+
minutesIdle,
|
|
1736
|
+
getSessionEndReason$1(session) || ""
|
|
1737
|
+
];
|
|
1738
|
+
});
|
|
1739
|
+
return [
|
|
1740
|
+
CSV_HEADERS.map(escapeCsvValue).join(","),
|
|
1741
|
+
...csvRows.map((row) => row.map(escapeCsvValue).join(","))
|
|
1742
|
+
].join("\n");
|
|
1743
|
+
}
|
|
1744
|
+
function buildSessionJson(sessions, {
|
|
1745
|
+
filterStatus,
|
|
1746
|
+
totalSessions,
|
|
1747
|
+
exportedAt,
|
|
1748
|
+
unavailableValue,
|
|
1749
|
+
getDeviceInfo,
|
|
1750
|
+
getSessionStatus: getSessionStatus2,
|
|
1751
|
+
getSessionEndReason: getSessionEndReason$1 = getSessionEndReason,
|
|
1752
|
+
truncated = false
|
|
1753
|
+
}) {
|
|
1754
|
+
const rows = Array.isArray(sessions) ? sessions : [];
|
|
1755
|
+
const exportData = {
|
|
1756
|
+
exportedAt,
|
|
1757
|
+
filter: filterStatus,
|
|
1758
|
+
totalSessions,
|
|
1759
|
+
exportedSessions: rows.length,
|
|
1760
|
+
...truncated ? { truncated: true } : {},
|
|
1761
|
+
sessions: rows.map((session) => {
|
|
1762
|
+
const deviceInfo = getDeviceInfo(session, unavailableValue);
|
|
1763
|
+
return {
|
|
1764
|
+
id: session.id,
|
|
1765
|
+
status: getSessionStatus2(session),
|
|
1766
|
+
endReason: getSessionEndReason$1(session) || null,
|
|
1767
|
+
user: {
|
|
1768
|
+
id: session.user?.documentId || session.user?.id,
|
|
1769
|
+
email: session.user?.email,
|
|
1770
|
+
username: session.user?.username
|
|
1771
|
+
},
|
|
1772
|
+
device: {
|
|
1773
|
+
type: deviceInfo.device,
|
|
1774
|
+
browser: deviceInfo.browser,
|
|
1775
|
+
browserVersion: deviceInfo.browserVersion,
|
|
1776
|
+
os: deviceInfo.os
|
|
1777
|
+
},
|
|
1778
|
+
ipAddress: session.ipAddress || unavailableValue,
|
|
1779
|
+
loginTime: session.loginTime,
|
|
1780
|
+
lastActive: session.lastActive,
|
|
1781
|
+
logoutTime: session.logoutTime,
|
|
1782
|
+
minutesSinceActive: session.minutesSinceActive,
|
|
1783
|
+
isActive: session.isActive,
|
|
1784
|
+
isTrulyActive: session.isTrulyActive
|
|
1785
|
+
};
|
|
1786
|
+
})
|
|
1787
|
+
};
|
|
1788
|
+
return JSON.stringify(exportData, null, 2);
|
|
1789
|
+
}
|
|
1790
|
+
const SETTINGS_TAB_IDS = Object.freeze([
|
|
1791
|
+
"sessions",
|
|
1792
|
+
"login-protection",
|
|
1793
|
+
"location-data",
|
|
1794
|
+
"alerts",
|
|
1795
|
+
"data-retention",
|
|
1796
|
+
"impersonation",
|
|
1797
|
+
"admin-activity"
|
|
1798
|
+
]);
|
|
1799
|
+
const PERMISSION_GATED_TABS = Object.freeze(["admin-activity"]);
|
|
1800
|
+
const DEFAULT_SETTINGS_TAB = "sessions";
|
|
1801
|
+
const SETTINGS_TAB_LABELS = Object.freeze({
|
|
1802
|
+
sessions: ["settings.config.tab.sessions", "Sessions"],
|
|
1803
|
+
"login-protection": ["settings.config.tab.loginProtection", "Login protection"],
|
|
1804
|
+
"location-data": ["settings.config.tab.locationData", "Location data"],
|
|
1805
|
+
alerts: ["settings.config.tab.alerts", "Alerts"],
|
|
1806
|
+
"data-retention": ["settings.config.tab.dataRetention", "Data and retention"],
|
|
1807
|
+
impersonation: ["settings.config.tab.impersonation", "Impersonation"],
|
|
1808
|
+
"admin-activity": ["settings.config.tab.adminActivity", "Admin activity"]
|
|
1809
|
+
});
|
|
1810
|
+
const SETTINGS_TAB_FIELDS = Object.freeze({
|
|
1811
|
+
sessions: [
|
|
1812
|
+
"inactivityTimeout",
|
|
1813
|
+
"maxSessionAgeDays",
|
|
1814
|
+
"lastSeenRateLimit",
|
|
1815
|
+
"cleanupInterval",
|
|
1816
|
+
"cleanupUseDbDirect",
|
|
1817
|
+
"strictSessionEnforcement",
|
|
1818
|
+
"sessionCreationGraceMs",
|
|
1819
|
+
"maxSessionsPerUser",
|
|
1820
|
+
"sessionLimitPolicy",
|
|
1821
|
+
"endOtherSessionsOnPasswordChange",
|
|
1822
|
+
"roleRules"
|
|
1823
|
+
],
|
|
1824
|
+
"login-protection": [
|
|
1825
|
+
"maxFailedLogins",
|
|
1826
|
+
"maxFailedLoginsPerAccount",
|
|
1827
|
+
"lockoutWindowMinutes",
|
|
1828
|
+
"lockoutDurationMinutes",
|
|
1829
|
+
"lockoutTrustedAddresses",
|
|
1830
|
+
"lockoutNotifyUser",
|
|
1831
|
+
"recordUserSignInEvents",
|
|
1832
|
+
"impossibleTravelEnabled",
|
|
1833
|
+
"impossibleTravelSpeedKmh",
|
|
1834
|
+
"impossibleTravelMinDistanceKm",
|
|
1835
|
+
"impossibleTravelAction",
|
|
1836
|
+
"trustedProxies",
|
|
1837
|
+
"blockSuspiciousSessions",
|
|
1838
|
+
"geoLookupFailureMode",
|
|
1839
|
+
"enableGeofencing",
|
|
1840
|
+
"allowedCountries",
|
|
1841
|
+
"blockedCountries"
|
|
1842
|
+
],
|
|
1843
|
+
"location-data": [
|
|
1844
|
+
"enableGeolocation",
|
|
1845
|
+
"enableSecurityScoring",
|
|
1846
|
+
"geoIpProvider",
|
|
1847
|
+
"geoIpDatabasePath"
|
|
1848
|
+
],
|
|
1849
|
+
alerts: [
|
|
1850
|
+
"enableEmailAlerts",
|
|
1851
|
+
"alertOnSuspiciousLogin",
|
|
1852
|
+
"alertOnNewLocation",
|
|
1853
|
+
"alertOnVpnProxy",
|
|
1854
|
+
"emailTemplates",
|
|
1855
|
+
"enableWebhooks",
|
|
1856
|
+
"discordWebhookUrl",
|
|
1857
|
+
"slackWebhookUrl",
|
|
1858
|
+
"alertOnNewDevice",
|
|
1859
|
+
"alertOnImpossibleTravel",
|
|
1860
|
+
"webhookEvents",
|
|
1861
|
+
"genericWebhookEnabled",
|
|
1862
|
+
"genericWebhookUrl",
|
|
1863
|
+
"genericWebhookSecret"
|
|
1864
|
+
],
|
|
1865
|
+
"data-retention": ["retentionDays", "sessionIpAnonymize"],
|
|
1866
|
+
impersonation: ["impersonationEnabled"],
|
|
1867
|
+
"admin-activity": [
|
|
1868
|
+
"adminSignInHistory",
|
|
1869
|
+
"adminContentActivity",
|
|
1870
|
+
"securityLogStoreIp",
|
|
1871
|
+
"securityLogAnonymizeIp",
|
|
1872
|
+
"securityLogGeoLookup",
|
|
1873
|
+
"securityLogRetentionDays"
|
|
1874
|
+
]
|
|
1875
|
+
});
|
|
1876
|
+
const PRESERVED_SETTINGS_KEYS = Object.freeze([
|
|
1877
|
+
"rateLimitWriteMax",
|
|
1878
|
+
"rateLimitReadMax",
|
|
1879
|
+
"rateLimitWindowSeconds"
|
|
1880
|
+
]);
|
|
1881
|
+
const SETTINGS_FIELD_LABELS = Object.freeze({
|
|
1882
|
+
inactivityTimeout: ["settings.config.sessions.inactivity.label", "Inactivity timeout"],
|
|
1883
|
+
maxSessionAgeDays: ["settings.config.sessions.maxAge.label", "Maximum session age"],
|
|
1884
|
+
lastSeenRateLimit: [
|
|
1885
|
+
"settings.config.sessions.lastSeen.label",
|
|
1886
|
+
'Update "Last active" at most every'
|
|
1887
|
+
],
|
|
1888
|
+
cleanupInterval: ["settings.config.sessions.idleCheck.label", "Run idle check every"],
|
|
1889
|
+
cleanupUseDbDirect: ["settings.config.sessions.idleMethod.label", "Idle check method"],
|
|
1890
|
+
strictSessionEnforcement: ["settings.config.token.check.label", "Strict token check"],
|
|
1891
|
+
sessionCreationGraceMs: ["settings.config.token.grace.label", "Grace period after sign-in"],
|
|
1892
|
+
maxFailedLogins: ["settings.config.failed.lockout.label", "Lock an IP address after"],
|
|
1893
|
+
maxFailedLoginsPerAccount: ["settings.config.failed.account.label", "Lock an account after"],
|
|
1894
|
+
lockoutWindowMinutes: ["settings.config.failed.window.label", "Count failed sign-ins within"],
|
|
1895
|
+
lockoutDurationMinutes: ["settings.config.failed.duration.label", "Lock for"],
|
|
1896
|
+
lockoutTrustedAddresses: ["settings.config.failed.trusted.label", "Trusted addresses"],
|
|
1897
|
+
lockoutNotifyUser: [
|
|
1898
|
+
"settings.config.failed.notify.label",
|
|
1899
|
+
"Email the user when their account is locked"
|
|
1900
|
+
],
|
|
1901
|
+
recordUserSignInEvents: [
|
|
1902
|
+
"settings.config.failed.record.label",
|
|
1903
|
+
"Record failed and refused sign-ins"
|
|
1904
|
+
],
|
|
1905
|
+
maxSessionsPerUser: ["settings.config.sessionLimit.max.label", "Open sessions per user"],
|
|
1906
|
+
sessionLimitPolicy: ["settings.config.sessionLimit.policy.label", "When the limit is reached"],
|
|
1907
|
+
endOtherSessionsOnPasswordChange: [
|
|
1908
|
+
"settings.config.passwordChange.label",
|
|
1909
|
+
"End other sessions after a password change"
|
|
1910
|
+
],
|
|
1911
|
+
roleRules: ["settings.roleRules.title", "Different rules for some roles"],
|
|
1912
|
+
impossibleTravelEnabled: ["settings.config.travel.enable.label", "Detect impossible travel"],
|
|
1913
|
+
impossibleTravelSpeedKmh: ["settings.config.travel.speed.label", "Faster than"],
|
|
1914
|
+
impossibleTravelMinDistanceKm: ["settings.config.travel.distance.label", "Over at least"],
|
|
1915
|
+
impossibleTravelAction: ["settings.config.travel.action.label", "Then"],
|
|
1916
|
+
alertOnNewDevice: ["settings.config.email.newDevice.label", "Sign-in from a new device"],
|
|
1917
|
+
alertOnImpossibleTravel: ["settings.config.email.travel.label", "Impossible travel"],
|
|
1918
|
+
webhookEvents: ["settings.webhookEvents.title", "Events to send"],
|
|
1919
|
+
genericWebhookEnabled: ["settings.signedWebhook.enable.label", "Send to the signed webhook"],
|
|
1920
|
+
genericWebhookUrl: ["settings.signedWebhook.url.label", "Webhook URL"],
|
|
1921
|
+
genericWebhookSecret: ["settings.signedWebhook.secret.label", "Signing secret"],
|
|
1922
|
+
sessionIpAnonymize: ["settings.config.privacy.shortIp.label", "Shorten IP addresses of sessions"],
|
|
1923
|
+
trustedProxies: ["settings.config.clientIp.trustProxy.label", "Trusted proxies"],
|
|
1924
|
+
blockSuspiciousSessions: [
|
|
1925
|
+
"settings.config.suspicious.reject.label",
|
|
1926
|
+
"Reject suspicious sign-ins"
|
|
1927
|
+
],
|
|
1928
|
+
geoLookupFailureMode: [
|
|
1929
|
+
"settings.config.suspicious.failureMode.label",
|
|
1930
|
+
"If the location cannot be determined"
|
|
1931
|
+
],
|
|
1932
|
+
enableGeofencing: ["settings.config.countries.enable.label", "Use country rules"],
|
|
1933
|
+
allowedCountries: ["settings.config.countries.list.label", "Countries"],
|
|
1934
|
+
blockedCountries: ["settings.config.countries.list.label", "Countries"],
|
|
1935
|
+
enableGeolocation: ["settings.config.lookup.enable.label", "IP location lookup"],
|
|
1936
|
+
enableSecurityScoring: ["settings.config.lookup.scoring.label", "Security scoring"],
|
|
1937
|
+
geoIpProvider: ["settings.config.provider.label", "Provider"],
|
|
1938
|
+
geoIpDatabasePath: ["settings.config.database.fileName.label", "Database file name"],
|
|
1939
|
+
enableEmailAlerts: ["settings.config.email.enable.label", "Send security emails"],
|
|
1940
|
+
alertOnSuspiciousLogin: ["settings.config.email.suspicious.label", "Suspicious sign-in"],
|
|
1941
|
+
alertOnNewLocation: ["settings.config.email.newCountry.label", "Sign-in from a new country"],
|
|
1942
|
+
alertOnVpnProxy: ["settings.config.email.vpnProxy.label", "VPN or proxy"],
|
|
1943
|
+
emailTemplates: ["settings.config.email.templates.field", "Email templates"],
|
|
1944
|
+
enableWebhooks: ["settings.config.webhooks.enable.label", "Send team notifications"],
|
|
1945
|
+
discordWebhookUrl: ["settings.config.webhooks.discord.label", "Discord webhook URL"],
|
|
1946
|
+
slackWebhookUrl: ["settings.config.webhooks.slack.label", "Slack webhook URL"],
|
|
1947
|
+
retentionDays: ["settings.config.retention.keep.label", "Keep ended sessions for"],
|
|
1948
|
+
impersonationEnabled: ["settings.impersonation.enable.label", "Allow impersonation"],
|
|
1949
|
+
adminSignInHistory: ["settings.config.adminActivity.signIns.label", "Record admin sign-ins"],
|
|
1950
|
+
adminContentActivity: [
|
|
1951
|
+
"settings.config.adminActivity.content.label",
|
|
1952
|
+
"Record Content Manager activity"
|
|
1953
|
+
],
|
|
1954
|
+
securityLogStoreIp: ["settings.config.adminActivity.storeIp.label", "Store IP addresses"],
|
|
1955
|
+
securityLogAnonymizeIp: [
|
|
1956
|
+
"settings.config.adminActivity.anonymize.label",
|
|
1957
|
+
"Anonymise the last part of IP addresses"
|
|
1958
|
+
],
|
|
1959
|
+
securityLogGeoLookup: [
|
|
1960
|
+
"settings.config.adminActivity.geoLookup.label",
|
|
1961
|
+
"Look up the location of security events"
|
|
1962
|
+
],
|
|
1963
|
+
securityLogRetentionDays: [
|
|
1964
|
+
"settings.config.adminActivity.retention.label",
|
|
1965
|
+
"Keep security events for"
|
|
1966
|
+
]
|
|
1967
|
+
});
|
|
1968
|
+
const SELECT_PRESETS = Object.freeze({
|
|
1969
|
+
inactivityTimeout: Object.freeze([5, 10, 15, 30, 60, 120]),
|
|
1970
|
+
maxSessionAgeDays: Object.freeze([1, 7, 14, 30, 60, 90, 180, 365]),
|
|
1971
|
+
lastSeenRateLimit: Object.freeze([10, 30, 60, 120, 300]),
|
|
1972
|
+
cleanupInterval: Object.freeze([15, 30, 60, 120]),
|
|
1973
|
+
sessionCreationGraceMs: Object.freeze([0, 2e3, 5e3, 1e4, 3e4]),
|
|
1974
|
+
retentionDays: Object.freeze([7, 30, 60, 90, 180, 365, -1]),
|
|
1975
|
+
securityLogRetentionDays: Object.freeze([7, 30, 90, 180, 365])
|
|
1976
|
+
});
|
|
1977
|
+
function resolveSettingsTab(value, tabs = SETTINGS_TAB_IDS) {
|
|
1978
|
+
const candidate = Array.isArray(value) ? value[0] : value;
|
|
1979
|
+
return tabs.includes(candidate) ? candidate : DEFAULT_SETTINGS_TAB;
|
|
1980
|
+
}
|
|
1981
|
+
function getVisibleSettingsTabs(canViewAdminActivity) {
|
|
1982
|
+
return SETTINGS_TAB_IDS.filter(
|
|
1983
|
+
(tab) => canViewAdminActivity || !PERMISSION_GATED_TABS.includes(tab)
|
|
1984
|
+
);
|
|
1985
|
+
}
|
|
1986
|
+
function buildTabSearch(search, tab) {
|
|
1987
|
+
const params = new URLSearchParams(typeof search === "string" ? search : "");
|
|
1988
|
+
params.set("tab", resolveSettingsTab(tab));
|
|
1989
|
+
return `?${params.toString()}`;
|
|
1990
|
+
}
|
|
1991
|
+
function fieldHasError(errors, field) {
|
|
1992
|
+
return Object.keys(errors || {}).some((path) => path === field || path.startsWith(`${field}.`));
|
|
1993
|
+
}
|
|
1994
|
+
function tabHasFieldErrors(errors, tab) {
|
|
1995
|
+
return (SETTINGS_TAB_FIELDS[tab] || []).some((field) => fieldHasError(errors, field));
|
|
1996
|
+
}
|
|
1997
|
+
function getErrorTab(errors) {
|
|
1998
|
+
return SETTINGS_TAB_IDS.find((tab) => tabHasFieldErrors(errors, tab));
|
|
1999
|
+
}
|
|
2000
|
+
function buildSelectOptions(presets, current) {
|
|
2001
|
+
const options = presets.map((value) => ({ value, custom: false }));
|
|
2002
|
+
const number = typeof current === "number" ? current : Number.parseInt(String(current ?? ""), 10);
|
|
2003
|
+
if (Number.isInteger(number) && !presets.includes(number)) {
|
|
2004
|
+
options.push({ value: number, custom: true });
|
|
2005
|
+
}
|
|
2006
|
+
return options;
|
|
2007
|
+
}
|
|
2008
|
+
function buildSavePayload(draft, saved) {
|
|
2009
|
+
const payload = { ...draft || {} };
|
|
2010
|
+
for (const key of PRESERVED_SETTINGS_KEYS) {
|
|
2011
|
+
if (saved && Object.prototype.hasOwnProperty.call(saved, key)) payload[key] = saved[key];
|
|
2012
|
+
}
|
|
2013
|
+
return payload;
|
|
2014
|
+
}
|
|
2015
|
+
function usesLocalDatabase(provider) {
|
|
2016
|
+
return provider === void 0 || provider === null || provider === "" || provider === "auto" || provider === "local-mmdb";
|
|
2017
|
+
}
|
|
2018
|
+
function getRevealScrollDelta(listRect, tabRect) {
|
|
2019
|
+
if (!listRect || !tabRect) return 0;
|
|
2020
|
+
if (tabRect.left < listRect.left - 0.5) return Math.round(tabRect.left - listRect.left);
|
|
2021
|
+
if (tabRect.right > listRect.right + 0.5) return Math.round(tabRect.right - listRect.right);
|
|
2022
|
+
return 0;
|
|
2023
|
+
}
|
|
2024
|
+
const SIGN_IN_FILTER_OPTIONS = Object.freeze(["all", "succeeded", "failed", "signed-out"]);
|
|
2025
|
+
const ALL_ADMINS_FILTER_OPTIONS = Object.freeze([...SIGN_IN_FILTER_OPTIONS, "changes"]);
|
|
2026
|
+
const ACTIVITY_ACTION_OPTIONS = Object.freeze([
|
|
2027
|
+
"all",
|
|
2028
|
+
"view",
|
|
2029
|
+
"create",
|
|
2030
|
+
"update",
|
|
2031
|
+
"publish",
|
|
2032
|
+
"unpublish",
|
|
2033
|
+
"discard",
|
|
2034
|
+
"delete",
|
|
2035
|
+
"clone"
|
|
2036
|
+
]);
|
|
2037
|
+
const PERIOD_OPTIONS = Object.freeze(["1", "7", "30", "90", "all"]);
|
|
2038
|
+
const EVENT_PAGE_SIZE = 20;
|
|
2039
|
+
const MAX_EVENT_EXPORT_ROWS = 1e4;
|
|
2040
|
+
function periodStart(period, now = /* @__PURE__ */ new Date()) {
|
|
2041
|
+
const days = Number.parseInt(period, 10);
|
|
2042
|
+
if (!Number.isInteger(days) || days <= 0) return void 0;
|
|
2043
|
+
return new Date(now.getTime() - days * 24 * 60 * 60 * 1e3).toISOString();
|
|
2044
|
+
}
|
|
2045
|
+
function buildSignInParams(filters, now) {
|
|
2046
|
+
const params = {
|
|
2047
|
+
page: filters.page || 1,
|
|
2048
|
+
pageSize: filters.pageSize || EVENT_PAGE_SIZE,
|
|
2049
|
+
event: ALL_ADMINS_FILTER_OPTIONS.includes(filters.event) ? filters.event : "all"
|
|
2050
|
+
};
|
|
2051
|
+
if (filters.adminId) params.adminId = String(filters.adminId);
|
|
2052
|
+
const from = periodStart(filters.period || "all", now);
|
|
2053
|
+
if (from) params.from = from;
|
|
2054
|
+
return params;
|
|
2055
|
+
}
|
|
2056
|
+
function buildActivityParams(filters, now) {
|
|
2057
|
+
const params = {
|
|
2058
|
+
page: filters.page || 1,
|
|
2059
|
+
pageSize: filters.pageSize || EVENT_PAGE_SIZE,
|
|
2060
|
+
action: ACTIVITY_ACTION_OPTIONS.includes(filters.action) ? filters.action : "all"
|
|
2061
|
+
};
|
|
2062
|
+
if (filters.adminId) params.adminId = String(filters.adminId);
|
|
2063
|
+
if (filters.contentType && filters.contentType !== "all")
|
|
2064
|
+
params.contentType = filters.contentType;
|
|
2065
|
+
const from = periodStart(filters.period || "all", now);
|
|
2066
|
+
if (from) params.from = from;
|
|
2067
|
+
return params;
|
|
2068
|
+
}
|
|
2069
|
+
function toExportParams(params, cursor) {
|
|
2070
|
+
const { page: _page, pageSize: _pageSize, ...rest } = params;
|
|
2071
|
+
return cursor ? { ...rest, cursor } : rest;
|
|
2072
|
+
}
|
|
2073
|
+
const message$1 = (messageId, defaultMessage) => ({ messageId, defaultMessage });
|
|
2074
|
+
const FAILURE_REASONS = Object.freeze({
|
|
2075
|
+
invalid_credentials: message$1(
|
|
2076
|
+
"adminPanel.activity.reason.invalidCredentials",
|
|
2077
|
+
"Wrong email or password"
|
|
2078
|
+
),
|
|
2079
|
+
account_inactive: message$1("adminPanel.activity.reason.accountInactive", "Account is deactivated"),
|
|
2080
|
+
login_not_allowed: message$1("adminPanel.activity.reason.notAllowed", "Sign-in is not allowed"),
|
|
2081
|
+
rate_limited: message$1("adminPanel.activity.reason.rateLimited", "Too many attempts")
|
|
2082
|
+
});
|
|
2083
|
+
const LOG_READ_DETAILS = Object.freeze({
|
|
2084
|
+
"sign-ins": [
|
|
2085
|
+
message$1("adminPanel.activity.read.signIns", "Sign-in history listed"),
|
|
2086
|
+
message$1("adminPanel.activity.read.signInsExport", "Sign-in history exported")
|
|
2087
|
+
],
|
|
2088
|
+
content: [
|
|
2089
|
+
message$1("adminPanel.activity.read.content", "Content Manager activity listed"),
|
|
2090
|
+
message$1("adminPanel.activity.read.contentExport", "Content Manager activity exported")
|
|
2091
|
+
],
|
|
2092
|
+
"user-activity": [
|
|
2093
|
+
message$1("adminPanel.activity.read.userActivity", "App-user security activity listed"),
|
|
2094
|
+
message$1("adminPanel.activity.read.userActivityExport", "App-user security activity exported")
|
|
2095
|
+
]
|
|
2096
|
+
});
|
|
2097
|
+
const appUserEvent = (key, tone, icon, messageId, defaultMessage) => ({
|
|
2098
|
+
key,
|
|
2099
|
+
tone,
|
|
2100
|
+
icon,
|
|
2101
|
+
label: message$1(messageId, defaultMessage),
|
|
2102
|
+
detail: null
|
|
2103
|
+
});
|
|
2104
|
+
function getEventPresentation(row) {
|
|
2105
|
+
switch (row?.event) {
|
|
2106
|
+
case "admin.sign-in":
|
|
2107
|
+
return {
|
|
2108
|
+
key: "sign-in",
|
|
2109
|
+
tone: "success",
|
|
2110
|
+
icon: "signIn",
|
|
2111
|
+
label: message$1("adminPanel.activity.event.signIn", "Signed in"),
|
|
2112
|
+
detail: row.reason === "registration" ? message$1("adminPanel.activity.reason.registration", "First sign-in after registration") : row.reason === "password_reset" ? message$1(
|
|
2113
|
+
"adminPanel.activity.reason.passwordReset",
|
|
2114
|
+
"Signed in after a password reset"
|
|
2115
|
+
) : null
|
|
2116
|
+
};
|
|
2117
|
+
case "admin.sign-in.failed":
|
|
2118
|
+
return {
|
|
2119
|
+
key: "failed",
|
|
2120
|
+
tone: "danger",
|
|
2121
|
+
icon: "failed",
|
|
2122
|
+
label: message$1("adminPanel.activity.event.failed", "Sign-in failed"),
|
|
2123
|
+
detail: FAILURE_REASONS[row.reason] || null
|
|
2124
|
+
};
|
|
2125
|
+
case "admin.lockout":
|
|
2126
|
+
return {
|
|
2127
|
+
key: "lockout",
|
|
2128
|
+
tone: "danger",
|
|
2129
|
+
icon: "lockout",
|
|
2130
|
+
label: message$1("adminPanel.activity.event.lockout", "Locked out"),
|
|
2131
|
+
detail: FAILURE_REASONS.rate_limited
|
|
2132
|
+
};
|
|
2133
|
+
case "admin.sign-out":
|
|
2134
|
+
return {
|
|
2135
|
+
key: "sign-out",
|
|
2136
|
+
tone: "neutral",
|
|
2137
|
+
icon: "signOut",
|
|
2138
|
+
label: message$1("adminPanel.activity.event.signOut", "Signed out"),
|
|
2139
|
+
detail: null
|
|
2140
|
+
};
|
|
2141
|
+
case "admin.session.revoked":
|
|
2142
|
+
return {
|
|
2143
|
+
key: "revoked",
|
|
2144
|
+
tone: "warning",
|
|
2145
|
+
icon: "revoked",
|
|
2146
|
+
label: message$1("adminPanel.activity.event.revoked", "Signed out by an admin"),
|
|
2147
|
+
detail: row.scope === "one_browser" ? message$1("adminPanel.activity.scope.oneBrowser", "One browser") : message$1("adminPanel.activity.scope.everywhere", "Every browser")
|
|
2148
|
+
};
|
|
2149
|
+
case "settings.updated":
|
|
2150
|
+
return {
|
|
2151
|
+
key: "settings",
|
|
2152
|
+
tone: "secondary",
|
|
2153
|
+
icon: "settings",
|
|
2154
|
+
label: message$1("adminPanel.activity.event.settings", "Settings changed"),
|
|
2155
|
+
detail: row.change?.viaToken ? message$1("adminPanel.activity.via.token", "With an admin API token") : null
|
|
2156
|
+
};
|
|
2157
|
+
case "security-log.read":
|
|
2158
|
+
return {
|
|
2159
|
+
key: "log-read",
|
|
2160
|
+
tone: "secondary",
|
|
2161
|
+
icon: row.read?.via === "admin-panel" ? "export" : "logRead",
|
|
2162
|
+
// 4.22: exports of the app-user activity from the admin panel are recorded too.
|
|
2163
|
+
label: row.read?.via === "admin-panel" ? message$1("adminPanel.activity.event.logExported", "Security log exported") : message$1("adminPanel.activity.event.logRead", "Log read with an API token"),
|
|
2164
|
+
detail: LOG_READ_DETAILS[row.read?.list || "sign-ins"]?.[row.read?.exported ? 1 : 0] || null
|
|
2165
|
+
};
|
|
2166
|
+
case "security-log.retention.purged":
|
|
2167
|
+
return {
|
|
2168
|
+
key: "purged",
|
|
2169
|
+
tone: "neutral",
|
|
2170
|
+
icon: "purged",
|
|
2171
|
+
label: message$1("adminPanel.activity.event.purged", "Old events deleted"),
|
|
2172
|
+
detail: null
|
|
2173
|
+
};
|
|
2174
|
+
// 4.22.1: recorded once per key at start-up.
|
|
2175
|
+
case "config.encryption-key.weak":
|
|
2176
|
+
return {
|
|
2177
|
+
key: "weak-key",
|
|
2178
|
+
tone: "danger",
|
|
2179
|
+
icon: "settings",
|
|
2180
|
+
label: message$1("adminPanel.activity.event.weakKey", "Weak encryption key"),
|
|
2181
|
+
detail: message$1(
|
|
2182
|
+
"adminPanel.activity.event.weakKey.detail",
|
|
2183
|
+
"SESSION_ENCRYPTION_KEY is shorter than 32 bytes. The next major version will refuse to start with it."
|
|
2184
|
+
)
|
|
2185
|
+
};
|
|
2186
|
+
// App-user events (4.17 / 4.18), listed by the app-user Security activity (4.22) only.
|
|
2187
|
+
// The admin lists never return them; the labels are plain because that view is about app
|
|
2188
|
+
// users already.
|
|
2189
|
+
case "user.sign-in.failed":
|
|
2190
|
+
return appUserEvent(
|
|
2191
|
+
"user-failed",
|
|
2192
|
+
"danger",
|
|
2193
|
+
"failed",
|
|
2194
|
+
"adminPanel.activity.event.userFailed",
|
|
2195
|
+
"Sign-in failed"
|
|
2196
|
+
);
|
|
2197
|
+
case "user.sign-in.refused":
|
|
2198
|
+
return appUserEvent(
|
|
2199
|
+
"user-refused",
|
|
2200
|
+
"danger",
|
|
2201
|
+
"refused",
|
|
2202
|
+
"adminPanel.activity.event.userRefused",
|
|
2203
|
+
"Sign-in refused"
|
|
2204
|
+
);
|
|
2205
|
+
case "user.lockout":
|
|
2206
|
+
return appUserEvent(
|
|
2207
|
+
"user-lockout",
|
|
2208
|
+
"danger",
|
|
2209
|
+
"lockout",
|
|
2210
|
+
"adminPanel.activity.event.userLockout",
|
|
2211
|
+
"Locked out"
|
|
2212
|
+
);
|
|
2213
|
+
case "user.lockout.lifted":
|
|
2214
|
+
return appUserEvent(
|
|
2215
|
+
"user-unlock",
|
|
2216
|
+
"secondary",
|
|
2217
|
+
"unlock",
|
|
2218
|
+
"adminPanel.activity.event.userUnlock",
|
|
2219
|
+
"Lock lifted"
|
|
2220
|
+
);
|
|
2221
|
+
case "user.session.limit":
|
|
2222
|
+
return appUserEvent(
|
|
2223
|
+
"user-limit",
|
|
2224
|
+
"warning",
|
|
2225
|
+
"limit",
|
|
2226
|
+
"adminPanel.activity.event.userLimit",
|
|
2227
|
+
"Session limit reached"
|
|
2228
|
+
);
|
|
2229
|
+
case "user.password-change.ended-others":
|
|
2230
|
+
return appUserEvent(
|
|
2231
|
+
"user-password",
|
|
2232
|
+
"warning",
|
|
2233
|
+
"password",
|
|
2234
|
+
"adminPanel.activity.event.userPassword",
|
|
2235
|
+
"Signed out after a password change"
|
|
2236
|
+
);
|
|
2237
|
+
case "user.sign-in.new-device":
|
|
2238
|
+
return appUserEvent(
|
|
2239
|
+
"user-device",
|
|
2240
|
+
"secondary",
|
|
2241
|
+
"device",
|
|
2242
|
+
"adminPanel.activity.event.userNewDevice",
|
|
2243
|
+
"Sign-in from a new device"
|
|
2244
|
+
);
|
|
2245
|
+
case "user.sign-in.impossible-travel":
|
|
2246
|
+
return appUserEvent(
|
|
2247
|
+
"user-travel",
|
|
2248
|
+
"danger",
|
|
2249
|
+
"travel",
|
|
2250
|
+
"adminPanel.activity.event.userTravel",
|
|
2251
|
+
"Impossible travel"
|
|
2252
|
+
);
|
|
2253
|
+
case "user.not-me":
|
|
2254
|
+
return appUserEvent(
|
|
2255
|
+
"user-not-me",
|
|
2256
|
+
"danger",
|
|
2257
|
+
"notMe",
|
|
2258
|
+
"adminPanel.activity.event.userNotMe",
|
|
2259
|
+
'Reported as "This wasn’t me"'
|
|
2260
|
+
);
|
|
2261
|
+
case "user.data.exported":
|
|
2262
|
+
return appUserEvent(
|
|
2263
|
+
"user-export",
|
|
2264
|
+
"secondary",
|
|
2265
|
+
"export",
|
|
2266
|
+
"adminPanel.activity.event.userExport",
|
|
2267
|
+
"Personal data exported"
|
|
2268
|
+
);
|
|
2269
|
+
case "impersonation.started":
|
|
2270
|
+
return appUserEvent(
|
|
2271
|
+
"impersonation-started",
|
|
2272
|
+
"warning",
|
|
2273
|
+
"impersonation",
|
|
2274
|
+
"adminPanel.activity.event.impersonationStarted",
|
|
2275
|
+
"Impersonation started"
|
|
2276
|
+
);
|
|
2277
|
+
case "impersonation.ended":
|
|
2278
|
+
return appUserEvent(
|
|
2279
|
+
"impersonation-ended",
|
|
2280
|
+
"neutral",
|
|
2281
|
+
"impersonationEnd",
|
|
2282
|
+
"adminPanel.activity.event.impersonationEnded",
|
|
2283
|
+
"Impersonation ended"
|
|
2284
|
+
);
|
|
2285
|
+
case "impersonation.expired":
|
|
2286
|
+
return appUserEvent(
|
|
2287
|
+
"impersonation-expired",
|
|
2288
|
+
"neutral",
|
|
2289
|
+
"expired",
|
|
2290
|
+
"adminPanel.activity.event.impersonationExpired",
|
|
2291
|
+
"Impersonation timed out"
|
|
2292
|
+
);
|
|
2293
|
+
case "impersonation.refused":
|
|
2294
|
+
return appUserEvent(
|
|
2295
|
+
"impersonation-refused",
|
|
2296
|
+
"danger",
|
|
2297
|
+
"refused",
|
|
2298
|
+
"adminPanel.activity.event.impersonationRefused",
|
|
2299
|
+
"Impersonation request refused"
|
|
2300
|
+
);
|
|
2301
|
+
default:
|
|
2302
|
+
if (typeof row?.event === "string" && row.event.startsWith("impersonation.")) {
|
|
2303
|
+
return appUserEvent(
|
|
2304
|
+
"impersonation",
|
|
2305
|
+
"warning",
|
|
2306
|
+
"impersonation",
|
|
2307
|
+
"adminPanel.activity.event.impersonation",
|
|
2308
|
+
"Impersonation"
|
|
2309
|
+
);
|
|
2310
|
+
}
|
|
2311
|
+
if (typeof row?.event === "string" && row.event.startsWith("webhook.")) {
|
|
2312
|
+
return appUserEvent(
|
|
2313
|
+
"webhook",
|
|
2314
|
+
"neutral",
|
|
2315
|
+
"webhook",
|
|
2316
|
+
"adminPanel.activity.event.webhook",
|
|
2317
|
+
"Webhook delivery"
|
|
2318
|
+
);
|
|
2319
|
+
}
|
|
2320
|
+
return {
|
|
2321
|
+
key: "other",
|
|
2322
|
+
tone: "neutral",
|
|
2323
|
+
icon: "other",
|
|
2324
|
+
label: message$1("adminPanel.activity.event.other", "Security event"),
|
|
2325
|
+
detail: null
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
function getSessionStatePresentation(session) {
|
|
2330
|
+
switch (session?.state) {
|
|
2331
|
+
case "active":
|
|
2332
|
+
return {
|
|
2333
|
+
tone: "success",
|
|
2334
|
+
label: message$1("adminPanel.activity.session.active", "Still signed in")
|
|
2335
|
+
};
|
|
2336
|
+
case "signed-out":
|
|
2337
|
+
return {
|
|
2338
|
+
tone: "neutral",
|
|
2339
|
+
label: message$1("adminPanel.activity.session.signedOut", "Signed out")
|
|
2340
|
+
};
|
|
2341
|
+
case "ended":
|
|
2342
|
+
return {
|
|
2343
|
+
tone: "neutral",
|
|
2344
|
+
label: message$1("adminPanel.activity.session.ended", "Session ended")
|
|
2345
|
+
};
|
|
2346
|
+
default:
|
|
2347
|
+
return null;
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
const RECENT_EVENT_LIMIT = 8;
|
|
2351
|
+
const ACTIVITY_PAGE_SIZE_OPTIONS = Object.freeze(["10", "20", "50", "100"]);
|
|
2352
|
+
const EVENT_TABLE_MIN_WIDTH = Object.freeze({ withAdmin: 800, withoutAdmin: 740 });
|
|
2353
|
+
const EVENT_TABLE_FULL_WIDTH = 1e3;
|
|
2354
|
+
function getEventListLayout(width, { showAdmin = false, wide = false, minWidth } = {}) {
|
|
2355
|
+
if (!width) return "full";
|
|
2356
|
+
const min = Number.isFinite(minWidth) && minWidth > 0 ? minWidth : showAdmin || wide ? EVENT_TABLE_MIN_WIDTH.withAdmin : EVENT_TABLE_MIN_WIDTH.withoutAdmin;
|
|
2357
|
+
if (width < min) return "stacked";
|
|
2358
|
+
return width >= EVENT_TABLE_FULL_WIDTH ? "full" : "table";
|
|
2359
|
+
}
|
|
2360
|
+
function getEventPlace(row) {
|
|
2361
|
+
return [row?.location?.city, row?.location?.country].filter(Boolean).join(", ");
|
|
2362
|
+
}
|
|
2363
|
+
function parseActivityPageQuery(query) {
|
|
2364
|
+
const source = query || {};
|
|
2365
|
+
const event = ALL_ADMINS_FILTER_OPTIONS.includes(String(source.event)) ? String(source.event) : "all";
|
|
2366
|
+
const period = PERIOD_OPTIONS.includes(String(source.period)) ? String(source.period) : "30";
|
|
2367
|
+
const adminId = /^[1-9][0-9]{0,11}$/.test(String(source.adminId ?? "")) ? Number(source.adminId) : null;
|
|
2368
|
+
const page = Number.parseInt(String(source.page ?? ""), 10);
|
|
2369
|
+
const pageSize = String(source.pageSize ?? "");
|
|
2370
|
+
return {
|
|
2371
|
+
event,
|
|
2372
|
+
period,
|
|
2373
|
+
adminId,
|
|
2374
|
+
page: Number.isInteger(page) && page > 0 ? page : 1,
|
|
2375
|
+
pageSize: ACTIVITY_PAGE_SIZE_OPTIONS.includes(pageSize) ? Number(pageSize) : EVENT_PAGE_SIZE
|
|
2376
|
+
};
|
|
2377
|
+
}
|
|
2378
|
+
function hasActivityPageFilters(view) {
|
|
2379
|
+
return view.event !== "all" || view.period !== "30" || view.adminId !== null;
|
|
2380
|
+
}
|
|
2381
|
+
function groupChangedSettings(keys) {
|
|
2382
|
+
const list = Array.isArray(keys) ? keys.filter((key) => typeof key === "string" && key) : [];
|
|
2383
|
+
const byTab = /* @__PURE__ */ new Map();
|
|
2384
|
+
const unknown = [];
|
|
2385
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2386
|
+
for (const key of list) {
|
|
2387
|
+
const tab = SETTINGS_TAB_IDS.find((id) => SETTINGS_TAB_FIELDS[id]?.includes(key));
|
|
2388
|
+
const entry = SETTINGS_FIELD_LABELS[key];
|
|
2389
|
+
if (!tab || !entry) {
|
|
2390
|
+
if (!seen.has(`raw:${key}`)) unknown.push({ key, label: null });
|
|
2391
|
+
seen.add(`raw:${key}`);
|
|
2392
|
+
continue;
|
|
2393
|
+
}
|
|
2394
|
+
if (seen.has(`label:${entry[0]}`)) continue;
|
|
2395
|
+
seen.add(`label:${entry[0]}`);
|
|
2396
|
+
if (!byTab.has(tab)) byTab.set(tab, []);
|
|
2397
|
+
byTab.get(tab).push({ key, label: message$1(entry[0], entry[1]) });
|
|
2398
|
+
}
|
|
2399
|
+
const groups = SETTINGS_TAB_IDS.filter((tab) => byTab.has(tab)).map((tab) => ({
|
|
2400
|
+
tab,
|
|
2401
|
+
label: message$1(SETTINGS_TAB_LABELS[tab][0], SETTINGS_TAB_LABELS[tab][1]),
|
|
2402
|
+
fields: byTab.get(tab)
|
|
2403
|
+
}));
|
|
2404
|
+
if (unknown.length) groups.push({ tab: null, label: null, fields: unknown });
|
|
2405
|
+
return groups;
|
|
2406
|
+
}
|
|
2407
|
+
const ACTIVITY_ACTION_LABELS = Object.freeze({
|
|
2408
|
+
all: message$1("adminPanel.activity.action.all", "All actions"),
|
|
2409
|
+
view: message$1("adminPanel.activity.action.view", "Opened"),
|
|
2410
|
+
create: message$1("adminPanel.activity.action.create", "Created"),
|
|
2411
|
+
update: message$1("adminPanel.activity.action.update", "Edited"),
|
|
2412
|
+
publish: message$1("adminPanel.activity.action.publish", "Published"),
|
|
2413
|
+
unpublish: message$1("adminPanel.activity.action.unpublish", "Unpublished"),
|
|
2414
|
+
discard: message$1("adminPanel.activity.action.discard", "Discarded draft"),
|
|
2415
|
+
delete: message$1("adminPanel.activity.action.delete", "Deleted"),
|
|
2416
|
+
clone: message$1("adminPanel.activity.action.clone", "Duplicated")
|
|
2417
|
+
});
|
|
2418
|
+
function getActivityTone(action) {
|
|
2419
|
+
if (action === "publish") return "success";
|
|
2420
|
+
if (action === "delete") return "warning";
|
|
2421
|
+
return "neutral";
|
|
2422
|
+
}
|
|
2423
|
+
function getEntryPath(row) {
|
|
2424
|
+
const type = row?.contentType;
|
|
2425
|
+
if (!type?.exists || row.action === "delete") return null;
|
|
2426
|
+
const uid = encodeURIComponent(type.uid);
|
|
2427
|
+
const locale = row.entry?.locale ? `?plugins[i18n][locale]=${encodeURIComponent(row.entry.locale)}` : "";
|
|
2428
|
+
if (type.kind === "single") return `/content-manager/single-types/${uid}${locale}`;
|
|
2429
|
+
if (!row.entry?.documentId) return null;
|
|
2430
|
+
return `/content-manager/collection-types/${uid}/${encodeURIComponent(row.entry.documentId)}${locale}`;
|
|
2431
|
+
}
|
|
2432
|
+
const SIGN_IN_CSV_HEADERS = Object.freeze([
|
|
2433
|
+
"Time",
|
|
2434
|
+
"Event",
|
|
2435
|
+
"Reason",
|
|
2436
|
+
"Admin",
|
|
2437
|
+
"Admin ID",
|
|
2438
|
+
"IP Address",
|
|
2439
|
+
"IP Anonymized",
|
|
2440
|
+
"Country",
|
|
2441
|
+
"City",
|
|
2442
|
+
"Browser",
|
|
2443
|
+
"OS",
|
|
2444
|
+
"Device",
|
|
2445
|
+
"Session",
|
|
2446
|
+
"Signed Out By"
|
|
2447
|
+
]);
|
|
2448
|
+
const ACTIVITY_CSV_HEADERS = Object.freeze([
|
|
2449
|
+
"Time",
|
|
2450
|
+
"Action",
|
|
2451
|
+
"Admin",
|
|
2452
|
+
"Admin ID",
|
|
2453
|
+
"Content Type",
|
|
2454
|
+
"Content Type UID",
|
|
2455
|
+
"Document ID",
|
|
2456
|
+
"Locale",
|
|
2457
|
+
"Title",
|
|
2458
|
+
"Entries"
|
|
2459
|
+
]);
|
|
2460
|
+
const toCsv = (headers, rows) => [headers, ...rows].map((cells) => cells.map(escapeCsvValue).join(",")).join("\n");
|
|
2461
|
+
function buildSignInCsv(rows) {
|
|
2462
|
+
return toCsv(
|
|
2463
|
+
SIGN_IN_CSV_HEADERS,
|
|
2464
|
+
rows.map((row) => [
|
|
2465
|
+
row.at || "",
|
|
2466
|
+
row.event || "",
|
|
2467
|
+
row.reason || row.scope || "",
|
|
2468
|
+
row.admin?.name || "",
|
|
2469
|
+
row.admin?.id ?? "",
|
|
2470
|
+
row.ipAddress || "",
|
|
2471
|
+
row.ipAnonymized ? "yes" : "no",
|
|
2472
|
+
row.location?.country || "",
|
|
2473
|
+
row.location?.city || "",
|
|
2474
|
+
row.browser || "",
|
|
2475
|
+
row.os || "",
|
|
2476
|
+
row.deviceType || "",
|
|
2477
|
+
row.session?.state || "",
|
|
2478
|
+
row.actor?.name || ""
|
|
2479
|
+
])
|
|
2480
|
+
);
|
|
2481
|
+
}
|
|
2482
|
+
function buildActivityCsv(rows) {
|
|
2483
|
+
return toCsv(
|
|
2484
|
+
ACTIVITY_CSV_HEADERS,
|
|
2485
|
+
rows.map((row) => [
|
|
2486
|
+
row.at || "",
|
|
2487
|
+
row.action || "",
|
|
2488
|
+
row.admin?.name || "",
|
|
2489
|
+
row.admin?.id ?? "",
|
|
2490
|
+
row.contentType?.name || "",
|
|
2491
|
+
row.contentType?.uid || "",
|
|
2492
|
+
row.entry?.documentId || "",
|
|
2493
|
+
row.entry?.locale || "",
|
|
2494
|
+
row.entry?.title || "",
|
|
2495
|
+
row.entry?.count ?? ""
|
|
2496
|
+
])
|
|
2497
|
+
);
|
|
2498
|
+
}
|
|
2499
|
+
const pluginId = "magic-sessionmanager";
|
|
2500
|
+
const USER_ACTIVITY_FILTER_OPTIONS = Object.freeze([
|
|
2501
|
+
"all",
|
|
2502
|
+
"failed",
|
|
2503
|
+
"lockouts",
|
|
2504
|
+
"suspicious",
|
|
2505
|
+
"sessions",
|
|
2506
|
+
"privacy",
|
|
2507
|
+
"impersonation"
|
|
2508
|
+
]);
|
|
2509
|
+
const USER_ACTIVITY_FILTER_LABELS = Object.freeze({
|
|
2510
|
+
all: ["userActivity.filter.all", "All events"],
|
|
2511
|
+
failed: ["userActivity.filter.failed", "Failed and refused sign-ins"],
|
|
2512
|
+
lockouts: ["userActivity.filter.lockouts", "Lockouts and unlocks"],
|
|
2513
|
+
suspicious: [
|
|
2514
|
+
"userActivity.filter.suspicious",
|
|
2515
|
+
"New devices, impossible travel, “This wasn’t me”"
|
|
2516
|
+
],
|
|
2517
|
+
sessions: ["userActivity.filter.sessions", "Session limit and password change"],
|
|
2518
|
+
privacy: ["userActivity.filter.privacy", "Personal data exports"],
|
|
2519
|
+
impersonation: ["userActivity.filter.impersonation", "Impersonation"]
|
|
2520
|
+
});
|
|
2521
|
+
const USER_ACTIVITY_API_PATH = `/${pluginId}/user-activity`;
|
|
2522
|
+
const USER_ACTIVITY_PAGE_PATH = `/plugins/${pluginId}/app-users/activity`;
|
|
2523
|
+
const USER_ACTIVITY_SETTINGS_PATH = `/settings/${pluginId}/general?tab=login-protection`;
|
|
2524
|
+
const RECENT_USER_EVENT_LIMIT = 8;
|
|
2525
|
+
const PANEL_USER_EVENT_LIMIT = 3;
|
|
2526
|
+
const USER_UID = "plugin::users-permissions.user";
|
|
2527
|
+
const DOCUMENT_ID = /^[A-Za-z0-9]{1,64}$/;
|
|
2528
|
+
function userActivityPagePath(userId) {
|
|
2529
|
+
return typeof userId === "string" && DOCUMENT_ID.test(userId) ? `${USER_ACTIVITY_PAGE_PATH}?userId=${encodeURIComponent(userId)}` : USER_ACTIVITY_PAGE_PATH;
|
|
2530
|
+
}
|
|
2531
|
+
function getUserEntryPath(user) {
|
|
2532
|
+
if (!user || typeof user.documentId !== "string" || !DOCUMENT_ID.test(user.documentId)) {
|
|
2533
|
+
return null;
|
|
2534
|
+
}
|
|
2535
|
+
return `/content-manager/collection-types/${USER_UID}/${encodeURIComponent(user.documentId)}`;
|
|
2536
|
+
}
|
|
2537
|
+
function buildUserActivityParams(filters, now) {
|
|
2538
|
+
const params = {
|
|
2539
|
+
page: filters.page || 1,
|
|
2540
|
+
pageSize: filters.pageSize || EVENT_PAGE_SIZE,
|
|
2541
|
+
event: USER_ACTIVITY_FILTER_OPTIONS.includes(filters.event) ? filters.event : "all"
|
|
2542
|
+
};
|
|
2543
|
+
if (typeof filters.userId === "string" && DOCUMENT_ID.test(filters.userId)) {
|
|
2544
|
+
params.userId = filters.userId;
|
|
2545
|
+
}
|
|
2546
|
+
const from = periodStart(filters.period || "all", now);
|
|
2547
|
+
if (from) params.from = from;
|
|
2548
|
+
return params;
|
|
2549
|
+
}
|
|
2550
|
+
function parseUserActivityQuery(query) {
|
|
2551
|
+
const source = query || {};
|
|
2552
|
+
const event = USER_ACTIVITY_FILTER_OPTIONS.includes(String(source.event)) ? String(source.event) : "all";
|
|
2553
|
+
const period = PERIOD_OPTIONS.includes(String(source.period)) ? String(source.period) : "30";
|
|
2554
|
+
const userId = DOCUMENT_ID.test(String(source.userId ?? "")) ? String(source.userId) : null;
|
|
2555
|
+
const page = Number.parseInt(String(source.page ?? ""), 10);
|
|
2556
|
+
const pageSize = String(source.pageSize ?? "");
|
|
2557
|
+
return {
|
|
2558
|
+
event,
|
|
2559
|
+
period,
|
|
2560
|
+
userId,
|
|
2561
|
+
page: Number.isInteger(page) && page > 0 ? page : 1,
|
|
2562
|
+
pageSize: ACTIVITY_PAGE_SIZE_OPTIONS.includes(pageSize) ? Number(pageSize) : EVENT_PAGE_SIZE
|
|
2563
|
+
};
|
|
2564
|
+
}
|
|
2565
|
+
function hasUserActivityFilters(view) {
|
|
2566
|
+
return view.event !== "all" || view.period !== "30" || view.userId !== null;
|
|
2567
|
+
}
|
|
2568
|
+
const message = (messageId, defaultMessage, values) => ({
|
|
2569
|
+
messageId,
|
|
2570
|
+
defaultMessage,
|
|
2571
|
+
...values ? { values } : {}
|
|
2572
|
+
});
|
|
2573
|
+
const REFUSAL_REASONS = Object.freeze({
|
|
2574
|
+
lockout: message("userActivity.detail.refused.lockout", "The account or IP address was locked"),
|
|
2575
|
+
"too-many-attempts": message(
|
|
2576
|
+
"userActivity.detail.refused.tooMany",
|
|
2577
|
+
"Too many sign-ins at the same time"
|
|
2578
|
+
),
|
|
2579
|
+
country: message("userActivity.detail.refused.country", "Sign-ins from this country are blocked"),
|
|
2580
|
+
risk: message("userActivity.detail.refused.risk", "Risky address (VPN, proxy or Tor)"),
|
|
2581
|
+
"location-unavailable": message(
|
|
2582
|
+
"userActivity.detail.refused.location",
|
|
2583
|
+
"The location could not be checked"
|
|
2584
|
+
)
|
|
2585
|
+
});
|
|
2586
|
+
const IMPERSONATION_REFUSALS = Object.freeze({
|
|
2587
|
+
disabled: message("userActivity.detail.impersonation.disabled", "Impersonation is turned off"),
|
|
2588
|
+
blocked: message("userActivity.detail.impersonation.blocked", "The account is blocked"),
|
|
2589
|
+
"already-active": message(
|
|
2590
|
+
"userActivity.detail.impersonation.alreadyActive",
|
|
2591
|
+
"Someone is already impersonating this user"
|
|
2592
|
+
),
|
|
2593
|
+
"api-token": message(
|
|
2594
|
+
"userActivity.detail.impersonation.apiToken",
|
|
2595
|
+
"Admin API tokens cannot impersonate"
|
|
2596
|
+
),
|
|
2597
|
+
"call-credentials": message(
|
|
2598
|
+
"userActivity.detail.impersonation.callCredentials",
|
|
2599
|
+
"A sign-in, password or email request was blocked"
|
|
2600
|
+
),
|
|
2601
|
+
"call-account": message(
|
|
2602
|
+
"userActivity.detail.impersonation.callAccount",
|
|
2603
|
+
"A data export or “This wasn’t me” request was blocked"
|
|
2604
|
+
),
|
|
2605
|
+
"call-sessions": message(
|
|
2606
|
+
"userActivity.detail.impersonation.callSessions",
|
|
2607
|
+
"A request to end sessions was blocked"
|
|
2608
|
+
),
|
|
2609
|
+
// 4.22.1: every GraphQL mutation is refused while impersonating.
|
|
2610
|
+
"call-mutation": message(
|
|
2611
|
+
"userActivity.detail.impersonation.callMutation",
|
|
2612
|
+
"A GraphQL mutation was blocked"
|
|
2613
|
+
)
|
|
2614
|
+
});
|
|
2615
|
+
const UNKNOWN_ACCOUNT = message(
|
|
2616
|
+
"userActivity.detail.unknownAccount",
|
|
2617
|
+
"No account with this email or username"
|
|
2618
|
+
);
|
|
2619
|
+
function getUserEventDetail(row) {
|
|
2620
|
+
const d = row?.details || {};
|
|
2621
|
+
const parts = [];
|
|
2622
|
+
switch (row?.event) {
|
|
2623
|
+
case "user.sign-in.failed":
|
|
2624
|
+
if (d.unknownAccount) parts.push(UNKNOWN_ACCOUNT);
|
|
2625
|
+
break;
|
|
2626
|
+
case "user.sign-in.refused":
|
|
2627
|
+
if (d.reason === "session-limit") {
|
|
2628
|
+
parts.push(
|
|
2629
|
+
Number.isInteger(d.limit) ? message(
|
|
2630
|
+
"userActivity.detail.refused.limit",
|
|
2631
|
+
"Session limit of {limit, number} reached",
|
|
2632
|
+
{ limit: d.limit }
|
|
2633
|
+
) : message("userActivity.detail.refused.limitReached", "Session limit reached")
|
|
2634
|
+
);
|
|
2635
|
+
} else if (REFUSAL_REASONS[d.reason]) parts.push(REFUSAL_REASONS[d.reason]);
|
|
2636
|
+
if (d.unknownAccount) parts.push(UNKNOWN_ACCOUNT);
|
|
2637
|
+
break;
|
|
2638
|
+
case "user.lockout":
|
|
2639
|
+
if (Number.isInteger(d.minutes) && Number.isInteger(d.failures)) {
|
|
2640
|
+
parts.push(
|
|
2641
|
+
d.kind === "ip" ? message(
|
|
2642
|
+
"userActivity.detail.lockout.ip",
|
|
2643
|
+
"IP address locked for {minutes, plural, one {# minute} other {# minutes}} after {failures, plural, one {# failed sign-in} other {# failed sign-ins}}",
|
|
2644
|
+
{ minutes: d.minutes, failures: d.failures }
|
|
2645
|
+
) : message(
|
|
2646
|
+
"userActivity.detail.lockout.account",
|
|
2647
|
+
"Account locked for {minutes, plural, one {# minute} other {# minutes}} after {failures, plural, one {# failed sign-in} other {# failed sign-ins}}",
|
|
2648
|
+
{ minutes: d.minutes, failures: d.failures }
|
|
2649
|
+
)
|
|
2650
|
+
);
|
|
2651
|
+
}
|
|
2652
|
+
break;
|
|
2653
|
+
case "user.lockout.lifted":
|
|
2654
|
+
parts.push(
|
|
2655
|
+
d.kind === "ip" ? message("userActivity.detail.unlock.ip", "An admin unlocked an IP address") : message("userActivity.detail.unlock.account", "An admin unlocked the account")
|
|
2656
|
+
);
|
|
2657
|
+
break;
|
|
2658
|
+
case "user.session.limit":
|
|
2659
|
+
if (Number.isInteger(d.ended)) {
|
|
2660
|
+
parts.push(
|
|
2661
|
+
Number.isInteger(d.limit) ? message(
|
|
2662
|
+
"userActivity.detail.limit.ended",
|
|
2663
|
+
"{ended, plural, one {# older session} other {# older sessions}} ended to stay within {limit, number}",
|
|
2664
|
+
{ ended: d.ended, limit: d.limit }
|
|
2665
|
+
) : message(
|
|
2666
|
+
"userActivity.detail.limit.endedOnly",
|
|
2667
|
+
"{ended, plural, one {# older session} other {# older sessions}} ended",
|
|
2668
|
+
{ ended: d.ended }
|
|
2669
|
+
)
|
|
2670
|
+
);
|
|
2671
|
+
}
|
|
2672
|
+
break;
|
|
2673
|
+
case "user.password-change.ended-others":
|
|
2674
|
+
if (Number.isInteger(d.ended)) {
|
|
2675
|
+
parts.push(
|
|
2676
|
+
message(
|
|
2677
|
+
"userActivity.detail.password.ended",
|
|
2678
|
+
"{ended, plural, =0 {No other session was open} one {# other session ended} other {# other sessions ended}}",
|
|
2679
|
+
{ ended: d.ended }
|
|
2680
|
+
)
|
|
2681
|
+
);
|
|
2682
|
+
}
|
|
2683
|
+
break;
|
|
2684
|
+
case "user.sign-in.impossible-travel":
|
|
2685
|
+
if (Number.isInteger(d.distanceKm) && Number.isInteger(d.speedKmh)) {
|
|
2686
|
+
parts.push(
|
|
2687
|
+
message(
|
|
2688
|
+
"userActivity.detail.travel.distance",
|
|
2689
|
+
"{distance, number} km from the last sign-in, {speed, number} km/h",
|
|
2690
|
+
{ distance: d.distanceKm, speed: d.speedKmh }
|
|
2691
|
+
)
|
|
2692
|
+
);
|
|
2693
|
+
}
|
|
2694
|
+
if (d.from && d.to) {
|
|
2695
|
+
parts.push(
|
|
2696
|
+
message("userActivity.detail.travel.countries", "{from} to {to}", {
|
|
2697
|
+
from: d.from,
|
|
2698
|
+
to: d.to
|
|
2699
|
+
})
|
|
2700
|
+
);
|
|
2701
|
+
}
|
|
2702
|
+
if (d.action === "reauthenticate") {
|
|
2703
|
+
parts.push(
|
|
2704
|
+
message(
|
|
2705
|
+
"userActivity.detail.travel.reauthenticate",
|
|
2706
|
+
"All sessions ended, a new sign-in was required"
|
|
2707
|
+
)
|
|
2708
|
+
);
|
|
2709
|
+
}
|
|
2710
|
+
break;
|
|
2711
|
+
case "user.not-me":
|
|
2712
|
+
parts.push(
|
|
2713
|
+
d.scope === "all" ? message("userActivity.detail.notMe.all", "The user ended all their sessions") : message("userActivity.detail.notMe.session", "The user ended that session")
|
|
2714
|
+
);
|
|
2715
|
+
break;
|
|
2716
|
+
case "user.data.exported":
|
|
2717
|
+
if (Number.isInteger(d.sessions) && Number.isInteger(d.events)) {
|
|
2718
|
+
parts.push(
|
|
2719
|
+
message(
|
|
2720
|
+
"userActivity.detail.export.counts",
|
|
2721
|
+
"The user downloaded {count, plural, one {# session} other {# sessions}} and {events, plural, one {# security event} other {# security events}}",
|
|
2722
|
+
{ count: d.sessions, events: d.events }
|
|
2723
|
+
)
|
|
2724
|
+
);
|
|
2725
|
+
}
|
|
2726
|
+
break;
|
|
2727
|
+
case "impersonation.started":
|
|
2728
|
+
if (Number.isInteger(d.durationMinutes)) {
|
|
2729
|
+
parts.push(
|
|
2730
|
+
message(
|
|
2731
|
+
"userActivity.detail.impersonation.duration",
|
|
2732
|
+
"For {minutes, plural, one {# minute} other {# minutes}}",
|
|
2733
|
+
{ minutes: d.durationMinutes }
|
|
2734
|
+
)
|
|
2735
|
+
);
|
|
2736
|
+
}
|
|
2737
|
+
break;
|
|
2738
|
+
case "impersonation.ended":
|
|
2739
|
+
if (d.endReason === "disabled") {
|
|
2740
|
+
parts.push(
|
|
2741
|
+
message(
|
|
2742
|
+
"userActivity.detail.impersonation.endedDisabled",
|
|
2743
|
+
"Ended because impersonation was turned off"
|
|
2744
|
+
)
|
|
2745
|
+
);
|
|
2746
|
+
} else if (d.endReason === "failed") {
|
|
2747
|
+
parts.push(
|
|
2748
|
+
message("userActivity.detail.impersonation.endedFailed", "Could not be completed")
|
|
2749
|
+
);
|
|
2750
|
+
} else {
|
|
2751
|
+
parts.push(message("userActivity.detail.impersonation.endedByAdmin", "Ended by an admin"));
|
|
2752
|
+
}
|
|
2753
|
+
break;
|
|
2754
|
+
case "impersonation.expired":
|
|
2755
|
+
parts.push(message("userActivity.detail.impersonation.expired", "The time ran out"));
|
|
2756
|
+
break;
|
|
2757
|
+
case "impersonation.refused":
|
|
2758
|
+
if (IMPERSONATION_REFUSALS[d.refusal]) parts.push(IMPERSONATION_REFUSALS[d.refusal]);
|
|
2759
|
+
break;
|
|
2760
|
+
}
|
|
2761
|
+
return parts;
|
|
2762
|
+
}
|
|
2763
|
+
const USER_ACTIVITY_CSV_HEADERS = Object.freeze([
|
|
2764
|
+
"Time",
|
|
2765
|
+
"Event",
|
|
2766
|
+
"Reason",
|
|
2767
|
+
"User",
|
|
2768
|
+
"User ID",
|
|
2769
|
+
"User Document ID",
|
|
2770
|
+
"IP Address",
|
|
2771
|
+
"IP Anonymized",
|
|
2772
|
+
"Country",
|
|
2773
|
+
"City",
|
|
2774
|
+
"Browser",
|
|
2775
|
+
"OS",
|
|
2776
|
+
"Device",
|
|
2777
|
+
"Done By",
|
|
2778
|
+
"Done By Admin ID"
|
|
2779
|
+
]);
|
|
2780
|
+
function buildUserActivityCsv(rows) {
|
|
2781
|
+
const lines = rows.map((row) => {
|
|
2782
|
+
const d = row.details || {};
|
|
2783
|
+
return [
|
|
2784
|
+
row.at || "",
|
|
2785
|
+
row.event || "",
|
|
2786
|
+
d.reason || d.refusal || d.endReason || d.kind || d.scope || "",
|
|
2787
|
+
row.user?.email || row.user?.username || "",
|
|
2788
|
+
row.user?.id ?? "",
|
|
2789
|
+
row.user?.documentId || "",
|
|
2790
|
+
row.ipAddress || "",
|
|
2791
|
+
row.ipAnonymized ? "yes" : "no",
|
|
2792
|
+
row.location?.country || "",
|
|
2793
|
+
row.location?.city || "",
|
|
2794
|
+
row.browser || "",
|
|
2795
|
+
row.os || "",
|
|
2796
|
+
row.deviceType || "",
|
|
2797
|
+
row.actor?.type === "system" ? "system" : row.actor?.name || "",
|
|
2798
|
+
row.actor?.type === "admin" ? row.actor.id ?? "" : ""
|
|
2799
|
+
];
|
|
2800
|
+
});
|
|
2801
|
+
return [USER_ACTIVITY_CSV_HEADERS, ...lines].map((cells) => cells.map(escapeCsvValue).join(",")).join("\n");
|
|
2802
|
+
}
|
|
2803
|
+
const settingsGroupText = (t, group) => {
|
|
2804
|
+
const fields = group.fields.map(
|
|
2805
|
+
(field) => field.label ? t(field.label.messageId, field.label.defaultMessage) : field.key
|
|
2806
|
+
).join(", ");
|
|
2807
|
+
return group.label ? t("adminPanel.activity.settingsGroup", "{tab}: {fields}", {
|
|
2808
|
+
tab: t(group.label.messageId, group.label.defaultMessage),
|
|
2809
|
+
fields
|
|
2810
|
+
}) : fields;
|
|
2811
|
+
};
|
|
2812
|
+
const changedSettingsText = (t, keys, { limit } = {}) => {
|
|
2813
|
+
const groups = groupChangedSettings(keys);
|
|
2814
|
+
const total = groups.reduce((sum, group) => sum + group.fields.length, 0);
|
|
2815
|
+
if (!total) return "";
|
|
2816
|
+
let budget = limit && limit > 0 ? limit : total;
|
|
2817
|
+
const shown = [];
|
|
2818
|
+
for (const group of groups) {
|
|
2819
|
+
if (budget <= 0) break;
|
|
2820
|
+
shown.push({ ...group, fields: group.fields.slice(0, budget) });
|
|
2821
|
+
budget -= Math.min(budget, group.fields.length);
|
|
2822
|
+
}
|
|
2823
|
+
const named = shown.reduce((sum, group) => sum + group.fields.length, 0);
|
|
2824
|
+
const text = shown.map((group) => settingsGroupText(t, group)).join(" · ");
|
|
2825
|
+
return named < total ? t("adminPanel.activity.settingsMore", "{names} and {count, number} more", {
|
|
2826
|
+
names: text,
|
|
2827
|
+
count: total - named
|
|
2828
|
+
}) : text;
|
|
2829
|
+
};
|
|
2830
|
+
const changedSettingsLines = (t, keys) => groupChangedSettings(keys).map((group) => settingsGroupText(t, group));
|
|
2831
|
+
const noAdminText = (t, row) => row?.event === "security-log.retention.purged" || row?.event === "config.encryption-key.weak" ? t("adminPanel.activity.system", "System") : t("adminPanel.activity.unknownAccount", "Unknown account");
|
|
2832
|
+
const deviceText = (t, row) => {
|
|
2833
|
+
if (row.browser && row.os) {
|
|
2834
|
+
return t("adminPanel.activity.browserOnOs", "{browser} on {os}", {
|
|
2835
|
+
browser: row.browser,
|
|
2836
|
+
os: row.os
|
|
2837
|
+
});
|
|
2838
|
+
}
|
|
2839
|
+
return row.browser || row.os || "";
|
|
2840
|
+
};
|
|
2841
|
+
const ipText = (t, row) => {
|
|
2842
|
+
if (!row.ipAddress) return "";
|
|
2843
|
+
return row.ipAnonymized ? t("adminPanel.activity.ipAnonymized", "{ip} (anonymised)", { ip: row.ipAddress }) : row.ipAddress;
|
|
2844
|
+
};
|
|
2845
|
+
const eventDetailText = (t, row, presentation, withActor) => {
|
|
2846
|
+
const parts = [];
|
|
2847
|
+
if (presentation.detail) {
|
|
2848
|
+
parts.push(t(presentation.detail.messageId, presentation.detail.defaultMessage));
|
|
2849
|
+
}
|
|
2850
|
+
if (Number.isInteger(row.attempts) && row.attempts > 1) {
|
|
2851
|
+
parts.push(
|
|
2852
|
+
t(
|
|
2853
|
+
"adminPanel.activity.attempts",
|
|
2854
|
+
"{count, plural, one {# attempt} other {# attempts}} within 5 minutes",
|
|
2855
|
+
{ count: row.attempts }
|
|
2856
|
+
)
|
|
2857
|
+
);
|
|
2858
|
+
}
|
|
2859
|
+
const changed = changedSettingsText(t, row.change?.keys, { limit: 3 });
|
|
2860
|
+
if (changed) parts.push(changed);
|
|
2861
|
+
if (Number.isInteger(row.purge?.count)) {
|
|
2862
|
+
parts.push(
|
|
2863
|
+
Number.isInteger(row.purge?.retentionDays) ? t(
|
|
2864
|
+
"adminPanel.activity.purgedDetail",
|
|
2865
|
+
"{count, plural, one {# event} other {# events}}, older than {days, plural, one {# day} other {# days}}",
|
|
2866
|
+
{ count: row.purge.count, days: row.purge.retentionDays }
|
|
2867
|
+
) : t("adminPanel.activity.purgedCount", "{count, plural, one {# event} other {# events}}", {
|
|
2868
|
+
count: row.purge.count
|
|
2869
|
+
})
|
|
2870
|
+
);
|
|
2871
|
+
}
|
|
2872
|
+
if (withActor && row.actor?.name) {
|
|
2873
|
+
parts.push(t("adminPanel.activity.byAdmin", "by {name}", { name: row.actor.name }));
|
|
2874
|
+
}
|
|
2875
|
+
return parts.join(" · ");
|
|
2876
|
+
};
|
|
2877
|
+
const contentTypeText = (row) => [row.contentType?.name, row.entry?.locale].filter(Boolean).join(" · ");
|
|
2878
|
+
const userEventDetailText = (t, row, withActor = false) => {
|
|
2879
|
+
const parts = getUserEventDetail(row).map(
|
|
2880
|
+
(part) => t(part.messageId, part.defaultMessage, part.values)
|
|
2881
|
+
);
|
|
2882
|
+
if (withActor && row?.actor?.type === "admin" && row.actor.name) {
|
|
2883
|
+
parts.push(t("adminPanel.activity.byAdmin", "by {name}", { name: row.actor.name }));
|
|
2884
|
+
}
|
|
2885
|
+
return parts.join(" · ");
|
|
2886
|
+
};
|
|
2887
|
+
const userText = (t, row) => {
|
|
2888
|
+
const user = row?.user;
|
|
2889
|
+
if (user) {
|
|
2890
|
+
return user.email || user.username || t("userActivity.identity.placeholder", "User #{id}", { id: user.id });
|
|
2891
|
+
}
|
|
2892
|
+
if (row?.target === "ip") return t("userActivity.identity.ipLock", "IP address");
|
|
2893
|
+
return t("adminPanel.activity.unknownAccount", "Unknown account");
|
|
2894
|
+
};
|
|
2895
|
+
const doneByText = (t, row) => {
|
|
2896
|
+
if (row?.actor?.type === "system") return t("userActivity.doneBy.system", "Automatic");
|
|
2897
|
+
if (row?.actor?.type === "admin") {
|
|
2898
|
+
return row.actor.name || t("adminPanel.identity.placeholder", "Admin #{id}", { id: row.actor.id ?? "?" });
|
|
2899
|
+
}
|
|
2900
|
+
return "";
|
|
2901
|
+
};
|
|
2902
|
+
const useT = () => {
|
|
2903
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
2904
|
+
return (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
|
|
2905
|
+
};
|
|
2906
|
+
const SHORT_DATE = Object.freeze({ dateStyle: "medium", timeStyle: "short" });
|
|
2907
|
+
const FULL_DATE = Object.freeze({ dateStyle: "full", timeStyle: "medium" });
|
|
2908
|
+
const EVENT_ICONS = Object.freeze({
|
|
2909
|
+
signIn: icons.CheckCircle,
|
|
2910
|
+
failed: icons.CrossCircle,
|
|
2911
|
+
lockout: icons.Lock,
|
|
2912
|
+
signOut: icons.SignOut,
|
|
2913
|
+
revoked: icons.Shield,
|
|
2914
|
+
settings: icons.Cog,
|
|
2915
|
+
logRead: icons.Key,
|
|
2916
|
+
purged: icons.Trash,
|
|
2917
|
+
refused: icons.CrossCircle,
|
|
2918
|
+
unlock: icons.Lock,
|
|
2919
|
+
limit: icons.Stack,
|
|
2920
|
+
password: icons.Key,
|
|
2921
|
+
device: icons.Monitor,
|
|
2922
|
+
travel: icons.Earth,
|
|
2923
|
+
notMe: icons.WarningCircle,
|
|
2924
|
+
export: icons.Download,
|
|
2925
|
+
impersonation: icons.User,
|
|
2926
|
+
impersonationEnd: icons.Stop,
|
|
2927
|
+
expired: icons.Clock,
|
|
2928
|
+
webhook: icons.Webhooks,
|
|
2929
|
+
other: icons.Information
|
|
2930
|
+
});
|
|
2931
|
+
const ICON_FILL = Object.freeze({
|
|
2932
|
+
success: "success600",
|
|
2933
|
+
danger: "danger600",
|
|
2934
|
+
warning: "warning700",
|
|
2935
|
+
secondary: "secondary600",
|
|
2936
|
+
neutral: "neutral600"
|
|
2937
|
+
});
|
|
2938
|
+
const stopCellKeys = (event) => {
|
|
2939
|
+
if (event.key === "Enter" || event.key === " " || event.key === "Spacebar") {
|
|
2940
|
+
event.stopPropagation();
|
|
2941
|
+
}
|
|
2942
|
+
};
|
|
2943
|
+
const ClickableRow = styled__default.default(designSystem.Tr)`
|
|
2944
|
+
cursor: pointer;
|
|
2945
|
+
`;
|
|
2946
|
+
const WrapCell = styled__default.default(designSystem.Td)`
|
|
2947
|
+
white-space: normal;
|
|
2948
|
+
`;
|
|
2949
|
+
const NoWrap = styled__default.default.span`
|
|
2950
|
+
white-space: nowrap;
|
|
2951
|
+
`;
|
|
2952
|
+
const NameButton = styled__default.default(designSystem.TextButton)`
|
|
2953
|
+
min-height: 3.2rem;
|
|
2954
|
+
text-align: start;
|
|
2955
|
+
`;
|
|
2956
|
+
const StackedList = styled__default.default.ul`
|
|
2957
|
+
margin: 0;
|
|
2958
|
+
padding: 0;
|
|
2959
|
+
list-style: none;
|
|
2960
|
+
border: 1px solid ${({ theme }) => theme.colors.neutral150};
|
|
2961
|
+
border-radius: ${({ theme }) => theme.borderRadius};
|
|
2962
|
+
background: ${({ theme }) => theme.colors.neutral0};
|
|
2963
|
+
min-width: 0;
|
|
2964
|
+
|
|
2965
|
+
& > li + li {
|
|
2966
|
+
border-top: 1px solid ${({ theme }) => theme.colors.neutral150};
|
|
2967
|
+
}
|
|
2968
|
+
`;
|
|
2969
|
+
const StackedItem = styled__default.default.li`
|
|
2970
|
+
cursor: pointer;
|
|
2971
|
+
min-width: 0;
|
|
2972
|
+
`;
|
|
2973
|
+
const BreakAnywhere = styled__default.default(designSystem.Typography)`
|
|
2974
|
+
overflow-wrap: anywhere;
|
|
2975
|
+
`;
|
|
2976
|
+
const getEventBadgeColors = (tone) => tone === "danger" ? { backgroundColor: "danger100", textColor: "danger700" } : getBadgeColors(tone);
|
|
2977
|
+
const EventBadge = ({ presentation, nowrap = false }) => {
|
|
2978
|
+
const t = useT();
|
|
2979
|
+
const Icon = EVENT_ICONS[presentation.icon] || icons.Information;
|
|
2980
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "center", shrink: 0, "data-event-kind": presentation.key, children: [
|
|
2981
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2982
|
+
Icon,
|
|
2983
|
+
{
|
|
2984
|
+
"aria-hidden": "true",
|
|
2985
|
+
focusable: "false",
|
|
2986
|
+
width: "1.6rem",
|
|
2987
|
+
height: "1.6rem",
|
|
2988
|
+
fill: ICON_FILL[presentation.tone] || ICON_FILL.neutral
|
|
2989
|
+
}
|
|
2990
|
+
),
|
|
2991
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { ...getEventBadgeColors(presentation.tone), "data-event-tone": presentation.tone, children: nowrap ? /* @__PURE__ */ jsxRuntime.jsx(NoWrap, { children: t(presentation.label.messageId, presentation.label.defaultMessage) }) : t(presentation.label.messageId, presentation.label.defaultMessage) })
|
|
2992
|
+
] });
|
|
2993
|
+
};
|
|
2994
|
+
const EventTime = ({ value, compact = false }) => {
|
|
2995
|
+
const { formatDate, formatRelativeTime } = useSessionFormatters();
|
|
2996
|
+
const date = toValidDate(value);
|
|
2997
|
+
if (!date) return /* @__PURE__ */ jsxRuntime.jsx(MissingValue, { variant: "omega" });
|
|
2998
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 1, minWidth: 0, children: [
|
|
2999
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3000
|
+
designSystem.Typography,
|
|
3001
|
+
{
|
|
3002
|
+
tag: "time",
|
|
3003
|
+
dateTime: date.toISOString(),
|
|
3004
|
+
variant: compact ? "pi" : "omega",
|
|
3005
|
+
textColor: "neutral800",
|
|
3006
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(NoWrap, { children: formatRelativeTime(date) })
|
|
3007
|
+
}
|
|
3008
|
+
),
|
|
3009
|
+
compact ? null : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: /* @__PURE__ */ jsxRuntime.jsx(NoWrap, { children: formatDate(date, SHORT_DATE) }) })
|
|
3010
|
+
] });
|
|
3011
|
+
};
|
|
3012
|
+
const AdminName = ({ admin, row, onOpenAdmin }) => {
|
|
3013
|
+
const t = useT();
|
|
3014
|
+
if (!admin) {
|
|
3015
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: onOpenAdmin ? "pi" : "omega", textColor: "neutral600", children: noAdminText(t, row) });
|
|
3016
|
+
}
|
|
3017
|
+
if (!onOpenAdmin) {
|
|
3018
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", textColor: "neutral800", children: admin.name });
|
|
3019
|
+
}
|
|
3020
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3021
|
+
NameButton,
|
|
3022
|
+
{
|
|
3023
|
+
onClick: (event) => {
|
|
3024
|
+
event.stopPropagation();
|
|
3025
|
+
onOpenAdmin(admin, event.currentTarget);
|
|
3026
|
+
},
|
|
3027
|
+
onKeyDown: stopCellKeys,
|
|
3028
|
+
"aria-label": t("adminPanel.activity.openAdmin", "Open the details of {name}", {
|
|
3029
|
+
name: admin.name
|
|
3030
|
+
}),
|
|
3031
|
+
children: admin.name
|
|
3032
|
+
}
|
|
3033
|
+
);
|
|
3034
|
+
};
|
|
3035
|
+
const SignInDetails = ({ row }) => {
|
|
3036
|
+
const t = useT();
|
|
3037
|
+
const ip = ipText(t, row);
|
|
3038
|
+
const second = [getEventPlace(row), deviceText(t, row)].filter(Boolean).join(" · ");
|
|
3039
|
+
if (!ip && !second) return /* @__PURE__ */ jsxRuntime.jsx(MissingValue, { variant: "omega" });
|
|
3040
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 1, minWidth: 0, children: [
|
|
3041
|
+
ip ? /* @__PURE__ */ jsxRuntime.jsx(BreakAnywhere, { variant: "omega", textColor: "neutral800", children: ip }) : null,
|
|
3042
|
+
second ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: second }) : null
|
|
3043
|
+
] });
|
|
3044
|
+
};
|
|
3045
|
+
const SessionState = ({ row }) => {
|
|
3046
|
+
const t = useT();
|
|
3047
|
+
const { formatRelativeTime } = useSessionFormatters();
|
|
3048
|
+
const state = getSessionStatePresentation(row.session);
|
|
3049
|
+
if (!state) return /* @__PURE__ */ jsxRuntime.jsx(MissingValue, { variant: "omega" });
|
|
3050
|
+
const endedAt = toValidDate(row.session?.endedAt);
|
|
3051
|
+
const second = [
|
|
3052
|
+
endedAt ? formatRelativeTime(endedAt) : "",
|
|
3053
|
+
row.session?.endedBy?.name ? t("adminPanel.activity.byAdmin", "by {name}", { name: row.session.endedBy.name }) : ""
|
|
3054
|
+
].filter(Boolean).join(" · ");
|
|
3055
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 1, minWidth: 0, children: [
|
|
3056
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3057
|
+
designSystem.Typography,
|
|
3058
|
+
{
|
|
3059
|
+
variant: "omega",
|
|
3060
|
+
fontWeight: state.tone === "success" ? "semiBold" : void 0,
|
|
3061
|
+
textColor: state.tone === "success" ? "success600" : "neutral800",
|
|
3062
|
+
"data-session-state": row.session?.state,
|
|
3063
|
+
children: t(state.label.messageId, state.label.defaultMessage)
|
|
3064
|
+
}
|
|
3065
|
+
),
|
|
3066
|
+
second ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: second }) : null
|
|
3067
|
+
] });
|
|
3068
|
+
};
|
|
3069
|
+
const HeaderCell = ({ children, hidden = false, ...rest }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { ...rest, children: hidden ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { children }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children }) });
|
|
3070
|
+
const DetailsButton = ({ label, onOpen }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
3071
|
+
designSystem.IconButton,
|
|
3072
|
+
{
|
|
3073
|
+
variant: "ghost",
|
|
3074
|
+
label,
|
|
3075
|
+
withTooltip: false,
|
|
3076
|
+
onClick: (event) => {
|
|
3077
|
+
event.stopPropagation();
|
|
3078
|
+
onOpen(event.currentTarget);
|
|
3079
|
+
},
|
|
3080
|
+
onKeyDown: stopCellKeys,
|
|
3081
|
+
"data-event-details": "",
|
|
3082
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.Eye, {})
|
|
3083
|
+
}
|
|
3084
|
+
);
|
|
3085
|
+
const ActivityEntry = ({ row }) => {
|
|
3086
|
+
const t = useT();
|
|
3087
|
+
const path = getEntryPath(row);
|
|
3088
|
+
const name2 = row.entry?.count !== null && row.entry?.count !== void 0 ? t("adminPanel.activity.entries", "{count, plural, one {# entry} other {# entries}}", {
|
|
3089
|
+
count: row.entry.count
|
|
3090
|
+
}) : row.entry?.title || row.entry?.documentId || row.contentType?.name || "";
|
|
3091
|
+
if (!name2) return /* @__PURE__ */ jsxRuntime.jsx(MissingValue, { variant: "omega" });
|
|
3092
|
+
if (!path) {
|
|
3093
|
+
return /* @__PURE__ */ jsxRuntime.jsx(BreakAnywhere, { variant: "omega", textColor: "neutral800", children: name2 });
|
|
3094
|
+
}
|
|
3095
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3096
|
+
TargetLink,
|
|
3097
|
+
{
|
|
3098
|
+
tag: reactRouterDom.Link,
|
|
3099
|
+
to: path,
|
|
3100
|
+
onClick: (event) => event.stopPropagation(),
|
|
3101
|
+
onKeyDown: stopCellKeys,
|
|
3102
|
+
"aria-label": t("adminPanel.activity.openEntry", "Open {entry} in the Content Manager", {
|
|
3103
|
+
entry: name2
|
|
3104
|
+
}),
|
|
3105
|
+
children: name2
|
|
3106
|
+
}
|
|
3107
|
+
);
|
|
3108
|
+
};
|
|
3109
|
+
const EventDetailsModal = ({ title, items, footerAction, onClose, onCloseAutoFocus }) => {
|
|
3110
|
+
const t = useT();
|
|
3111
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Root, { open: true, onOpenChange: (open) => open ? null : onClose(), children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Content, { onCloseAutoFocus, "aria-describedby": void 0, children: [
|
|
3112
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Header, { closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Title, { children: title }) }),
|
|
3113
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { background: "neutral100", hasRadius: true, padding: { initial: 4, medium: 6 }, children: /* @__PURE__ */ jsxRuntime.jsx(PropertyList, { columns: 2, items }) }) }),
|
|
3114
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Footer, { children: [
|
|
3115
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Close, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: t("common.close", "Close") }) }),
|
|
3116
|
+
footerAction || null
|
|
3117
|
+
] })
|
|
3118
|
+
] }) });
|
|
3119
|
+
};
|
|
3120
|
+
const useEventDetails = () => {
|
|
3121
|
+
const [selected, setSelected] = react.useState(null);
|
|
3122
|
+
const [opener, setOpener] = react.useState(null);
|
|
3123
|
+
const [container, setContainer] = react.useState(null);
|
|
3124
|
+
return {
|
|
3125
|
+
selected,
|
|
3126
|
+
setContainer,
|
|
3127
|
+
open: (row, trigger) => {
|
|
3128
|
+
const button = trigger?.matches?.("[data-event-details]") ? trigger : trigger?.querySelector?.("[data-event-details]");
|
|
3129
|
+
setOpener(button || null);
|
|
3130
|
+
setSelected(row);
|
|
3131
|
+
},
|
|
3132
|
+
close: () => setSelected(null),
|
|
3133
|
+
onCloseAutoFocus: (event) => restoreDialogFocus(event, opener, container)
|
|
3134
|
+
};
|
|
3135
|
+
};
|
|
3136
|
+
const signInDetails = (t, formatDate, row) => {
|
|
3137
|
+
const presentation = getEventPresentation(row);
|
|
3138
|
+
const label = t(presentation.label.messageId, presentation.label.defaultMessage);
|
|
3139
|
+
const state = getSessionStatePresentation(row.session);
|
|
3140
|
+
const revoked = presentation.key === "revoked";
|
|
3141
|
+
const adminName = row.admin?.name || noAdminText(t, row);
|
|
3142
|
+
const items = [
|
|
3143
|
+
{
|
|
3144
|
+
id: "event",
|
|
3145
|
+
label: t("adminPanel.activity.column.event", "Event"),
|
|
3146
|
+
render: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 1, children: [
|
|
3147
|
+
/* @__PURE__ */ jsxRuntime.jsx(EventBadge, { presentation }),
|
|
3148
|
+
presentation.detail ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: t(presentation.detail.messageId, presentation.detail.defaultMessage) }) : null
|
|
3149
|
+
] })
|
|
3150
|
+
},
|
|
3151
|
+
{
|
|
3152
|
+
id: "time",
|
|
3153
|
+
label: t("adminPanel.activity.details.exactTime", "Exact time"),
|
|
3154
|
+
value: row.at ? formatDate(row.at, FULL_DATE) : null
|
|
3155
|
+
},
|
|
3156
|
+
{ id: "admin", label: t("adminPanel.activity.column.admin", "Admin"), value: adminName }
|
|
3157
|
+
];
|
|
3158
|
+
if (revoked) {
|
|
3159
|
+
items.push(
|
|
3160
|
+
{
|
|
3161
|
+
id: "actor",
|
|
3162
|
+
label: t("adminPanel.activity.column.doneBy", "Done by"),
|
|
3163
|
+
value: row.actor?.name || null
|
|
3164
|
+
},
|
|
3165
|
+
{
|
|
3166
|
+
id: "scope",
|
|
3167
|
+
label: t("adminPanel.activity.details.signedOutOf", "Signed out of"),
|
|
3168
|
+
value: Number.isInteger(row.sessionsEnded) && row.sessionsEnded >= 0 ? t(
|
|
3169
|
+
"adminPanel.activity.details.scopeCount",
|
|
3170
|
+
"{scope} ({count, plural, =0 {no open session} one {# session ended} other {# sessions ended}})",
|
|
3171
|
+
{
|
|
3172
|
+
scope: t(presentation.detail.messageId, presentation.detail.defaultMessage),
|
|
3173
|
+
count: row.sessionsEnded
|
|
3174
|
+
}
|
|
3175
|
+
) : t(presentation.detail.messageId, presentation.detail.defaultMessage)
|
|
3176
|
+
}
|
|
3177
|
+
);
|
|
3178
|
+
}
|
|
3179
|
+
if (state) {
|
|
3180
|
+
const endedAt = toValidDate(row.session?.endedAt);
|
|
3181
|
+
items.push({
|
|
3182
|
+
id: "session",
|
|
3183
|
+
label: t("adminPanel.activity.column.session", "Session"),
|
|
3184
|
+
value: [
|
|
3185
|
+
t(state.label.messageId, state.label.defaultMessage),
|
|
3186
|
+
endedAt ? formatDate(endedAt, SHORT_DATE) : "",
|
|
3187
|
+
row.session?.endedBy?.name ? t("adminPanel.activity.byAdmin", "by {name}", { name: row.session.endedBy.name }) : ""
|
|
3188
|
+
].filter(Boolean).join(" · ")
|
|
3189
|
+
});
|
|
3190
|
+
}
|
|
3191
|
+
if (row.change) {
|
|
3192
|
+
const lines = changedSettingsLines(t, row.change.keys);
|
|
3193
|
+
items.push({
|
|
3194
|
+
id: "settings",
|
|
3195
|
+
label: t("adminPanel.activity.details.changedSettings", "Changed settings"),
|
|
3196
|
+
...lines.length ? {
|
|
3197
|
+
render: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 1, "data-changed-settings": "", children: lines.map((line) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", textColor: "neutral800", children: line }, line)) })
|
|
3198
|
+
} : { value: null },
|
|
3199
|
+
fullWidth: true
|
|
3200
|
+
});
|
|
3201
|
+
}
|
|
3202
|
+
if (row.purge) {
|
|
3203
|
+
items.push(
|
|
3204
|
+
{
|
|
3205
|
+
id: "purged",
|
|
3206
|
+
label: t("adminPanel.activity.details.deleted", "Deleted events"),
|
|
3207
|
+
value: Number.isInteger(row.purge.count) ? row.purge.count : null
|
|
3208
|
+
},
|
|
3209
|
+
{
|
|
3210
|
+
id: "retention",
|
|
3211
|
+
label: t("adminPanel.activity.details.retention", "Kept for"),
|
|
3212
|
+
value: Number.isInteger(row.purge.retentionDays) ? t("adminPanel.duration.days", "{count, plural, one {# day} other {# days}}", {
|
|
3213
|
+
count: row.purge.retentionDays
|
|
3214
|
+
}) : null
|
|
3215
|
+
}
|
|
3216
|
+
);
|
|
3217
|
+
}
|
|
3218
|
+
if (Number.isInteger(row.attempts) && row.attempts > 1) {
|
|
3219
|
+
items.push({
|
|
3220
|
+
id: "attempts",
|
|
3221
|
+
label: t("adminPanel.activity.details.attempts", "Attempts"),
|
|
3222
|
+
value: row.attempts
|
|
3223
|
+
});
|
|
3224
|
+
}
|
|
3225
|
+
items.push(
|
|
3226
|
+
{
|
|
3227
|
+
id: "ip",
|
|
3228
|
+
label: t("adminPanel.activity.details.ip", "IP address"),
|
|
3229
|
+
value: ipText(t, row) || null,
|
|
3230
|
+
kind: "id"
|
|
3231
|
+
},
|
|
3232
|
+
{
|
|
3233
|
+
id: "place",
|
|
3234
|
+
label: t("adminPanel.activity.details.location", "Location"),
|
|
3235
|
+
value: getEventPlace(row) || null
|
|
3236
|
+
},
|
|
3237
|
+
{
|
|
3238
|
+
id: "browser",
|
|
3239
|
+
label: t("adminPanel.activity.details.browser", "Browser"),
|
|
3240
|
+
value: row.browser || null
|
|
3241
|
+
},
|
|
3242
|
+
{
|
|
3243
|
+
id: "os",
|
|
3244
|
+
label: t("adminPanel.activity.details.os", "Operating system"),
|
|
3245
|
+
value: row.os || null
|
|
3246
|
+
},
|
|
3247
|
+
{
|
|
3248
|
+
id: "userAgent",
|
|
3249
|
+
label: t("adminPanel.activity.details.userAgent", "User agent"),
|
|
3250
|
+
value: row.userAgent || null,
|
|
3251
|
+
kind: "id",
|
|
3252
|
+
fullWidth: true
|
|
3253
|
+
},
|
|
3254
|
+
{
|
|
3255
|
+
id: "eventId",
|
|
3256
|
+
label: t("adminPanel.activity.details.eventId", "Event ID"),
|
|
3257
|
+
value: row.id,
|
|
3258
|
+
kind: "id"
|
|
3259
|
+
}
|
|
3260
|
+
);
|
|
3261
|
+
const title = row.admin?.name ? t("adminPanel.activity.details.title", "{event}: {name}", { event: label, name: adminName }) : label;
|
|
3262
|
+
const logEvent = ["settings", "log-read", "purged"].includes(presentation.key);
|
|
3263
|
+
const deviceFields = /* @__PURE__ */ new Set(["ip", "place", "browser", "os", "userAgent"]);
|
|
3264
|
+
return {
|
|
3265
|
+
title,
|
|
3266
|
+
items: logEvent ? items.filter(
|
|
3267
|
+
(item) => !deviceFields.has(item.id) || item.value !== null && item.value !== ""
|
|
3268
|
+
) : items
|
|
3269
|
+
};
|
|
3270
|
+
};
|
|
3271
|
+
const activityDetails = (t, formatDate, row) => {
|
|
3272
|
+
const label = ACTIVITY_ACTION_LABELS[row.action] || ACTIVITY_ACTION_LABELS.view;
|
|
3273
|
+
const action = t(label.messageId, label.defaultMessage);
|
|
3274
|
+
return {
|
|
3275
|
+
title: row.entry?.title ? t("adminPanel.activity.details.title", "{event}: {name}", {
|
|
3276
|
+
event: action,
|
|
3277
|
+
name: row.entry.title
|
|
3278
|
+
}) : action,
|
|
3279
|
+
items: [
|
|
3280
|
+
{
|
|
3281
|
+
id: "action",
|
|
3282
|
+
label: t("adminPanel.activity.column.action", "Action"),
|
|
3283
|
+
render: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { ...getBadgeColors(getActivityTone(row.action)), children: action })
|
|
3284
|
+
},
|
|
3285
|
+
{
|
|
3286
|
+
id: "time",
|
|
3287
|
+
label: t("adminPanel.activity.details.exactTime", "Exact time"),
|
|
3288
|
+
value: row.at ? formatDate(row.at, FULL_DATE) : null
|
|
3289
|
+
},
|
|
3290
|
+
{
|
|
3291
|
+
id: "entry",
|
|
3292
|
+
label: t("adminPanel.activity.column.entry", "Entry"),
|
|
3293
|
+
render: /* @__PURE__ */ jsxRuntime.jsx(ActivityEntry, { row })
|
|
3294
|
+
},
|
|
3295
|
+
{
|
|
3296
|
+
id: "admin",
|
|
3297
|
+
label: t("adminPanel.activity.column.admin", "Admin"),
|
|
3298
|
+
value: row.admin?.name || null
|
|
3299
|
+
},
|
|
3300
|
+
{
|
|
3301
|
+
id: "type",
|
|
3302
|
+
label: t("adminPanel.activity.column.contentType", "Content type"),
|
|
3303
|
+
value: row.contentType?.name || null
|
|
3304
|
+
},
|
|
3305
|
+
{
|
|
3306
|
+
id: "uid",
|
|
3307
|
+
label: t("adminPanel.activity.details.uid", "Content type UID"),
|
|
3308
|
+
value: row.contentType?.uid || null,
|
|
3309
|
+
kind: "id"
|
|
3310
|
+
},
|
|
3311
|
+
{
|
|
3312
|
+
id: "documentId",
|
|
3313
|
+
label: t("adminPanel.activity.details.documentId", "Document ID"),
|
|
3314
|
+
value: row.entry?.documentId || null,
|
|
3315
|
+
kind: "id"
|
|
3316
|
+
},
|
|
3317
|
+
{
|
|
3318
|
+
id: "locale",
|
|
3319
|
+
label: t("adminPanel.activity.details.locale", "Locale"),
|
|
3320
|
+
value: row.entry?.locale || null
|
|
3321
|
+
},
|
|
3322
|
+
{
|
|
3323
|
+
id: "eventId",
|
|
3324
|
+
label: t("adminPanel.activity.details.eventId", "Event ID"),
|
|
3325
|
+
value: row.id,
|
|
3326
|
+
kind: "id"
|
|
3327
|
+
}
|
|
3328
|
+
]
|
|
3329
|
+
};
|
|
3330
|
+
};
|
|
3331
|
+
const userEventDetails = (t, formatDate, row) => {
|
|
3332
|
+
const presentation = getEventPresentation(row);
|
|
3333
|
+
const label = t(presentation.label.messageId, presentation.label.defaultMessage);
|
|
3334
|
+
const lines = getUserEventDetail(row).map(
|
|
3335
|
+
(part) => t(part.messageId, part.defaultMessage, part.values)
|
|
3336
|
+
);
|
|
3337
|
+
const who = userText(t, row);
|
|
3338
|
+
const doneBy = doneByText(t, row);
|
|
3339
|
+
const items = [
|
|
3340
|
+
{
|
|
3341
|
+
id: "event",
|
|
3342
|
+
label: t("adminPanel.activity.column.event", "Event"),
|
|
3343
|
+
render: /* @__PURE__ */ jsxRuntime.jsx(EventBadge, { presentation })
|
|
3344
|
+
},
|
|
3345
|
+
{
|
|
3346
|
+
id: "time",
|
|
3347
|
+
label: t("adminPanel.activity.details.exactTime", "Exact time"),
|
|
3348
|
+
value: row.at ? formatDate(row.at, FULL_DATE) : null
|
|
3349
|
+
},
|
|
3350
|
+
// Only events with facts get "What happened"; a dash there would say nothing.
|
|
3351
|
+
...lines.length ? [
|
|
3352
|
+
{
|
|
3353
|
+
id: "what",
|
|
3354
|
+
label: t("userActivity.details.what", "What happened"),
|
|
3355
|
+
render: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 1, "data-event-facts": "", children: lines.map((line) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", textColor: "neutral800", children: line }, line)) }),
|
|
3356
|
+
fullWidth: true
|
|
3357
|
+
}
|
|
3358
|
+
] : [],
|
|
3359
|
+
{ id: "user", label: t("userActivity.column.user", "User"), value: who, kind: "id" }
|
|
3360
|
+
];
|
|
3361
|
+
if (doneBy) {
|
|
3362
|
+
items.push({
|
|
3363
|
+
id: "doneBy",
|
|
3364
|
+
label: t("adminPanel.activity.column.doneBy", "Done by"),
|
|
3365
|
+
value: doneBy
|
|
3366
|
+
});
|
|
3367
|
+
}
|
|
3368
|
+
if (row.details?.reason && presentation.key.startsWith("impersonation")) {
|
|
3369
|
+
items.push({
|
|
3370
|
+
id: "reasonGiven",
|
|
3371
|
+
label: t("userActivity.details.reasonGiven", "Reason given"),
|
|
3372
|
+
value: row.details.reason,
|
|
3373
|
+
fullWidth: true
|
|
3374
|
+
});
|
|
3375
|
+
}
|
|
3376
|
+
items.push(
|
|
3377
|
+
{
|
|
3378
|
+
id: "ip",
|
|
3379
|
+
label: t("adminPanel.activity.details.ip", "IP address"),
|
|
3380
|
+
value: ipText(t, row) || null,
|
|
3381
|
+
kind: "id"
|
|
3382
|
+
},
|
|
3383
|
+
{
|
|
3384
|
+
id: "place",
|
|
3385
|
+
label: t("adminPanel.activity.details.location", "Location"),
|
|
3386
|
+
value: getEventPlace(row) || null
|
|
3387
|
+
},
|
|
3388
|
+
{
|
|
3389
|
+
id: "browser",
|
|
3390
|
+
label: t("adminPanel.activity.details.browser", "Browser"),
|
|
3391
|
+
value: row.browser || null
|
|
3392
|
+
},
|
|
3393
|
+
{
|
|
3394
|
+
id: "os",
|
|
3395
|
+
label: t("adminPanel.activity.details.os", "Operating system"),
|
|
3396
|
+
value: row.os || null
|
|
3397
|
+
},
|
|
3398
|
+
{
|
|
3399
|
+
id: "userAgent",
|
|
3400
|
+
label: t("adminPanel.activity.details.userAgent", "User agent"),
|
|
3401
|
+
value: row.userAgent || null,
|
|
3402
|
+
kind: "id",
|
|
3403
|
+
fullWidth: true
|
|
3404
|
+
},
|
|
3405
|
+
{
|
|
3406
|
+
id: "eventId",
|
|
3407
|
+
label: t("adminPanel.activity.details.eventId", "Event ID"),
|
|
3408
|
+
value: row.id,
|
|
3409
|
+
kind: "id"
|
|
3410
|
+
}
|
|
3411
|
+
);
|
|
3412
|
+
const deviceFields = /* @__PURE__ */ new Set(["ip", "place", "browser", "os", "userAgent"]);
|
|
3413
|
+
const byAdmin = row.actor?.type === "admin" || row.actor?.type === "system";
|
|
3414
|
+
return {
|
|
3415
|
+
title: t("adminPanel.activity.details.title", "{event}: {name}", { event: label, name: who }),
|
|
3416
|
+
items: byAdmin ? items.filter(
|
|
3417
|
+
(item) => !deviceFields.has(item.id) || item.value !== null && item.value !== ""
|
|
3418
|
+
) : items
|
|
3419
|
+
};
|
|
3420
|
+
};
|
|
3421
|
+
const EventTable = ({
|
|
3422
|
+
rows,
|
|
3423
|
+
label,
|
|
3424
|
+
wide = false,
|
|
3425
|
+
busy = false,
|
|
3426
|
+
nameOf,
|
|
3427
|
+
badge,
|
|
3428
|
+
columns,
|
|
3429
|
+
stackedSubject,
|
|
3430
|
+
stackedDetail,
|
|
3431
|
+
details,
|
|
3432
|
+
detailsAction,
|
|
3433
|
+
rowKind
|
|
3434
|
+
}) => {
|
|
3435
|
+
const t = useT();
|
|
3436
|
+
const { formatRelativeTime } = useSessionFormatters();
|
|
3437
|
+
const [measureRef, width] = useElementWidth();
|
|
3438
|
+
const {
|
|
3439
|
+
selected,
|
|
3440
|
+
open: openDetails,
|
|
3441
|
+
close: closeDetails,
|
|
3442
|
+
onCloseAutoFocus,
|
|
3443
|
+
setContainer
|
|
3444
|
+
} = useEventDetails();
|
|
3445
|
+
const layout = getEventListLayout(width, { wide });
|
|
3446
|
+
const detailsLabel = (row) => t("adminPanel.activity.details.open", "Details of {event}, {time}", {
|
|
3447
|
+
event: nameOf(row),
|
|
3448
|
+
time: formatRelativeTime(row.at)
|
|
3449
|
+
});
|
|
3450
|
+
const kindOf = (row) => rowKind ? rowKind(row) : void 0;
|
|
3451
|
+
let list;
|
|
3452
|
+
if (layout === "stacked") {
|
|
3453
|
+
list = /* @__PURE__ */ jsxRuntime.jsx(StackedList, { "aria-label": label, "data-event-list": "stacked", children: rows.map((row) => {
|
|
3454
|
+
const subject = stackedSubject ? stackedSubject(row) : null;
|
|
3455
|
+
const detail = stackedDetail ? stackedDetail(row) : "";
|
|
3456
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3457
|
+
StackedItem,
|
|
3458
|
+
{
|
|
3459
|
+
"data-event-row": kindOf(row),
|
|
3460
|
+
"data-event-id": row.id,
|
|
3461
|
+
onClick: (event) => openDetails(row, event.currentTarget),
|
|
3462
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 1, padding: 3, minWidth: 0, children: [
|
|
3463
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, wrap: "wrap", alignItems: "center", minWidth: 0, children: [
|
|
3464
|
+
badge(row),
|
|
3465
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, alignItems: "center", marginLeft: "auto", children: [
|
|
3466
|
+
/* @__PURE__ */ jsxRuntime.jsx(EventTime, { value: row.at, compact: true }),
|
|
3467
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3468
|
+
DetailsButton,
|
|
3469
|
+
{
|
|
3470
|
+
label: detailsLabel(row),
|
|
3471
|
+
onOpen: (trigger) => openDetails(row, trigger)
|
|
3472
|
+
}
|
|
3473
|
+
)
|
|
3474
|
+
] })
|
|
3475
|
+
] }),
|
|
3476
|
+
subject ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { minWidth: 0, children: subject }) : null,
|
|
3477
|
+
detail ? /* @__PURE__ */ jsxRuntime.jsx(BreakAnywhere, { variant: "pi", textColor: "neutral600", children: detail }) : null
|
|
3478
|
+
] })
|
|
3479
|
+
},
|
|
3480
|
+
row.id
|
|
3481
|
+
);
|
|
3482
|
+
}) });
|
|
3483
|
+
} else {
|
|
3484
|
+
const cols = columns(layout);
|
|
3485
|
+
list = /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { background: "neutral0", hasRadius: true, shadow: "tableShadow", "data-event-list": layout, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3486
|
+
designSystem.Table,
|
|
3487
|
+
{
|
|
3488
|
+
colCount: cols.length + 2,
|
|
3489
|
+
rowCount: rows.length + 1,
|
|
3490
|
+
"aria-label": label,
|
|
3491
|
+
"aria-busy": busy,
|
|
3492
|
+
children: [
|
|
3493
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Thead, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
|
|
3494
|
+
/* @__PURE__ */ jsxRuntime.jsx(HeaderCell, { children: t("adminPanel.activity.column.time", "Time") }),
|
|
3495
|
+
cols.map((column) => /* @__PURE__ */ jsxRuntime.jsx(HeaderCell, { children: column.header }, column.id)),
|
|
3496
|
+
/* @__PURE__ */ jsxRuntime.jsx(HeaderCell, { hidden: true, children: t("adminPanel.table.actions", "Actions") })
|
|
3497
|
+
] }) }),
|
|
3498
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: rows.map((row) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3499
|
+
ClickableRow,
|
|
3500
|
+
{
|
|
3501
|
+
"data-event-row": kindOf(row),
|
|
3502
|
+
"data-event-id": row.id,
|
|
3503
|
+
onClick: (event) => openDetails(row, event.currentTarget),
|
|
3504
|
+
children: [
|
|
3505
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(EventTime, { value: row.at }) }),
|
|
3506
|
+
cols.map(
|
|
3507
|
+
(column) => column.wrap === false ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: column.render(row, layout) }, column.id) : /* @__PURE__ */ jsxRuntime.jsx(WrapCell, { children: column.render(row, layout) }, column.id)
|
|
3508
|
+
),
|
|
3509
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { onClick: (event) => event.stopPropagation(), children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "flex-end", gap: 1, onKeyDown: stopCellKeys, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3510
|
+
DetailsButton,
|
|
3511
|
+
{
|
|
3512
|
+
label: detailsLabel(row),
|
|
3513
|
+
onOpen: (trigger) => openDetails(row, trigger)
|
|
3514
|
+
}
|
|
3515
|
+
) }) })
|
|
3516
|
+
]
|
|
3517
|
+
},
|
|
3518
|
+
row.id
|
|
3519
|
+
)) })
|
|
3520
|
+
]
|
|
3521
|
+
}
|
|
3522
|
+
) });
|
|
3523
|
+
}
|
|
3524
|
+
const content = selected ? details(selected) : null;
|
|
3525
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { ref: measureRef, minWidth: 0, width: "100%", children: [
|
|
3526
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { ref: setContainer, tabIndex: -1, minWidth: 0, children: list }),
|
|
3527
|
+
content ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3528
|
+
EventDetailsModal,
|
|
3529
|
+
{
|
|
3530
|
+
title: content.title,
|
|
3531
|
+
items: content.items,
|
|
3532
|
+
footerAction: detailsAction ? detailsAction(selected, closeDetails) : null,
|
|
3533
|
+
onClose: closeDetails,
|
|
3534
|
+
onCloseAutoFocus
|
|
3535
|
+
}
|
|
3536
|
+
) : null
|
|
3537
|
+
] });
|
|
3538
|
+
};
|
|
3539
|
+
const EventCell = ({ presentation, detail }) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 1, minWidth: 0, children: [
|
|
3540
|
+
/* @__PURE__ */ jsxRuntime.jsx(EventBadge, { presentation, nowrap: true }),
|
|
3541
|
+
detail ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: detail }) : null
|
|
3542
|
+
] });
|
|
3543
|
+
const CellText = ({ text, strong = false }) => text ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3544
|
+
BreakAnywhere,
|
|
3545
|
+
{
|
|
3546
|
+
variant: "omega",
|
|
3547
|
+
fontWeight: strong ? "semiBold" : void 0,
|
|
3548
|
+
textColor: "neutral800",
|
|
3549
|
+
children: text
|
|
3550
|
+
}
|
|
3551
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(MissingValue, { variant: "omega" });
|
|
3552
|
+
const SignInEventTable = ({
|
|
3553
|
+
rows,
|
|
3554
|
+
label,
|
|
3555
|
+
showAdmin = false,
|
|
3556
|
+
onOpenAdmin,
|
|
3557
|
+
detailsAction,
|
|
3558
|
+
busy = false
|
|
3559
|
+
}) => {
|
|
3560
|
+
const t = useT();
|
|
3561
|
+
const { formatDate } = useSessionFormatters();
|
|
3562
|
+
const nameOf = (row) => {
|
|
3563
|
+
const presentation = getEventPresentation(row);
|
|
3564
|
+
return t(presentation.label.messageId, presentation.label.defaultMessage);
|
|
3565
|
+
};
|
|
3566
|
+
const adminName = (row) => /* @__PURE__ */ jsxRuntime.jsx(AdminName, { admin: row.admin, row, onOpenAdmin });
|
|
3567
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3568
|
+
EventTable,
|
|
3569
|
+
{
|
|
3570
|
+
rows,
|
|
3571
|
+
label,
|
|
3572
|
+
wide: showAdmin,
|
|
3573
|
+
busy,
|
|
3574
|
+
nameOf,
|
|
3575
|
+
rowKind: (row) => getEventPresentation(row).key,
|
|
3576
|
+
badge: (row) => /* @__PURE__ */ jsxRuntime.jsx(EventBadge, { presentation: getEventPresentation(row) }),
|
|
3577
|
+
columns: (layout) => [
|
|
3578
|
+
{
|
|
3579
|
+
id: "event",
|
|
3580
|
+
header: t("adminPanel.activity.column.event", "Event"),
|
|
3581
|
+
render: (row) => {
|
|
3582
|
+
const presentation = getEventPresentation(row);
|
|
3583
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3584
|
+
EventCell,
|
|
3585
|
+
{
|
|
3586
|
+
presentation,
|
|
3587
|
+
detail: eventDetailText(t, row, presentation, layout !== "full")
|
|
3588
|
+
}
|
|
3589
|
+
);
|
|
3590
|
+
}
|
|
3591
|
+
},
|
|
3592
|
+
...showAdmin ? [
|
|
3593
|
+
{
|
|
3594
|
+
id: "admin",
|
|
3595
|
+
header: t("adminPanel.activity.column.admin", "Admin"),
|
|
3596
|
+
render: adminName
|
|
3597
|
+
}
|
|
3598
|
+
] : [],
|
|
3599
|
+
{
|
|
3600
|
+
id: "details",
|
|
3601
|
+
header: t("adminPanel.activity.column.details", "IP address and device"),
|
|
3602
|
+
render: (row) => /* @__PURE__ */ jsxRuntime.jsx(SignInDetails, { row })
|
|
3603
|
+
},
|
|
3604
|
+
{
|
|
3605
|
+
id: "session",
|
|
3606
|
+
header: t("adminPanel.activity.column.session", "Session"),
|
|
3607
|
+
render: (row) => /* @__PURE__ */ jsxRuntime.jsx(SessionState, { row })
|
|
3608
|
+
},
|
|
3609
|
+
...layout === "full" ? [
|
|
3610
|
+
{
|
|
3611
|
+
id: "doneBy",
|
|
3612
|
+
header: t("adminPanel.activity.column.doneBy", "Done by"),
|
|
3613
|
+
render: (row) => /* @__PURE__ */ jsxRuntime.jsx(CellText, { text: row.actor?.name || "" })
|
|
3614
|
+
}
|
|
3615
|
+
] : []
|
|
3616
|
+
],
|
|
3617
|
+
stackedSubject: showAdmin ? adminName : void 0,
|
|
3618
|
+
stackedDetail: (row) => {
|
|
3619
|
+
const presentation = getEventPresentation(row);
|
|
3620
|
+
const state = getSessionStatePresentation(row.session);
|
|
3621
|
+
return [
|
|
3622
|
+
eventDetailText(t, row, presentation, true),
|
|
3623
|
+
ipText(t, row),
|
|
3624
|
+
getEventPlace(row),
|
|
3625
|
+
deviceText(t, row),
|
|
3626
|
+
state ? t(state.label.messageId, state.label.defaultMessage) : ""
|
|
3627
|
+
].filter(Boolean).join(" · ");
|
|
3628
|
+
},
|
|
3629
|
+
details: (row) => signInDetails(t, formatDate, row),
|
|
3630
|
+
detailsAction
|
|
3631
|
+
}
|
|
3632
|
+
);
|
|
3633
|
+
};
|
|
3634
|
+
const ActivityEventTable = ({ rows, label, showAdmin = false, busy = false }) => {
|
|
3635
|
+
const t = useT();
|
|
3636
|
+
const { formatDate } = useSessionFormatters();
|
|
3637
|
+
const actionOf = (row) => {
|
|
3638
|
+
const entry = ACTIVITY_ACTION_LABELS[row.action] || ACTIVITY_ACTION_LABELS.view;
|
|
3639
|
+
return t(entry.messageId, entry.defaultMessage);
|
|
3640
|
+
};
|
|
3641
|
+
const badge = (row) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
3642
|
+
designSystem.Badge,
|
|
3643
|
+
{
|
|
3644
|
+
...getBadgeColors(getActivityTone(row.action)),
|
|
3645
|
+
"data-event-tone": getActivityTone(row.action),
|
|
3646
|
+
children: actionOf(row)
|
|
3647
|
+
}
|
|
3648
|
+
);
|
|
3649
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3650
|
+
EventTable,
|
|
3651
|
+
{
|
|
3652
|
+
rows,
|
|
3653
|
+
label,
|
|
3654
|
+
wide: showAdmin,
|
|
3655
|
+
busy,
|
|
3656
|
+
nameOf: actionOf,
|
|
3657
|
+
rowKind: (row) => row.action,
|
|
3658
|
+
badge,
|
|
3659
|
+
columns: () => [
|
|
3660
|
+
{
|
|
3661
|
+
id: "action",
|
|
3662
|
+
header: t("adminPanel.activity.column.action", "Action"),
|
|
3663
|
+
render: badge,
|
|
3664
|
+
wrap: false
|
|
3665
|
+
},
|
|
3666
|
+
{
|
|
3667
|
+
id: "entry",
|
|
3668
|
+
header: t("adminPanel.activity.column.entry", "Entry"),
|
|
3669
|
+
render: (row) => /* @__PURE__ */ jsxRuntime.jsx(ActivityEntry, { row })
|
|
3670
|
+
},
|
|
3671
|
+
{
|
|
3672
|
+
id: "type",
|
|
3673
|
+
header: t("adminPanel.activity.column.contentType", "Content type"),
|
|
3674
|
+
render: (row) => /* @__PURE__ */ jsxRuntime.jsx(CellText, { text: contentTypeText(row) })
|
|
3675
|
+
},
|
|
3676
|
+
...showAdmin ? [
|
|
3677
|
+
{
|
|
3678
|
+
id: "admin",
|
|
3679
|
+
header: t("adminPanel.activity.column.admin", "Admin"),
|
|
3680
|
+
render: (row) => /* @__PURE__ */ jsxRuntime.jsx(AdminName, { admin: row.admin })
|
|
3681
|
+
}
|
|
3682
|
+
] : []
|
|
3683
|
+
],
|
|
3684
|
+
stackedSubject: (row) => /* @__PURE__ */ jsxRuntime.jsx(ActivityEntry, { row }),
|
|
3685
|
+
stackedDetail: (row) => [contentTypeText(row), showAdmin ? row.admin?.name : ""].filter(Boolean).join(" · "),
|
|
3686
|
+
details: (row) => activityDetails(t, formatDate, row)
|
|
3687
|
+
}
|
|
3688
|
+
);
|
|
3689
|
+
};
|
|
3690
|
+
const UserEventTable = ({ rows, label, showUser = true, busy = false, detailsAction }) => {
|
|
3691
|
+
const t = useT();
|
|
3692
|
+
const { formatDate } = useSessionFormatters();
|
|
3693
|
+
const nameOf = (row) => {
|
|
3694
|
+
const presentation = getEventPresentation(row);
|
|
3695
|
+
return t(presentation.label.messageId, presentation.label.defaultMessage);
|
|
3696
|
+
};
|
|
3697
|
+
const userCell = (row) => /* @__PURE__ */ jsxRuntime.jsx(CellText, { text: userText(t, row), strong: Boolean(row.user?.email || row.user?.username) });
|
|
3698
|
+
const openUser = (row) => {
|
|
3699
|
+
const path = row.user?.email || row.user?.username ? getUserEntryPath(row.user) : null;
|
|
3700
|
+
return path && showUser ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.LinkButton, { tag: reactRouterDom.Link, to: path, variant: "tertiary", "data-open-user": "", children: t("userActivity.details.openUser", "Open user") }) : null;
|
|
3701
|
+
};
|
|
3702
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3703
|
+
EventTable,
|
|
3704
|
+
{
|
|
3705
|
+
rows,
|
|
3706
|
+
label,
|
|
3707
|
+
wide: showUser,
|
|
3708
|
+
busy,
|
|
3709
|
+
nameOf,
|
|
3710
|
+
rowKind: (row) => getEventPresentation(row).key,
|
|
3711
|
+
badge: (row) => /* @__PURE__ */ jsxRuntime.jsx(EventBadge, { presentation: getEventPresentation(row) }),
|
|
3712
|
+
columns: (layout) => [
|
|
3713
|
+
{
|
|
3714
|
+
id: "event",
|
|
3715
|
+
header: t("adminPanel.activity.column.event", "Event"),
|
|
3716
|
+
render: (row) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
3717
|
+
EventCell,
|
|
3718
|
+
{
|
|
3719
|
+
presentation: getEventPresentation(row),
|
|
3720
|
+
detail: userEventDetailText(t, row, layout !== "full")
|
|
3721
|
+
}
|
|
3722
|
+
)
|
|
3723
|
+
},
|
|
3724
|
+
...showUser ? [{ id: "user", header: t("userActivity.column.user", "User"), render: userCell }] : [],
|
|
3725
|
+
{
|
|
3726
|
+
id: "details",
|
|
3727
|
+
header: t("adminPanel.activity.column.details", "IP address and device"),
|
|
3728
|
+
render: (row) => /* @__PURE__ */ jsxRuntime.jsx(SignInDetails, { row })
|
|
3729
|
+
},
|
|
3730
|
+
...layout === "full" ? [
|
|
3731
|
+
{
|
|
3732
|
+
id: "doneBy",
|
|
3733
|
+
header: t("adminPanel.activity.column.doneBy", "Done by"),
|
|
3734
|
+
render: (row) => /* @__PURE__ */ jsxRuntime.jsx(CellText, { text: doneByText(t, row) })
|
|
3735
|
+
}
|
|
3736
|
+
] : []
|
|
3737
|
+
],
|
|
3738
|
+
stackedSubject: showUser ? userCell : void 0,
|
|
3739
|
+
stackedDetail: (row) => [userEventDetailText(t, row, true), ipText(t, row), getEventPlace(row), deviceText(t, row)].filter(Boolean).join(" · "),
|
|
3740
|
+
details: (row) => userEventDetails(t, formatDate, row),
|
|
3741
|
+
detailsAction: (row, close) => {
|
|
3742
|
+
const open = openUser(row);
|
|
3743
|
+
const extra = detailsAction ? detailsAction(row, close) : null;
|
|
3744
|
+
if (!open && !extra) return null;
|
|
3745
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, wrap: "wrap", children: [
|
|
3746
|
+
open,
|
|
3747
|
+
extra
|
|
3748
|
+
] });
|
|
3749
|
+
}
|
|
3750
|
+
}
|
|
3751
|
+
);
|
|
3752
|
+
};
|
|
3753
|
+
const ADMIN_FILTER_OPTIONS = Object.freeze(["all", "signed-in", "not-signed-in"]);
|
|
3754
|
+
const ADMIN_PAGE_SIZE_OPTIONS = Object.freeze(["10", "25", "50", "100"]);
|
|
3755
|
+
const ADMIN_DEFAULT_PAGE_SIZE = "25";
|
|
3756
|
+
const ADMIN_MAX_SEARCH_LENGTH = 100;
|
|
3757
|
+
function parseAdminPanelQuery(query = {}) {
|
|
3758
|
+
const page = Number.parseInt(String(query?.page ?? ""), 10);
|
|
3759
|
+
const pageSize = String(query?.pageSize ?? "");
|
|
3760
|
+
const filter = String(query?.filter ?? "");
|
|
3761
|
+
let search = "";
|
|
3762
|
+
if (typeof query?.search === "string") {
|
|
3763
|
+
try {
|
|
3764
|
+
search = decodeURIComponent(query.search).trim();
|
|
3765
|
+
} catch {
|
|
3766
|
+
search = query.search.trim();
|
|
3767
|
+
}
|
|
3768
|
+
}
|
|
3769
|
+
return {
|
|
3770
|
+
page: Number.isInteger(page) && page >= 1 && page <= 1e6 ? page : 1,
|
|
3771
|
+
pageSize: Number(
|
|
3772
|
+
ADMIN_PAGE_SIZE_OPTIONS.includes(pageSize) ? pageSize : ADMIN_DEFAULT_PAGE_SIZE
|
|
3773
|
+
),
|
|
3774
|
+
filter: ADMIN_FILTER_OPTIONS.includes(filter) ? filter : "all",
|
|
3775
|
+
search: search.slice(0, ADMIN_MAX_SEARCH_LENGTH)
|
|
3776
|
+
};
|
|
3777
|
+
}
|
|
3778
|
+
function buildAdminListParams(state) {
|
|
3779
|
+
return {
|
|
3780
|
+
page: state.page,
|
|
3781
|
+
pageSize: state.pageSize,
|
|
3782
|
+
filter: state.filter,
|
|
3783
|
+
...state.search ? { search: state.search } : {}
|
|
3784
|
+
};
|
|
3785
|
+
}
|
|
3786
|
+
function hasAdminFilters(state) {
|
|
3787
|
+
return state.filter !== "all" || Boolean(state.search);
|
|
3788
|
+
}
|
|
3789
|
+
function getAdminStatusPresentation(row) {
|
|
3790
|
+
if (row?.account === "invited") {
|
|
3791
|
+
return {
|
|
3792
|
+
key: "invited",
|
|
3793
|
+
tone: "secondary",
|
|
3794
|
+
label: { messageId: "adminPanel.status.invited", defaultMessage: "Invited" },
|
|
3795
|
+
detail: {
|
|
3796
|
+
messageId: "adminPanel.status.invited.detail",
|
|
3797
|
+
defaultMessage: "Invitation not accepted yet"
|
|
3798
|
+
}
|
|
3799
|
+
};
|
|
3800
|
+
}
|
|
3801
|
+
if (row?.account === "deactivated") {
|
|
3802
|
+
return {
|
|
3803
|
+
key: "deactivated",
|
|
3804
|
+
tone: "neutral",
|
|
3805
|
+
label: { messageId: "adminPanel.status.deactivated", defaultMessage: "Deactivated" },
|
|
3806
|
+
detail: {
|
|
3807
|
+
messageId: "adminPanel.status.deactivated.detail",
|
|
3808
|
+
defaultMessage: "Cannot sign in"
|
|
3809
|
+
}
|
|
3810
|
+
};
|
|
3811
|
+
}
|
|
3812
|
+
const count = Number(row?.sessionCount) || 0;
|
|
3813
|
+
if (count > 0) {
|
|
3814
|
+
return {
|
|
3815
|
+
key: "signed-in",
|
|
3816
|
+
tone: "success",
|
|
3817
|
+
label: { messageId: "adminPanel.status.signedIn", defaultMessage: "Signed in" },
|
|
3818
|
+
detail: {
|
|
3819
|
+
messageId: "adminPanel.status.signedIn.detail",
|
|
3820
|
+
defaultMessage: "{count, plural, one {# session} other {# sessions}}",
|
|
3821
|
+
values: { count }
|
|
3822
|
+
}
|
|
3823
|
+
};
|
|
3824
|
+
}
|
|
3825
|
+
return {
|
|
3826
|
+
key: "not-signed-in",
|
|
3827
|
+
tone: "neutral",
|
|
3828
|
+
label: { messageId: "adminPanel.status.notSignedIn", defaultMessage: "Not signed in" },
|
|
3829
|
+
detail: {
|
|
3830
|
+
messageId: "adminPanel.status.notSignedIn.detail",
|
|
3831
|
+
defaultMessage: "No open session"
|
|
3832
|
+
}
|
|
3833
|
+
};
|
|
3834
|
+
}
|
|
3835
|
+
function splitDuration(seconds) {
|
|
3836
|
+
const value = Number(seconds);
|
|
3837
|
+
if (!Number.isFinite(value) || value <= 0) return null;
|
|
3838
|
+
if (value % 86400 === 0) return { unit: "days", count: value / 86400 };
|
|
3839
|
+
if (value % 3600 === 0) return { unit: "hours", count: value / 3600 };
|
|
3840
|
+
return { unit: "minutes", count: Math.max(1, Math.round(value / 60)) };
|
|
3841
|
+
}
|
|
3842
|
+
function getSignOutErrorMessage(error) {
|
|
3843
|
+
const response = (
|
|
3844
|
+
/** @type {any} */
|
|
3845
|
+
error?.response
|
|
3846
|
+
);
|
|
3847
|
+
const status = Number(response?.status ?? /** @type {any} */
|
|
3848
|
+
error?.status);
|
|
3849
|
+
const reason = response?.data?.error?.details?.reason;
|
|
3850
|
+
if (status === 403 && reason === "super-admin-protected") {
|
|
3851
|
+
return {
|
|
3852
|
+
messageId: "adminPanel.signOut.error.protected",
|
|
3853
|
+
defaultMessage: "Only a Super Admin can sign out a Super Admin."
|
|
3854
|
+
};
|
|
3855
|
+
}
|
|
3856
|
+
if (status === 403) {
|
|
3857
|
+
return {
|
|
3858
|
+
messageId: "adminPanel.signOut.error.forbidden",
|
|
3859
|
+
defaultMessage: "You do not have permission to sign admins out."
|
|
3860
|
+
};
|
|
3861
|
+
}
|
|
3862
|
+
if (status === 404) {
|
|
3863
|
+
return {
|
|
3864
|
+
messageId: "adminPanel.signOut.error.gone",
|
|
3865
|
+
defaultMessage: "This session has already ended. The list is up to date now."
|
|
3866
|
+
};
|
|
3867
|
+
}
|
|
3868
|
+
if (status === 429) {
|
|
3869
|
+
return {
|
|
3870
|
+
messageId: "adminPanel.signOut.error.rateLimited",
|
|
3871
|
+
defaultMessage: "Too many sign-outs in a short time. Wait a minute and try again."
|
|
3872
|
+
};
|
|
3873
|
+
}
|
|
3874
|
+
return {
|
|
3875
|
+
messageId: "adminPanel.signOut.error.generic",
|
|
3876
|
+
defaultMessage: "The admin could not be signed out. Try again."
|
|
3877
|
+
};
|
|
3878
|
+
}
|
|
3879
|
+
function withIdentityPlaceholders(admin, placeholderName, identity) {
|
|
3880
|
+
if (!admin || typeof admin !== "object") return admin;
|
|
3881
|
+
const hidden = !admin.self && !admin.name;
|
|
3882
|
+
return {
|
|
3883
|
+
...admin,
|
|
3884
|
+
name: admin.name || placeholderName(admin.id),
|
|
3885
|
+
identityHidden: hidden,
|
|
3886
|
+
rolesHidden: hidden && identity?.roles === false
|
|
3887
|
+
};
|
|
3888
|
+
}
|
|
3889
|
+
function withEventAdminNames(row, placeholderName) {
|
|
3890
|
+
if (!row || typeof row !== "object") return row;
|
|
3891
|
+
const fill = (admin) => admin && typeof admin === "object" && !admin.name && admin.type !== "system" && admin.id !== null && admin.id !== void 0 ? { ...admin, name: placeholderName(admin.id), identityHidden: true } : admin;
|
|
3892
|
+
return {
|
|
3893
|
+
...row,
|
|
3894
|
+
...row.admin !== void 0 ? { admin: fill(row.admin) } : {},
|
|
3895
|
+
...row.actor !== void 0 ? { actor: fill(row.actor) } : {}
|
|
3896
|
+
};
|
|
3897
|
+
}
|
|
3898
|
+
function useEventList({ path, params, logKey }) {
|
|
3899
|
+
const { get } = StrapiAdmin.useFetchClient();
|
|
3900
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
3901
|
+
const fillNames = react.useCallback(
|
|
3902
|
+
(list) => list.map(
|
|
3903
|
+
(row) => withEventAdminNames(
|
|
3904
|
+
row,
|
|
3905
|
+
(id) => formatMessage(
|
|
3906
|
+
{
|
|
3907
|
+
id: getTranslation("adminPanel.identity.placeholder"),
|
|
3908
|
+
defaultMessage: "Admin #{id}"
|
|
3909
|
+
},
|
|
3910
|
+
{ id }
|
|
3911
|
+
)
|
|
3912
|
+
)
|
|
3913
|
+
),
|
|
3914
|
+
[formatMessage]
|
|
3915
|
+
);
|
|
3916
|
+
const [rows, setRows] = react.useState([]);
|
|
3917
|
+
const [meta, setMeta] = react.useState(null);
|
|
3918
|
+
const [page, setPage] = react.useState(1);
|
|
3919
|
+
const [loading, setLoading] = react.useState(true);
|
|
3920
|
+
const [loadingMore, setLoadingMore] = react.useState(false);
|
|
3921
|
+
const [error, setError] = react.useState(false);
|
|
3922
|
+
const requestRef = react.useRef(0);
|
|
3923
|
+
const key = JSON.stringify(params);
|
|
3924
|
+
const firstPage = Number(params?.page) > 0 ? Number(params.page) : 1;
|
|
3925
|
+
const load = react.useCallback(
|
|
3926
|
+
async (nextPage) => {
|
|
3927
|
+
const requestId = requestRef.current + 1;
|
|
3928
|
+
requestRef.current = requestId;
|
|
3929
|
+
if (nextPage === firstPage) setLoading(true);
|
|
3930
|
+
else setLoadingMore(true);
|
|
3931
|
+
try {
|
|
3932
|
+
const response = await get(path, { params: { ...JSON.parse(key), page: nextPage } });
|
|
3933
|
+
if (requestId !== requestRef.current) return;
|
|
3934
|
+
const body = response?.data || {};
|
|
3935
|
+
const data = fillNames(Array.isArray(body.data) ? body.data : []);
|
|
3936
|
+
setRows((current) => nextPage === firstPage ? data : [...current, ...data]);
|
|
3937
|
+
setMeta(body.meta || null);
|
|
3938
|
+
setPage(nextPage);
|
|
3939
|
+
setError(false);
|
|
3940
|
+
} catch (err) {
|
|
3941
|
+
if (requestId !== requestRef.current || isCancelledRequest(err)) return;
|
|
3942
|
+
setError(true);
|
|
3943
|
+
logSafeAdminError(logKey, err);
|
|
3944
|
+
} finally {
|
|
3945
|
+
if (requestId === requestRef.current) {
|
|
3946
|
+
setLoading(false);
|
|
3947
|
+
setLoadingMore(false);
|
|
3948
|
+
}
|
|
3949
|
+
}
|
|
3950
|
+
},
|
|
3951
|
+
[get, path, key, logKey, fillNames, firstPage]
|
|
3952
|
+
);
|
|
3953
|
+
react.useEffect(() => {
|
|
3954
|
+
load(firstPage);
|
|
3955
|
+
return () => {
|
|
3956
|
+
requestRef.current += 1;
|
|
3957
|
+
};
|
|
3958
|
+
}, [load, firstPage]);
|
|
3959
|
+
const pagination = meta?.pagination;
|
|
3960
|
+
const hasMore = Boolean(pagination && page < pagination.pageCount);
|
|
3961
|
+
const exportAll = react.useCallback(async () => {
|
|
3962
|
+
const all = [];
|
|
3963
|
+
let cursor = null;
|
|
3964
|
+
do {
|
|
3965
|
+
const response = await get(`${path}/export`, {
|
|
3966
|
+
params: toExportParams(JSON.parse(key), cursor)
|
|
3967
|
+
});
|
|
3968
|
+
const body = response?.data || {};
|
|
3969
|
+
if (!Array.isArray(body.data)) throw new Error("Invalid export response");
|
|
3970
|
+
all.push(...fillNames(body.data));
|
|
3971
|
+
cursor = typeof body.meta?.nextCursor === "string" ? body.meta.nextCursor : null;
|
|
3972
|
+
} while (cursor && all.length < MAX_EVENT_EXPORT_ROWS);
|
|
3973
|
+
return {
|
|
3974
|
+
rows: all.slice(0, MAX_EVENT_EXPORT_ROWS),
|
|
3975
|
+
capped: all.length > MAX_EVENT_EXPORT_ROWS || Boolean(cursor)
|
|
3976
|
+
};
|
|
3977
|
+
}, [get, path, key, fillNames]);
|
|
3978
|
+
return {
|
|
3979
|
+
rows,
|
|
3980
|
+
meta,
|
|
3981
|
+
loading,
|
|
3982
|
+
loadingMore,
|
|
3983
|
+
error,
|
|
3984
|
+
hasMore,
|
|
3985
|
+
loadMore: () => load(page + 1),
|
|
3986
|
+
reload: () => load(firstPage),
|
|
3987
|
+
exportAll
|
|
3988
|
+
};
|
|
3989
|
+
}
|
|
3990
|
+
function downloadCsv(content, name2) {
|
|
3991
|
+
const blob = new Blob([content], { type: "text/csv;charset=utf-8;" });
|
|
3992
|
+
const url = URL.createObjectURL(blob);
|
|
3993
|
+
const link = document.createElement("a");
|
|
3994
|
+
link.href = url;
|
|
3995
|
+
link.download = `${name2}-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}.csv`;
|
|
3996
|
+
link.click();
|
|
3997
|
+
window.setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
3998
|
+
}
|
|
3999
|
+
const UserActivityList = ({ documentId, userLabel }) => {
|
|
4000
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
4001
|
+
const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
|
|
4002
|
+
const params = react.useMemo(
|
|
4003
|
+
() => buildUserActivityParams({ userId: documentId, pageSize: PANEL_USER_EVENT_LIMIT }),
|
|
4004
|
+
[documentId]
|
|
4005
|
+
);
|
|
4006
|
+
const list = useEventList({ path: USER_ACTIVITY_API_PATH, params, logKey: "userActivity.panel" });
|
|
4007
|
+
const title = t("userActivity.panel.title", "Security activity");
|
|
4008
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-panel-user-activity": "", children: [
|
|
4009
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", tag: "h3", children: title }),
|
|
4010
|
+
list.loading && list.rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { small: true, children: t("adminPanel.activity.loading", "Loading events") }) }) : null,
|
|
4011
|
+
!list.loading && list.error ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4012
|
+
PersistentAlert,
|
|
4013
|
+
{
|
|
4014
|
+
variant: "danger",
|
|
4015
|
+
action: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { size: "S", variant: "secondary", onClick: list.reload, children: t("common.tryAgain", "Try again") }),
|
|
4016
|
+
children: t("adminPanel.activity.error", "The events could not be loaded.")
|
|
4017
|
+
}
|
|
4018
|
+
) : null,
|
|
4019
|
+
!list.loading && !list.error && list.rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 3, background: "neutral0", borderColor: "neutral200", hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsx(ReadableText, { variant: "omega", textColor: "neutral800", tag: "p", children: t("userActivity.panel.empty", "No security events recorded for {user}.", {
|
|
4020
|
+
user: userLabel
|
|
4021
|
+
}) }) }) : null,
|
|
4022
|
+
list.rows.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4023
|
+
UserEventTable,
|
|
4024
|
+
{
|
|
4025
|
+
rows: list.rows,
|
|
4026
|
+
showUser: false,
|
|
4027
|
+
busy: list.loading,
|
|
4028
|
+
label: t("userActivity.panel.listLabel", "Security activity of {user}", {
|
|
4029
|
+
user: userLabel
|
|
4030
|
+
})
|
|
4031
|
+
}
|
|
4032
|
+
) : null,
|
|
4033
|
+
/* @__PURE__ */ jsxRuntime.jsx(TargetLink, { tag: reactRouterDom.NavLink, to: userActivityPagePath(documentId), "data-user-activity-link": "", children: t("userActivity.panel.showAll", "Show all security activity") })
|
|
4034
|
+
] });
|
|
4035
|
+
};
|
|
4036
|
+
const UserActivityPanelSection = ({ documentId, userLabel }) => {
|
|
4037
|
+
const {
|
|
4038
|
+
allowedActions: { canRead },
|
|
4039
|
+
isLoading
|
|
4040
|
+
} = StrapiAdmin.useRBAC(pluginPermissions.userActivityRead);
|
|
4041
|
+
if (isLoading || !canRead || !documentId) return null;
|
|
4042
|
+
return /* @__PURE__ */ jsxRuntime.jsx(UserActivityList, { documentId, userLabel });
|
|
4043
|
+
};
|
|
4044
|
+
function requireSessionList(payload) {
|
|
4045
|
+
if (!Array.isArray(payload?.data)) throw new Error("Invalid session response");
|
|
4046
|
+
return payload.data;
|
|
4047
|
+
}
|
|
4048
|
+
function requireSuccessfulMutation(payload) {
|
|
4049
|
+
if (payload?.success !== true) throw new Error("Invalid mutation response");
|
|
4050
|
+
return payload;
|
|
4051
|
+
}
|
|
4052
|
+
const DEFAULT_SESSION_FILTER = "all";
|
|
4053
|
+
const SESSION_FILTER_OPTIONS = Object.freeze(["all", "open", "active", "idle", "ended"]);
|
|
4054
|
+
const DEFAULT_END_REASON_FILTER = "all";
|
|
4055
|
+
const END_REASON_FILTER_OPTIONS = Object.freeze(["all", ...SESSION_END_REASONS]);
|
|
4056
|
+
const VALID_SESSION_FILTERS = new Set(SESSION_FILTER_OPTIONS);
|
|
4057
|
+
const VALID_END_REASON_FILTERS = new Set(END_REASON_FILTER_OPTIONS);
|
|
4058
|
+
function isSessionFilter(value) {
|
|
4059
|
+
return typeof value === "string" && VALID_SESSION_FILTERS.has(value);
|
|
4060
|
+
}
|
|
4061
|
+
function isEndReasonFilter(value) {
|
|
4062
|
+
return typeof value === "string" && VALID_END_REASON_FILTERS.has(value);
|
|
4063
|
+
}
|
|
4064
|
+
function getManageableSessions(sessions) {
|
|
4065
|
+
if (!Array.isArray(sessions)) return [];
|
|
4066
|
+
return sessions.filter((session) => session?.isActive === true);
|
|
4067
|
+
}
|
|
4068
|
+
const USER_MODEL_UID = "plugin::users-permissions.user";
|
|
4069
|
+
const PANEL_SESSION_LIMIT = 5;
|
|
4070
|
+
const DASHBOARD_PATH = "/plugins/magic-sessionmanager";
|
|
4071
|
+
function isUserModel(model) {
|
|
4072
|
+
return model === USER_MODEL_UID;
|
|
4073
|
+
}
|
|
4074
|
+
const getActivity = (session) => toValidDate(session?.lastActive) || toValidDate(session?.loginTime);
|
|
4075
|
+
function getUserSessionSummary(sessions) {
|
|
4076
|
+
const rows = Array.isArray(sessions) ? sessions.filter((row) => row && typeof row === "object") : [];
|
|
4077
|
+
const open = rows.filter((session) => session.isActive === true);
|
|
4078
|
+
const activeCount = open.filter((session) => session.isTrulyActive === true).length;
|
|
4079
|
+
let lastActive = null;
|
|
4080
|
+
for (const session of rows) {
|
|
4081
|
+
const activity = getActivity(session);
|
|
4082
|
+
if (activity && (!lastActive || activity.getTime() > lastActive.getTime()))
|
|
4083
|
+
lastActive = activity;
|
|
4084
|
+
}
|
|
4085
|
+
return { isOnline: activeCount > 0, openCount: open.length, activeCount, lastActive };
|
|
4086
|
+
}
|
|
4087
|
+
function getVisiblePanelSessions(sessions, limit = PANEL_SESSION_LIMIT) {
|
|
4088
|
+
const rows = Array.isArray(sessions) ? [...sessions] : [];
|
|
4089
|
+
rows.sort(
|
|
4090
|
+
(a, b) => (getActivity(b)?.getTime() ?? -Infinity) - (getActivity(a)?.getTime() ?? -Infinity)
|
|
4091
|
+
);
|
|
4092
|
+
return { visible: rows.slice(0, limit), hiddenCount: Math.max(0, rows.length - limit) };
|
|
4093
|
+
}
|
|
4094
|
+
function endOpenSessions(sessions, reason) {
|
|
4095
|
+
if (!Array.isArray(sessions)) return [];
|
|
4096
|
+
return sessions.map(
|
|
4097
|
+
(session) => session?.isActive === true ? { ...session, isActive: false, isTrulyActive: false, terminationReason: reason } : session
|
|
4098
|
+
);
|
|
4099
|
+
}
|
|
4100
|
+
function getPanelUserLabel(user) {
|
|
4101
|
+
return presentText(user?.username) || presentText(user?.email);
|
|
4102
|
+
}
|
|
4103
|
+
function isNotFoundError(error) {
|
|
4104
|
+
if (!error || typeof error !== "object") return false;
|
|
4105
|
+
return error.status === 404 || error.response?.status === 404;
|
|
4106
|
+
}
|
|
4107
|
+
function buildUserSessionsHref(user) {
|
|
4108
|
+
const query = presentText(user?.email) || presentText(user?.username);
|
|
4109
|
+
if (!query) return DASHBOARD_PATH;
|
|
4110
|
+
return `${DASHBOARD_PATH}?${new URLSearchParams({ search: query }).toString()}`;
|
|
4111
|
+
}
|
|
4112
|
+
function planBlockedFormSync({ initialValues, modified, blocked }) {
|
|
4113
|
+
const hasBlockedField = Boolean(initialValues) && typeof initialValues === "object" && Object.prototype.hasOwnProperty.call(initialValues, "blocked");
|
|
4114
|
+
if (!hasBlockedField || typeof blocked !== "boolean") return { mode: "notice" };
|
|
4115
|
+
if (!modified) return { mode: "reset", initialValues: { ...initialValues, blocked } };
|
|
4116
|
+
return { mode: "change", field: "blocked", value: blocked };
|
|
4117
|
+
}
|
|
4118
|
+
function applyBlockedFormSync(plan, form) {
|
|
4119
|
+
try {
|
|
4120
|
+
if (plan.mode === "reset" && typeof form?.resetForm === "function") {
|
|
4121
|
+
form.resetForm(plan.initialValues);
|
|
4122
|
+
return true;
|
|
4123
|
+
}
|
|
4124
|
+
if (plan.mode === "change" && typeof form?.onChange === "function") {
|
|
4125
|
+
form.onChange(plan.field, plan.value);
|
|
4126
|
+
return true;
|
|
4127
|
+
}
|
|
4128
|
+
} catch {
|
|
4129
|
+
return false;
|
|
4130
|
+
}
|
|
4131
|
+
return false;
|
|
4132
|
+
}
|
|
4133
|
+
const FORM_CONSUMER = "MagicSessionManagerPanel";
|
|
4134
|
+
const PanelSessionCard = ({ session, t }) => {
|
|
4135
|
+
const { formatDate, formatRelativeTime, translate } = useSessionFormatters();
|
|
4136
|
+
const device = getDevicePresentation(session);
|
|
4137
|
+
const hasSummary = Boolean(device.browserLabel || device.os);
|
|
4138
|
+
const summary = hasSummary ? device.summary.text ?? translate(device.summary, device.summary.values) : "";
|
|
4139
|
+
const lastActivity = toValidDate(session.lastActive) || toValidDate(session.loginTime);
|
|
4140
|
+
const ipAddress = presentText(session.ipAddress);
|
|
4141
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4142
|
+
designSystem.Box,
|
|
4143
|
+
{
|
|
4144
|
+
tag: "li",
|
|
4145
|
+
padding: 3,
|
|
4146
|
+
background: "neutral0",
|
|
4147
|
+
borderColor: "neutral200",
|
|
4148
|
+
hasRadius: true,
|
|
4149
|
+
minWidth: 0,
|
|
4150
|
+
"data-panel-session": "",
|
|
4151
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, alignItems: "flex-start", minWidth: 0, children: [
|
|
4152
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4153
|
+
designSystem.Flex,
|
|
4154
|
+
{
|
|
4155
|
+
background: "neutral100",
|
|
4156
|
+
color: "neutral700",
|
|
4157
|
+
hasRadius: true,
|
|
4158
|
+
padding: 2,
|
|
4159
|
+
shrink: 0,
|
|
4160
|
+
justifyContent: "center",
|
|
4161
|
+
alignItems: "center",
|
|
4162
|
+
"aria-hidden": true,
|
|
4163
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(DeviceIcon, { icon: device.icon })
|
|
4164
|
+
}
|
|
4165
|
+
),
|
|
4166
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 1, minWidth: 0, flex: "1 1 auto", children: [
|
|
4167
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", gap: 2, wrap: "wrap", children: [
|
|
4168
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", textColor: "neutral800", children: translate(device.deviceTypeMessage) }),
|
|
4169
|
+
/* @__PURE__ */ jsxRuntime.jsx(StatusBadge, { session, size: "S" })
|
|
4170
|
+
] }),
|
|
4171
|
+
summary ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: summary }) : null,
|
|
4172
|
+
ipAddress ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: t("panel.sessions.ip", "IP {ip}", { ip: ipAddress }) }) : null,
|
|
4173
|
+
lastActivity ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", title: formatDate(lastActivity), children: t("panel.sessions.lastActive", "Last active {time}", {
|
|
4174
|
+
time: formatRelativeTime(lastActivity)
|
|
4175
|
+
}) }) : null
|
|
4176
|
+
] })
|
|
4177
|
+
] })
|
|
4178
|
+
}
|
|
4179
|
+
);
|
|
4180
|
+
};
|
|
4181
|
+
const SessionInfoPanel = ({ documentId, model, document: document2 }) => {
|
|
4182
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
4183
|
+
const { formatDate, formatRelativeTime } = useSessionFormatters();
|
|
4184
|
+
const {
|
|
4185
|
+
allowedActions: { canAccess },
|
|
4186
|
+
isLoading: permissionsLoading
|
|
4187
|
+
} = StrapiAdmin.useRBAC(pluginPermissions.access);
|
|
4188
|
+
const [sessions, setSessions] = react.useState([]);
|
|
4189
|
+
const [loading, setLoading] = react.useState(true);
|
|
4190
|
+
const [loadError, setLoadError] = react.useState(false);
|
|
4191
|
+
const [reloadKey, setReloadKey] = react.useState(0);
|
|
4192
|
+
const [isBlocked, setIsBlocked] = react.useState(Boolean(document2?.blocked));
|
|
4193
|
+
const [pendingAction, setPendingAction] = react.useState(null);
|
|
4194
|
+
const [formOutOfSync, setFormOutOfSync] = react.useState(false);
|
|
4195
|
+
const panelRef = react.useRef(null);
|
|
4196
|
+
const blockToggleRef = react.useRef(null);
|
|
4197
|
+
const focusBlockToggle = react.useRef(false);
|
|
4198
|
+
const noOpenSessionsHintId = react.useId();
|
|
4199
|
+
const { get, post: postRequest } = StrapiAdmin.useFetchClient();
|
|
4200
|
+
const { toggleNotification } = StrapiAdmin.useNotification();
|
|
4201
|
+
const formInitialValues = StrapiAdmin.useForm(FORM_CONSUMER, (state) => state.initialValues, false);
|
|
4202
|
+
const formModified = StrapiAdmin.useForm(FORM_CONSUMER, (state) => state.modified, false);
|
|
4203
|
+
const formOnChange = StrapiAdmin.useForm(FORM_CONSUMER, (state) => state.onChange, false);
|
|
4204
|
+
const formResetForm = StrapiAdmin.useForm(FORM_CONSUMER, (state) => state.resetForm, false);
|
|
4205
|
+
const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
|
|
4206
|
+
const userId = document2?.documentId || documentId;
|
|
4207
|
+
const isUserPanel = isUserModel(model);
|
|
4208
|
+
const persistedBlocked = Boolean(document2?.blocked);
|
|
4209
|
+
const userLabel = getPanelUserLabel(document2) || String(userId ?? "");
|
|
4210
|
+
react.useEffect(() => {
|
|
4211
|
+
setIsBlocked(persistedBlocked);
|
|
4212
|
+
setFormOutOfSync(false);
|
|
4213
|
+
}, [persistedBlocked, userId]);
|
|
4214
|
+
react.useEffect(() => {
|
|
4215
|
+
if (!focusBlockToggle.current || pendingAction !== null) return void 0;
|
|
4216
|
+
const expected = isBlocked ? "unblock" : "block";
|
|
4217
|
+
let attempts = 0;
|
|
4218
|
+
let timer;
|
|
4219
|
+
const tryFocus = () => {
|
|
4220
|
+
const button = blockToggleRef.current;
|
|
4221
|
+
if (button?.isConnected && !button.disabled && button.dataset.blockToggle === expected) {
|
|
4222
|
+
focusBlockToggle.current = false;
|
|
4223
|
+
button.focus();
|
|
4224
|
+
return;
|
|
4225
|
+
}
|
|
4226
|
+
attempts += 1;
|
|
4227
|
+
if (attempts < 20) timer = window.setTimeout(tryFocus, 25);
|
|
4228
|
+
else focusBlockToggle.current = false;
|
|
4229
|
+
};
|
|
4230
|
+
timer = window.setTimeout(tryFocus, 0);
|
|
4231
|
+
return () => window.clearTimeout(timer);
|
|
4232
|
+
}, [isBlocked, pendingAction]);
|
|
4233
|
+
react.useEffect(() => {
|
|
4234
|
+
if (model !== "plugin::users-permissions.user" || !userId || permissionsLoading || !canAccess) {
|
|
4235
|
+
setLoading(false);
|
|
4236
|
+
return void 0;
|
|
4237
|
+
}
|
|
4238
|
+
let cancelled = false;
|
|
4239
|
+
const fetchData = async () => {
|
|
4240
|
+
setLoading(true);
|
|
4241
|
+
setLoadError(false);
|
|
4242
|
+
try {
|
|
4243
|
+
const { data } = await get(`/magic-sessionmanager/user/${userId}/sessions`);
|
|
4244
|
+
if (cancelled) return;
|
|
4245
|
+
setSessions(requireSessionList(data));
|
|
4246
|
+
} catch (err) {
|
|
4247
|
+
if (!cancelled) setLoadError(true);
|
|
4248
|
+
logSafeAdminError("userSessions.load", err);
|
|
4249
|
+
} finally {
|
|
4250
|
+
if (!cancelled) setLoading(false);
|
|
4251
|
+
}
|
|
4252
|
+
};
|
|
4253
|
+
fetchData();
|
|
4254
|
+
return () => {
|
|
4255
|
+
cancelled = true;
|
|
4256
|
+
};
|
|
4257
|
+
}, [userId, model, get, reloadKey, canAccess, permissionsLoading]);
|
|
4258
|
+
const handleEndAll = async () => {
|
|
4259
|
+
if (!userId) return;
|
|
4260
|
+
setPendingAction("endAll");
|
|
4261
|
+
try {
|
|
4262
|
+
const response = await postRequest(`/magic-sessionmanager/user/${userId}/terminate-all`);
|
|
4263
|
+
requireSuccessfulMutation(response.data);
|
|
4264
|
+
setSessions((rows) => endOpenSessions(rows, "manual"));
|
|
4265
|
+
toggleNotification({
|
|
4266
|
+
type: "success",
|
|
4267
|
+
message: t("panel.notify.endAllSuccess", "All sessions of {user} ended.", {
|
|
4268
|
+
user: userLabel
|
|
4269
|
+
})
|
|
4270
|
+
});
|
|
4271
|
+
} catch (error) {
|
|
4272
|
+
toggleNotification({
|
|
4273
|
+
type: "danger",
|
|
4274
|
+
message: isNotFoundError(error) ? t("panel.notify.userNotFound", "User not found.") : t("panel.notify.endAllError", "The sessions could not be ended. Please try again.")
|
|
4275
|
+
});
|
|
4276
|
+
logSafeAdminError("userSessions.endAll", error);
|
|
4277
|
+
throw error;
|
|
4278
|
+
} finally {
|
|
4279
|
+
setPendingAction(null);
|
|
4280
|
+
}
|
|
4281
|
+
};
|
|
4282
|
+
const changeBlocked = async (blocked) => {
|
|
4283
|
+
const response = await postRequest(`/magic-sessionmanager/user/${userId}/toggle-block`, {
|
|
4284
|
+
blocked
|
|
4285
|
+
});
|
|
4286
|
+
requireSuccessfulMutation(response.data);
|
|
4287
|
+
const newBlockedStatus = response.data.blocked === true;
|
|
4288
|
+
focusBlockToggle.current = newBlockedStatus !== isBlocked;
|
|
4289
|
+
setIsBlocked(newBlockedStatus);
|
|
4290
|
+
if (newBlockedStatus) setSessions((rows) => endOpenSessions(rows, "blocked"));
|
|
4291
|
+
const plan = planBlockedFormSync({
|
|
4292
|
+
initialValues: formInitialValues,
|
|
4293
|
+
modified: formModified,
|
|
4294
|
+
blocked: newBlockedStatus
|
|
4295
|
+
});
|
|
4296
|
+
const synced = applyBlockedFormSync(plan, { resetForm: formResetForm, onChange: formOnChange });
|
|
4297
|
+
setFormOutOfSync(!synced);
|
|
4298
|
+
return newBlockedStatus;
|
|
4299
|
+
};
|
|
4300
|
+
const handleBlock = async () => {
|
|
4301
|
+
if (!userId) return;
|
|
4302
|
+
setPendingAction("block");
|
|
4303
|
+
try {
|
|
4304
|
+
await changeBlocked(true);
|
|
4305
|
+
toggleNotification({
|
|
4306
|
+
type: "success",
|
|
4307
|
+
message: t("panel.notify.blockSuccess", "{user} is blocked.", { user: userLabel })
|
|
4308
|
+
});
|
|
4309
|
+
} catch (error) {
|
|
4310
|
+
toggleNotification({
|
|
4311
|
+
type: "danger",
|
|
4312
|
+
message: isNotFoundError(error) ? t("panel.notify.userNotFound", "User not found.") : t("panel.notify.blockError", "The user could not be blocked. Please try again.")
|
|
4313
|
+
});
|
|
4314
|
+
logSafeAdminError("userSessions.block", error);
|
|
4315
|
+
throw error;
|
|
4316
|
+
} finally {
|
|
4317
|
+
setPendingAction(null);
|
|
4318
|
+
}
|
|
4319
|
+
};
|
|
4320
|
+
const handleUnblock = async () => {
|
|
4321
|
+
if (!userId) return;
|
|
4322
|
+
setPendingAction("unblock");
|
|
4323
|
+
try {
|
|
4324
|
+
await changeBlocked(false);
|
|
4325
|
+
toggleNotification({
|
|
4326
|
+
type: "success",
|
|
4327
|
+
message: t("panel.notify.unblockSuccess", "{user} can sign in again.", { user: userLabel })
|
|
4328
|
+
});
|
|
4329
|
+
} catch (error) {
|
|
4330
|
+
toggleNotification({
|
|
4331
|
+
type: "danger",
|
|
4332
|
+
message: isNotFoundError(error) ? t("panel.notify.userNotFound", "User not found.") : t("panel.notify.unblockError", "The block could not be removed. Please try again.")
|
|
4333
|
+
});
|
|
4334
|
+
logSafeAdminError("userSessions.unblock", error);
|
|
4335
|
+
} finally {
|
|
4336
|
+
setPendingAction(null);
|
|
4337
|
+
}
|
|
4338
|
+
};
|
|
4339
|
+
if (!isUserPanel) {
|
|
4340
|
+
return null;
|
|
4341
|
+
}
|
|
4342
|
+
if (permissionsLoading || !canAccess) {
|
|
4343
|
+
return null;
|
|
4344
|
+
}
|
|
4345
|
+
const title = t("panel.title", "Sessions");
|
|
4346
|
+
if (!userId) {
|
|
4347
|
+
return {
|
|
4348
|
+
title,
|
|
4349
|
+
content: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { width: "100%", minWidth: 0, children: /* @__PURE__ */ jsxRuntime.jsx(ReadableText, { variant: "omega", textColor: "neutral700", tag: "p", children: t("panel.unsaved.description", "Save this user before you can manage sessions.") }) })
|
|
4350
|
+
};
|
|
4351
|
+
}
|
|
4352
|
+
if (loadError) {
|
|
4353
|
+
return {
|
|
4354
|
+
title,
|
|
4355
|
+
content: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { width: "100%", minWidth: 0, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4356
|
+
PersistentAlert,
|
|
4357
|
+
{
|
|
4358
|
+
variant: "danger",
|
|
4359
|
+
closeLabel: t("common.close", "Close"),
|
|
4360
|
+
action: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { size: "S", variant: "secondary", onClick: () => setReloadKey((key) => key + 1), children: t("common.tryAgain", "Try again") }),
|
|
4361
|
+
children: t("panel.error.message", "Sessions could not be loaded.")
|
|
4362
|
+
}
|
|
4363
|
+
) })
|
|
4364
|
+
};
|
|
4365
|
+
}
|
|
4366
|
+
const openSessions = getManageableSessions(sessions);
|
|
4367
|
+
const summary = getUserSessionSummary(sessions);
|
|
4368
|
+
const { visible, hiddenCount } = getVisiblePanelSessions(openSessions);
|
|
4369
|
+
const actionsDisabled = loading || pendingAction !== null;
|
|
4370
|
+
const hasOpenSessions = summary.openCount > 0;
|
|
4371
|
+
const endAllLabel = t("panel.actions.endAll", "End all sessions");
|
|
4372
|
+
const blockLabel = t("panel.actions.blockUser", "Block user");
|
|
4373
|
+
const unblockLabel = t("panel.actions.unblock", "Unblock user");
|
|
4374
|
+
return {
|
|
4375
|
+
title,
|
|
4376
|
+
content: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4377
|
+
designSystem.Flex,
|
|
4378
|
+
{
|
|
4379
|
+
ref: panelRef,
|
|
4380
|
+
direction: "column",
|
|
4381
|
+
alignItems: "stretch",
|
|
4382
|
+
gap: 4,
|
|
4383
|
+
width: "100%",
|
|
4384
|
+
minWidth: 0,
|
|
4385
|
+
tabIndex: -1,
|
|
4386
|
+
children: [
|
|
4387
|
+
loading ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 2, "data-panel-summary": "", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { small: true, children: t("panel.loading", "Loading sessions") }) }) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 1, "data-panel-summary": "", children: [
|
|
4388
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "center", wrap: "wrap", children: [
|
|
4389
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { variant: summary.isOnline ? "success" : "neutral", size: "M", children: summary.isOnline ? t("panel.status.online", "Online") : t("panel.status.notOnline", "Not online") }),
|
|
4390
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", textColor: "neutral800", children: t(
|
|
4391
|
+
"panel.summary.openCount",
|
|
4392
|
+
"{count, plural, one {# open session} other {# open sessions}}",
|
|
4393
|
+
{ count: summary.openCount }
|
|
4394
|
+
) })
|
|
4395
|
+
] }),
|
|
4396
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: t("panel.summary.openHint", "Active or idle") }),
|
|
4397
|
+
summary.lastActive ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4398
|
+
designSystem.Typography,
|
|
4399
|
+
{
|
|
4400
|
+
variant: "pi",
|
|
4401
|
+
textColor: "neutral600",
|
|
4402
|
+
title: formatDate(summary.lastActive),
|
|
4403
|
+
children: t("panel.sessions.lastActive", "Last active {time}", {
|
|
4404
|
+
time: formatRelativeTime(summary.lastActive)
|
|
4405
|
+
})
|
|
4406
|
+
}
|
|
4407
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: t("panel.summary.noSessions", "No sessions recorded") })
|
|
4408
|
+
] }),
|
|
4409
|
+
isBlocked ? /* @__PURE__ */ jsxRuntime.jsx(PersistentAlert, { variant: "danger", closeLabel: t("common.close", "Close"), children: t("panel.blocked.message", "This account is blocked. The user cannot sign in.") }) : null,
|
|
4410
|
+
formOutOfSync ? /* @__PURE__ */ jsxRuntime.jsx(PersistentAlert, { variant: "warning", closeLabel: t("common.close", "Close"), children: t(
|
|
4411
|
+
"panel.form.reloadNotice",
|
|
4412
|
+
"Reload this page before saving, or the Blocked field will be overwritten."
|
|
4413
|
+
) }) : null,
|
|
4414
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-panel-actions": "", children: [
|
|
4415
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ActionStack, { children: [
|
|
4416
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4417
|
+
ConfirmAction,
|
|
4418
|
+
{
|
|
4419
|
+
title: t("panel.confirm.endAllTitle", "End all sessions of {user}?", {
|
|
4420
|
+
user: userLabel
|
|
4421
|
+
}),
|
|
4422
|
+
body: t(
|
|
4423
|
+
"panel.confirm.endAllBody",
|
|
4424
|
+
"{count, plural, one {# open session ends} other {# open sessions end}} on all devices. {user} can sign in again unless you also block the account.",
|
|
4425
|
+
{ count: summary.openCount, user: userLabel }
|
|
4426
|
+
),
|
|
4427
|
+
confirmLabel: endAllLabel,
|
|
4428
|
+
onConfirm: handleEndAll,
|
|
4429
|
+
fallbackFocusRef: panelRef,
|
|
4430
|
+
disabled: actionsDisabled || !hasOpenSessions,
|
|
4431
|
+
trigger: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4432
|
+
designSystem.Button,
|
|
4433
|
+
{
|
|
4434
|
+
fullWidth: true,
|
|
4435
|
+
size: "S",
|
|
4436
|
+
variant: "danger-light",
|
|
4437
|
+
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.SignOut, { "aria-hidden": true, focusable: false }),
|
|
4438
|
+
loading: pendingAction === "endAll",
|
|
4439
|
+
disabled: actionsDisabled || !hasOpenSessions,
|
|
4440
|
+
"aria-describedby": !loading && !hasOpenSessions ? noOpenSessionsHintId : void 0,
|
|
4441
|
+
type: "button",
|
|
4442
|
+
children: endAllLabel
|
|
4443
|
+
}
|
|
4444
|
+
)
|
|
4445
|
+
}
|
|
4446
|
+
),
|
|
4447
|
+
isBlocked ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4448
|
+
designSystem.Button,
|
|
4449
|
+
{
|
|
4450
|
+
ref: blockToggleRef,
|
|
4451
|
+
"data-block-toggle": "unblock",
|
|
4452
|
+
fullWidth: true,
|
|
4453
|
+
size: "S",
|
|
4454
|
+
variant: "secondary",
|
|
4455
|
+
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.CheckCircle, { "aria-hidden": true, focusable: false }),
|
|
4456
|
+
loading: pendingAction === "unblock",
|
|
4457
|
+
disabled: actionsDisabled,
|
|
4458
|
+
onClick: handleUnblock,
|
|
4459
|
+
type: "button",
|
|
4460
|
+
children: unblockLabel
|
|
4461
|
+
}
|
|
4462
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
4463
|
+
ConfirmAction,
|
|
4464
|
+
{
|
|
4465
|
+
title: t("panel.confirm.blockTitle", "Block {user}?", { user: userLabel }),
|
|
4466
|
+
body: t(
|
|
4467
|
+
"panel.confirm.blockBody",
|
|
4468
|
+
"{user} can no longer sign in, and {count, plural, =0 {no open sessions are affected} one {# open session ends now} other {# open sessions end now}}. You can unblock the account later; ended sessions stay ended.",
|
|
4469
|
+
{ count: summary.openCount, user: userLabel }
|
|
4470
|
+
),
|
|
4471
|
+
confirmLabel: blockLabel,
|
|
4472
|
+
onConfirm: handleBlock,
|
|
4473
|
+
fallbackFocusRef: panelRef,
|
|
4474
|
+
disabled: actionsDisabled,
|
|
4475
|
+
trigger: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4476
|
+
designSystem.Button,
|
|
4477
|
+
{
|
|
4478
|
+
ref: blockToggleRef,
|
|
4479
|
+
"data-block-toggle": "block",
|
|
4480
|
+
fullWidth: true,
|
|
4481
|
+
size: "S",
|
|
4482
|
+
variant: "danger-light",
|
|
4483
|
+
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Lock, { "aria-hidden": true, focusable: false }),
|
|
4484
|
+
loading: pendingAction === "block",
|
|
4485
|
+
disabled: actionsDisabled,
|
|
4486
|
+
type: "button",
|
|
4487
|
+
children: blockLabel
|
|
4488
|
+
}
|
|
4489
|
+
)
|
|
4490
|
+
}
|
|
4491
|
+
)
|
|
4492
|
+
] }),
|
|
4493
|
+
!loading && !hasOpenSessions ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { id: noOpenSessionsHintId, variant: "pi", textColor: "neutral600", children: t("panel.actions.noOpenSessions", "No open sessions") }) : null,
|
|
4494
|
+
/* @__PURE__ */ jsxRuntime.jsx(ReadableText, { variant: "pi", textColor: "neutral600", tag: "p", children: t(
|
|
4495
|
+
"panel.actions.hint",
|
|
4496
|
+
"End all sessions lets the user sign in again. Block user also prevents new sign-ins."
|
|
4497
|
+
) })
|
|
4498
|
+
] }),
|
|
4499
|
+
userId ? /* @__PURE__ */ jsxRuntime.jsx(ImpersonationPanelSection, { documentId: String(userId), userLabel }) : null,
|
|
4500
|
+
loading ? null : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-panel-sessions": "", children: [
|
|
4501
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", tag: "h3", children: t("panel.sessions.openTitle", "Open sessions") }),
|
|
4502
|
+
visible.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4503
|
+
designSystem.Flex,
|
|
4504
|
+
{
|
|
4505
|
+
tag: "ul",
|
|
4506
|
+
direction: "column",
|
|
4507
|
+
alignItems: "stretch",
|
|
4508
|
+
gap: 2,
|
|
4509
|
+
margin: 0,
|
|
4510
|
+
padding: 0,
|
|
4511
|
+
style: { listStyle: "none" },
|
|
4512
|
+
children: visible.map((session) => /* @__PURE__ */ jsxRuntime.jsx(PanelSessionCard, { session, t }, session.id))
|
|
4513
|
+
}
|
|
4514
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 3, background: "neutral0", borderColor: "neutral200", hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsx(ReadableText, { variant: "omega", textColor: "neutral800", tag: "p", children: t(
|
|
4515
|
+
"panel.empty.noOpenSessions",
|
|
4516
|
+
"No open sessions. {user} is not signed in on any device.",
|
|
4517
|
+
{ user: userLabel }
|
|
4518
|
+
) }) }),
|
|
4519
|
+
hiddenCount > 0 ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: t("panel.sessions.more", "{count, plural, other {+# more}}", {
|
|
4520
|
+
count: hiddenCount
|
|
4521
|
+
}) }) : null
|
|
4522
|
+
] }),
|
|
4523
|
+
/* @__PURE__ */ jsxRuntime.jsx(TargetLink, { tag: reactRouterDom.NavLink, to: buildUserSessionsHref(document2), children: t("panel.sessions.showAllLink", "Show all sessions") }),
|
|
4524
|
+
userId ? /* @__PURE__ */ jsxRuntime.jsx(UserActivityPanelSection, { documentId: String(userId), userLabel }) : null
|
|
4525
|
+
]
|
|
4526
|
+
}
|
|
4527
|
+
)
|
|
4528
|
+
};
|
|
4529
|
+
};
|
|
4530
|
+
const prefixPluginTranslations = (data, pluginId2) => {
|
|
4531
|
+
const prefixed = {};
|
|
4532
|
+
Object.keys(data).forEach((key) => {
|
|
4533
|
+
prefixed[`${pluginId2}.${key}`] = data[key];
|
|
4534
|
+
});
|
|
4535
|
+
return prefixed;
|
|
4536
|
+
};
|
|
4537
|
+
const name = pluginPkg.strapi.name;
|
|
4538
|
+
const index = {
|
|
4539
|
+
register(app) {
|
|
4540
|
+
const pluginPermissions$1 = pluginPermissions.access;
|
|
4541
|
+
app.addMenuLink({
|
|
4542
|
+
to: `plugins/${pluginId$1}`,
|
|
4543
|
+
icon: PluginIcon,
|
|
4544
|
+
intlLabel: {
|
|
4545
|
+
id: `${pluginId$1}.plugin.name`,
|
|
4546
|
+
defaultMessage: pluginPkg.strapi.displayName
|
|
4547
|
+
},
|
|
4548
|
+
Component: () => Promise.resolve().then(() => require("./App-DJkJC06E.js")),
|
|
4549
|
+
permissions: pluginPermissions$1
|
|
4550
|
+
});
|
|
4551
|
+
app.addSettingsLink(
|
|
4552
|
+
{
|
|
4553
|
+
id: pluginId$1,
|
|
4554
|
+
intlLabel: { id: `${pluginId$1}.settings.section`, defaultMessage: "Session Manager" }
|
|
4555
|
+
},
|
|
4556
|
+
[
|
|
4557
|
+
{
|
|
4558
|
+
intlLabel: {
|
|
4559
|
+
id: `${pluginId$1}.settings.link.configuration`,
|
|
4560
|
+
defaultMessage: "Configuration"
|
|
4561
|
+
},
|
|
4562
|
+
id: "general",
|
|
4563
|
+
to: `${pluginId$1}/general`,
|
|
4564
|
+
Component: () => Promise.resolve().then(() => require("./Settings--eEiHv_a.js")),
|
|
4565
|
+
permissions: pluginPermissions$1
|
|
4566
|
+
},
|
|
4567
|
+
{
|
|
4568
|
+
intlLabel: {
|
|
4569
|
+
id: `${pluginId$1}.settings.link.analytics`,
|
|
4570
|
+
defaultMessage: "Analytics"
|
|
4571
|
+
},
|
|
4572
|
+
id: "analytics",
|
|
4573
|
+
to: `${pluginId$1}/analytics`,
|
|
4574
|
+
Component: () => Promise.resolve().then(() => require("./Analytics-B7BAjApz.js")),
|
|
4575
|
+
permissions: pluginPermissions$1
|
|
4576
|
+
}
|
|
4577
|
+
]
|
|
4578
|
+
);
|
|
4579
|
+
app.registerPlugin({
|
|
4580
|
+
id: pluginId$1,
|
|
4581
|
+
initializer: Initializer,
|
|
4582
|
+
isReady: true,
|
|
4583
|
+
name
|
|
4584
|
+
});
|
|
4585
|
+
if ("widgets" in app && app.widgets && typeof app.widgets.register === "function") {
|
|
4586
|
+
app.widgets.register({
|
|
4587
|
+
icon: PluginIcon,
|
|
4588
|
+
title: {
|
|
4589
|
+
id: `${pluginId$1}.widget.online-users.title`,
|
|
4590
|
+
defaultMessage: "Online users"
|
|
4591
|
+
},
|
|
4592
|
+
link: {
|
|
4593
|
+
label: {
|
|
4594
|
+
id: `${pluginId$1}.widget.link`,
|
|
4595
|
+
defaultMessage: "Open Session Manager"
|
|
4596
|
+
},
|
|
4597
|
+
href: `/plugins/${pluginId$1}`
|
|
4598
|
+
},
|
|
4599
|
+
component: async () => {
|
|
4600
|
+
const component = await Promise.resolve().then(() => require("./OnlineUsersWidget-CcjNfzzf.js"));
|
|
4601
|
+
return component.default;
|
|
4602
|
+
},
|
|
4603
|
+
id: "online-users-widget",
|
|
4604
|
+
pluginId: pluginId$1,
|
|
4605
|
+
permissions: pluginPermissions$1
|
|
4606
|
+
});
|
|
4607
|
+
}
|
|
4608
|
+
},
|
|
4609
|
+
bootstrap(app) {
|
|
4610
|
+
try {
|
|
4611
|
+
const contentManagerPlugin = app.getPlugin("content-manager");
|
|
4612
|
+
if (contentManagerPlugin?.apis?.addEditViewSidePanel) {
|
|
4613
|
+
contentManagerPlugin.apis.addEditViewSidePanel([SessionInfoPanel]);
|
|
4614
|
+
}
|
|
4615
|
+
} catch (error) {
|
|
4616
|
+
logSafeAdminError("plugin.bootstrap", error);
|
|
4617
|
+
}
|
|
4618
|
+
},
|
|
4619
|
+
async registerTrads({ locales }) {
|
|
4620
|
+
const importedTrads = {
|
|
4621
|
+
en: () => Promise.resolve().then(() => require("./en-B1TN5F62.js")),
|
|
4622
|
+
de: () => Promise.resolve().then(() => require("./de-oBmcAcXj.js")),
|
|
4623
|
+
es: () => Promise.resolve().then(() => require("./es-Bb515J0p.js")),
|
|
4624
|
+
fr: () => Promise.resolve().then(() => require("./fr-yDdwunmg.js")),
|
|
4625
|
+
pt: () => Promise.resolve().then(() => require("./pt-BAB07LY-.js"))
|
|
4626
|
+
};
|
|
4627
|
+
const translatedLanguages = Object.keys(importedTrads).filter((lang) => locales.includes(lang));
|
|
4628
|
+
const translations = await Promise.all(
|
|
4629
|
+
translatedLanguages.map(
|
|
4630
|
+
(language) => importedTrads[language]().then(({ default: data }) => ({
|
|
4631
|
+
data: prefixPluginTranslations(data, pluginId$1),
|
|
4632
|
+
locale: language
|
|
4633
|
+
})).catch(() => ({
|
|
4634
|
+
data: {},
|
|
4635
|
+
locale: language
|
|
4636
|
+
}))
|
|
4637
|
+
)
|
|
4638
|
+
);
|
|
4639
|
+
return Promise.resolve(translations);
|
|
4640
|
+
}
|
|
4641
|
+
};
|
|
4642
|
+
exports.ACTIVITY_ACTION_LABELS = ACTIVITY_ACTION_LABELS;
|
|
4643
|
+
exports.ACTIVITY_ACTION_OPTIONS = ACTIVITY_ACTION_OPTIONS;
|
|
4644
|
+
exports.ACTIVITY_PAGE_SIZE_OPTIONS = ACTIVITY_PAGE_SIZE_OPTIONS;
|
|
4645
|
+
exports.ADMIN_DEFAULT_PAGE_SIZE = ADMIN_DEFAULT_PAGE_SIZE;
|
|
4646
|
+
exports.ADMIN_FILTER_OPTIONS = ADMIN_FILTER_OPTIONS;
|
|
4647
|
+
exports.ADMIN_PAGE_SIZE_OPTIONS = ADMIN_PAGE_SIZE_OPTIONS;
|
|
4648
|
+
exports.ALL_ADMINS_FILTER_OPTIONS = ALL_ADMINS_FILTER_OPTIONS;
|
|
4649
|
+
exports.ActivityEventTable = ActivityEventTable;
|
|
4650
|
+
exports.ConfirmAction = ConfirmAction;
|
|
4651
|
+
exports.DEFAULT_END_REASON_FILTER = DEFAULT_END_REASON_FILTER;
|
|
4652
|
+
exports.DEFAULT_SESSION_FILTER = DEFAULT_SESSION_FILTER;
|
|
4653
|
+
exports.DeviceIcon = DeviceIcon;
|
|
4654
|
+
exports.END_REASON_FILTER_OPTIONS = END_REASON_FILTER_OPTIONS;
|
|
4655
|
+
exports.EVENT_PAGE_SIZE = EVENT_PAGE_SIZE;
|
|
4656
|
+
exports.EqualGrid = EqualGrid;
|
|
4657
|
+
exports.MAX_EVENT_EXPORT_ROWS = MAX_EVENT_EXPORT_ROWS;
|
|
4658
|
+
exports.MissingValue = MissingValue;
|
|
4659
|
+
exports.PERIOD_OPTIONS = PERIOD_OPTIONS;
|
|
4660
|
+
exports.PageShell = PageShell;
|
|
4661
|
+
exports.PersistentAlert = PersistentAlert;
|
|
4662
|
+
exports.PropertyList = PropertyList;
|
|
4663
|
+
exports.REASON_MAX = REASON_MAX;
|
|
4664
|
+
exports.RECENT_EVENT_LIMIT = RECENT_EVENT_LIMIT;
|
|
4665
|
+
exports.RECENT_USER_EVENT_LIMIT = RECENT_USER_EVENT_LIMIT;
|
|
4666
|
+
exports.ReadableParagraphs = ReadableParagraphs;
|
|
4667
|
+
exports.ReadableText = ReadableText;
|
|
4668
|
+
exports.SELECT_PRESETS = SELECT_PRESETS;
|
|
4669
|
+
exports.SESSION_FILTER_OPTIONS = SESSION_FILTER_OPTIONS;
|
|
4670
|
+
exports.SESSION_STATES = SESSION_STATES;
|
|
4671
|
+
exports.SESSION_STATUS_PRESENTATION = SESSION_STATUS_PRESENTATION;
|
|
4672
|
+
exports.SETTINGS_FIELD_LABELS = SETTINGS_FIELD_LABELS;
|
|
4673
|
+
exports.SETTINGS_TAB_LABELS = SETTINGS_TAB_LABELS;
|
|
4674
|
+
exports.SIGN_IN_FILTER_OPTIONS = SIGN_IN_FILTER_OPTIONS;
|
|
4675
|
+
exports.SignInEventTable = SignInEventTable;
|
|
4676
|
+
exports.StatCard = StatCard;
|
|
4677
|
+
exports.StatGrid = StatGrid;
|
|
4678
|
+
exports.StatusBadge = StatusBadge;
|
|
4679
|
+
exports.USER_ACTIVITY_API_PATH = USER_ACTIVITY_API_PATH;
|
|
4680
|
+
exports.USER_ACTIVITY_FILTER_LABELS = USER_ACTIVITY_FILTER_LABELS;
|
|
4681
|
+
exports.USER_ACTIVITY_FILTER_OPTIONS = USER_ACTIVITY_FILTER_OPTIONS;
|
|
4682
|
+
exports.USER_ACTIVITY_PAGE_PATH = USER_ACTIVITY_PAGE_PATH;
|
|
4683
|
+
exports.USER_ACTIVITY_SETTINGS_PATH = USER_ACTIVITY_SETTINGS_PATH;
|
|
4684
|
+
exports.UserEventTable = UserEventTable;
|
|
4685
|
+
exports.ValueOrMissing = ValueOrMissing;
|
|
4686
|
+
exports.buildActivityCsv = buildActivityCsv;
|
|
4687
|
+
exports.buildActivityParams = buildActivityParams;
|
|
4688
|
+
exports.buildAdminListParams = buildAdminListParams;
|
|
4689
|
+
exports.buildSavePayload = buildSavePayload;
|
|
4690
|
+
exports.buildSelectOptions = buildSelectOptions;
|
|
4691
|
+
exports.buildSessionCsv = buildSessionCsv;
|
|
4692
|
+
exports.buildSessionJson = buildSessionJson;
|
|
4693
|
+
exports.buildSignInCsv = buildSignInCsv;
|
|
4694
|
+
exports.buildSignInParams = buildSignInParams;
|
|
4695
|
+
exports.buildTabSearch = buildTabSearch;
|
|
4696
|
+
exports.buildUserActivityCsv = buildUserActivityCsv;
|
|
4697
|
+
exports.buildUserActivityParams = buildUserActivityParams;
|
|
4698
|
+
exports.copyText = copyText;
|
|
4699
|
+
exports.downloadCsv = downloadCsv;
|
|
4700
|
+
exports.fieldHasError = fieldHasError;
|
|
4701
|
+
exports.formatClock = formatClock;
|
|
4702
|
+
exports.formatSessionDate = formatSessionDate;
|
|
4703
|
+
exports.getAdminStatusPresentation = getAdminStatusPresentation;
|
|
4704
|
+
exports.getBadgeColors = getBadgeColors;
|
|
4705
|
+
exports.getDevicePresentation = getDevicePresentation;
|
|
4706
|
+
exports.getDeviceTypeMessage = getDeviceTypeMessage;
|
|
4707
|
+
exports.getEndReasonPresentation = getEndReasonPresentation;
|
|
4708
|
+
exports.getErrorTab = getErrorTab;
|
|
4709
|
+
exports.getRevealScrollDelta = getRevealScrollDelta;
|
|
4710
|
+
exports.getSessionEndReason = getSessionEndReason;
|
|
4711
|
+
exports.getSessionEndReasonPresentation = getSessionEndReasonPresentation;
|
|
4712
|
+
exports.getSessionStatus = getSessionStatus;
|
|
4713
|
+
exports.getSignOutErrorMessage = getSignOutErrorMessage;
|
|
4714
|
+
exports.getTranslation = getTranslation;
|
|
4715
|
+
exports.getVisibleSettingsTabs = getVisibleSettingsTabs;
|
|
4716
|
+
exports.hasActivityPageFilters = hasActivityPageFilters;
|
|
4717
|
+
exports.hasAdminFilters = hasAdminFilters;
|
|
4718
|
+
exports.hasUserActivityFilters = hasUserActivityFilters;
|
|
4719
|
+
exports.index = index;
|
|
4720
|
+
exports.isCancelledRequest = isCancelledRequest;
|
|
4721
|
+
exports.isEndReasonFilter = isEndReasonFilter;
|
|
4722
|
+
exports.isNativeOnlySession = isNativeOnlySession;
|
|
4723
|
+
exports.isSessionFilter = isSessionFilter;
|
|
4724
|
+
exports.logSafeAdminError = logSafeAdminError;
|
|
4725
|
+
exports.normalizeDeviceType = normalizeDeviceType;
|
|
4726
|
+
exports.parseActivityPageQuery = parseActivityPageQuery;
|
|
4727
|
+
exports.parseAdminPanelQuery = parseAdminPanelQuery;
|
|
4728
|
+
exports.parseUserActivityQuery = parseUserActivityQuery;
|
|
4729
|
+
exports.pluginId = pluginId$1;
|
|
4730
|
+
exports.pluginPermissions = pluginPermissions;
|
|
4731
|
+
exports.presentText = presentText;
|
|
4732
|
+
exports.refocusIfLost = refocusIfLost;
|
|
4733
|
+
exports.requireSessionList = requireSessionList;
|
|
4734
|
+
exports.requireSuccessfulMutation = requireSuccessfulMutation;
|
|
4735
|
+
exports.resolveSettingsTab = resolveSettingsTab;
|
|
4736
|
+
exports.restoreDialogFocus = restoreDialogFocus;
|
|
4737
|
+
exports.splitDuration = splitDuration;
|
|
4738
|
+
exports.toValidDate = toValidDate;
|
|
4739
|
+
exports.useElementWidth = useElementWidth;
|
|
4740
|
+
exports.useEventList = useEventList;
|
|
4741
|
+
exports.useSecondsLeft = useSecondsLeft;
|
|
4742
|
+
exports.useSessionFormatters = useSessionFormatters;
|
|
4743
|
+
exports.useSettingsTranslate = useSettingsTranslate;
|
|
4744
|
+
exports.userText = userText;
|
|
4745
|
+
exports.usesLocalDatabase = usesLocalDatabase;
|
|
4746
|
+
exports.validateReason = validateReason;
|
|
4747
|
+
exports.withIdentityPlaceholders = withIdentityPlaceholders;
|