@open-mercato/core 0.6.6 → 0.6.7-develop.6553.1.2ec7246e04

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 (271) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/dist/generated/entities/gateway_session_initialization/index.js +23 -0
  3. package/dist/generated/entities/gateway_session_initialization/index.js.map +7 -0
  4. package/dist/generated/entities.ids.generated.js +1 -0
  5. package/dist/generated/entities.ids.generated.js.map +2 -2
  6. package/dist/generated/entity-fields-registry.js +12 -0
  7. package/dist/generated/entity-fields-registry.js.map +2 -2
  8. package/dist/modules/api_keys/api/keys/route.js +30 -13
  9. package/dist/modules/api_keys/api/keys/route.js.map +2 -2
  10. package/dist/modules/api_keys/cli.js +2 -1
  11. package/dist/modules/api_keys/cli.js.map +2 -2
  12. package/dist/modules/attachments/api/file/[id]/route.js +9 -7
  13. package/dist/modules/attachments/api/file/[id]/route.js.map +2 -2
  14. package/dist/modules/attachments/api/image/[id]/[[...slug]]/route.js +9 -7
  15. package/dist/modules/attachments/api/image/[id]/[[...slug]]/route.js.map +2 -2
  16. package/dist/modules/attachments/api/route.js +21 -17
  17. package/dist/modules/attachments/api/route.js.map +2 -2
  18. package/dist/modules/attachments/components/AttachmentContentPreview.js +6 -35
  19. package/dist/modules/attachments/components/AttachmentContentPreview.js.map +2 -2
  20. package/dist/modules/attachments/lib/reconcileOrganization.js +110 -0
  21. package/dist/modules/attachments/lib/reconcileOrganization.js.map +7 -0
  22. package/dist/modules/attachments/lib/requestScope.js +10 -0
  23. package/dist/modules/attachments/lib/requestScope.js.map +7 -0
  24. package/dist/modules/audit_logs/backend/audit-logs/page.js +14 -24
  25. package/dist/modules/audit_logs/backend/audit-logs/page.js.map +2 -2
  26. package/dist/modules/auth/api/autologin.js +85 -0
  27. package/dist/modules/auth/api/autologin.js.map +7 -0
  28. package/dist/modules/auth/api/users/route.js +6 -2
  29. package/dist/modules/auth/api/users/route.js.map +2 -2
  30. package/dist/modules/auth/cli.js +3 -2
  31. package/dist/modules/auth/cli.js.map +2 -2
  32. package/dist/modules/auth/lib/autologin.js +19 -0
  33. package/dist/modules/auth/lib/autologin.js.map +7 -0
  34. package/dist/modules/configs/lib/upgrade-actions.js +22 -0
  35. package/dist/modules/configs/lib/upgrade-actions.js.map +2 -2
  36. package/dist/modules/customer_accounts/api/admin/roles/[id]/acl.js +1 -0
  37. package/dist/modules/customer_accounts/api/admin/roles/[id]/acl.js.map +2 -2
  38. package/dist/modules/customer_accounts/api/admin/roles/[id].js +17 -3
  39. package/dist/modules/customer_accounts/api/admin/roles/[id].js.map +2 -2
  40. package/dist/modules/customer_accounts/api/portal/users/[id]/roles.js +6 -1
  41. package/dist/modules/customer_accounts/api/portal/users/[id]/roles.js.map +2 -2
  42. package/dist/modules/customer_accounts/api/portal/users-invite.js +6 -1
  43. package/dist/modules/customer_accounts/api/portal/users-invite.js.map +2 -2
  44. package/dist/modules/customer_accounts/services/customerInvitationService.js +1 -0
  45. package/dist/modules/customer_accounts/services/customerInvitationService.js.map +2 -2
  46. package/dist/modules/customer_accounts/services/customerRbacService.js +6 -1
  47. package/dist/modules/customer_accounts/services/customerRbacService.js.map +2 -2
  48. package/dist/modules/customer_accounts/widgets/injection-table.js +0 -2
  49. package/dist/modules/customer_accounts/widgets/injection-table.js.map +2 -2
  50. package/dist/modules/customers/backend/customers/companies-v2/[id]/page.js +7 -1
  51. package/dist/modules/customers/backend/customers/companies-v2/[id]/page.js.map +2 -2
  52. package/dist/modules/customers/backend/customers/deals/pipeline/components/ViewTabsRow.js +2 -2
  53. package/dist/modules/customers/backend/customers/deals/pipeline/components/ViewTabsRow.js.map +2 -2
  54. package/dist/modules/customers/components/detail/CompanyDetailTabs.js +37 -43
  55. package/dist/modules/customers/components/detail/CompanyDetailTabs.js.map +2 -2
  56. package/dist/modules/customers/components/detail/DealDetailTabs.js +23 -35
  57. package/dist/modules/customers/components/detail/DealDetailTabs.js.map +2 -2
  58. package/dist/modules/customers/components/detail/DetailTabsLayout.js +6 -21
  59. package/dist/modules/customers/components/detail/DetailTabsLayout.js.map +2 -2
  60. package/dist/modules/customers/components/detail/MobilePersonDetail.js +26 -32
  61. package/dist/modules/customers/components/detail/MobilePersonDetail.js.map +2 -2
  62. package/dist/modules/customers/components/detail/PersonDetailTabs.js +29 -39
  63. package/dist/modules/customers/components/detail/PersonDetailTabs.js.map +2 -2
  64. package/dist/modules/customers/components/detail/useDealsAccess.js +16 -0
  65. package/dist/modules/customers/components/detail/useDealsAccess.js.map +7 -0
  66. package/dist/modules/dashboards/api/roles/widgets/route.js +22 -3
  67. package/dist/modules/dashboards/api/roles/widgets/route.js.map +2 -2
  68. package/dist/modules/dashboards/api/users/widgets/route.js +22 -3
  69. package/dist/modules/dashboards/api/users/widgets/route.js.map +2 -2
  70. package/dist/modules/dashboards/cli.js +4 -3
  71. package/dist/modules/dashboards/cli.js.map +2 -2
  72. package/dist/modules/dashboards/lib/widgetAssignmentScope.js +9 -1
  73. package/dist/modules/dashboards/lib/widgetAssignmentScope.js.map +2 -2
  74. package/dist/modules/dictionaries/commands/entries.js +7 -14
  75. package/dist/modules/dictionaries/commands/entries.js.map +2 -2
  76. package/dist/modules/dictionaries/commands/entry-operations.js +7 -16
  77. package/dist/modules/dictionaries/commands/entry-operations.js.map +2 -2
  78. package/dist/modules/dictionaries/commands/factory.js +9 -3
  79. package/dist/modules/dictionaries/commands/factory.js.map +2 -2
  80. package/dist/modules/dictionaries/fields/dictionary.js +56 -41
  81. package/dist/modules/dictionaries/fields/dictionary.js.map +2 -2
  82. package/dist/modules/directory/utils/organizationScope.js +10 -3
  83. package/dist/modules/directory/utils/organizationScope.js.map +2 -2
  84. package/dist/modules/entities/api/records.js +5 -4
  85. package/dist/modules/entities/api/records.js.map +2 -2
  86. package/dist/modules/entities/backend/entities/system/[entityId]/page.meta.js +1 -0
  87. package/dist/modules/entities/backend/entities/system/[entityId]/page.meta.js.map +2 -2
  88. package/dist/modules/entities/backend/entities/user/[entityId]/page.js +49 -49
  89. package/dist/modules/entities/backend/entities/user/[entityId]/page.js.map +2 -2
  90. package/dist/modules/entities/backend/entities/user/[entityId]/page.meta.js +1 -0
  91. package/dist/modules/entities/backend/entities/user/[entityId]/page.meta.js.map +2 -2
  92. package/dist/modules/entities/cli.js +2 -1
  93. package/dist/modules/entities/cli.js.map +2 -2
  94. package/dist/modules/feature_toggles/api/check/boolean/route.js +0 -14
  95. package/dist/modules/feature_toggles/api/check/boolean/route.js.map +2 -2
  96. package/dist/modules/feature_toggles/defaults.json +8 -0
  97. package/dist/modules/integrations/backend/integrations/[id]/page.js +9 -80
  98. package/dist/modules/integrations/backend/integrations/[id]/page.js.map +2 -2
  99. package/dist/modules/payment_gateways/data/entities.js +45 -0
  100. package/dist/modules/payment_gateways/data/entities.js.map +2 -2
  101. package/dist/modules/payment_gateways/lib/gateway-service.js +173 -38
  102. package/dist/modules/payment_gateways/lib/gateway-service.js.map +3 -3
  103. package/dist/modules/payment_gateways/lib/session-idempotency.js +104 -0
  104. package/dist/modules/payment_gateways/lib/session-idempotency.js.map +7 -0
  105. package/dist/modules/payment_gateways/migrations/Migration20260709220938_payment_gateways.js +11 -0
  106. package/dist/modules/payment_gateways/migrations/Migration20260709220938_payment_gateways.js.map +7 -0
  107. package/dist/modules/planner/backend/planner/availability-rulesets/[id]/page.js +16 -14
  108. package/dist/modules/planner/backend/planner/availability-rulesets/[id]/page.js.map +2 -2
  109. package/dist/modules/planner/components/AvailabilityRulesEditor.js +18 -30
  110. package/dist/modules/planner/components/AvailabilityRulesEditor.js.map +2 -2
  111. package/dist/modules/query_index/api/status.js +2 -8
  112. package/dist/modules/query_index/api/status.js.map +2 -2
  113. package/dist/modules/resources/backend/resources/resources/[id]/page.js +24 -24
  114. package/dist/modules/resources/backend/resources/resources/[id]/page.js.map +2 -2
  115. package/dist/modules/sales/backend/sales/channels/create/page.js +6 -0
  116. package/dist/modules/sales/backend/sales/channels/create/page.js.map +2 -2
  117. package/dist/modules/sales/backend/sales/channels/create/page.meta.js +2 -0
  118. package/dist/modules/sales/backend/sales/channels/create/page.meta.js.map +2 -2
  119. package/dist/modules/sales/backend/sales/channels/offers/page.js +6 -0
  120. package/dist/modules/sales/backend/sales/channels/offers/page.js.map +2 -2
  121. package/dist/modules/sales/backend/sales/channels/offers/page.meta.js +2 -0
  122. package/dist/modules/sales/backend/sales/channels/offers/page.meta.js.map +2 -2
  123. package/dist/modules/sales/backend/sales/channels/page.js +6 -0
  124. package/dist/modules/sales/backend/sales/channels/page.js.map +2 -2
  125. package/dist/modules/sales/backend/sales/channels/page.meta.js +2 -0
  126. package/dist/modules/sales/backend/sales/channels/page.meta.js.map +2 -2
  127. package/dist/modules/sales/backend/sales/documents/[id]/page.js +6 -4
  128. package/dist/modules/sales/backend/sales/documents/[id]/page.js.map +2 -2
  129. package/dist/modules/sales/commands/documents.js +44 -0
  130. package/dist/modules/sales/commands/documents.js.map +2 -2
  131. package/dist/modules/sales/commands/returns.js +2 -27
  132. package/dist/modules/sales/commands/returns.js.map +2 -2
  133. package/dist/modules/sales/components/SalesChannelsDisabledNotice.js +15 -0
  134. package/dist/modules/sales/components/SalesChannelsDisabledNotice.js.map +7 -0
  135. package/dist/modules/sales/components/documents/AddressesSection.js +6 -2
  136. package/dist/modules/sales/components/documents/AddressesSection.js.map +2 -2
  137. package/dist/modules/sales/components/documents/ItemsSection.js +1 -0
  138. package/dist/modules/sales/components/documents/ItemsSection.js.map +2 -2
  139. package/dist/modules/sales/components/documents/LineItemDialog.js +9 -0
  140. package/dist/modules/sales/components/documents/LineItemDialog.js.map +2 -2
  141. package/dist/modules/sales/components/documents/SalesDocumentForm.js +51 -3
  142. package/dist/modules/sales/components/documents/SalesDocumentForm.js.map +2 -2
  143. package/dist/modules/sales/components/documents/SalesDocumentsTable.js +10 -8
  144. package/dist/modules/sales/components/documents/SalesDocumentsTable.js.map +2 -2
  145. package/dist/modules/sales/components/documents/ShipmentDialog.js +59 -38
  146. package/dist/modules/sales/components/documents/ShipmentDialog.js.map +2 -2
  147. package/dist/modules/sales/components/useSalesChannelsEnabled.js +44 -0
  148. package/dist/modules/sales/components/useSalesChannelsEnabled.js.map +7 -0
  149. package/dist/modules/sales/lib/calculations.js +6 -0
  150. package/dist/modules/sales/lib/calculations.js.map +2 -2
  151. package/dist/modules/sales/lib/salesChannelsToggle.js +18 -0
  152. package/dist/modules/sales/lib/salesChannelsToggle.js.map +7 -0
  153. package/dist/modules/sales/lib/salesChannelsToggleId.js +5 -0
  154. package/dist/modules/sales/lib/salesChannelsToggleId.js.map +7 -0
  155. package/dist/modules/sales/lib/shipments/snapshots.js +27 -1
  156. package/dist/modules/sales/lib/shipments/snapshots.js.map +2 -2
  157. package/dist/modules/staff/backend/staff/team-members/[id]/page.js +22 -25
  158. package/dist/modules/staff/backend/staff/team-members/[id]/page.js.map +2 -2
  159. package/dist/modules/staff/backend/staff/teams/[id]/edit/page.js +12 -14
  160. package/dist/modules/staff/backend/staff/teams/[id]/edit/page.js.map +2 -2
  161. package/dist/modules/staff/lib/timesheets-projects-ui/SavedViewTabs.js +10 -29
  162. package/dist/modules/staff/lib/timesheets-projects-ui/SavedViewTabs.js.map +2 -2
  163. package/dist/modules/sync_excel/lib/adapters/customers.js +19 -20
  164. package/dist/modules/sync_excel/lib/adapters/customers.js.map +2 -2
  165. package/dist/modules/sync_excel/lib/parser.js +185 -0
  166. package/dist/modules/sync_excel/lib/parser.js.map +2 -2
  167. package/dist/modules/sync_excel/lib/upload-storage.js +20 -1
  168. package/dist/modules/sync_excel/lib/upload-storage.js.map +2 -2
  169. package/generated/entities/gateway_session_initialization/index.ts +10 -0
  170. package/generated/entities.ids.generated.ts +1 -0
  171. package/generated/entity-fields-registry.ts +12 -0
  172. package/package.json +9 -8
  173. package/src/modules/api_keys/api/keys/route.ts +36 -13
  174. package/src/modules/api_keys/cli.ts +2 -3
  175. package/src/modules/attachments/api/file/[id]/route.ts +11 -7
  176. package/src/modules/attachments/api/image/[id]/[[...slug]]/route.ts +11 -7
  177. package/src/modules/attachments/api/route.ts +26 -21
  178. package/src/modules/attachments/components/AttachmentContentPreview.tsx +9 -44
  179. package/src/modules/attachments/lib/reconcileOrganization.ts +188 -0
  180. package/src/modules/attachments/lib/requestScope.ts +27 -0
  181. package/src/modules/audit_logs/backend/audit-logs/page.tsx +12 -22
  182. package/src/modules/auth/api/autologin.ts +100 -0
  183. package/src/modules/auth/api/users/route.ts +11 -2
  184. package/src/modules/auth/cli.ts +3 -2
  185. package/src/modules/auth/lib/autologin.ts +36 -0
  186. package/src/modules/configs/i18n/de.json +5 -1
  187. package/src/modules/configs/i18n/en.json +5 -1
  188. package/src/modules/configs/i18n/es.json +5 -1
  189. package/src/modules/configs/i18n/pl.json +5 -1
  190. package/src/modules/configs/lib/upgrade-actions.ts +24 -0
  191. package/src/modules/customer_accounts/AGENTS.md +8 -6
  192. package/src/modules/customer_accounts/api/admin/roles/[id]/acl.ts +1 -0
  193. package/src/modules/customer_accounts/api/admin/roles/[id].ts +17 -3
  194. package/src/modules/customer_accounts/api/portal/users/[id]/roles.ts +6 -1
  195. package/src/modules/customer_accounts/api/portal/users-invite.ts +6 -1
  196. package/src/modules/customer_accounts/services/customerInvitationService.ts +1 -0
  197. package/src/modules/customer_accounts/services/customerRbacService.ts +9 -2
  198. package/src/modules/customer_accounts/widgets/injection-table.ts +0 -2
  199. package/src/modules/customers/backend/customers/companies-v2/[id]/page.tsx +11 -1
  200. package/src/modules/customers/backend/customers/deals/pipeline/components/ViewTabsRow.tsx +6 -2
  201. package/src/modules/customers/components/detail/CompanyDetailTabs.tsx +39 -55
  202. package/src/modules/customers/components/detail/DealDetailTabs.tsx +24 -49
  203. package/src/modules/customers/components/detail/DetailTabsLayout.tsx +13 -24
  204. package/src/modules/customers/components/detail/MobilePersonDetail.tsx +25 -31
  205. package/src/modules/customers/components/detail/PersonDetailTabs.tsx +29 -50
  206. package/src/modules/customers/components/detail/useDealsAccess.ts +19 -0
  207. package/src/modules/dashboards/api/roles/widgets/route.ts +22 -3
  208. package/src/modules/dashboards/api/users/widgets/route.ts +22 -3
  209. package/src/modules/dashboards/cli.ts +4 -9
  210. package/src/modules/dashboards/lib/widgetAssignmentScope.ts +18 -0
  211. package/src/modules/dictionaries/commands/entries.ts +7 -16
  212. package/src/modules/dictionaries/commands/entry-operations.ts +8 -18
  213. package/src/modules/dictionaries/commands/factory.ts +8 -2
  214. package/src/modules/dictionaries/fields/dictionary.tsx +55 -32
  215. package/src/modules/dictionaries/i18n/de.json +2 -0
  216. package/src/modules/dictionaries/i18n/en.json +2 -0
  217. package/src/modules/dictionaries/i18n/es.json +2 -0
  218. package/src/modules/dictionaries/i18n/pl.json +2 -0
  219. package/src/modules/directory/utils/organizationScope.ts +36 -2
  220. package/src/modules/entities/api/records.ts +5 -7
  221. package/src/modules/entities/backend/entities/system/[entityId]/page.meta.ts +1 -0
  222. package/src/modules/entities/backend/entities/user/[entityId]/page.meta.ts +1 -0
  223. package/src/modules/entities/backend/entities/user/[entityId]/page.tsx +51 -49
  224. package/src/modules/entities/cli.ts +2 -1
  225. package/src/modules/entities/i18n/de.json +34 -0
  226. package/src/modules/entities/i18n/en.json +34 -0
  227. package/src/modules/entities/i18n/es.json +34 -0
  228. package/src/modules/entities/i18n/pl.json +34 -0
  229. package/src/modules/feature_toggles/api/check/boolean/route.ts +0 -15
  230. package/src/modules/feature_toggles/defaults.json +8 -0
  231. package/src/modules/integrations/backend/integrations/[id]/page.tsx +16 -59
  232. package/src/modules/payment_gateways/data/entities.ts +39 -0
  233. package/src/modules/payment_gateways/lib/gateway-service.ts +211 -40
  234. package/src/modules/payment_gateways/lib/session-idempotency.ts +142 -0
  235. package/src/modules/payment_gateways/migrations/.snapshot-open-mercato.json +236 -0
  236. package/src/modules/payment_gateways/migrations/Migration20260709220938_payment_gateways.ts +10 -0
  237. package/src/modules/planner/backend/planner/availability-rulesets/[id]/page.tsx +14 -20
  238. package/src/modules/planner/components/AvailabilityRulesEditor.tsx +16 -34
  239. package/src/modules/query_index/api/status.ts +2 -8
  240. package/src/modules/resources/backend/resources/resources/[id]/page.tsx +27 -37
  241. package/src/modules/sales/backend/sales/channels/create/page.meta.ts +3 -0
  242. package/src/modules/sales/backend/sales/channels/create/page.tsx +7 -0
  243. package/src/modules/sales/backend/sales/channels/offers/page.meta.ts +3 -0
  244. package/src/modules/sales/backend/sales/channels/offers/page.tsx +7 -0
  245. package/src/modules/sales/backend/sales/channels/page.meta.ts +4 -0
  246. package/src/modules/sales/backend/sales/channels/page.tsx +7 -0
  247. package/src/modules/sales/backend/sales/documents/[id]/page.tsx +7 -5
  248. package/src/modules/sales/commands/documents.ts +65 -0
  249. package/src/modules/sales/commands/returns.ts +2 -32
  250. package/src/modules/sales/components/SalesChannelsDisabledNotice.tsx +21 -0
  251. package/src/modules/sales/components/documents/AddressesSection.tsx +6 -2
  252. package/src/modules/sales/components/documents/ItemsSection.tsx +5 -0
  253. package/src/modules/sales/components/documents/LineItemDialog.tsx +10 -0
  254. package/src/modules/sales/components/documents/SalesDocumentForm.tsx +53 -3
  255. package/src/modules/sales/components/documents/SalesDocumentsTable.tsx +10 -8
  256. package/src/modules/sales/components/documents/ShipmentDialog.tsx +65 -40
  257. package/src/modules/sales/components/useSalesChannelsEnabled.ts +59 -0
  258. package/src/modules/sales/i18n/de.json +5 -0
  259. package/src/modules/sales/i18n/en.json +5 -0
  260. package/src/modules/sales/i18n/es.json +5 -0
  261. package/src/modules/sales/i18n/pl.json +5 -0
  262. package/src/modules/sales/lib/calculations.ts +15 -0
  263. package/src/modules/sales/lib/salesChannelsToggle.ts +26 -0
  264. package/src/modules/sales/lib/salesChannelsToggleId.ts +1 -0
  265. package/src/modules/sales/lib/shipments/snapshots.ts +30 -0
  266. package/src/modules/staff/backend/staff/team-members/[id]/page.tsx +25 -34
  267. package/src/modules/staff/backend/staff/teams/[id]/edit/page.tsx +11 -17
  268. package/src/modules/staff/lib/timesheets-projects-ui/SavedViewTabs.tsx +11 -28
  269. package/src/modules/sync_excel/lib/adapters/customers.ts +20 -22
  270. package/src/modules/sync_excel/lib/parser.ts +245 -0
  271. package/src/modules/sync_excel/lib/upload-storage.ts +23 -1
