simple-module-sharing 0.0.49__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.
Files changed (64) hide show
  1. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/PKG-INFO +5 -5
  2. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/pyproject.toml +5 -5
  3. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/contracts/schemas.py +7 -1
  4. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/contracts/subjects.py +3 -3
  5. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/core/audience.py +4 -4
  6. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/core/constants.py +3 -11
  7. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/core/policy.py +3 -2
  8. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/core/service.py +5 -5
  9. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/core/subjects.py +7 -6
  10. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/core/tenant_cleanup.py +2 -2
  11. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/core/user_cleanup.py +1 -1
  12. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/models.py +2 -2
  13. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/module.py +17 -8
  14. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/pages/api.generated.ts +108 -0
  15. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/pages/i18n.generated.ts +1 -1
  16. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/ui/components/ShareDialog.tsx +78 -15
  17. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/web/deps.py +3 -3
  18. simple_module_sharing-0.0.51/sharing/web/endpoints/admin_api.py +69 -0
  19. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/web/endpoints/api.py +5 -5
  20. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/web/endpoints/views.py +14 -28
  21. simple_module_sharing-0.0.51/sharing/web/listing.py +52 -0
  22. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/web/present.py +2 -2
  23. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests/_sharing_support.py +3 -3
  24. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests/core/audience/test_sharing_tenant_audience.py +2 -2
  25. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests/core/cleanup/test_sharing_tenant_cleanup.py +3 -3
  26. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests/core/service/test_role_candidates_i18n.py +4 -4
  27. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests/core/service/test_sharing_candidates.py +4 -4
  28. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests/core/service/test_sharing_custom_roles.py +6 -5
  29. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests/core/service/test_sharing_service.py +5 -5
  30. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests/core/service/test_sharing_subjects.py +2 -2
  31. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests/core/service/test_subject_policy.py +4 -4
  32. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests/core/service/test_subject_providers.py +5 -5
  33. simple_module_sharing-0.0.51/tests/web/endpoints/test_sharing_admin_api.py +147 -0
  34. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests/web/endpoints/test_sharing_candidates.py +13 -9
  35. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests/web/endpoints/test_sharing_candidates_long_email.py +2 -2
  36. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests/web/endpoints/test_sharing_http.py +7 -7
  37. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests/web/endpoints/test_subject_providers.py +3 -3
  38. simple_module_sharing-0.0.51/tests-js/ShareDialog.test.tsx +276 -0
  39. simple_module_sharing-0.0.49/tests-js/ShareDialog.test.tsx +0 -107
  40. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/.gitignore +0 -0
  41. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/LICENSE +0 -0
  42. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/README.md +0 -0
  43. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/package.json +0 -0
  44. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/__init__.py +0 -0
  45. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/contracts/__init__.py +0 -0
  46. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/contracts/cleanup.py +0 -0
  47. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/core/__init__.py +0 -0
  48. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/locales/de.json +0 -0
  49. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/locales/en.json +0 -0
  50. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/pages/Admin.tsx +0 -0
  51. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/py.typed +0 -0
  52. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/ui/components/ShareTable.tsx +0 -0
  53. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/ui/hooks/useShares.ts +0 -0
  54. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/ui/index.ts +0 -0
  55. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/ui/types.ts +0 -0
  56. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/web/__init__.py +0 -0
  57. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/sharing/web/endpoints/__init__.py +0 -0
  58. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests/core/cleanup/test_sharing_resource_cleanup.py +0 -0
  59. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests-js/ShareDialog_subjects.test.tsx +0 -0
  60. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests-js/ShareDialog_translations.test.tsx +0 -0
  61. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests-js/sharing_Admin.test.tsx +0 -0
  62. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests-js/sharing_Admin_errors.test.tsx +0 -0
  63. {simple_module_sharing-0.0.49 → simple_module_sharing-0.0.51}/tests-js/useShares.test.tsx +0 -0
  64. {simple_module_sharing-0.0.49 → 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.49
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.49
15
- Requires-Dist: simple-module-db==0.0.49
16
- Requires-Dist: simple-module-hosting==0.0.49
17
- Requires-Dist: simple-module-inertia==0.0.49
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.49"
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.49",
13
- "simple_module_db==0.0.49",
14
- "simple_module_hosting==0.0.49",
15
- "simple_module_inertia==0.0.49",
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]
@@ -5,7 +5,8 @@ from __future__ import annotations
5
5
  import uuid
