simple-module-sharing 0.0.50__tar.gz → 0.0.51__tar.gz
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.
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/PKG-INFO +5 -5
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/pyproject.toml +5 -5
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/core/subjects.py +3 -2
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/ui/components/ShareDialog.tsx +78 -15
- simple_module_sharing-0.0.51/tests-js/ShareDialog.test.tsx +276 -0
- simple_module_sharing-0.0.50/tests-js/ShareDialog.test.tsx +0 -107
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/.gitignore +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/LICENSE +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/README.md +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/package.json +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/__init__.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/contracts/__init__.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/contracts/cleanup.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/contracts/schemas.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/contracts/subjects.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/core/__init__.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/core/audience.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/core/constants.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/core/policy.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/core/service.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/core/tenant_cleanup.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/core/user_cleanup.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/locales/de.json +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/locales/en.json +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/models.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/module.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/pages/Admin.tsx +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/pages/api.generated.ts +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/pages/i18n.generated.ts +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/py.typed +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/ui/components/ShareTable.tsx +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/ui/hooks/useShares.ts +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/ui/index.ts +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/ui/types.ts +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/web/__init__.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/web/deps.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/web/endpoints/__init__.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/web/endpoints/admin_api.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/web/endpoints/api.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/web/endpoints/views.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/web/listing.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/web/present.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/_sharing_support.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/core/audience/test_sharing_tenant_audience.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/core/cleanup/test_sharing_resource_cleanup.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/core/cleanup/test_sharing_tenant_cleanup.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/core/service/test_role_candidates_i18n.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/core/service/test_sharing_candidates.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/core/service/test_sharing_custom_roles.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/core/service/test_sharing_service.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/core/service/test_sharing_subjects.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/core/service/test_subject_policy.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/core/service/test_subject_providers.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/web/endpoints/test_sharing_admin_api.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/web/endpoints/test_sharing_candidates.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/web/endpoints/test_sharing_candidates_long_email.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/web/endpoints/test_sharing_http.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests/web/endpoints/test_subject_providers.py +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests-js/ShareDialog_subjects.test.tsx +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests-js/ShareDialog_translations.test.tsx +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests-js/sharing_Admin.test.tsx +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests-js/sharing_Admin_errors.test.tsx +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests-js/useShares.test.tsx +0 -0
- {simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests-js/useShares_subjects.test.tsx +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: simple_module_sharing
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.51
|
|
4
4
|
Summary: Generic resource shares (owner / shared-with-user) for simple_module resource-scoped access
|
|
5
5
|
Project-URL: Homepage, https://github.com/antosubash/simple_module_python
|
|
6
6
|
Project-URL: Repository, https://github.com/antosubash/simple_module_python
|
|
@@ -11,10 +11,10 @@ License-Expression: MIT
|
|
|
11
11
|
License-File: LICENSE
|
|
12
12
|
Keywords: access-control,permissions,sharing,simple-module
|
|
13
13
|
Requires-Python: >=3.12
|
|
14
|
-
Requires-Dist: simple-module-core==0.0.
|
|
15
|
-
Requires-Dist: simple-module-db==0.0.
|
|
16
|
-
Requires-Dist: simple-module-hosting==0.0.
|
|
17
|
-
Requires-Dist: simple-module-inertia==0.0.
|
|
14
|
+
Requires-Dist: simple-module-core==0.0.51
|
|
15
|
+
Requires-Dist: simple-module-db==0.0.51
|
|
16
|
+
Requires-Dist: simple-module-hosting==0.0.51
|
|
17
|
+
Requires-Dist: simple-module-inertia==0.0.51
|
|
18
18
|
Description-Content-Type: text/markdown
|
|
19
19
|
|
|
20
20
|
# simple_module_sharing
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "simple_module_sharing"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.51"
|
|
4
4
|
description = "Generic resource shares (owner / shared-with-user) for simple_module resource-scoped access"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -9,10 +9,10 @@ requires-python = ">=3.12"
|
|
|
9
9
|
authors = [{ name = "Anto Subash", email = "antosubash@live.com" }]
|
|
10
10
|
keywords = ["simple-module", "sharing", "permissions", "access-control"]
|
|
11
11
|
dependencies = [
|
|
12
|
-
"simple_module_core==0.0.
|
|
13
|
-
"simple_module_db==0.0.
|
|
14
|
-
"simple_module_hosting==0.0.
|
|
15
|
-
"simple_module_inertia==0.0.
|
|
12
|
+
"simple_module_core==0.0.51",
|
|
13
|
+
"simple_module_db==0.0.51",
|
|
14
|
+
"simple_module_hosting==0.0.51",
|
|
15
|
+
"simple_module_inertia==0.0.51",
|
|
16
16
|
]
|
|
17
17
|
|
|
18
18
|
[project.entry-points.simple_module]
|
|
@@ -41,8 +41,9 @@ async def _user_candidates(ctx: SubjectContext, term: str, owner_id: str) -> lis
|
|
|
41
41
|
)
|
|
42
42
|
candidates = []
|
|
43
43
|
for user in found:
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
raw_email = user.email or ""
|
|
45
|
+
local, separator, domain = raw_email.rpartition("@")
|
|
46
|
+
email = f"{local[:1]}•••@{domain}" if separator else ("•••" if raw_email else "")
|
|
46
47
|
# Names may themselves contain an email; never echo those verbatim.
|
|
47
48
|
label = user.label if "@" not in user.label else email
|
|
48
49
|
candidates.append(ShareCandidate(id=user.id, display_name=label, email=email))
|
{simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/ui/components/ShareDialog.tsx
RENAMED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import { Input } from '@simple-module-py/ui/components/ui/input';
|
|
13
13
|
import { Label } from '@simple-module-py/ui/components/ui/label';
|
|
14
14
|
import { NativeSelect } from '@simple-module-py/ui/components/ui/native-select';
|
|
15
|
-
import { useId, useState } from 'react';
|
|
15
|
+
import { Fragment, isValidElement, type ReactNode, useId, useRef, useState } from 'react';
|
|
16
16
|
import { MIN_QUERY, useShares } from '../hooks/useShares';
|
|
17
17
|
|
|
18
18
|
export interface ShareRole {
|
|
@@ -24,6 +24,31 @@ export interface ShareDialogProps {
|
|
|
24
24
|
resourceId: string;
|
|
25
25
|
/** Translated labels for the resource's custom share_roles. Defaults to view/edit. */
|
|
26
26
|
roles?: readonly ShareRole[];
|
|
27
|
+
/**
|
|
28
|
+
* Controlled open state. When omitted, the dialog manages its own open state.
|
|
29
|
+
* Keep a given instance either controlled or uncontrolled for its lifetime.
|
|
30
|
+
*/
|
|
31
|
+
open?: boolean;
|
|
32
|
+
/** Called when the dialog requests an open-state change. */
|
|
33
|
+
onOpenChange?: (open: boolean) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Custom trigger rendered inside `<DialogTrigger>`.
|
|
36
|
+
* - `undefined`: renders the default Share button.
|
|
37
|
+
* - `null` (or `false`): omits `<DialogTrigger>` entirely (restoring focus to the invoking control on close).
|
|
38
|
+
* - Interactive element (`<button>`, `<a>`, or a keyboard-operable component forwarding props/refs): slotted via `asChild`.
|
|
39
|
+
* - Plain text or non-interactive element (e.g. `<span>`): wrapped in a native `<DialogTrigger type="button">`.
|
|
40
|
+
*/
|
|
41
|
+
trigger?: ReactNode | null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isSlottableTrigger(node: ReactNode): boolean {
|
|
45
|
+
if (!isValidElement(node) || node.type === Fragment) return false;
|
|
46
|
+
return (
|
|
47
|
+
typeof node.type === 'function' ||
|
|
48
|
+
typeof node.type === 'object' ||
|
|
49
|
+
node.type === 'button' ||
|
|
50
|
+
node.type === 'a'
|
|
51
|
+
);
|
|
27
52
|
}
|
|
28
53
|
|
|
29
54
|
export function ShareDialog(props: ShareDialogProps) {
|
|
@@ -31,14 +56,31 @@ export function ShareDialog(props: ShareDialogProps) {
|
|
|
31
56
|
return <ResourceShareDialog key={`${props.resourceType}/${props.resourceId}`} {...props} />;
|
|
32
57
|
}
|
|
33
58
|
|
|
34
|
-
function ResourceShareDialog({
|
|
59
|
+
function ResourceShareDialog({
|
|
60
|
+
resourceType,
|
|
61
|
+
resourceId,
|
|
62
|
+
roles,
|
|
63
|
+
open: controlledOpen,
|
|
64
|
+
onOpenChange,
|
|
65
|
+
trigger,
|
|
66
|
+
}: ShareDialogProps) {
|
|
35
67
|
const { t } = useT();
|
|
36
68
|
const id = useId();
|
|
37
69
|
const options = roles ?? [
|
|
38
70
|
{ value: 'view', label: t(keys.sharing.dialog.role_view) },
|
|
39
71
|
{ value: 'edit', label: t(keys.sharing.dialog.role_edit) },
|
|
40
72
|
];
|
|
41
|
-
const [
|
|
73
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
|
74
|
+
const isControlled = controlledOpen !== undefined;
|
|
75
|
+
const open = isControlled ? controlledOpen : uncontrolledOpen;
|
|
76
|
+
const triggerOmitted = trigger === null || trigger === false;
|
|
77
|
+
const prevOpenRef = useRef(false);
|
|
78
|
+
const returnFocusRef = useRef<HTMLElement | null>(null);
|
|
79
|
+
if (open && !prevOpenRef.current && triggerOmitted) {
|
|
80
|
+
const active = typeof document !== 'undefined' ? document.activeElement : null;
|
|
81
|
+
returnFocusRef.current = active instanceof HTMLElement ? active : null;
|
|
82
|
+
}
|
|
83
|
+
prevOpenRef.current = open;
|
|
42
84
|
const [selected, setSelected] = useState(options[0]?.value ?? '');
|
|
43
85
|
const role = options.some((option) => option.value === selected) ? selected : options[0]?.value;
|
|
44
86
|
const state = useShares(resourceType, resourceId, open);
|
|
@@ -51,20 +93,41 @@ function ResourceShareDialog({ resourceType, resourceId, roles }: ShareDialogPro
|
|
|
51
93
|
};
|
|
52
94
|
return labels[subjectId] ?? fallback;
|
|
53
95
|
};
|
|
96
|
+
const handleOpenChange = (next: boolean) => {
|
|
97
|
+
if (state.pending) return;
|
|
98
|
+
if (!isControlled) setUncontrolledOpen(next);
|
|
99
|
+
onOpenChange?.(next);
|
|
100
|
+
};
|
|
54
101
|
|
|
55
102
|
return (
|
|
56
|
-
<Dialog
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
103
|
+
<Dialog open={open} onOpenChange={handleOpenChange}>
|
|
104
|
+
{triggerOmitted ? null : trigger === undefined ? (
|
|
105
|
+
<DialogTrigger asChild>
|
|
106
|
+
<Button type="button" variant="outline">
|
|
107
|
+
{t(keys.sharing.dialog.button)}
|
|
108
|
+
</Button>
|
|
109
|
+
</DialogTrigger>
|
|
110
|
+
) : isSlottableTrigger(trigger) ? (
|
|
111
|
+
<DialogTrigger asChild>{trigger}</DialogTrigger>
|
|
112
|
+
) : (
|
|
113
|
+
<DialogTrigger type="button">{trigger}</DialogTrigger>
|
|
114
|
+
)}
|
|
115
|
+
<DialogContent
|
|
116
|
+
className="max-h-[85vh] overflow-y-auto"
|
|
117
|
+
showCloseButton={false}
|
|
118
|
+
onCloseAutoFocus={
|
|
119
|
+
triggerOmitted
|
|
120
|
+
? (event) => {
|
|
121
|
+
const target = returnFocusRef.current;
|
|
122
|
+
returnFocusRef.current = null;
|
|
123
|
+
if (target?.isConnected) {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
target.focus();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
: undefined
|
|
129
|
+
}
|
|
130
|
+
>
|
|
68
131
|
<DialogHeader>
|
|
69
132
|
<DialogTitle>{t(keys.sharing.dialog.title)}</DialogTitle>
|
|
70
133
|
<DialogDescription>{t(keys.sharing.dialog.description)}</DialogDescription>
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { configureI18n, keys } from '@simple-module-py/i18n';
|
|
2
|
+
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
|
|
5
|
+
import { ShareDialog } from '../sharing/ui';
|
|
6
|
+
|
|
7
|
+
configureI18n({ locale: 'en', messages: {} });
|
|
8
|
+
let held: boolean;
|
|
9
|
+
let grantedBody: unknown;
|
|
10
|
+
let mutationGate: Promise<void> | undefined;
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
mutationGate = undefined;
|
|
13
|
+
held = false;
|
|
14
|
+
grantedBody = null;
|
|
15
|
+
vi.stubGlobal(
|
|
16
|
+
'fetch',
|
|
17
|
+
vi.fn(async (request: Request) => {
|
|
18
|
+
if (request.method === 'POST') {
|
|
19
|
+
await mutationGate;
|
|
20
|
+
held = true;
|
|
21
|
+
grantedBody = await request.json();
|
|
22
|
+
}
|
|
23
|
+
if (request.method === 'DELETE') {
|
|
24
|
+
held = false;
|
|
25
|
+
return new Response(null, { status: 204 });
|
|
26
|
+
}
|
|
27
|
+
if (request.url.includes('/candidates'))
|
|
28
|
+
return Response.json([{ id: 'friend', display_name: 'Friend', email: 'friend@test' }]);
|
|
29
|
+
const share = {
|
|
30
|
+
id: 'share',
|
|
31
|
+
resource_type: 'notes.note',
|
|
32
|
+
resource_id: 'note',
|
|
33
|
+
subject_type: 'user',
|
|
34
|
+
subject_id: 'friend',
|
|
35
|
+
subject_label: 'Friend',
|
|
36
|
+
role: 'reviewer',
|
|
37
|
+
granted_by: 'owner',
|
|
38
|
+
granted_by_label: null,
|
|
39
|
+
expires_at: null,
|
|
40
|
+
expired: false,
|
|
41
|
+
created_at: null,
|
|
42
|
+
};
|
|
43
|
+
return Response.json(request.method === 'POST' ? share : held ? [share] : []);
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
48
|
+
|
|
49
|
+
it('renders, searches, grants a custom role and revokes it', async () => {
|
|
50
|
+
render(
|
|
51
|
+
<ShareDialog
|
|
52
|
+
resourceType="notes.note"
|
|
53
|
+
resourceId="note"
|
|
54
|
+
roles={[{ value: 'reviewer', label: 'Reviewer' }]}
|
|
55
|
+
/>,
|
|
56
|
+
);
|
|
57
|
+
fireEvent.click(screen.getByRole('button', { name: keys.sharing.dialog.button }));
|
|
58
|
+
const dialog = await screen.findByRole('dialog');
|
|
59
|
+
expect(within(dialog).getByText(keys.sharing.dialog.title)).toBeInTheDocument();
|
|
60
|
+
await waitFor(() =>
|
|
61
|
+
expect(within(dialog).getByText(keys.sharing.dialog.none)).toBeInTheDocument(),
|
|
62
|
+
);
|
|
63
|
+
fireEvent.change(within(dialog).getByLabelText(keys.sharing.dialog.search_label), {
|
|
64
|
+
target: { value: 'friend' },
|
|
65
|
+
});
|
|
66
|
+
fireEvent.click(await within(dialog).findByRole('button', { name: keys.sharing.dialog.grant }));
|
|
67
|
+
await waitFor(() =>
|
|
68
|
+
expect(within(dialog).queryByRole('button', { name: keys.sharing.dialog.grant })).toBeNull(),
|
|
69
|
+
);
|
|
70
|
+
expect(within(dialog).getAllByText('Reviewer').length).toBeGreaterThan(0);
|
|
71
|
+
expect(grantedBody).toMatchObject({ subject_id: 'friend', role: 'reviewer' });
|
|
72
|
+
fireEvent.click(within(dialog).getByRole('button', { name: keys.sharing.dialog.revoke_for }));
|
|
73
|
+
await waitFor(() =>
|
|
74
|
+
expect(within(dialog).getByText(keys.sharing.dialog.none)).toBeInTheDocument(),
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('keeps pending grants visible through dismissal attempts and reopening', async () => {
|
|
79
|
+
let finish!: () => void;
|
|
80
|
+
mutationGate = new Promise<void>((resolve) => {
|
|
81
|
+
finish = resolve;
|
|
82
|
+
});
|
|
83
|
+
render(<ShareDialog resourceType="notes.note" resourceId="note" />);
|
|
84
|
+
const trigger = screen.getByRole('button', { name: keys.sharing.dialog.button });
|
|
85
|
+
fireEvent.click(trigger);
|
|
86
|
+
const dialog = await screen.findByRole('dialog');
|
|
87
|
+
await waitFor(() => expect(within(dialog).getByText(keys.sharing.dialog.none)).toBeVisible());
|
|
88
|
+
fireEvent.change(within(dialog).getByLabelText(keys.sharing.dialog.search_label), {
|
|
89
|
+
target: { value: 'friend' },
|
|
90
|
+
});
|
|
91
|
+
fireEvent.click(await within(dialog).findByRole('button', { name: keys.sharing.dialog.grant }));
|
|
92
|
+
const close = within(dialog).getByRole('button', { name: keys.sharing.dialog.close });
|
|
93
|
+
expect(close).toBeDisabled();
|
|
94
|
+
fireEvent.click(close);
|
|
95
|
+
fireEvent.keyDown(dialog, { key: 'Escape' });
|
|
96
|
+
const overlay = document.querySelector('[data-slot="dialog-overlay"]');
|
|
97
|
+
if (!overlay) throw new Error('Missing dialog overlay');
|
|
98
|
+
fireEvent.pointerDown(overlay, { button: 0, ctrlKey: false });
|
|
99
|
+
expect(screen.getByRole('dialog')).toBeVisible();
|
|
100
|
+
finish();
|
|
101
|
+
await waitFor(() => expect(close).toBeEnabled());
|
|
102
|
+
expect(within(dialog).getByText('Friend')).toBeVisible();
|
|
103
|
+
fireEvent.click(close);
|
|
104
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
105
|
+
fireEvent.click(trigger);
|
|
106
|
+
expect(await screen.findByText('Friend')).toBeVisible();
|
|
107
|
+
expect(screen.queryByText(keys.sharing.dialog.none)).toBeNull();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('notifies onOpenChange in uncontrolled mode with the default trigger', async () => {
|
|
111
|
+
const onOpenChange = vi.fn();
|
|
112
|
+
render(<ShareDialog resourceType="notes.note" resourceId="note" onOpenChange={onOpenChange} />);
|
|
113
|
+
|
|
114
|
+
fireEvent.click(screen.getByRole('button', { name: keys.sharing.dialog.button }));
|
|
115
|
+
const dialog = await screen.findByRole('dialog');
|
|
116
|
+
expect(onOpenChange).toHaveBeenCalledWith(true);
|
|
117
|
+
|
|
118
|
+
await waitFor(() =>
|
|
119
|
+
expect(within(dialog).getByText(keys.sharing.dialog.none)).toBeInTheDocument(),
|
|
120
|
+
);
|
|
121
|
+
fireEvent.click(within(dialog).getByRole('button', { name: keys.sharing.dialog.close }));
|
|
122
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
123
|
+
expect(onOpenChange).toHaveBeenLastCalledWith(false);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('supports controlled open/onOpenChange and loads shares on false -> true transition', async () => {
|
|
127
|
+
held = true;
|
|
128
|
+
const onOpenChange = vi.fn();
|
|
129
|
+
const { rerender } = render(
|
|
130
|
+
<ShareDialog
|
|
131
|
+
resourceType="notes.note"
|
|
132
|
+
resourceId="note"
|
|
133
|
+
open={false}
|
|
134
|
+
onOpenChange={onOpenChange}
|
|
135
|
+
trigger={null}
|
|
136
|
+
/>,
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
140
|
+
expect(screen.queryByRole('button', { name: keys.sharing.dialog.button })).toBeNull();
|
|
141
|
+
expect(fetch).not.toHaveBeenCalled();
|
|
142
|
+
|
|
143
|
+
rerender(
|
|
144
|
+
<ShareDialog
|
|
145
|
+
resourceType="notes.note"
|
|
146
|
+
resourceId="note"
|
|
147
|
+
open={true}
|
|
148
|
+
onOpenChange={onOpenChange}
|
|
149
|
+
trigger={null}
|
|
150
|
+
/>,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const dialog = await screen.findByRole('dialog');
|
|
154
|
+
expect(await within(dialog).findByText('Friend')).toBeVisible();
|
|
155
|
+
|
|
156
|
+
fireEvent.click(within(dialog).getByRole('button', { name: keys.sharing.dialog.close }));
|
|
157
|
+
expect(onOpenChange).toHaveBeenCalledWith(false);
|
|
158
|
+
// Controlled: stays open until parent updates `open`.
|
|
159
|
+
expect(screen.getByRole('dialog')).toBeVisible();
|
|
160
|
+
|
|
161
|
+
rerender(
|
|
162
|
+
<ShareDialog
|
|
163
|
+
resourceType="notes.note"
|
|
164
|
+
resourceId="note"
|
|
165
|
+
open={false}
|
|
166
|
+
onOpenChange={onOpenChange}
|
|
167
|
+
trigger={null}
|
|
168
|
+
/>,
|
|
169
|
+
);
|
|
170
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('blocks controlled onOpenChange(false) while a grant is pending', async () => {
|
|
174
|
+
let finish!: () => void;
|
|
175
|
+
mutationGate = new Promise<void>((resolve) => {
|
|
176
|
+
finish = resolve;
|
|
177
|
+
});
|
|
178
|
+
const onOpenChange = vi.fn();
|
|
179
|
+
render(
|
|
180
|
+
<ShareDialog
|
|
181
|
+
resourceType="notes.note"
|
|
182
|
+
resourceId="note"
|
|
183
|
+
open={true}
|
|
184
|
+
onOpenChange={onOpenChange}
|
|
185
|
+
trigger={null}
|
|
186
|
+
/>,
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
const dialog = await screen.findByRole('dialog');
|
|
190
|
+
await waitFor(() => expect(within(dialog).getByText(keys.sharing.dialog.none)).toBeVisible());
|
|
191
|
+
fireEvent.change(within(dialog).getByLabelText(keys.sharing.dialog.search_label), {
|
|
192
|
+
target: { value: 'friend' },
|
|
193
|
+
});
|
|
194
|
+
fireEvent.click(await within(dialog).findByRole('button', { name: keys.sharing.dialog.grant }));
|
|
195
|
+
|
|
196
|
+
fireEvent.keyDown(dialog, { key: 'Escape' });
|
|
197
|
+
expect(onOpenChange).not.toHaveBeenCalledWith(false);
|
|
198
|
+
|
|
199
|
+
finish();
|
|
200
|
+
await waitFor(() =>
|
|
201
|
+
expect(within(dialog).getByRole('button', { name: keys.sharing.dialog.close })).toBeEnabled(),
|
|
202
|
+
);
|
|
203
|
+
fireEvent.click(within(dialog).getByRole('button', { name: keys.sharing.dialog.close }));
|
|
204
|
+
expect(onOpenChange).toHaveBeenCalledWith(false);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('renders a custom trigger element without nesting buttons and opens the dialog', async () => {
|
|
208
|
+
render(
|
|
209
|
+
<ShareDialog
|
|
210
|
+
resourceType="notes.note"
|
|
211
|
+
resourceId="note"
|
|
212
|
+
trigger={<button type="button">Manage access</button>}
|
|
213
|
+
/>,
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
expect(screen.queryByRole('button', { name: keys.sharing.dialog.button })).toBeNull();
|
|
217
|
+
const trigger = screen.getByRole('button', { name: 'Manage access' });
|
|
218
|
+
expect(trigger.querySelector('button')).toBeNull();
|
|
219
|
+
|
|
220
|
+
fireEvent.click(trigger);
|
|
221
|
+
expect(await screen.findByRole('dialog')).toBeVisible();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('wraps plain-text and non-interactive custom triggers in a native button', async () => {
|
|
225
|
+
const { rerender } = render(
|
|
226
|
+
<ShareDialog resourceType="notes.note" resourceId="note" trigger="Share item" />,
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
fireEvent.click(screen.getByRole('button', { name: 'Share item' }));
|
|
230
|
+
expect(await screen.findByRole('dialog')).toBeVisible();
|
|
231
|
+
|
|
232
|
+
rerender(
|
|
233
|
+
<ShareDialog
|
|
234
|
+
resourceType="notes.note"
|
|
235
|
+
resourceId="note-2"
|
|
236
|
+
trigger={<span>Share via span</span>}
|
|
237
|
+
/>,
|
|
238
|
+
);
|
|
239
|
+
const button = screen.getByRole('button', { name: 'Share via span' });
|
|
240
|
+
expect(button.tagName).toBe('BUTTON');
|
|
241
|
+
fireEvent.click(button);
|
|
242
|
+
expect(await screen.findByRole('dialog')).toBeVisible();
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('restores focus to the external control when closing a triggerless dialog with Escape', async () => {
|
|
246
|
+
function Host() {
|
|
247
|
+
const [open, setOpen] = useState(false);
|
|
248
|
+
return (
|
|
249
|
+
<>
|
|
250
|
+
<button type="button" onClick={() => setOpen(true)}>
|
|
251
|
+
Row share action
|
|
252
|
+
</button>
|
|
253
|
+
<ShareDialog
|
|
254
|
+
resourceType="notes.note"
|
|
255
|
+
resourceId="note"
|
|
256
|
+
open={open}
|
|
257
|
+
onOpenChange={setOpen}
|
|
258
|
+
trigger={null}
|
|
259
|
+
/>
|
|
260
|
+
</>
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
render(<Host />);
|
|
265
|
+
const external = screen.getByRole('button', { name: 'Row share action' });
|
|
266
|
+
external.focus();
|
|
267
|
+
expect(external).toHaveFocus();
|
|
268
|
+
fireEvent.click(external);
|
|
269
|
+
|
|
270
|
+
const dialog = await screen.findByRole('dialog');
|
|
271
|
+
await waitFor(() => expect(within(dialog).getByText(keys.sharing.dialog.none)).toBeVisible());
|
|
272
|
+
fireEvent.keyDown(dialog, { key: 'Escape' });
|
|
273
|
+
|
|
274
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
275
|
+
expect(external).toHaveFocus();
|
|
276
|
+
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { configureI18n, keys } from '@simple-module-py/i18n';
|
|
2
|
-
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
|
3
|
-
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
|
|
4
|
-
import { ShareDialog } from '../sharing/ui';
|
|
5
|
-
|
|
6
|
-
configureI18n({ locale: 'en', messages: {} });
|
|
7
|
-
let held: boolean;
|
|
8
|
-
let grantedBody: unknown;
|
|
9
|
-
let mutationGate: Promise<void> | undefined;
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
mutationGate = undefined;
|
|
12
|
-
held = false;
|
|
13
|
-
grantedBody = null;
|
|
14
|
-
vi.stubGlobal(
|
|
15
|
-
'fetch',
|
|
16
|
-
vi.fn(async (request: Request) => {
|
|
17
|
-
if (request.method === 'POST') {
|
|
18
|
-
await mutationGate;
|
|
19
|
-
held = true;
|
|
20
|
-
grantedBody = await request.json();
|
|
21
|
-
}
|
|
22
|
-
if (request.method === 'DELETE') {
|
|
23
|
-
held = false;
|
|
24
|
-
return new Response(null, { status: 204 });
|
|
25
|
-
}
|
|
26
|
-
if (request.url.includes('/candidates'))
|
|
27
|
-
return Response.json([{ id: 'friend', display_name: 'Friend', email: 'friend@test' }]);
|
|
28
|
-
const share = {
|
|
29
|
-
id: 'share',
|
|
30
|
-
resource_type: 'notes.note',
|
|
31
|
-
resource_id: 'note',
|
|
32
|
-
subject_type: 'user',
|
|
33
|
-
subject_id: 'friend',
|
|
34
|
-
subject_label: 'Friend',
|
|
35
|
-
role: 'reviewer',
|
|
36
|
-
granted_by: 'owner',
|
|
37
|
-
granted_by_label: null,
|
|
38
|
-
expires_at: null,
|
|
39
|
-
expired: false,
|
|
40
|
-
created_at: null,
|
|
41
|
-
};
|
|
42
|
-
return Response.json(request.method === 'POST' ? share : held ? [share] : []);
|
|
43
|
-
}),
|
|
44
|
-
);
|
|
45
|
-
});
|
|
46
|
-
afterEach(() => vi.unstubAllGlobals());
|
|
47
|
-
|
|
48
|
-
it('renders, searches, grants a custom role and revokes it', async () => {
|
|
49
|
-
render(
|
|
50
|
-
<ShareDialog
|
|
51
|
-
resourceType="notes.note"
|
|
52
|
-
resourceId="note"
|
|
53
|
-
roles={[{ value: 'reviewer', label: 'Reviewer' }]}
|
|
54
|
-
/>,
|
|
55
|
-
);
|
|
56
|
-
fireEvent.click(screen.getByRole('button', { name: keys.sharing.dialog.button }));
|
|
57
|
-
const dialog = await screen.findByRole('dialog');
|
|
58
|
-
expect(within(dialog).getByText(keys.sharing.dialog.title)).toBeInTheDocument();
|
|
59
|
-
await waitFor(() =>
|
|
60
|
-
expect(within(dialog).getByText(keys.sharing.dialog.none)).toBeInTheDocument(),
|
|
61
|
-
);
|
|
62
|
-
fireEvent.change(within(dialog).getByLabelText(keys.sharing.dialog.search_label), {
|
|
63
|
-
target: { value: 'friend' },
|
|
64
|
-
});
|
|
65
|
-
fireEvent.click(await within(dialog).findByRole('button', { name: keys.sharing.dialog.grant }));
|
|
66
|
-
await waitFor(() =>
|
|
67
|
-
expect(within(dialog).queryByRole('button', { name: keys.sharing.dialog.grant })).toBeNull(),
|
|
68
|
-
);
|
|
69
|
-
expect(within(dialog).getAllByText('Reviewer').length).toBeGreaterThan(0);
|
|
70
|
-
expect(grantedBody).toMatchObject({ subject_id: 'friend', role: 'reviewer' });
|
|
71
|
-
fireEvent.click(within(dialog).getByRole('button', { name: keys.sharing.dialog.revoke_for }));
|
|
72
|
-
await waitFor(() =>
|
|
73
|
-
expect(within(dialog).getByText(keys.sharing.dialog.none)).toBeInTheDocument(),
|
|
74
|
-
);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('keeps pending grants visible through dismissal attempts and reopening', async () => {
|
|
78
|
-
let finish!: () => void;
|
|
79
|
-
mutationGate = new Promise<void>((resolve) => {
|
|
80
|
-
finish = resolve;
|
|
81
|
-
});
|
|
82
|
-
render(<ShareDialog resourceType="notes.note" resourceId="note" />);
|
|
83
|
-
const trigger = screen.getByRole('button', { name: keys.sharing.dialog.button });
|
|
84
|
-
fireEvent.click(trigger);
|
|
85
|
-
const dialog = await screen.findByRole('dialog');
|
|
86
|
-
await waitFor(() => expect(within(dialog).getByText(keys.sharing.dialog.none)).toBeVisible());
|
|
87
|
-
fireEvent.change(within(dialog).getByLabelText(keys.sharing.dialog.search_label), {
|
|
88
|
-
target: { value: 'friend' },
|
|
89
|
-
});
|
|
90
|
-
fireEvent.click(await within(dialog).findByRole('button', { name: keys.sharing.dialog.grant }));
|
|
91
|
-
const close = within(dialog).getByRole('button', { name: keys.sharing.dialog.close });
|
|
92
|
-
expect(close).toBeDisabled();
|
|
93
|
-
fireEvent.click(close);
|
|
94
|
-
fireEvent.keyDown(dialog, { key: 'Escape' });
|
|
95
|
-
const overlay = document.querySelector('[data-slot="dialog-overlay"]');
|
|
96
|
-
if (!overlay) throw new Error('Missing dialog overlay');
|
|
97
|
-
fireEvent.pointerDown(overlay, { button: 0, ctrlKey: false });
|
|
98
|
-
expect(screen.getByRole('dialog')).toBeVisible();
|
|
99
|
-
finish();
|
|
100
|
-
await waitFor(() => expect(close).toBeEnabled());
|
|
101
|
-
expect(within(dialog).getByText('Friend')).toBeVisible();
|
|
102
|
-
fireEvent.click(close);
|
|
103
|
-
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
104
|
-
fireEvent.click(trigger);
|
|
105
|
-
expect(await screen.findByText('Friend')).toBeVisible();
|
|
106
|
-
expect(screen.queryByText(keys.sharing.dialog.none)).toBeNull();
|
|
107
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/core/tenant_cleanup.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/pages/api.generated.ts
RENAMED
|
File without changes
|
{simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/pages/i18n.generated.ts
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/ui/components/ShareTable.tsx
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/web/endpoints/__init__.py
RENAMED
|
File without changes
|
{simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/web/endpoints/admin_api.py
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/sharing/web/endpoints/views.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests-js/ShareDialog_subjects.test.tsx
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests-js/sharing_Admin.test.tsx
RENAMED
|
File without changes
|
{simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests-js/sharing_Admin_errors.test.tsx
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_sharing-0.0.50 → simple_module_sharing-0.0.51}/tests-js/useShares_subjects.test.tsx
RENAMED
|
File without changes
|