@@ -1,10 +1,9 @@
1
1
  "use client"
2
2
 
3
3
  import * as React from 'react'
4
- import { cn } from '@open-mercato/shared/lib/utils'
5
4
  import { useT } from '@open-mercato/shared/lib/i18n/context'
6
5
  import { Button } from '@open-mercato/ui/primitives/button'
7
- import { Badge } from '@open-mercato/ui/primitives/badge'
6
+ import { Tabs, TabsList, TabsTrigger } from '@open-mercato/ui/primitives/tabs'
8
7
  import {
9
8
  Users,
10
9
  Handshake,
@@ -14,6 +13,7 @@ import {
14
13
  Plus,
15
14
  } from 'lucide-react'
16
15
  import type { SectionAction } from '@open-mercato/ui/backend/detail'
16
+ import { useDealsAccess } from './useDealsAccess'
17
17
 
18
18
  export type CompanyTabId =
19
19
  | 'people'
@@ -27,7 +27,7 @@ type TabDef = {
27
27
  id: CompanyTabId
28
28
  label: string
29
29
  icon?: React.ReactNode
30
- badge?: React.ReactNode
30
+ count?: React.ReactNode
31
31
  }
32
32
 
33
33
  type CompanyDetailTabsProps = {
@@ -58,21 +58,9 @@ export function resolveLegacyTab(tab: string | null | undefined): CompanyTabId {
58
58
  return tab as CompanyTabId
59
59
  }
60
60
 
61
- function NewBadge() {
62
- return (
63
- <span className="ml-1.5 rounded bg-foreground px-1.5 py-0.5 text-overline font-semibold leading-none text-background">
64
- NEW
65
- </span>
66
- )
67
- }
68
-
69
- function CountBadge({ count }: { count: number }) {
70
- if (count <= 0) return null
71
- return (
72
- <span className="ml-1.5 rounded-full bg-muted px-1.5 py-0.5 text-xs font-medium leading-none text-muted-foreground">
73
- {count > 999 ? '999+' : count}
74
- </span>
75
- )
61
+ function formatTabCount(count: number): string | number | undefined {
62
+ if (count <= 0) return undefined
63
+ return count > 999 ? '999+' : count
76
64
  }
77
65
 
78
66
  export function CompanyDetailTabs({
@@ -87,6 +75,7 @@ export function CompanyDetailTabs({
87
75
  children,
88
76
  }: CompanyDetailTabsProps) {
89
77
  const t = useT()
78
+ const { canViewDeals } = useDealsAccess()
90
79
 
91
80
  const builtInTabs: TabDef[] = React.useMemo(
92
81
  () => [
@@ -94,34 +83,38 @@ export function CompanyDetailTabs({
94
83
  id: 'people',
95
84
  label: t('customers.companies.detail.tabs.people', 'People'),
96
85
  icon: <Users className="size-4" />,
97
- badge: <CountBadge count={peopleCount} />,
98
- },
99
- {
100
- id: 'deals',
101
- label: t('customers.companies.detail.tabs.deals', 'Deals'),
102
- icon: <Handshake className="size-4" />,
103
- badge: <CountBadge count={dealsCount} />,
86
+ count: formatTabCount(peopleCount),
104
87
  },
88
+ ...(canViewDeals
89
+ ? [
90
+ {
91
+ id: 'deals' as CompanyTabId,
92
+ label: t('customers.companies.detail.tabs.deals', 'Deals'),
93
+ icon: <Handshake className="size-4" />,
94
+ count: formatTabCount(dealsCount),
95
+ },
96
+ ]
97
+ : []),
105
98
  {
106
99
  id: 'activity-log',
107
100
  label: t('customers.companies.detail.tabs.activityLog', 'Activity log'),
108
101
  icon: <Clock className="size-4" />,
109
- badge: <CountBadge count={activitiesCount} />,
102
+ count: formatTabCount(activitiesCount),
110
103
  },
111
104
  {
112
105
  id: 'changelog',
113
106
  label: t('customers.companies.detail.tabs.changelog', 'Changelog'),
114
107
  icon: <History className="size-4" />,
115
- badge: <NewBadge />,
108
+ count: 'NEW',
116
109
  },
117
110
  {
118
111
  id: 'files',
119
112
  label: t('customers.companies.detail.tabs.files', 'Files'),
120
113
  icon: <Paperclip className="size-4" />,
121
- badge: <CountBadge count={filesCount} />,
114
+ count: formatTabCount(filesCount),
122
115
  },
123
116
  ],
124
- [t, peopleCount, dealsCount, activitiesCount, filesCount],
117
+ [t, canViewDeals, peopleCount, dealsCount, activitiesCount, filesCount],
125
118
  )
126
119
 
127
120
  const allTabs: TabDef[] = React.useMemo(
@@ -138,33 +131,24 @@ export function CompanyDetailTabs({
138
131
  return (
139
132
  <div>
140
133
  {/* Tab navigation */}
141
- <div className="flex items-end justify-between gap-2 border-b" role="tablist" aria-label={t('customers.companies.detail.tabs.label', 'Company detail sections')}>
142
- <nav className="-mb-px flex flex-1 gap-1 overflow-x-auto px-1">
143
- {allTabs.map((tab) => {
144
- const isActive = activeTab === tab.id
145
- return (
146
- <Button
147
- key={tab.id}
148
- type="button"
149
- variant="ghost"
150
- size="sm"
151
- role="tab"
152
- aria-selected={isActive}
153
- onClick={() => onTabChange(tab.id)}
154
- className={cn(
155
- 'h-auto shrink-0 rounded-none border-b-2 px-3 py-2.5 hover:bg-transparent',
156
- isActive
157
- ? 'border-foreground text-foreground font-semibold'
158
- : 'border-transparent text-muted-foreground hover:text-foreground',
159
- )}
160
- >
161
- {tab.icon && <span className="mr-1.5">{tab.icon}</span>}
134
+ <div className="flex items-end justify-between gap-2 border-b">
135
+ <Tabs
136
+ value={activeTab}
137
+ onValueChange={(value) => onTabChange(value as CompanyTabId)}
138
+ variant="underline"
139
+ className="min-w-0 flex-1"
140
+ >
141
+ <TabsList
142
+ aria-label={t('customers.companies.detail.tabs.label', 'Company detail sections')}
143
+ className="-mb-px w-full overflow-x-auto border-b-0 px-1"
144
+ >
145
+ {allTabs.map((tab) => (
146
+ <TabsTrigger key={tab.id} value={tab.id} leading={tab.icon} count={tab.count}>
162
147
  {tab.label}
163
- {tab.badge}
164
- </Button>
165
- )
166
- })}
167
- </nav>
148
+ </TabsTrigger>
149
+ ))}
150
+ </TabsList>
151
+ </Tabs>
168
152
  {sectionAction ? (
169
153
  <Button
170
154
  type="button"
@@ -2,9 +2,8 @@
2
2
 
3
3
  import * as React from 'react'
4
4
  import { Activity, Building2, History, NotebookPen, Paperclip, Users } from 'lucide-react'
5
- import { cn } from '@open-mercato/shared/lib/utils'
6
5
  import { useT } from '@open-mercato/shared/lib/i18n/context'
7
- import { Button } from '@open-mercato/ui/primitives/button'
6
+ import { Tabs, TabsList, TabsTrigger } from '@open-mercato/ui/primitives/tabs'
8
7
 
9
8
  export type DealTabId =
10
9
  | 'activities'
@@ -19,7 +18,7 @@ type TabDef = {
19
18
  id: DealTabId
20
19
  label: string
21
20
  icon?: React.ReactNode
22
- badge?: React.ReactNode
21
+ count?: React.ReactNode
23
22
  }
24
23
 
25
24
  type DealDetailTabsProps = {
@@ -38,21 +37,9 @@ export function resolveLegacyTab(tab: string | null | undefined): DealTabId {
38
37
  return SUPPORTED_TAB_IDS.has(tab as DealTabId) ? (tab as DealTabId) : 'activities'
39
38
  }
40
39
 
41
- function CountBadge({ count }: { count: number }) {
42
- if (count <= 0) return null
43
- return (
44
- <span className="ml-1.5 rounded-sm bg-muted px-1.5 py-px text-xs font-semibold leading-none text-muted-foreground">
45
- {count > 999 ? '999+' : count}
46
- </span>
47
- )
48
- }
49
-
50
- function NewBadge() {
51
- return (
52
- <span className="ml-1.5 rounded-sm bg-muted px-1.5 py-px text-xs font-semibold leading-none text-muted-foreground">
53
- NEW
54
- </span>
55
- )
40
+ function formatTabCount(count: number): string | number | undefined {
41
+ if (count <= 0) return undefined
42
+ return count > 999 ? '999+' : count
56
43
  }
57
44
 
58
45
  export function DealDetailTabs({
@@ -76,13 +63,13 @@ export function DealDetailTabs({
76
63
  id: 'people',
77
64
  label: t('customers.deals.detail.tabs.people', 'People'),
78
65
  icon: <Users className="size-4" />,
79
- badge: <CountBadge count={peopleCount} />,
66
+ count: formatTabCount(peopleCount),
80
67
  },
81
68
  {
82
69
  id: 'companies',
83
70
  label: t('customers.deals.detail.tabs.companies', 'Companies'),
84
71
  icon: <Building2 className="size-4" />,
85
- badge: <CountBadge count={companiesCount} />,
72
+ count: formatTabCount(companiesCount),
86
73
  },
87
74
  {
88
75
  id: 'notes',
@@ -98,7 +85,7 @@ export function DealDetailTabs({
98
85
  id: 'changelog',
99
86
  label: t('customers.deals.detail.tabs.changelog', 'Changelog'),
100
87
  icon: <History className="size-4" />,
101
- badge: <NewBadge />,
88
+ count: 'NEW',
102
89
  },
103
90
  ],
104
91
  [companiesCount, peopleCount, t],
@@ -117,34 +104,22 @@ export function DealDetailTabs({
117
104
 
118
105
  return (
119
106
  <div>
120
- <div className="border-b border-border" role="tablist" aria-label={t('customers.deals.detail.tabs.label', 'Deal detail sections')}>
121
- <nav className="-mb-px flex gap-7 overflow-x-auto" role="presentation">
122
- {allTabs.map((tab) => {
123
- const isActive = activeTab === tab.id
124
- return (
125
- <Button
126
- key={tab.id}
127
- type="button"
128
- variant="ghost"
129
- size="sm"
130
- role="tab"
131
- aria-selected={isActive}
132
- onClick={() => onTabChange(tab.id)}
133
- className={cn(
134
- 'h-auto shrink-0 rounded-none border-b-2 px-3 py-2.5 hover:bg-transparent',
135
- isActive
136
- ? 'border-foreground text-foreground font-semibold'
137
- : 'border-transparent text-muted-foreground hover:text-foreground',
138
- )}
139
- >
140
- {tab.icon ? <span className="mr-1.5">{tab.icon}</span> : null}
141
- {tab.label}
142
- {tab.badge}
143
- </Button>
144
- )
145
- })}
146
- </nav>
147
- </div>
107
+ <Tabs
108
+ value={activeTab}
109
+ onValueChange={(value) => onTabChange(value as DealTabId)}
110
+ variant="underline"
111
+ >
112
+ <TabsList
113
+ aria-label={t('customers.deals.detail.tabs.label', 'Deal detail sections')}
114
+ className="w-full overflow-x-auto"
115
+ >
116
+ {allTabs.map((tab) => (
117
+ <TabsTrigger key={tab.id} value={tab.id} leading={tab.icon} count={tab.count}>
118
+ {tab.label}
119
+ </TabsTrigger>
120
+ ))}
121
+ </TabsList>
122
+ </Tabs>
148
123
 
149
124
  <div className="pt-5" role="tabpanel">
150
125
  {children}
@@ -3,6 +3,7 @@
3
3
  import * as React from 'react'
4
4
  import type { SectionAction } from '@open-mercato/ui/backend/detail'
5
5
  import { Button } from '@open-mercato/ui/primitives/button'
6
+ import { Tabs, TabsList, TabsTrigger } from '@open-mercato/ui/primitives/tabs'
6
7
  import { cn } from '@open-mercato/shared/lib/utils'
7
8
  import { Plus } from 'lucide-react'
8
9
 
@@ -46,31 +47,19 @@ export function DetailTabsLayout<TId extends string = string>({
46
47
  return (
47
48
  <div className={cn('space-y-4', className)}>
48
49
  <div className={cn('flex flex-wrap items-center justify-between gap-3', headerClassName)}>
49
- <nav
50
- className={cn('flex flex-wrap items-center gap-3 text-sm', navClassName)}
51
- role="tablist"
52
- aria-label={navAriaLabel}
50
+ <Tabs
51
+ value={activeTab}
52
+ onValueChange={(value) => handleTabChange(value as TId)}
53
+ variant="underline"
53
54
  >
54
- {tabs.map((tab) => (
55
- <Button
56
- key={tab.id}
57
- type="button"
58
- variant="ghost"
59
- size="sm"
60
- role="tab"
61
- aria-selected={activeTab === tab.id}
62
- onClick={() => handleTabChange(tab.id)}
63
- className={cn(
64
- 'h-auto rounded-none border-b-2 px-0 py-1',
65
- activeTab === tab.id
66
- ? 'border-accent-indigo text-foreground hover:bg-transparent'
67
- : 'border-transparent text-muted-foreground hover:text-foreground hover:bg-transparent'
68
- )}
69
- >
70
- {tab.label}
71
- </Button>
72
- ))}
73
- </nav>
55
+ <TabsList className={cn('h-auto flex-wrap border-b-0', navClassName)} aria-label={navAriaLabel}>
56
+ {tabs.map((tab) => (
57
+ <TabsTrigger key={tab.id} value={tab.id}>
58
+ {tab.label}
59
+ </TabsTrigger>
60
+ ))}
61
+ </TabsList>
62
+ </Tabs>
74
63
  {sectionAction ? (
75
64
  <Button
76
65
  type="button"
@@ -3,8 +3,7 @@
3
3
  import * as React from 'react'
4
4
  import { useRouter, useSearchParams } from 'next/navigation'
5
5
  import { useT } from '@open-mercato/shared/lib/i18n/context'
6
- import { cn } from '@open-mercato/shared/lib/utils'
7
- import { Button } from '@open-mercato/ui/primitives/button'
6
+ import { Tabs, TabsList, TabsTrigger } from '@open-mercato/ui/primitives/tabs'
8
7
 
9
8
  export type MobilePersonZone = 'details' | 'activity'
10
9
 
@@ -80,35 +79,30 @@ export function MobilePersonDetail({
80
79
 
81
80
  return (
82
81
  <div className="space-y-4">
83
- <div
84
- role="tablist"
85
- aria-label={t(
86
- 'customers.people.mobile.zoneSwitcher.ariaLabel',
87
- 'Zone selector',
88
- )}
89
- className="grid grid-cols-2 gap-1 rounded-lg border border-border/70 bg-muted/20 p-1"
90
- onKeyDown={handleKeyDown}
91
- >
92
- {ZONES.map((entry) => {
93
- const isActive = zone === entry.id
94
- return (
95
- <Button
96
- key={entry.id}
97
- type="button"
98
- role="tab"
99
- aria-selected={isActive}
100
- aria-controls={`mobile-person-zone-${entry.id}`}
101
- variant={isActive ? 'default' : 'ghost'}
102
- className={cn(
103
- 'h-11 rounded-lg text-sm font-semibold',
104
- isActive ? '' : 'text-muted-foreground',
105
- )}
106
- onClick={() => handleZoneChange(entry.id)}
107
- >
108
- {t(entry.labelKey, entry.fallback)}
109
- </Button>
110
- )
111
- })}
82
+ <div onKeyDown={handleKeyDown}>
83
+ <Tabs
84
+ value={zone}
85
+ onValueChange={(value) => handleZoneChange(value as MobilePersonZone)}
86
+ variant="underline"
87
+ >
88
+ <TabsList
89
+ aria-label={t(
90
+ 'customers.people.mobile.zoneSwitcher.ariaLabel',
91
+ 'Zone selector',
92
+ )}
93
+ className="w-full"
94
+ >
95
+ {ZONES.map((entry) => (
96
+ <TabsTrigger
97
+ key={entry.id}
98
+ value={entry.id}
99
+ className="flex-1 justify-center"
100
+ >
101
+ {t(entry.labelKey, entry.fallback)}
102
+ </TabsTrigger>
103
+ ))}
104
+ </TabsList>
105
+ </Tabs>
112
106
  </div>
113
107
  <div
114
108
  id={`mobile-person-zone-${zone}`}
@@ -1,9 +1,9 @@
1
1
  "use client"
2
2
 
3
3
  import * as React from 'react'
4
- import { cn } from '@open-mercato/shared/lib/utils'
5
4
  import { useT } from '@open-mercato/shared/lib/i18n/context'
6
5
  import { Button } from '@open-mercato/ui/primitives/button'
6
+ import { Tabs, TabsList, TabsTrigger } from '@open-mercato/ui/primitives/tabs'
7
7
  import {
8
8
  SquareCheckBig,
9
9
  Mail,
@@ -32,7 +32,7 @@ type TabDef = {
32
32
  id: PersonTabId
33
33
  label: string
34
34
  icon?: React.ReactNode
35
- badge?: React.ReactNode
35
+ count?: React.ReactNode
36
36
  }
37
37
 
38
38
  type PersonDetailTabsProps = {
@@ -56,21 +56,9 @@ export function resolveLegacyTab(tab: string | null | undefined): PersonTabId {
56
56
  return SUPPORTED_TAB_IDS.has(tab as PersonTabId) ? (tab as PersonTabId) : 'activities'
57
57
  }
58
58
 
59
- function CountBadge({ count }: { count: number }) {
60
- if (count <= 0) return null
61
- return (
62
- <span className="ml-1 rounded-full bg-muted px-1.5 py-0.5 text-xs font-medium leading-none text-muted-foreground">
63
- {count > 999 ? '999+' : count}
64
- </span>
65
- )
66
- }
67
-
68
- function NewBadge() {
69
- return (
70
- <span className="ml-1.5 rounded bg-foreground px-1.5 py-0.5 text-overline font-semibold leading-none text-background">
71
- NEW
72
- </span>
73
- )
59
+ function formatTabCount(count: number): string | number | undefined {
60
+ if (count <= 0) return undefined
61
+ return count > 999 ? '999+' : count
74
62
  }
75
63
 
76
64
  export function PersonDetailTabs({
@@ -94,7 +82,7 @@ export function PersonDetailTabs({
94
82
  id: 'activities',
95
83
  label: t('customers.people.detail.tabs.activities', 'Activities'),
96
84
  icon: <SquareCheckBig className="size-4" />,
97
- badge: <CountBadge count={activitiesCount} />,
85
+ count: formatTabCount(activitiesCount),
98
86
  },
99
87
  {
100
88
  id: 'emails',
@@ -105,37 +93,37 @@ export function PersonDetailTabs({
105
93
  id: 'deals',
106
94
  label: t('customers.people.detail.tabs.deals', 'Deals'),
107
95
  icon: <Briefcase className="size-4" />,
108
- badge: <CountBadge count={dealsCount} />,
96
+ count: formatTabCount(dealsCount),
109
97
  },
110
98
  {
111
99
  id: 'companies',
112
100
  label: t('customers.people.detail.tabs.companies', 'Companies'),
113
101
  icon: <Building2 className="size-4" />,
114
- badge: <CountBadge count={companiesCount} />,
102
+ count: formatTabCount(companiesCount),
115
103
  },
116
104
  {
117
105
  id: 'addresses',
118
106
  label: t('customers.people.detail.tabs.addresses', 'Addresses'),
119
107
  icon: <MapPin className="size-4" />,
120
- badge: <CountBadge count={addressesCount} />,
108
+ count: formatTabCount(addressesCount),
121
109
  },
122
110
  {
123
111
  id: 'tasks',
124
112
  label: t('customers.people.detail.tabs.tasks', 'Tasks'),
125
113
  icon: <Check className="size-4" />,
126
- badge: <CountBadge count={tasksCount} />,
114
+ count: formatTabCount(tasksCount),
127
115
  },
128
116
  {
129
117
  id: 'changelog',
130
118
  label: t('customers.people.detail.tabs.changelog', 'Change log'),
131
119
  icon: <History className="size-4" />,
132
- badge: <NewBadge />,
120
+ count: 'NEW',
133
121
  },
134
122
  {
135
123
  id: 'files',
136
124
  label: t('customers.people.detail.tabs.files', 'Files'),
137
125
  icon: <Paperclip className="size-4" />,
138
- badge: <CountBadge count={filesCount} />,
126
+ count: formatTabCount(filesCount),
139
127
  },
140
128
  ],
141
129
  [t, activitiesCount, dealsCount, companiesCount, addressesCount, tasksCount, filesCount],
@@ -155,33 +143,24 @@ export function PersonDetailTabs({
155
143
  return (
156
144
  <div>
157
145
  {/* Tab navigation — full width above both zones */}
158
- <div className="flex items-end justify-between gap-2 border-b" role="tablist" aria-label={t('customers.people.detail.tabs.label', 'Person detail sections')}>
159
- <nav className="-mb-px flex flex-1 gap-1 overflow-x-auto px-1">
160
- {allTabs.map((tab) => {
161
- const isActive = activeTab === tab.id
162
- return (
163
- <Button
164
- key={tab.id}
165
- type="button"
166
- variant="ghost"
167
- size="sm"
168
- role="tab"
169
- aria-selected={isActive}
170
- onClick={() => onTabChange(tab.id)}
171
- className={cn(
172
- 'h-auto shrink-0 rounded-none border-b-2 px-3 py-2.5 hover:bg-transparent',
173
- isActive
174
- ? 'border-foreground text-foreground font-semibold'
175
- : 'border-transparent text-muted-foreground hover:text-foreground',
176
- )}
177
- >
178
- {tab.icon && <span className="mr-1.5">{tab.icon}</span>}
146
+ <div className="flex items-end justify-between gap-2 border-b">
147
+ <Tabs
148
+ value={activeTab}
149
+ onValueChange={(value) => onTabChange(value as PersonTabId)}
150
+ variant="underline"
151
+ className="min-w-0 flex-1"
152
+ >
153
+ <TabsList
154
+ aria-label={t('customers.people.detail.tabs.label', 'Person detail sections')}
155
+ className="-mb-px w-full overflow-x-auto border-b-0 px-1"
156
+ >
157
+ {allTabs.map((tab) => (
158
+ <TabsTrigger key={tab.id} value={tab.id} leading={tab.icon} count={tab.count}>
179
159
  {tab.label}
180
- {tab.badge}
181
- </Button>
182
- )
183
- })}
184
- </nav>
160
+ </TabsTrigger>
161
+ ))}
162
+ </TabsList>
163
+ </Tabs>
185
164
  {sectionAction ? (
186
165
  <Button
187
166
  type="button"
@@ -0,0 +1,19 @@
1
+ "use client"
2
+
3
+ import * as React from 'react'
4
+ import { useBackendChrome } from '@open-mercato/ui/backend/BackendChromeProvider'
5
+ import { hasFeature } from '@open-mercato/shared/security/features'
6
+
7
+ export type DealsAccess = {
8
+ canViewDeals: boolean
9
+ isReady: boolean
10
+ }
11
+
12
+ export function useDealsAccess(): DealsAccess {
13
+ const { payload, isReady } = useBackendChrome()
14
+ const canViewDeals = React.useMemo(
15
+ () => hasFeature(payload?.grantedFeatures ?? [], 'customers.deals.view'),
16
+ [payload?.grantedFeatures],
17
+ )
18
+ return { canViewDeals, isReady }
19
+ }
@@ -6,7 +6,10 @@ import { DashboardRoleWidgets } from '@open-mercato/core/modules/dashboards/data
6
6
  import { Role } from '@open-mercato/core/modules/auth/data/entities'
7
7
  import { roleWidgetSettingsSchema } from '@open-mercato/core/modules/dashboards/data/validators'
8
8
  import { loadAllWidgets } from '@open-mercato/core/modules/dashboards/lib/widgets'
9
- import { resolveWidgetAssignmentReadScope } from '@open-mercato/core/modules/dashboards/lib/widgetAssignmentScope'
9
+ import {
10
+ resolveWidgetAssignmentReadScope,
11
+ resolveWidgetAssignmentTargetAccess,
12
+ } from '@open-mercato/core/modules/dashboards/lib/widgetAssignmentScope'
10
13
  import { hasFeature } from '@open-mercato/shared/security/features'
11
14
  import {
12
15
  runCrudMutationGuardAfterSuccess,
@@ -70,7 +73,15 @@ export async function GET(req: Request) {
70
73
  })
71
74
 
72
75
  const role = await em.findOne(Role, { id: roleId, deletedAt: null })
73
- if (!role || (tenantId && role.tenantId !== tenantId)) {
76
+ const access = resolveWidgetAssignmentTargetAccess({
77
+ isSuperAdmin: !!acl.isSuperAdmin,
78
+ scopeTenantId: tenantId,
79
+ target: role,
80
+ })
81
+ if (access === 'forbidden') {
82
+ return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
83
+ }
84
+ if (access === 'not-found') {
74
85
  return NextResponse.json({ error: 'Role not found' }, { status: 404 })
75
86
  }
76
87
 
@@ -121,7 +132,15 @@ export async function PUT(req: Request) {
121
132
  const organizationId = auth.orgId ?? null
122
133
 
123
134
  const role = await em.findOne(Role, { id: parsed.data.roleId, deletedAt: null })
124
- if (!role || (tenantId && role.tenantId !== tenantId)) {
135
+ const access = resolveWidgetAssignmentTargetAccess({
136
+ isSuperAdmin: !!acl.isSuperAdmin,
137
+ scopeTenantId: tenantId,
138
+ target: role,
139
+ })
140
+ if (access === 'forbidden') {
141
+ return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
142
+ }
143
+ if (access === 'not-found') {
125
144
  return NextResponse.json({ error: 'Role not found' }, { status: 404 })
126
145
  }
127
146
 
@@ -7,7 +7,10 @@ import { User } from '@open-mercato/core/modules/auth/data/entities'
7
7
  import { userWidgetSettingsSchema } from '@open-mercato/core/modules/dashboards/data/validators'
8
8
  import { loadAllWidgets } from '@open-mercato/core/modules/dashboards/lib/widgets'
9
9
  import { resolveAllowedWidgetIds } from '@open-mercato/core/modules/dashboards/lib/access'
10
- import { resolveWidgetAssignmentReadScope } from '@open-mercato/core/modules/dashboards/lib/widgetAssignmentScope'
10
+ import {
11
+ resolveWidgetAssignmentReadScope,
12
+ resolveWidgetAssignmentTargetAccess,
13
+ } from '@open-mercato/core/modules/dashboards/lib/widgetAssignmentScope'
11
14
  import { hasFeature } from '@open-mercato/shared/security/features'
12
15
  import {
13
16
  runCrudMutationGuardAfterSuccess,
@@ -53,7 +56,15 @@ export async function GET(req: Request) {
53
56
  })
54
57
 
55
58
  const targetUserForRead = await em.findOne(User, { id: userId, deletedAt: null })
56
- if (!targetUserForRead || (tenantId && (targetUserForRead.tenantId ?? null) !== tenantId)) {
59
+ const readAccess = resolveWidgetAssignmentTargetAccess({
60
+ isSuperAdmin: !!acl.isSuperAdmin,
61
+ scopeTenantId: tenantId,
62
+ target: targetUserForRead,
63
+ })
64
+ if (readAccess === 'forbidden') {
65
+ return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
66
+ }
67
+ if (readAccess === 'not-found') {
57
68
  return NextResponse.json({ error: 'User not found' }, { status: 404 })
58
69
  }
59
70
 
@@ -121,7 +132,15 @@ export async function PUT(req: Request) {
121
132
  const organizationId = auth.orgId ?? null
122
133
 
123
134
  const targetUser = await em.findOne(User, { id: parsed.data.userId, deletedAt: null })
124
- if (!targetUser || (tenantId && (targetUser.tenantId ?? null) !== tenantId)) {
135
+ const writeAccess = resolveWidgetAssignmentTargetAccess({
136
+ isSuperAdmin: !!acl.isSuperAdmin,
137
+ scopeTenantId: tenantId,
138
+ target: targetUser,
139
+ })
140
+ if (writeAccess === 'forbidden') {
141
+ return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
142
+ }
143
+ if (writeAccess === 'not-found') {
125
144
  return NextResponse.json({ error: 'User not found' }, { status: 404 })
126
145
  }
127
146