@7365admin1/layer-common 4.11.1-staging.315 → 4.11.1-staging.317

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.
@@ -68,8 +68,50 @@
68
68
  </v-autocomplete>
69
69
  </v-col>
70
70
 
71
- <!-- ROLE -->
72
- <v-col cols="12">
71
+ <!--
72
+ MODULES, for a NEW client (owner, 2026-09-14). Its owner gets the
73
+ client's own full-access owner role, bounded by exactly these, so
74
+ there is no role to pick; everything of the chosen service starts
75
+ ticked. A module unticked here is hidden from the client's people.
76
+ -->
77
+ <v-col v-if="newClient" cols="12" class="mt-2">
78
+ <div v-for="app in invite.app" :key="`modules-${app}`" class="mb-4">
79
+ <InputLabel :title="`Modules for ${appTitle(app)}`" required />
80
+ <p class="text-caption text-medium-emphasis mb-2">
81
+ The client's owner gets full access to the modules ticked here,
82
+ and nothing else. You can change this later on the client's
83
+ details.
84
+ </p>
85
+ <div v-for="group in inviteModuleGroups(app)" :key="`${app}-${group.key}`" class="mb-2">
86
+ <div class="text-subtitle-2">{{ group.label }}</div>
87
+ <v-row no-gutters>
88
+ <v-col v-for="key in group.modules" :key="`${app}-${group.key}-${key}`" cols="12" sm="6">
89
+ <v-checkbox
90
+ v-if="ALWAYS_ALLOWED_MODULES.includes(key)"
91
+ :model-value="true"
92
+ :label="`${formatResourceLabel(key)} — always included`"
93
+ disabled
94
+ density="compact"
95
+ hide-details
96
+ color="primary"
97
+ />
98
+ <v-checkbox
99
+ v-else
100
+ v-model="modulesByApp[app]"
101
+ :value="key"
102
+ :label="formatResourceLabel(key)"
103
+ density="compact"
104
+ hide-details
105
+ color="primary"
106
+ />
107
+ </v-col>
108
+ </v-row>
109
+ </div>
110
+ </div>
111
+ </v-col>
112
+
113
+ <!-- ROLE: only for an organisation that already exists -->
114
+ <v-col v-if="!newClient" cols="12">
73
115
  <InputLabel title="Role" required />
74
116
  <v-autocomplete
75
117
  v-model="invite.role"
@@ -147,6 +189,9 @@ import useUser from '../composables/useUser'
147
189
  import useUtils from '../composables/useUtils'
148
190
  import useOrg from '../composables/useOrg'
149
191
  import useMember from '../composables/useMember'
192
+ import { inviteModuleGroups } from '../utils/client-invite-modules'
193
+ import { ALWAYS_ALLOWED_MODULES } from '../utils/org-modules'
194
+ import { formatResourceLabel } from '../utils/permission-labels'
150
195
 
151
196
  const APP = useRuntimeConfig().public.APP
152
197
 
@@ -319,10 +364,34 @@ watch(
319
364
  }
320
365
  )
321
366
 
367
+ /* ================= NEW CLIENT: MODULES ================= */
368
+ /*
369
+ * No organisation yet means this invitation creates a client. The server drops
370
+ * any role on such an invitation (the owner gets the client's own owner role)
371
+ * and stores the modules chosen here, one application per request.
372
+ */
373
+ const newClient = computed(() => !org.value?._id)
374
+
375
+ const appTitle = (value: string) => APP_LIST.find(app => app.value === value)?.title ?? value
376
+
377
+ /** Ticked modules per chosen application; a newly chosen one starts with all ticked. */
378
+ const modulesByApp = ref<Record<string, string[]>>({})
379
+
380
+ function syncModules(chosen: string[]) {
381
+ const next: Record<string, string[]> = {}
382
+ for (const app of chosen) {
383
+ next[app] = modulesByApp.value[app] ?? inviteModuleGroups(app).flatMap(group => group.modules)
384
+ }
385
+ modulesByApp.value = next
386
+ }
387
+
388
+ syncModules(invite.value.app)
389
+
322
390
  /* ================= EVENTS ================= */
323
391
  async function handleUpdateApp(value: string[]) {
324
392
  invite.value.role = ""
325
393
  invite.value.site = ""
394
+ syncModules(value)
326
395
  await refreshRoles()
327
396
  }
328
397
 
