@7365admin1/layer-common 4.2.21-staging.281 → 4.2.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.2.22
4
+
5
+ ### Patch Changes
6
+
7
+ - 4977a90: Let the console's Roles and Permissions screen list every role a super admin can hand out.
8
+
9
+ The screen passed `type="admin"` and so listed only the 2 platform-staff roles, while Client List -> Invite Client asks `GET /api/roles` with no type and is offered all 12 org-less roles. `RolePermissionMain` takes an optional `listType` that filters the LIST independently of the type a newly created role is given, and draws a Scope column when a page asks for one. No other page changes.
10
+
11
+ ## 4.2.21
12
+
13
+ ### Patch Changes
14
+
15
+ - 58d9405: Add `useRole.getInvitableRoles` so an invite screen offers exactly the roles the invite endpoint accepts: the organisation's own roles plus the org-less template roles, never a `type: "admin"` console staff role, and optionally narrowed to one site.
16
+
3
17
  ## 4.2.20
4
18
 
5
19
  ### Patch Changes
@@ -726,11 +740,11 @@
726
740
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
727
741
  own rule from two endpoints the console already calls, unprojected:
728
742
 
729
- GET /api/members/user/:user/app/admin the Seven365 staff membership
730
- GET /api/roles/id/:role that membership's role document
743
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
744
+ GET /api/roles/id/:role that membership's role document
731
745
 
732
- owner = member.type === "admin" && role.type === "admin" && role.default === true
733
- staff = member.type === "admin" && role.type === "admin"
746
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
747
+ staff = member.type === "admin" && role.type === "admin"
734
748
 
735
749
  `role.default` is the marker because it is the only property of a platform