6
6
  from datetime import datetime
7
7
 
8
- from simple_module_core.resources import ACTION_VIEW
8
+ from simple_module_core.access.resources import ACTION_VIEW
9
+ from simple_module_db import Page
9
10
  from sqlmodel import Field, SQLModel
10
11
 
11
12
  from sharing.core.constants import (
@@ -54,3 +55,8 @@ class ShareOut(SQLModel):
54
55
  expires_at: datetime | None = None
55
56
  expired: bool = False
56
57
  created_at: datetime | None = None
58
+
59
+
60
+ class SharePage(Page[ShareOut]):
61
+ # SQLModel needs a concrete field annotation to retain item types in OpenAPI.
62
+ items: list[ShareOut]
@@ -7,9 +7,9 @@ from collections.abc import Awaitable, Callable, Collection, Mapping
7
7
  from dataclasses import dataclass
8
8
  from typing import Any
9
9
 
10
- from simple_module_core.principals import PRINCIPALS_KEY, PrincipalRegistry
11
- from simple_module_core.resources import ResourcePrincipal
12
- from simple_module_core.user_directory import UserDirectory
10
+ from simple_module_core.access.principals import PRINCIPALS_KEY, PrincipalRegistry
11
+ from simple_module_core.access.resources import ResourcePrincipal
12
+ from simple_module_core.access.user_directory import UserDirectory
13
13
  from sqlalchemy.ext.asyncio import AsyncSession
14
14
 
15
15
  from sharing.contracts.schemas import ShareCandidate
@@ -3,7 +3,7 @@
3
3
  On a multi-tenant app a grantee, and any user label shown, must belong to the
4
4
  active tenant; otherwise ``sharing`` would let a caller share with (and probe
5
5
  for) accounts in other tenants and read their directory labels. Membership is
6
- asked through ``simple_module_core.tenancy.tenant_member_ids`` (the
6
+ asked through ``simple_module_core.access.tenancy.tenant_member_ids`` (the
7
7
  ``tenants`` module publishes it), so this module never imports ``tenants``.
8
8
  With no active tenant, or no membership store installed, nobody is in the
9
9
  audience (fail closed). A single-tenant app has no such boundary.
@@ -14,9 +14,9 @@ from __future__ import annotations
14
14
  from collections.abc import Collection
15
15
  from typing import Any
16
16
 
17
- from simple_module_core.tenancy import TenancyMode, tenant_member_ids
18
- from simple_module_db.tenancy import current_tenant_id
19
- from simple_module_hosting.tenancy import tenancy_mode
17
+ from simple_module_core.access.tenancy import TenancyMode, tenant_member_ids
18
+ from simple_module_db.scoping.tenancy import current_tenant_id
19
+ from simple_module_hosting.pipeline.tenancy import tenancy_mode
20
20
 
21
21
 
22
22
  class Audience:
@@ -4,9 +4,8 @@ from __future__ import annotations
4
4
 
5
5
  from typing import Final
6
6
 
7
- from simple_module_core.deprecation import deprecate
8
- from simple_module_core.permissions import PermissionCatalogue
9
- from simple_module_core.resources import ACTION_EDIT, ACTION_VIEW
7
+ from simple_module_core.access.permissions import PermissionCatalogue
8
+ from simple_module_core.access.resources import ACTION_EDIT, ACTION_VIEW
10
9
 
11
10
  MODULE_NAME: Final = "Sharing"
12
11
  MODULE_PACKAGE: Final = "sharing"
@@ -26,19 +25,12 @@ class Permissions(PermissionCatalogue, group=PERM_GROUP, label_key="sharing.perm
26
25
  DIRECTORY_SEARCH = "sharing.directory_search"
27
26
 
28
27
 
29
- deprecate(
30
- "sharing PERM_* constants",
31
- remove_in="0.0.50",
32
- use="sharing.core.constants.Permissions",
33
- )
34
- PERM_SHARE: Final = Permissions.SHARE
35
- PERM_MANAGE: Final = Permissions.MANAGE
36
-
37
28
  USER_ROLE: Final = "user"
38
29
 
39
30
  PAGE_ADMIN: Final = "Sharing/Admin"
40
31
 
41
32
  API_PREFIX: Final = "/api/sharing"
33
+ ADMIN_API_PATH: Final = "/admin"
42
34
  CANDIDATES_URL: Final = f"{API_PREFIX}/candidates"
43
35
  CANDIDATES_RATE: Final = "60/minute"
44
36
  CANDIDATES_DAILY_RATE: Final = "500/day"
@@ -2,11 +2,12 @@
2
2
 
3
3
  ::
4
4
 
5
+ from notes.core.constants import Permissions
5
6
  from sharing.core.policy import share_exists_for
6
7
 
7
8
  NOTE_POLICY = OwnedResourcePolicy(
8
9
  Note.owner_id,
9
- bypass_perm=PERM_NOTES_MANAGE,
10
+ bypass_perm=Permissions.MANAGE,
10
11
  share_exists=share_exists_for(NOTE_TYPE, Note.id),
11
12
  )
12
13
  """
@@ -18,7 +19,7 @@ from collections.abc import Callable, Mapping
18
19
  from datetime import UTC, datetime
19
20
  from typing import Any
20
21
 
21
- from simple_module_core.resources import ResourcePrincipal
22
+ from simple_module_core.access.resources import ResourcePrincipal
22
23
  from sqlalchemy import String, cast, func, inspect, or_
23
24
  from sqlmodel import exists, select
24
25
 
@@ -12,16 +12,16 @@ import uuid
12
12
  from collections.abc import Callable
13
13
  from typing import Any
14
14
 
15
- from simple_module_core.datetimes import aware as _aware
16
- from simple_module_core.datetimes import utcnow
17
- from simple_module_core.resources import (
15
+ from simple_module_core.access.resources import (
18
16
  ACTION_SHARE,
19
17
  ResourcePrincipal,
20
18
  ResourceType,
21
19
  ResourceTypeRegistry,
22
20
  )
23
- from simple_module_core.user_directory import UserDirectory
24
- from simple_module_db.resource_policy import load_authorized
21
+ from simple_module_core.access.user_directory import UserDirectory
22
+ from simple_module_core.runtime.datetimes import aware as _aware
23
+ from simple_module_core.runtime.datetimes import utcnow
24
+ from simple_module_db.queries.resource_policy import load_authorized
25
25
  from sqlalchemy.exc import IntegrityError
26
26
  from sqlalchemy.ext.asyncio import AsyncSession
27
27
  from sqlmodel import select
@@ -5,10 +5,10 @@ from __future__ import annotations
5
5
  import unicodedata
6
6
  from collections.abc import Collection, Mapping
7
7
 
8
- from simple_module_core.resources import ResourcePrincipal
9
- from simple_module_core.tenancy import TenantRole, tenant_role
10
- from simple_module_core.user_directory import resolve_user_labels
11
- from simple_module_db.tenancy import current_tenant_id
8
+ from simple_module_core.access.resources import ResourcePrincipal
9
+ from simple_module_core.access.tenancy import TenantRole, tenant_role
10
+ from simple_module_core.access.user_directory import resolve_user_labels
11
+ from simple_module_db.scoping.tenancy import current_tenant_id
12
12
  from sqlalchemy import false
13
13
 
14
14
  from sharing.contracts.schemas import ShareCandidate
@@ -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
- local, separator, domain = user.email.rpartition("@")
45
- email = f"{local[:1]}•••@{domain}" if separator else "•••"
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))
@@ -1,8 +1,8 @@
1
1
  """Durable teardown of tenant-owned sharing rows."""
2
2
 
3
- from simple_module_core.durable_events import DurableContext
3
+ from simple_module_core.eventing.durable_events import DurableContext
4
4
  from simple_module_core.tenant_events import TenantDeleted
5
- from simple_module_db.tenancy import tenant_context
5
+ from simple_module_db.scoping.tenancy import tenant_context
6
6
  from sqlmodel import delete
7
7
 
8
8
  from sharing.models import ResourceShare
@@ -4,7 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  from typing import TYPE_CHECKING
6
6
 
7
- from simple_module_core.durable_events import DurableContext
7
+ from simple_module_core.eventing.durable_events import DurableContext
8
8
  from simple_module_db import all_tenants
9
9
  from sqlmodel import col, delete
10
10
 
@@ -5,8 +5,8 @@ from __future__ import annotations
5
5
  import uuid
6
6
  from datetime import datetime
7
7
 
8
- from simple_module_db.base import create_module_base
9
- from simple_module_db.mixins import AuditMixin, MultiTenantMixin
8
+ from simple_module_db.models.base import create_module_base
9
+ from simple_module_db.models.mixins import AuditMixin, MultiTenantMixin
10
10
  from sqlalchemy import Index, UniqueConstraint
11
11
  from sqlmodel import Field
12
12
 
@@ -5,18 +5,18 @@ from __future__ import annotations
5
5
  from typing import TYPE_CHECKING
6
6
 
7
7
  from simple_module_core import ModuleBase, ModuleMeta
8
- from simple_module_core.audit_links import AuditLink
9
- from simple_module_core.menu import MenuItem, MenuRegistry, MenuSection
10
- from simple_module_core.tenancy import TenantRole, tenant_role
8
+ from simple_module_core.access.tenancy import TenantRole, tenant_role
9
+ from simple_module_core.web.audit_links import AuditLink
10
+ from simple_module_core.web.menu import MenuItem, MenuRegistry, MenuSection
11
11
 
12
12
  from sharing.core import constants as c
13
13
 
14
14
  if TYPE_CHECKING:
15
15
  from fastapi import FastAPI
16
- from simple_module_core.audit_links import AuditLinkRegistry
17
- from simple_module_core.events import EventBus
18
- from simple_module_core.permissions import PermissionRegistry
19
- from simple_module_core.rate_limit import RateLimitRegistry
16
+ from simple_module_core.access.permissions import PermissionRegistry
17
+ from simple_module_core.eventing.events import EventBus
18
+ from simple_module_core.web.audit_links import AuditLinkRegistry
19
+ from simple_module_core.web.rate_limit import RateLimitRegistry
20
20
 
21
21
 
22
22
  class SharingModule(ModuleBase):
@@ -28,6 +28,15 @@ class SharingModule(ModuleBase):
28
28
  view_prefix=c.VIEW_PREFIX,
29
29
  )
30
30
 
31
+ def register_routes(self, api_router, view_router) -> None:
32
+ from sharing.web.endpoints.admin_api import router as admin_api
33
+ from sharing.web.endpoints.api import router as api
34
+ from sharing.web.endpoints.views import router as views
35
+
36
+ api_router.include_router(api)
37
+ api_router.include_router(admin_api)
38
+ view_router.include_router(views)
39
+
31
40
  def register_principal_builder(self, registry) -> None:
32
41
  from sharing.contracts.subjects import get_subject_registry
33
42
 
@@ -70,7 +79,7 @@ class SharingModule(ModuleBase):
70
79
  registry.map_role(tenant_role(role), [c.Permissions.SHARE])
71
80
 
72
81
  def register_rate_limits(self, registry: RateLimitRegistry) -> None:
73
- from simple_module_core.rate_limit import RateLimitRule
82
+ from simple_module_core.web.rate_limit import RateLimitRule
74
83
 
75
84
  registry.add_exact(
76
85
  c.CANDIDATES_URL,
@@ -78,6 +78,40 @@ export interface paths {
78
78
  patch?: never;
79
79
  trace?: never;
80
80
  };
81
+ "/api/sharing/admin/shares": {
82
+ parameters: {
83
+ query?: never;
84
+ header?: never;
85
+ path?: never;
86
+ cookie?: never;
87
+ };
88
+ /** Admin List Shares */
89
+ get: operations["sharing_admin_list_shares"];
90
+ put?: never;
91
+ post?: never;
92
+ delete?: never;
93
+ options?: never;
94
+ head?: never;
95
+ patch?: never;
96
+ trace?: never;
97
+ };
98
+ "/api/sharing/admin/shares/{share_id}/revoke": {
99
+ parameters: {
100
+ query?: never;
101
+ header?: never;
102
+ path?: never;
103
+ cookie?: never;
104
+ };
105
+ get?: never;
106
+ put?: never;
107
+ /** Admin Revoke Share */
108
+ post: operations["sharing_admin_revoke_share"];
109
+ delete?: never;
110
+ options?: never;
111
+ head?: never;
112
+ patch?: never;
113
+ trace?: never;
114
+ };
81
115
  }
82
116
  export type webhooks = Record<string, never>;
83
117
  export interface components {
@@ -161,6 +195,19 @@ export interface components {
161
195
  /** Created At */
162
196
  created_at?: string | null;
163
197
  };
198
+ /** SharePage */
199
+ SharePage: {
200
+ /** Items */
201
+ items: components["schemas"]["ShareOut"][];
202
+ /** Total */
203
+ total: number;
204
+ /** Page */
205
+ page: number;
206
+ /** Per Page */
207
+ per_page: number;
208
+ /** Pages */
209
+ pages: number;
210
+ };
164
211
  /** ShareSubjectType */
165
212
  ShareSubjectType: {
166
213
  /** Subject Type */
@@ -350,6 +397,67 @@ export interface operations {
350
397
  };
351
398
  };
352
399
  };
400
+ sharing_admin_list_shares: {
401
+ parameters: {
402
+ query?: {
403
+ page?: number;
404
+ per_page?: number;
405
+ };
406
+ header?: never;
407
+ path?: never;
408
+ cookie?: never;
409
+ };
410
+ requestBody?: never;
411
+ responses: {
412
+ /** @description Successful Response */
413
+ 200: {
414
+ headers: {
415
+ [name: string]: unknown;
416
+ };
417
+ content: {
418
+ "application/json": components["schemas"]["SharePage"];
419
+ };
420
+ };
421
+ /** @description Validation Error */
422
+ 422: {
423
+ headers: {
424
+ [name: string]: unknown;
425
+ };
426
+ content: {
427
+ "application/json": components["schemas"]["HTTPValidationError"];
428
+ };
429
+ };
430
+ };
431
+ };
432
+ sharing_admin_revoke_share: {
433
+ parameters: {
434
+ query?: never;
435
+ header?: never;
436
+ path: {
437
+ share_id: string;
438
+ };
439
+ cookie?: never;
440
+ };
441
+ requestBody?: never;
442
+ responses: {
443
+ /** @description Successful Response */
444
+ 204: {
445
+ headers: {
446
+ [name: string]: unknown;
447
+ };
448
+ content?: never;
449
+ };
450
+ /** @description Validation Error */
451
+ 422: {
452
+ headers: {
453
+ [name: string]: unknown;
454
+ };
455
+ content: {
456
+ "application/json": components["schemas"]["HTTPValidationError"];
457
+ };
458
+ };
459
+ };
460
+ };
353
461
  }
354
462
 
355
463
  export const api = createApi<paths>();
@@ -1,6 +1,6 @@
1
1
  import '@simple-module-py/i18n';
2
2
 
3
- // AUTO-GENERATED by simple_module_hosting.i18n_manifest — do not edit by hand.
3
+ // AUTO-GENERATED by simple_module_hosting.i18n.i18n_manifest — do not edit by hand.
4
4
  // Regenerate by booting the host in development mode or `make gen-i18n`.
5
5
 
6
6
  export const keys = {
@@ -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({ resourceType, resourceId, roles }: ShareDialogProps) {
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 [open, setOpen] = useState(false);
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
- open={open}
58
- onOpenChange={(next) => {
59
- if (!state.pending) setOpen(next);
60
- }}
61
- >
62
- <DialogTrigger asChild>
63
- <Button type="button" variant="outline">
64
- {t(keys.sharing.dialog.button)}
65
- </Button>
66
- </DialogTrigger>
67
- <DialogContent className="max-h-[85vh] overflow-y-auto" showCloseButton={false}>
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>
@@ -5,9 +5,9 @@ from __future__ import annotations
5
5
  from typing import Annotated
6
6
 
7
7
  from fastapi import Depends, HTTPException, Request
8
- from simple_module_core.user_directory import get_user_directory
9
- from simple_module_db.deps import get_db
10
- from simple_module_hosting.i18n_deps import TranslatorDep
8
+ from simple_module_core.access.user_directory import get_user_directory
9
+ from simple_module_db.engine.deps import get_db
10
+ from simple_module_hosting.i18n.i18n_deps import TranslatorDep
11
11
  from sqlalchemy.ext.asyncio import AsyncSession
12
12
 
13
13
  from sharing.contracts import get_subject_registry
@@ -0,0 +1,69 @@
1
+ """Admin REST API for shares — mounted under ``/api/sharing/admin``.
2
+
3
+ Mirrors the admin page (``sharing.view`` to list, ``sharing.manage`` to revoke)
4
+ and deliberately sits outside the ``sharing.share`` router in ``api.py``, so a
5
+ token scoped to the admin permissions does not also need ``sharing.share``.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import uuid
11
+
12
+ from fastapi import APIRouter, Depends, HTTPException, Request
13
+ from simple_module_core.access.resources import ResourcePrincipal
14
+ from simple_module_db import TenantIsolationError
15
+ from simple_module_hosting.auth.csrf import RequiresCsrf
16
+ from simple_module_hosting.auth.permissions import RequiresPermission
17
+ from simple_module_hosting.auth.resource_deps import resource_principal
18
+ from simple_module_hosting.frontend.pagination import PageParamsDep
19
+
20
+ from sharing.contracts.schemas import SharePage
21
+ from sharing.core.constants import ADMIN_API_PATH, Permissions
22
+ from sharing.core.service import SharingError
23
+ from sharing.web.deps import SharingServiceDep, http_error
24
+ from sharing.web.listing import list_admin_shares
25
+
26
+ TENANT_REQUIRED = "tenant_required"
27
+
28
+ router = APIRouter(prefix=ADMIN_API_PATH)
29
+
30
+
31
+ @router.get(
32
+ "/shares",
33
+ response_model=SharePage,
34
+ dependencies=[Depends(RequiresPermission(Permissions.VIEW))],
35
+ )
36
+ async def admin_list_shares(
37
+ request: Request,
38
+ service: SharingServiceDep,
39
+ params: PageParamsDep,
40
+ who: ResourcePrincipal = Depends(resource_principal),
41
+ ) -> SharePage:
42
+ listing = await list_admin_shares(request, service, params, who)
43
+ return SharePage(
44
+ items=listing.shares,
45
+ total=listing.total,
46
+ page=listing.page,
47
+ per_page=params.per_page,
48
+ pages=listing.pages,
49
+ )
50
+
51
+
52
+ @router.post(
53
+ "/shares/{share_id}/revoke",
54
+ status_code=204,
55
+ dependencies=[Depends(RequiresPermission(Permissions.MANAGE)), Depends(RequiresCsrf())],
56
+ )
57
+ async def admin_revoke_share(
58
+ share_id: uuid.UUID,
59
+ service: SharingServiceDep,
60
+ who: ResourcePrincipal = Depends(resource_principal),
61
+ ) -> None:
62
+ try:
63
+ await service.revoke(who, share_id)
64
+ except SharingError as exc:
65
+ raise http_error(exc) from None
66
+ except TenantIsolationError:
67
+ # Strict tenancy and no active tenant (a platform admin before picking one):
68
+ # same fail-closed answer the tenant-level APIs give.
69
+ raise HTTPException(status_code=403, detail=TENANT_REQUIRED) from None
@@ -9,11 +9,11 @@ from __future__ import annotations
9
9
  import uuid
10
10
 
11
11
  from fastapi import APIRouter, Depends, Query, Request
12
- from simple_module_core.resources import ResourcePrincipal
13
- from simple_module_core.user_directory import get_user_directory
14
- from simple_module_hosting.permissions import RequiresPermission
15
- from simple_module_hosting.rate_limit_deps import RateLimit
16
- from simple_module_hosting.resource_deps import resource_principal
12
+ from simple_module_core.access.resources import ResourcePrincipal
13
+ from simple_module_core.access.user_directory import get_user_directory
14
+ from simple_module_hosting.auth.permissions import RequiresPermission
15
+ from simple_module_hosting.auth.resource_deps import resource_principal
16
+ from simple_module_hosting.rate_limit.rate_limit_deps import RateLimit
17
17
 
18
18
  from sharing.contracts.schemas import ShareCandidate, ShareGrant, ShareOut, ShareSubjectType
19
19
  from sharing.core.constants import CANDIDATES_DAILY_RATE, SUBJECT_USER, Permissions