@@ -403,7 +472,18 @@ async function submit() {
403
472
 
404
473
  app: [app],
405
474
 
406
- role: invite.value.role,
475
+ ...(newClient.value
476
+ ? {
477
+ // Always-allowed modules are ticked and locked, so the list is
478
+ // never empty (an empty list would mean "everything").
479
+ modules: [
480
+ ...new Set([
481
+ ...ALWAYS_ALLOWED_MODULES,
482
+ ...(modulesByApp.value[app] ?? inviteModuleGroups(app).flatMap(group => group.modules)),
483
+ ]),
484
+ ],
485
+ }
486
+ : { role: invite.value.role }),
407
487
 
408
488
  org: org.value?._id,
409
489
 
@@ -179,5 +179,6 @@ export default function useMember() {
179
179
  getAllByUserId,
180
180
  getByUserTypeOrg,
181
181
  completeMemberOnboarding,
182
+ getDeniedModules,
182
183
  };
183
184
  }
@@ -21,7 +21,8 @@ export default function useUser() {
21
21
  name = '',
22
22
  org = '',
23
23
  site = '',
24
- siteName = ''
24
+ siteName = '',
25
+ modules
25
26
  }: {
26
27
  email?: string
27
28
  app?: string[]
@@ -30,6 +31,8 @@ export default function useUser() {
30
31
  org?: string
31
32
  site?: string
32
33
  siteName?: string
34
+ /** A new client's modules (Seven365 staff only). */
35
+ modules?: string[]
33
36
  } = {}) {
34
37
  return useNuxtApp().$api<Record<string, any>>('/api/auth/invite/user', {
35
38
  method: 'POST',
@@ -40,7 +43,8 @@ export default function useUser() {
40
43
  name,
41
44
  org,
42
45
  ...(site && { siteId: site }),
43
- ...(siteName && { siteName })
46
+ ...(siteName && { siteName }),
47
+ ...(modules && { modules })
44
48
  }
45
49
  })
46
50
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "4.11.1-staging.315",
5
+ "version": "4.11.1-staging.317",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
@@ -0,0 +1,56 @@
1
+ import { PERMISSIONS } from "../constants/permissions";
2
+ import { applicationModules, groupModulesByApplication } from "./module-applications";
3
+
4
+ /**
5
+ * THE MODULES A NEW CLIENT IS OFFERED ON "INVITE CLIENT".
6
+ *
7
+ * Owner, 2026-09-14: *"Client Owner Super Admin can only have the full access on
8
+ * what Seven365 Super Admin given to them, same goes to the modules that they
9
+ * can access."* So the Super Admin chooses the modules when inviting, and the
10
+ * server enforces that list from the day the client is created.
11
+ *
12
+ * The same catalogue and the same narrowing as the Client details card
13
+ * (`web-app-org pages/super-admin/client-details.vue` + `utils/module-nature.js`):
14
+ * the flat catalogue plus every application's modules, grouped by application,
15
+ * then only the applications that go with the client's nature, plus the modules
16
+ * no application claims (`sites`, `customers`, ...). A client created here and
17
+ * opened on that card shows exactly what was ticked.
18
+ */
19
+
20
+ /**
21
+ * Nature of business -> the application groups that client is offered.
22
+ * Mirrors `web-app-org utils/module-nature.js NATURE_APPLICATIONS` (owner,
23
+ * 2026-09-12); `test/client-invite-modules.test.mjs` pins the pairs.
24
+ */
25
+ export const NATURE_APPLICATIONS: Readonly<Record<string, readonly string[]>> = Object.freeze({
26
+ security_agency: ["security"],
27
+ cleaning_services: ["cleaning"],
28
+ pest_control_services: ["pest"],
29
+ mechanical_electrical_services: ["mechanical-electrical"],
30
+ landscaping_services: ["landscape"],
31
+ pool_maintenance_services: ["pool"],
32
+ property_management_agency: ["property-management"],
33
+ real_estate_developer: ["property-management"],
34
+ });
35
+
36
+ export type ModuleGroup = { key: string; label: string; modules: string[] };
37
+
38
+ /**
39
+ * The groups to offer for a new client of `nature`, every module in them ticked
40
+ * by default. An unknown nature is offered everything, like the card.
41
+ */
42
+ export function inviteModuleGroups(nature: string): ModuleGroup[] {
43
+ const keys = [
44
+ ...new Set([
45
+ ...Object.keys(PERMISSIONS),
46
+ ...applicationModules().flatMap((application) => application.modules),
47
+ ]),
48
+ ];
49
+ const { groups, ungrouped } = groupModulesByApplication(keys);
50
+ const applications = Object.hasOwn(NATURE_APPLICATIONS, nature) ? NATURE_APPLICATIONS[nature] : null;
51
+
52
+ const shown = applications ? groups.filter((group) => applications.includes(group.key)) : groups;
53
+ return ungrouped.length
54
+ ? [...shown, { key: "other", label: "Not tied to a service application", modules: ungrouped }]
55
+ : shown;
56
+ }