736
750
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -251,27 +251,9 @@ watch(
251
251
  const roles = ref<any[]>([])
252
252
  const { getRoles } = useRole()
253
253
 
254
- /*
255
- * `type` is the ROLE type, not the service the client subscribes to, and the
256
- * only caller (`ClientMain.vue` "Invite Client") passes no `app` prop -- so
257
- * this sent `type: ""` and the endpoint applied no type filter at all. The
258
- * dropdown therefore listed every org-less role of every type, which includes
259
- * the platform's OWN staff roles (`type: "admin"` -- the two rows the console's
260
- * `/super-admin/role-permissions` screen edits). Offering a Seven365 console
261
- * staff role on a CLIENT invitation is the defect.
262
- *
263
- * A client admin's role is `type: "organization"`, which is what the client
264
- * roles screen (`org/[organization]/roles-permissions.vue`) already lists. This
265
- * narrows to exactly that. It is a narrowing of this one picker only: no role
266
- * changes, no permission changes, and the org-less `organization` roles that
267
- * were already being picked are all still offered.
268
- *
269
- * Keying off the selected service instead would empty the dropdown -- no
270
- * org-less role carries a service type -- so `props.app` is not the filter.
271
- */
272
254
  const { data: roleData, refresh: refreshRoles } = await useLazyAsyncData(
273
255
  "roles",
274
- () => getRoles({ org: org.value?._id, type: "organization", limit: 50 }),
256
+ () => getRoles({ org: org.value?._id, type: props.app, limit: 50 }),
275
257
  { watch: [() => props.app] }
276
258
  )
277
259
 
@@ -52,6 +52,20 @@
52
52
  @click:row="tableRowClickHandler"
53
53
  style="max-height: calc(100vh - (180px))"
54
54
  >
55
+ <!--
56
+ SCOPE. Only rendered when a page puts `scope` in its `headers`,
57
+ which is the console's Roles and Permissions screen and nothing
58
+ else. Two kinds share that list and they are governed differently,
59
+ so the row has to say which it is.
60
+ -->
61
+ <template #item.scope="{ item }">
62
+ <StatusChip
63
+ :dot="false"
64
+ :tone="item.type === 'admin' ? 'info' : 'neutral'"
65
+ :label="scopeLabel(item)"
66
+ />
67
+ </template>
68
+
55
69
  <template #item.permissions="{ value }">
56
70
  <span class="text-caption font-weight-bold text-capitalize">
57
71
  permissions
@@ -221,6 +235,29 @@ const props = defineProps({
221
235
  required: true,
222
236
  default: "app",
223
237
  },
238
+ /*
239
+ * The `type` the LIST is filtered by, when it differs from the `type` a
240
+ * newly created role is given.
241
+ *
242
+ * They were the same value, and on the Seven365 console that was the defect:
243
+ * the screen passed `type="admin"`, so it listed the 2 platform-staff roles
244
+ * and nothing else -- while the console's own "Invite Client" picker asks
245
+ * `GET /api/roles` with no `type` and is offered all 12 ORG-LESS roles
246
+ * (10 `type: "organization"` templates + those same 2). A super admin could
247
+ * therefore hand out ten roles the Roles and Permissions screen could not
248
+ * show, edit or delete.
249
+ *
250
+ * The server has always allowed it: an org-less role of ANY type goes to
251
+ * `requireConsolePermission("roles-and-permissions")`
252
+ * (`core role.controller requireRoleOrg`), so this only stops the UI hiding
253
+ * what the console may already manage. `null` keeps every other page exactly
254
+ * as it was; `""` means "do not filter by type", which for an org-less
255
+ * caller IS the administrative scope.
256
+ */
257
+ listType: {
258
+ type: String,
259
+ default: null,
260
+ },
224
261
  permissions: {
225
262
  type: Object,
226
263
  required: true,
@@ -296,7 +333,7 @@ const {
296
333
  _getRoles({
297
334
  page: page.value,
298
335
  search: headerSearch.value,
299
- type: props.type,
336
+ type: props.listType ?? props.type,
300
337
  org: props.orgId,
301
338
  site: props.siteId,
302
339
  }),
@@ -338,6 +375,19 @@ const emptyText = computed(() => {
338
375
  return "No roles have been created yet.";
339
376
  });
340
377
 
378
+ /**
379
+ * What KIND of role a row is, in the words the console needs.
380
+ *
381
+ * A role with no `org` is not a client's -- it is either the Seven365 console's
382
+ * own staff role (`type: "admin"`) or an org-less TEMPLATE that any invitation
383
+ * may hand out. Both are managed here; only the second one leaves this system.
384
+ */
385
+ function scopeLabel(item: Record<string, any>) {
386
+ if (item?.type === "admin") return "Platform staff";
387
+ if (props.orgId) return "Organisation";
388
+ return "Client template";
389
+ }
390
+
341
391
  function tableRowClickHandler(_: any, data: any) {
342
392
  // "See role details". Ungated until now, which is why granting or withholding
343
393
  // it changed nothing.
@@ -742,35 +742,11 @@
742
742
  class="visitor-preview__row"
743
743
  >
744
744
  <div class="visitor-preview__label">{{ label }}</div>
745
- <div>
746
- <!-- Was a hover tooltip on the value: the full NRIC only
747
- reachable by hovering, which says nothing is there to
748
- reach and cannot be reached at all on a touch screen.
749
- The eye alone, at the 14px the Incident Report screens
750
- draw it, is a 14px target - the floor is 24px. So the
751
- NUMBER is the control and the eye is its affordance:
752
- the whole masked value is pressable, which makes the
753
- target the width of the digits rather than of a glyph,
754
- and being a real `button` it also takes a tab stop,
755
- which a `v-icon` with a click handler never did. -->
756
- <button
757
- type="button"
758
- class="visitor-preview__reveal"
759
- :aria-label="showVisitorNric ? 'Hide NRIC' : 'Show NRIC'"
760
- :aria-pressed="showVisitorNric"
761
- @click="showVisitorNric = !showVisitorNric"
762
- >
763
- <span class="visitor-preview__value">
764
- {{
765
- showVisitorNric
766
- ? selectedVisitorObject[key]
767
- : maskNRIC(selectedVisitorObject[key])
768
- }}
769
- </span>
770
- <v-icon size="16" class="visitor-preview__eye">
771
- {{ showVisitorNric ? "mdi-eye-off-outline" : "mdi-eye-outline" }}
772
- </v-icon>
773
- </button>
745
+ <div
746
+ v-tooltip:top="selectedVisitorObject[key]"
747
+ class="visitor-preview__value"
748
+ >
749
+ {{ maskNRIC(selectedVisitorObject[key]) }}
774
750
  </div>
775
751
  </div>
776
752
 
@@ -820,84 +796,6 @@
820
796
  </div>
821
797
  </div>
822
798
 
823
- <!--
824
- THE CONTRACTOR'S PARTY.
825
-
826
- The list row has always said `( +2 members)` beside the name
827
- and then had nowhere to send you for the names themselves. The
828
- block spans both columns rather than sitting in the 116px
829
- value track: a member is a record, not a value, and several of
830
- them in a 250px column is unreadable.
831
-
832
- Read off `selectedVisitorDataObject` (the raw row) and not
833
- `selectedVisitorObject`, which filters itself down to
834
- `typeFieldMap` plus five fixed keys - `members` is on neither
835
- list, and widening that computed would change what four other
836
- dialogs on this screen see.
837
- -->
838
- <div
839
- v-else-if="key === 'members' && selectedVisitorMembers.length"
840
- class="visitor-preview__row visitor-preview__row--block"
841
- >
842
- <div class="visitor-preview__label">
843
- {{ label }} ({{ selectedVisitorMembers.length }})
844
- </div>
845
- <div class="visitor-preview__members">
846
- <div
847
- v-for="(member, index) in selectedVisitorMembers"
848
- :key="member?.nric || member?.name || index"
849
- class="visitor-preview__member"
850
- >
851
- <div class="visitor-preview__value">
852
- {{ member?.name || "N/A" }}
853
- </div>
854
- <template v-for="field in memberDetailFields" :key="field.key">
855
- <div
856
- v-if="member?.[field.key]"
857
- class="visitor-preview__member-line"
858
- >
859
- <span class="visitor-preview__member-key">
860
- {{ field.label }}
861
- </span>
862
- <!-- A member's NRIC is the same class of data as the
863
- visitor's, so it gets the same control. Each
864
- member reveals separately - one toggle for the
865
- whole card would show three people's NRICs to
866
- read one. -->
867
- <button
868
- v-if="field.key === 'nric'"
869
- type="button"
870
- class="visitor-preview__reveal"
871
- :aria-label="
872
- isMemberNricShown(index)
873
- ? `Hide NRIC for ${member?.name || 'this member'}`
874
- : `Show NRIC for ${member?.name || 'this member'}`
875
- "
876
- :aria-pressed="isMemberNricShown(index)"
877
- @click="toggleMemberNric(index)"
878
- >
879
- <span>
880
- {{
881
- isMemberNricShown(index)
882
- ? member.nric
883
- : maskNRIC(member.nric)
884
- }}
885
- </span>
886
- <v-icon size="16" class="visitor-preview__eye">
887
- {{
888
- isMemberNricShown(index)
889
- ? "mdi-eye-off-outline"
890
- : "mdi-eye-outline"
891
- }}
892
- </v-icon>
893
- </button>
894
- <span v-else>{{ member[field.key] }}</span>
895
- </div>
896
- </template>
897
- </div>
898
- </div>
899
- </div>
900
-
901
799
  <div
902
800
  v-else-if="selectedVisitorObject[key]"
903
801
  class="visitor-preview__row"
@@ -2000,71 +1898,6 @@ const isSelectedVisitorPendingApproval = computed(
2000
1898
  () => selectedVisitorStatus.value === "pending"
2001
1899
  );
2002
1900
 
2003
- /**
2004
- * The members a contractor brought with them. Not gated on the Guests tab: the
2005
- * list row's own `( +N members)` count is not either, and a contractor with a
2006
- * party has one wherever the screen shows it.
2007
- *
2008
- * Blank entries are dropped rather than drawn as an empty card - the payload
2009
- * carries `""` for every detail nobody filled in, so a member with no name and
2010
- * no details would otherwise render as a bare inset box.
2011
- */
2012
- const selectedVisitorMembers = computed<Record<string, any>[]>(() => {
2013
- const members = selectedVisitorDataObject.value?.members;
2014
- if (!Array.isArray(members)) return [];
2015
-
2016
- return members.filter(
2017
- (member: Record<string, any>) =>
2018
- member?.name || member?.nric || member?.contact || member?.plateNumber
2019
- );
2020
- });
2021
-
2022
- /**
2023
- * WHICH NRICs ARE UNCOVERED RIGHT NOW.
2024
- *
2025
- * Per member and not per card, so revealing one person's number does not
2026
- * uncover the rest of the party's. Both are cleared when the dialog closes -
2027
- * a preview must not open on the next visitor with the last one's NRIC
2028
- * already showing, and it is the same `selectedVisitorId` that would carry it
2029
- * across if the same row were reopened.
2030
- */
2031
- const showVisitorNric = ref(false);
2032
- const shownMemberNrics = ref<number[]>([]);
2033
-
2034
- function isMemberNricShown(index: number) {
2035
- return shownMemberNrics.value.includes(index);
2036
- }
2037
-
2038
- function toggleMemberNric(index: number) {
2039
- shownMemberNrics.value = isMemberNricShown(index)
2040
- ? shownMemberNrics.value.filter((x) => x !== index)
2041
- : [...shownMemberNrics.value, index];
2042
- }
2043
-
2044
- watch(
2045
- () => dialog.viewVisitor,
2046
- (open) => {
2047
- if (open) return;
2048
- showVisitorNric.value = false;
2049
- shownMemberNrics.value = [];
2050
- }
2051
- );
2052
-
2053
- /**
2054
- * What a member row prints under the name, in order. `plateNumber` is in here
2055
- * because the API returns it on `members[]` even though neither
2056
- * `TMemberInfo` (this package) nor `TContractorMembers` (API-core's visitor
2057
- * model, name and nric only) declares it - the two types have drifted from the
2058
- * document and from each other. Reading the key defensively costs nothing and
2059
- * shows the vehicle a member actually arrived in; the types are somebody's to
2060
- * reconcile separately.
2061
- */
2062
- const memberDetailFields = [
2063
- { key: "nric", label: "NRIC" },
2064
- { key: "contact", label: "Contact" },
2065
- { key: "plateNumber", label: "Vehicle" },
2066
- ] as const;
2067
-
2068
1901
  const formatType = (item: any) =>
2069
1902
  (item.deliveryType ? item.deliveryType + "-" : "") + item.type;
2070
1903
 
@@ -2078,7 +1911,6 @@ const formattedFields = {
2078
1911
  level: "Level",
2079
1912
  unit: "Unit",
2080
1913
  purpose: "Purpose",
2081
- members: "Members",
2082
1914
  checkIn: "Check In",
2083
1915
  snapshotEntryImage: "Entry Image",
2084
1916
  checkOut: "Check Out",
@@ -3057,100 +2889,6 @@ watchEffect(async () => {
3057
2889
  word-break: break-word;
3058
2890
  }
3059
2891
 
3060
- /* A row whose value is a set of records rather than a value - it drops the
3061
- two-column grid and runs the full width of the card body. */
3062
- .visitor-preview__row--block {
3063
- display: block;
3064
- }
3065
-
3066
- .visitor-preview__members {
3067
- display: flex;
3068
- flex-direction: column;
3069
- gap: 8px;
3070
- margin-top: 8px;
3071
- }
3072
-
3073
- /*
3074
- * An added member reads as an inset on the card it sits in - `--hover` on
3075
- * `--border` at the inner radius. Those are `Card/MemberInfoSummary`'s three
3076
- * decisions, unchanged, so a member looks the same in the preview as it does
3077
- * in the form that created it. Only the TYPE differs: that card still prints
3078
- * `<strong>Label:</strong> value`, which is the pattern this dialog just moved
3079
- * off, so the lines below are set on the scale rather than inherited.
3080
- */
3081
- .visitor-preview__member {
3082
- padding: 9px 12px;
3083
- border: 1px solid var(--border);
3084
- border-radius: var(--r-inner);
3085
- background: var(--hover);
3086
- }
3087
-
3088
- .visitor-preview__member-line {
3089
- display: flex;
3090
- gap: 8px;
3091
- margin-top: 3px;
3092
- font-size: var(--fs-breadcrumb);
3093
- color: var(--text2);
3094
- word-break: break-word;
3095
- }
3096
-
3097
- .visitor-preview__member-key {
3098
- flex: 0 0 52px;
3099
- color: var(--muted);
3100
- }
3101
-
3102
- /*
3103
- * THE NRIC REVEAL.
3104
- *
3105
- * The pressable thing is the masked number, not the glyph beside it: an eye on
3106
- * its own is a 14-16px target where 24px is the floor, and on a 12.5px member
3107
- * line an `AppButton variant="icon"` - the layer's 32px icon square - would
3108
- * make the NRIC line half again the height of the Contact line under it.
3109
- * Pressing the digits gives a target the width of the value at no cost to the
3110
- * rhythm, and reads the right way round: the number is what changes.
3111
- *
3112
- * It inherits its type rather than setting any, so the visitor's NRIC stays on
3113
- * `--fs-cell` and a member's on the `--fs-breadcrumb` of the line it sits in.
3114
- * The negative margin pays back the padding, so a revealed value starts on the
3115
- * same left edge as every other value in the card.
3116
- */
3117
- .visitor-preview__reveal {
3118
- display: inline-flex;
3119
- align-items: center;
3120
- gap: 6px;
3121
- margin: -3px -7px;
3122
- padding: 3px 7px;
3123
- border: none;
3124
- border-radius: var(--r-inner-sm);
3125
- background: transparent;
3126
- font: inherit;
3127
- color: inherit;
3128
- text-align: left;
3129
- cursor: pointer;
3130
- transition: background var(--motion) ease;
3131
- }
3132
-
3133
- .visitor-preview__reveal:hover {
3134
- background: var(--hover);
3135
- }
3136
-
3137
- .visitor-preview__reveal:focus-visible {
3138
- outline: 2px solid var(--accent);
3139
- outline-offset: 1px;
3140
- }
3141
-
3142
- /* The design's interactive ink - not Vuetify's fixed blue, which is one colour
3143
- on both themes. `affectedEntities` gives its NRIC eye the same value. */
3144
- .visitor-preview__eye {
3145
- color: var(--accent-text);
3146
- }
3147
-
3148
- @media (prefers-reduced-motion: reduce) {
3149
- .visitor-preview__reveal {
3150
- transition: none;
3151
- }
3152
- }
3153
-
3154
2892
  /* The width the type filter carried as `max-width="200"` on the v-select. */
3155
2893
  .visitor-type-filter {
3156
2894
  max-width: 200px;
@@ -31,6 +31,60 @@ export default function useRole() {
31
31
  });
32
32
  }
33
33
 
34
+ /**
35
+ * The roles an INVITATION into `org` may actually hand out.
36
+ *
37
+ * The invite endpoints refuse a role the invitation is not entitled to
38
+ * (`core console-authz.util requireRoleInvitable` -> `invite-role-scope.util
39
+ * roleInvitable`), and that decision is a UNION that `GET /api/roles` cannot
40
+ * express in one call:
41
+ *
42
+ * - an ORG-LESS role is a template and is accepted for any organisation.
43
+ * Measured on staging: 341 of the 942 role-carrying invitations name one,
44
+ * so a picker that asks only for `org: <id>` locks every one of them out.
45
+ * - a role whose `org` IS the invited organisation.
46
+ * - never a `type: "admin"` role -- that is the Seven365 console's own staff
47
+ * type, and the server refuses it on any non-staff invitation.
48
+ *
49
+ * So: two reads, merged. `type: "organization"` on the org-less read is what
50
+ * excludes the staff roles there (the 12 org-less roles are 10 "organization"
51
+ * + 2 "admin"); the explicit filter covers the 1 org-SCOPED "admin" role,
52
+ * which the org read would otherwise return.
53
+ *
54
+ * `site` narrows the tenant half only, and only in the UI -- the server
55
+ * deliberately does not check a role's site, because a site is not a tenant
56
+ * boundary. A site-scoped screen still gets the organisation's site-less
57
+ * roles, because `getRoles` matches those too.
58
+ */
59
+ async function getInvitableRoles(
60
+ { search = "", org = "", site = "", limit = 50 } = {} as {
61
+ search?: string;
62
+ org?: string;
63
+ site?: string;
64
+ limit?: number;
65
+ }
66
+ ) {
67
+ const [tenant, templates] = await Promise.all([
68
+ org
69
+ ? getRoles({ search, org, site, limit })
70
+ : Promise.resolve({ items: [] } as Record<string, any>),
71
+ getRoles({ search, type: "organization", limit }),
72
+ ]);
73
+
74
+ const seen = new Set<string>();
75
+ const items = [...(tenant?.items ?? []), ...(templates?.items ?? [])].filter(
76
+ (role: Record<string, any>) => {
77
+ if (role?.type === "admin") return false;
78
+ const id = String(role?._id ?? "");
79
+ if (!id || seen.has(id)) return false;
80
+ seen.add(id);
81
+ return true;
82
+ }
83
+ );
84
+
85
+ return { items };
86
+ }
87
+
34
88
  function getRoleById(id: string) {
35
89
  return useNuxtApp().$api<TRole>(`/api/roles/id/${id}`, {
36
90
  method: "GET",
@@ -120,6 +174,7 @@ export default function useRole() {
120
174
  role,
121
175
  createRole,
122
176
  getRoles,
177
+ getInvitableRoles,
123
178
  getRoleById,
124
179
  updateRoleById,
125
180
  updateRoleFieldById,
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.2.21-staging.281",
5
+ "version": "4.2.22",
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.",