@7365admin1/layer-common 4.188.1 → 4.188.3

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,28 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.188.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 6fc06d5: Super Admin Client List / Client Details: a nature is now spelt the way the Invite Client dropdown spells it. `formatNature` title-cased the stored slug, so `mechanical_electrical_services` showed as "Mechanical Electrical Services" (no "&") and `estate_ranger_services` as "Estate Ranger Services"; they now read "Mechanical & Electrical Services" and "iRanger365". The stored value was always the correct slug - no API or data change. Workspace #1860.
8
+ - 6f6ffb8: Delete Role lists each person once, with one Reassign role field that moves all of their memberships on the role (Organisation and the app). It used to list the same e-mail twice (DV-1858).
9
+ - a1f8b08: Invitations: when the invite API saves the invitation but its e-mail could not be sent (`emailSent: false`, needs `@7365admin1/core` with the #1416 fix), Invite member closes as usual and the page shows the server's warning ("Invitation created, but the email could not be sent: ... Use Resend ..."); Resend shows the same warning instead of "Invitation re-sent". `InvitationForm` emits `email-not-sent` with that text. Workspace #1416.
10
+ - d115901: Members (all apps): the organisation owner's row no longer offers Assign Role, Suspend, Activate or Delete - to anybody, the owner included - and your own row no longer offers Suspend or Delete. The owner is the server's own test (core `hasOrgOwnership`): the organisation's `createdBy`, or its e-mail. The server already refused every one of these; the menu offered them anyway, and suspending or deleting the owner risks locking the organisation out. Every other row is unchanged. No API or data change. Workspace #1859.
11
+ - 1b9b278: Create Role: Submit stays off until at least one permission is ticked, and the footer says "Select at least one permission." A role with no permission was saved as full access (DV-1847).
12
+
13
+ ## 4.188.2
14
+
15
+ ### Patch Changes
16
+
17
+ - fc09b4b: Add a Resident QR Code Validity field to the Entry Pass QR Code tab. It edits
18
+ `settings.validityMinutes`, which the screen already loaded and saved but never
19
+ showed: whole minutes from 1 to 1440, empty saves null. Another section's Save
20
+ never sends an invalid, unsaved entry; it sends what is already saved.
21
+ - 4d19050: Import from Excel: a template made on another property can now be checked against this property (rows saved here only) instead of being refused outright.
22
+ - 0cd912b: Members list (all apps): the NAME column shows the person's own name instead of their e-mail (DV-1857).
23
+
24
+ The list showed the membership's name, which is often saved as the e-mail. It now shows the account's name first (`userName`, which GET /api/members already returns), then the membership's name, then the e-mail. The Site access dialog title uses the same name.
25
+
3
26
  ## 4.188.1
4
27
 
5
28
  ### Patch Changes
@@ -4106,11 +4129,11 @@ Monthly report: a month that had patrols opens the list of that month's patrol r
4106
4129
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
4107
4130
  own rule from two endpoints the console already calls, unprojected:
4108
4131
 
4109
- GET /api/members/user/:user/app/admin the Seven365 staff membership
4110
- GET /api/roles/id/:role that membership's role document
4132
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
4133
+ GET /api/roles/id/:role that membership's role document
4111
4134
 
4112
- owner = member.type === "admin" && role.type === "admin" && role.default === true
4113
- staff = member.type === "admin" && role.type === "admin"
4135
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
4136
+ staff = member.type === "admin" && role.type === "admin"
4114
4137
 
4115
4138
  `role.default` is the marker because it is the only property of a platform
4116
4139
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -321,8 +321,8 @@
321
321
  duplicate-note="Areas already on the list (same name and type) are skipped and left unchanged."
322
322
  template-file-name="areas-import-template.xlsx"
323
323
  :download-template="() => downloadTemplate('areas', importQuery)"
324
- :check="(file: File) => checkImport('areas', file, importQuery)"
325
- :commit="(file: File) => commitImport('areas', file, importQuery)"
324
+ :check="(file: File, extra?: { otherProperty?: boolean }) => checkImport('areas', file, { ...importQuery, ...extra })"
325
+ :commit="(file: File, extra?: { otherProperty?: boolean }) => commitImport('areas', file, { ...importQuery, ...extra })"
326
326
  @done="getTaskRefresh()"
327
327
  @error="(text: string) => showMessage(text, 'error')"
328
328
  />
@@ -35,8 +35,8 @@
35
35
  duplicate-note="Units already on that level are skipped and left unchanged."
36
36
  template-file-name="units-import-template.xlsx"
37
37
  :download-template="() => downloadTemplate('building-units', { site })"
38
- :check="(file: File) => checkImport('building-units', file, { site })"
39
- :commit="(file: File) => commitImport('building-units', file, { site })"
38
+ :check="(file: File, extra?: { otherProperty?: boolean }) => checkImport('building-units', file, { site, ...extra })"
39
+ :commit="(file: File, extra?: { otherProperty?: boolean }) => commitImport('building-units', file, { site, ...extra })"
40
40
  @done="getBuildingUnit()"
41
41
  @error="(text: string) => showMessage(text, 'error')"
42
42
  />
@@ -190,6 +190,55 @@
190
190
  </div>
191
191
  </v-col>
192
192
 
193
+ <v-divider />
194
+
195
+ <!-- Resident QR Code Validity -->
196
+ <!--
197
+ How long a resident's access QR stays valid before the app renews
198
+ it. Stored as `settings.validityMinutes`, which this screen already
199
+ loaded and saved but never showed. Empty saves null.
200
+ -->
201
+ <v-col cols="12">
202
+ <div class="mt-5 pb-5">
203
+ <p class="font-weight-medium mb-1">
204
+ Resident QR Code Validity
205
+ <span class="d-block text-caption screen-hint mt-1">
206
+ How long a resident's access QR code stays valid, in minutes,
207
+ before the resident app renews it.
208
+ </span>
209
+ </p>
210
+ <v-row class="mt-2">
211
+ <v-col cols="12" md="3">
212
+ <v-text-field
213
+ data-testid="entrypass-resident-qr-validity"
214
+ label="Validity (minutes)"
215
+ placeholder="e.g. 20"
216
+ type="number"
217
+ min="1"
218
+ :max="QR_VALIDITY_MAX_MINUTES"
219
+ density="comfortable"
220
+ clearable
221
+ :error-messages="qrValidityError"
222
+ v-model="currentEntryPassSettings.qrCodeValidityMinutes"
223
+ @update:modelValue="qrValidityError = ''"
224
+ />
225
+ </v-col>
226
+ </v-row>
227
+ <v-row>
228
+ <v-col cols="12" md="3">
229
+ <v-btn
230
+ color="primary"
231
+ variant="flat"
232
+ prepend-icon="mdi-content-save"
233
+ block
234
+ @click="saveQrValidity()"
235
+ >
236
+ Save
237
+ </v-btn>
238
+ </v-col>
239
+ </v-row>
240
+ </div>
241
+ </v-col>
193
242
 
194
243
  </v-row>
195
244
  </v-window-item>
@@ -933,7 +982,7 @@ function buildPayload() {
933
982
  subText: currentEntryPassSettings.value.qrCodeTemplateHeaderSubText,
934
983
  date: currentEntryPassSettings.value.qrCodeTemplateDate || null,
935
984
  },
936
- validityMinutes: currentEntryPassSettings.value.qrCodeValidityMinutes || null,
985
+ validityMinutes: validityMinutesForSave(),
937
986
  disclaimerMessage: currentEntryPassSettings.value.disclaimerMessage || "",
938
987
  url: currentEntryPassSettings.value.url,
939
988
  template: currentEntryPassSettings.value.template?.id
@@ -1003,6 +1052,44 @@ async function saveQrCodeTemplate() {
1003
1052
  getSiteEntryPassSettings();
1004
1053
  }
1005
1054
 
1055
+ /** One day. The QR payload can carry up to 65535 minutes, but a resident
1056
+ access QR lasting longer than a day defeats the point of renewing it. */
1057
+ const QR_VALIDITY_MAX_MINUTES = 1440;
1058
+ const qrValidityError = ref("");
1059
+
1060
+ /** Every Save on this screen sends the whole payload, so an unsaved, invalid
1061
+ entry in the validity field must not ride along with another section's
1062
+ save: anything but whole minutes in range sends what is already saved. */
1063
+ function validityMinutesForSave(): number | null {
1064
+ const minutes = Number(currentEntryPassSettings.value.qrCodeValidityMinutes);
1065
+ if (Number.isInteger(minutes) && minutes >= 1 && minutes <= QR_VALIDITY_MAX_MINUTES) {
1066
+ return minutes;
1067
+ }
1068
+ const raw = currentEntryPassSettings.value.qrCodeValidityMinutes;
1069
+ if (raw === null || raw === undefined || String(raw).trim() === "") return null;
1070
+ return getSiteEntryPassSettingsReq.value?.data?.settings?.validityMinutes ?? null;
1071
+ }
1072
+
1073
+ async function saveQrValidity() {
1074
+ const raw = currentEntryPassSettings.value.qrCodeValidityMinutes;
1075
+ // Cleared (null, or "" from the number field) saves null: no site value.
1076
+ if (raw === null || raw === undefined || String(raw).trim() === "") {
1077
+ currentEntryPassSettings.value.qrCodeValidityMinutes = null;
1078
+ } else {
1079
+ const minutes = Number(raw);
1080
+ if (!Number.isInteger(minutes) || minutes < 1 || minutes > QR_VALIDITY_MAX_MINUTES) {
1081
+ qrValidityError.value = `Enter whole minutes from 1 to ${QR_VALIDITY_MAX_MINUTES}.`;
1082
+ return;
1083
+ }
1084
+ // The number field hands back a string; store a number.
1085
+ currentEntryPassSettings.value.qrCodeValidityMinutes = minutes;
1086
+ }
1087
+ qrValidityError.value = "";
1088
+ await _save(buildPayload());
1089
+ showMessage("Resident QR code validity saved successfully!", "success");
1090
+ getSiteEntryPassSettings();
1091
+ }
1092
+
1006
1093
  async function saveResidentAppDisclaimerMsg() {
1007
1094
  await _save(buildPayload());
1008
1095
  showMessage("Disclaimer message saved successfully!", "success");
@@ -25,12 +25,20 @@
25
25
  density="comfortable"
26
26
  show-size
27
27
  :disabled="busy"
28
- @update:model-value="result = null"
28
+ @update:model-value="reset"
29
29
  />
30
30
 
31
+ <!-- Template made on another property: offer to check its rows here instead of starting again. -->
32
+ <v-alert v-if="otherPlaceMessage" type="warning" variant="tonal" class="mb-3">
33
+ {{ otherPlaceMessage }}
34
+ <div class="mt-2">Or keep your rows: they are checked against this property and shown to you before anything is saved, and saved to this property only.</div>
35
+ <v-btn size="small" variant="outlined" class="text-none mt-2" prepend-icon="mdi-file-check-outline" :loading="busy" @click="useOtherPlaceFile">Check these rows for this property</v-btn>
36
+ </v-alert>
37
+
31
38
  <template v-if="result">
32
39
  <v-alert :type="result.committed ? 'success' : result.errors ? 'error' : 'info'" variant="tonal" class="mb-3">
33
40
  {{ importSummary(result, noun) }}
41
+ <div v-if="otherProperty" class="mt-1">This file was made on another property. Its rows were checked against this property and are saved here only.</div>
34
42
  <div v-if="result.errors && !result.committed" class="mt-2">
35
43
  Fix the rows marked "Needs fixing" in your file, save it, then choose it again above.
36
44
  <br />
@@ -87,8 +95,8 @@ const props = defineProps({
87
95
  duplicateNote: { type: String, default: "Rows already in the system are skipped and left unchanged." },
88
96
  templateFileName: { type: String, required: true },
89
97
  downloadTemplate: { type: Function as PropType<() => Promise<Blob>>, required: true },
90
- check: { type: Function as PropType<(file: File) => Promise<TImportResult>>, required: true },
91
- commit: { type: Function as PropType<(file: File) => Promise<TImportResult>>, required: true },
98
+ check: { type: Function as PropType<(file: File, extra?: { otherProperty?: boolean }) => Promise<TImportResult>>, required: true },
99
+ commit: { type: Function as PropType<(file: File, extra?: { otherProperty?: boolean }) => Promise<TImportResult>>, required: true },
92
100
  });
93
101
  const emit = defineEmits<{ done: [result: TImportResult]; error: [message: string] }>();
94
102
 
@@ -97,6 +105,21 @@ const selected = computed<File | null>(() => (Array.isArray(file.value) ? (file.
97
105
  const result = ref<TImportResult | null>(null);
98
106
  const busy = ref(false);
99
107
  const downloading = ref(false);
108
+ /** Set when the user chose to check a file made on another property against this one. */
109
+ const otherProperty = ref(false);
110
+ const otherPlaceMessage = ref("");
111
+
112
+ function reset() {
113
+ result.value = null;
114
+ otherProperty.value = false;
115
+ otherPlaceMessage.value = "";
116
+ }
117
+
118
+ function useOtherPlaceFile() {
119
+ otherProperty.value = true;
120
+ otherPlaceMessage.value = "";
121
+ run(false);
122
+ }
100
123
 
101
124
  async function download() {
102
125
  downloading.value = true;
@@ -118,10 +141,11 @@ async function run(commit: boolean) {
118
141
  if (!selected.value) return;
119
142
  busy.value = true;
120
143
  try {
121
- result.value = await (commit ? props.commit : props.check)(selected.value);
144
+ result.value = await (commit ? props.commit : props.check)(selected.value, otherProperty.value ? { otherProperty: true } : undefined);
122
145
  if (commit) emit("done", result.value);
123
146
  } catch (error: any) {
124
- emit("error", error?.data?.message || "Could not read the file.");
147
+ if (error?.data?.name === "OtherPropertyFile" && !otherProperty.value) otherPlaceMessage.value = error.data.message;
148
+ else emit("error", error?.data?.message || "Could not read the file.");
125
149
  } finally {
126
150
  busy.value = false;
127
151
  }
@@ -130,7 +154,7 @@ async function run(commit: boolean) {
130
154
  watch(show, (open) => {
131
155
  if (open) {
132
156
  file.value = null;
133
- result.value = null;
157
+ reset();
134
158
  }
135
159
  });
136
160
  </script>
@@ -175,6 +175,7 @@ import useRole from '../composables/useRole';
175
175
  import useSite from '../composables/useSite';
176
176
  import { inviteRoleOptions } from '../utils/invite-role-options';
177
177
  import { roleSiteFor } from '../utils/invite-sites';
178
+ import { inviteNotEmailedNotice } from '../utils/invite-email-notice';
178
179
  import useUser from '../composables/useUser';
179
180
  import useUtils from '../composables/useUtils';
180
181
 
@@ -260,7 +261,7 @@ const props = defineProps({
260
261
  }
261
262
  });
262
263
 
263
- const emit = defineEmits(["cancel", "success", "success:create-more"]);
264
+ const emit = defineEmits(["cancel", "success", "success:create-more", "email-not-sent"]);
264
265
 
265
266
  const validForm = ref(false);
266
267
  const form = ref<HTMLFormElement | null>(null);
@@ -586,11 +587,15 @@ async function submit() {
586
587
  loading.submittingForm = true;
587
588
 
588
589
  try {
589
- if (props.inviteMember) {
590
- await inviteMemberClient(invite.value);
591
- } else {
592
- await inviteUser(invite.value);
593
- }
590
+ const res = props.inviteMember
591
+ ? await inviteMemberClient(invite.value)
592
+ : await inviteUser(invite.value);
593
+
594
+ // Saved, but its e-mail did not go out (#1416): still a success - the
595
+ // invitation is listed and can be re-sent - so close as usual and let the
596
+ // page warn.
597
+ const notice = inviteNotEmailedNotice(res);
598
+ if (notice) emit("email-not-sent", notice);
594
599
 
595
600
  if (createMore.value) {
596
601
  form.value?.reset();
@@ -187,6 +187,7 @@
187
187
  :invite-member="true"
188
188
  @cancel="dialogMember = false"
189
189
  @success="handleSuccess"
190
+ @email-not-sent="showMessage($event, 'warning')"
190
191
  @invited="getVerifications()"
191
192
  :app="props.app"
192
193
  />
@@ -198,6 +199,7 @@
198
199
  <script setup lang="ts">
199
200
  // Relative import: this layer's `utils/` is not auto-imported into consumers.
200
201
  import { invitationsEmptyText } from "../utils/invitations-empty-text";
202
+ import { inviteNotEmailedNotice } from "../utils/invite-email-notice";
201
203
  import {
202
204
  groupIds,
203
205
  resendArgs,
@@ -432,8 +434,11 @@ async function onResend(item: any) {
432
434
  if (resending.value) return;
433
435
  resending.value = true;
434
436
  try {
435
- await inviteMemberClient(args);
436
- showMessage("Invitation re-sent (one e-mail).", "success");
437
+ const res = await inviteMemberClient(args);
438
+ // The invitation is re-issued either way; say when its e-mail failed (#1416).
439
+ const notice = inviteNotEmailedNotice(res);
440
+ if (notice) showMessage(notice, "warning");
441
+ else showMessage("Invitation re-sent (one e-mail).", "success");
437
442
  await getVerifications();
438
443
  } catch (error: any) {
439
444
  showMessage(error?.data?.message || error?.message || "Failed to resend invitation", "error");
@@ -224,14 +224,10 @@
224
224
  `members:assign-member-role` and nothing else got no menu at all,
225
225
  and the permission was unreachable.
226
226
  -->
227
+ <!-- #1859: the organisation owner's row offers none of them, and
228
+ your own row no Suspend / Delete (`utils/member-row-actions`). -->
227
229
  <v-menu
228
- v-if="!isLimited(item) && (
229
- props.assignRole ||
230
- (currentStatus === 'active' &&
231
- (canSuspendMembers || canDeleteMembers)) ||
232
- (currentStatus === 'suspended' &&
233
- (canActivateMembers || canDeleteMembers)))
234
- "
230
+ v-if="!isLimited(item) && rowActions(item).menu"
235
231
  v-model="item.menuOpen"
236
232
  :close-on-content-click="false"
237
233
  offset-y
@@ -249,7 +245,7 @@
249
245
  <!-- Highlighted when the row's role chip is a warning (no /
250
246
  deleted / other org / other site role): this is the fix. -->
251
247
  <v-list-item
252
- v-if="props.assignRole"
248
+ v-if="rowActions(item).assignRole"
253
249
  :class="{
254
250
  'text-warning font-weight-bold':
255
251
  memberRoleChip(item)?.tone === 'warn',
@@ -280,19 +276,19 @@
280
276
  </v-list-item>
281
277
 
282
278
  <v-list-item
283
- v-if="currentStatus === 'active' && canSuspendMembers"
279
+ v-if="rowActions(item).suspend"
284
280
  @click="openUpdateDialog(item._id, 'suspended')"
285
281
  >
286
282
  Suspend
287
283
  </v-list-item>
288
284
  <v-list-item
289
- v-if="currentStatus === 'suspended' && canActivateMembers"
285
+ v-if="rowActions(item).activate"
290
286
  @click="openUpdateDialog(item._id, 'active')"
291
287
  >
292
288
  Activate
293
289
  </v-list-item>
294
290
  <v-list-item
295
- v-if="canDeleteMembers"
291
+ v-if="rowActions(item).delete"
296
292
  @click="openUpdateDialog(item._id, 'deleted')"
297
293
  >
298
294
  Delete
@@ -440,6 +436,7 @@ import {
440
436
  } from "../utils/role";
441
437
  import { formatLastActive } from "../utils/last-active";
442
438
  import { formatMemberDate, memberAccess, memberPerson } from "../utils/member-row";
439
+ import { memberRowActions } from "../utils/member-row-actions";
443
440
 
444
441
  const props = defineProps({
445
442
  /** The design's page title. Every app that mounts this screen calls it
@@ -707,6 +704,35 @@ const siteAccessAllowed = computed(() => props.assignRole && !props.siteId);
707
704
  one-membership actions (Assign Role, Suspend, Delete) are not offered on it;
708
705
  Site access manages them. */
709
706
  const isLimited = (item: Record<string, any>) => orgLevel.value && limitedSites(item).length > 0;
707
+ /*
708
+ * #1859: the organisation owner's row offered Assign Role, Suspend and Delete
709
+ * (all seven apps). The organisation's record names its owner - `createdBy`
710
+ * and its e-mail, the server's own test (core `hasOrgOwnership`) - and the
711
+ * signed-in user is the viewer. A failed or name-only read names no owner;
712
+ * the server still refuses, as it always did.
713
+ */
714
+ const { currentUser } = useLocalAuth();
715
+ const { data: ownerOrg } = useAsyncData(
716
+ `member-owner-org-${props.orgId}`,
717
+ () =>
718
+ props.orgId
719
+ ? useNuxtApp()
720
+ .$api<Record<string, any>>(`/api/organizations/id/${props.orgId}`)
721
+ .catch(() => null)
722
+ : Promise.resolve(null),
723
+ { watch: [() => props.orgId] }
724
+ );
725
+ const rowActions = (item: Record<string, any>) =>
726
+ memberRowActions({
727
+ item,
728
+ org: ownerOrg.value,
729
+ viewerId: String(currentUser.value?._id ?? ""),
730
+ status: currentStatus.value,
731
+ assignRole: props.assignRole,
732
+ canSuspend: props.canSuspendMembers,
733
+ canActivate: props.canActivateMembers,
734
+ canDelete: props.canDeleteMembers,
735
+ });
710
736
  /* Keep the actions column on screen however wide the table gets. */
711
737
  const actionLast = computed(() => props.headers[props.headers.length - 1]?.value === "action-table");
712
738
  const siteAccessDialog = ref(false);
@@ -714,7 +740,7 @@ const siteAccessUser = ref("");
714
740
  const siteAccessName = ref("");
715
741
  function openSiteAccess(item: Record<string, any>) {
716
742
  siteAccessUser.value = String(item.user ?? "");
717
- siteAccessName.value = String(item.name || item.email || "");
743
+ siteAccessName.value = memberPerson(item).name;
718
744
  siteAccessDialog.value = true;
719
745
  }
720
746
  function onSiteAccessSaved(msg: string) {
@@ -262,6 +262,10 @@
262
262
  <div v-if="message" class="role-create__save-error" role="alert">
263
263
  Couldn't save: {{ message }}
264
264
  </div>
265
+ <!-- DV-1847: a role with no permission was saved as full access. -->
266
+ <div v-else-if="!hasPermission" class="role-create__save-error" role="status">
267
+ Select at least one permission.
268
+ </div>
265
269
 
266
270
  <div class="role-create__footer">
267
271
  <AppButton
@@ -278,7 +282,7 @@
278
282
  </AppButton>
279
283
 
280
284
  <AppButton variant="ghost" @click="cancel">{{ props.cancelText }}</AppButton>
281
- <AppButton :disabled="!validForm || disable" @click="submit">Submit</AppButton>
285
+ <AppButton :disabled="!validForm || !hasPermission || disable" @click="submit">Submit</AppButton>
282
286
  </div>
283
287
  </v-card>
284
288
  </template>
@@ -294,7 +298,7 @@ import useRole from "../composables/useRole";
294
298
  import useUtils from "../composables/useUtils";
295
299
  import useSite from "../composables/useSite";
296
300
  import { readApiError } from "../utils/subscription-form";
297
- import { withSecurityMarker } from "../utils/security-catalogue";
301
+ import { countRealPermissions, withSecurityMarker } from "../utils/security-catalogue";
298
302
  import { isTradeCatalogue, withTradeMarker } from "../utils/trade-catalogue";
299
303
  import { applyRolePreset, ROLE_PRESETS, type TRolePreset } from "../utils/inventory-presets";
300
304
 
@@ -393,6 +397,11 @@ const catalogueSize = computed(() =>
393
397
  )
394
398
  );
395
399
 
400
+ // DV-1847: the catalogue marker is not a permission.
401
+ const hasPermission = computed(
402
+ () => countRealPermissions(permState.value.selected) > 0
403
+ );
404
+
396
405
  const totalLabel = computed(() => {
397
406
  const selected = permState.value.selected.length;
398
407
  return catalogueSize.value > 0
@@ -541,6 +550,7 @@ watch(
541
550
  );
542
551
 
543
552
  async function submit() {
553
+ if (!hasPermission.value) return;
544
554
  disable.value = true;
545
555
  message.value = "";
546
556
  try {
@@ -155,26 +155,33 @@
155
155
  <p class="mb-4">
156
156
  There are currently
157
157
  <span class="text-error font-weight-bold">
158
- {{ deletionPreview.members.length }}
159
- {{ deletionPreview.members.length === 1 ? "user" : "users" }}
158
+ {{ deletionPeople.length }}
159
+ {{ deletionPeople.length === 1 ? "user" : "users" }}
160
160
  </span>
161
161
  assigned to this role. Reassign each user before deleting it so
162
162
  they do not lose access.
163
163
  </p>
164
164
 
165
+ <!-- DV-1858: one row per person; their memberships move together. -->
165
166
  <v-row
166
- v-for="member in deletionPreview.members"
167
- :key="member._id"
167
+ v-for="person in deletionPeople"
168
+ :key="person.key"
168
169
  no-gutters
169
170
  class="mb-3 pa-3 border rounded-lg"
170
171
  align="center"
171
172
  >
172
173
  <v-col cols="12" sm="5" class="mb-2 mb-sm-0">
173
- {{ member.name || member.user }}
174
+ {{ person.name || person.email || person.key }}
175
+ <div
176
+ v-if="person.name && person.email && person.name !== person.email"
177
+ class="text-caption text-medium-emphasis"
178
+ >
179
+ {{ person.email }}
180
+ </div>
174
181
  </v-col>
175
182
  <v-col cols="12" sm="7">
176
183
  <v-select
177
- v-model="memberReassignments[member._id]"
184
+ v-model="memberReassignments[person.key]"
178
185
  :items="deletionPreview.replacementRoles"
179
186
  :item-title="props.siteId ? sitePickerRoleLabel : roleLabel"
180
187
  item-value="_id"
@@ -219,6 +226,7 @@
219
226
  import { roleAppLabel, roleLabel, safeReturnTo, showSiteField, sitePickerRoleLabel } from "../utils/role";
220
227
  import { holdsPermission } from "../utils/permission-spellings";
221
228
  import { countRealPermissions } from "../utils/security-catalogue";
229
+ import { groupDeletionMembers, reassignmentsFor } from "../utils/role-deletion-people";
222
230
  import {
223
231
  catalogueForOrg,
224
232
  catalogueForOwnerGrant,
@@ -728,9 +736,14 @@ const hasAssignedMembers = computed(
728
736
  () => deletionPreview.value.members.length > 0
729
737
  );
730
738
 
739
+ // DV-1858: a person has a membership per scope (Organisation and the app).
740
+ const deletionPeople = computed(() =>
741
+ groupDeletionMembers(deletionPreview.value.members)
742
+ );
743
+
731
744
  const canConfirmDeletion = computed(() =>
732
- deletionPreview.value.members.every(
733
- (member) => Boolean(memberReassignments.value[member._id])
745
+ deletionPeople.value.every((person) =>
746
+ Boolean(memberReassignments.value[person.key])
734
747
  )
735
748
  );
736
749
 
@@ -773,10 +786,10 @@ async function handleDeleteRole() {
773
786
  if (!selectedRoleId.value) return;
774
787
  deleteLoading.value = true;
775
788
  try {
776
- const reassignments = deletionPreview.value.members.map((member) => ({
777
- memberId: member._id,
778
- roleId: memberReassignments.value[member._id],
779
- }));
789
+ const reassignments = reassignmentsFor(
790
+ deletionPeople.value,
791
+ memberReassignments.value
792
+ );
780
793
  const res = hasAssignedMembers.value
781
794
  ? await deleteWithReassignments(selectedRoleId.value, reassignments)
782
795
  : await deleteRole(selectedRoleId.value);
@@ -193,8 +193,8 @@
193
193
  duplicate-note="Units already on the list are skipped and left unchanged."
194
194
  template-file-name="units-import-template.xlsx"
195
195
  :download-template="() => downloadTemplate('units', importQuery)"
196
- :check="(file: File) => checkImport('units', file, importQuery)"
197
- :commit="(file: File) => commitImport('units', file, importQuery)"
196
+ :check="(file: File, extra?: { otherProperty?: boolean }) => checkImport('units', file, { ...importQuery, ...extra })"
197
+ :commit="(file: File, extra?: { otherProperty?: boolean }) => commitImport('units', file, { ...importQuery, ...extra })"
198
198
  @done="getUnitsRefresh()"
199
199
  @error="(text: string) => showMessage(text, 'error')"
200
200
  />
@@ -8,17 +8,20 @@ import type { TImportResult } from "../utils/import-result";
8
8
  */
9
9
  export type TTemplateKind = "building-units" | "areas" | "units" | "vehicles" | "cameras";
10
10
 
11
+ type TImportQuery = { site: string; serviceType?: string; otherProperty?: boolean };
12
+
11
13
  export default function useImportTemplates() {
12
14
  const api = <T = any>(kind: TTemplateKind, path: string, options: Record<string, any> = {}) =>
13
15
  useNuxtApp().$api<T>(`/api/import-templates/${kind}/${path}`, options);
14
- const send = (kind: TTemplateKind, path: "check" | "commit", file: File, query: Record<string, string | undefined>) => {
16
+ const send = (kind: TTemplateKind, path: "check" | "commit", file: File, query: TImportQuery) => {
15
17
  const body = new FormData();
16
18
  body.append("file", file);
17
19
  return api<TImportResult>(kind, path, { method: "POST", body, query });
18
20
  };
19
21
  return {
20
22
  downloadTemplate: (kind: TTemplateKind, query: { site: string; serviceType?: string }) => api<Blob>(kind, "template", { query, responseType: "blob" }),
21
- checkImport: (kind: TTemplateKind, file: File, query: { site: string; serviceType?: string }) => send(kind, "check", file, query),
22
- commitImport: (kind: TTemplateKind, file: File, query: { site: string; serviceType?: string }) => send(kind, "commit", file, query),
23
+ // otherProperty: the user chose to check a file made on another property against this one (rows still saved to `site`).
24
+ checkImport: (kind: TTemplateKind, file: File, query: TImportQuery) => send(kind, "check", file, query),
25
+ commitImport: (kind: TTemplateKind, file: File, query: TImportQuery) => send(kind, "commit", file, query),
23
26
  };
24
27
  }
@@ -316,8 +316,25 @@ export default function useUtils() {
316
316
  return `${day}/${month}/${year}`;
317
317
  }
318
318
 
319
+ /*
320
+ * A nature is stored as a slug (`mechanical_electrical_services`), so
321
+ * title-casing it cannot bring back what the slug never held: the "&" of
322
+ * "Mechanical & Electrical Services", or the product name "iRanger365".
323
+ * Natures whose name is not their slug in words are spelt here exactly as
324
+ * the Invite Client dropdown spells them (`InvitationClientForm.vue`
325
+ * APP_LIST); every other value - including ones the model does not list,
326
+ * like `property_owner` - is still title-cased.
327
+ */
328
+ const NATURE_LABELS: Readonly<Record<string, string>> = {
329
+ mechanical_electrical_services: "Mechanical & Electrical Services",
330
+ estate_ranger_services: "iRanger365",
331
+ };
332
+
319
333
  function formatNature(value: string): string {
320
334
  if (!value) return "";
335
+ if (Object.prototype.hasOwnProperty.call(NATURE_LABELS, value)) {
336
+ return NATURE_LABELS[value];
337
+ }
321
338
  return value
322
339
  .split("_")
323
340
  .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
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.188.1",
5
+ "version": "4.188.3",
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,16 @@
1
+ /**
2
+ * Workspace #1416: Invite member / Resend used to get a 500 when the
3
+ * invitation was saved but its e-mail failed, so the dialog stayed open over
4
+ * an invitation that already existed. The API now answers 201 with
5
+ * `emailSent: false` and a message; this is the warning to show, or "" when
6
+ * the e-mail went out (or the API is older and does not say).
7
+ */
8
+ export function inviteNotEmailedNotice(
9
+ res: { message?: string; emailSent?: boolean } | null | undefined,
10
+ ): string {
11
+ if (res?.emailSent !== false) return "";
12
+ return (
13
+ res.message ||
14
+ "Invitation created, but the email could not be sent. Use Resend on the invitation to try again."
15
+ );
16
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Which actions one row of the Members table offers (#1859).
3
+ *
4
+ * The organisation owner's row offered Assign Role, Suspend and Delete - in all
5
+ * seven apps, to the owner looking at their own row too. Suspending or deleting
6
+ * the owner can lock the organisation out. The server already refuses each of
7
+ * them (core `requireNotOwnerUnlessOwner`, and "You cannot suspend or remove
8
+ * your own access." in `requireMemberStatusChanger`); the screen offered them
9
+ * anyway, so pressing one ended in a red error.
10
+ *
11
+ * - The owner's row: no Assign Role, Suspend, Activate or Delete, for anybody.
12
+ * - Your own row: no Suspend or Delete.
13
+ * - Every other row: exactly what the permissions gave it before.
14
+ */
15
+
16
+ type TRow = Record<string, any> | null | undefined;
17
+
18
+ function idOf(value: unknown): string {
19
+ if (typeof value === "string") return value.trim();
20
+ const hex = (value as any)?.toHexString;
21
+ return typeof hex === "function" ? String(hex.call(value)).trim() : "";
22
+ }
23
+
24
+ function emailOf(value: unknown): string {
25
+ return typeof value === "string" ? value.trim().toLowerCase() : "";
26
+ }
27
+
28
+ /**
29
+ * Is this the organisation owner's row? The same test the server applies
30
+ * (core `hasOrgOwnership`): the account that created the organisation
31
+ * (`createdBy`), or the organisation's own e-mail. A name-only organisation
32
+ * record (no `createdBy`, no `email`) names nobody.
33
+ */
34
+ export function isOrgOwnerRow(item: TRow, org: TRow): boolean {
35
+ const user = idOf(item?.user);
36
+ const owner = idOf(org?.createdBy);
37
+ if (user && owner && user === owner) return true;
38
+ const email = emailOf(item?.email);
39
+ const orgEmail = emailOf(org?.email);
40
+ return !!email && !!orgEmail && email === orgEmail;
41
+ }
42
+
43
+ export type TMemberRowActions = {
44
+ /** Whether the row's three-dot menu is drawn at all. */
45
+ menu: boolean;
46
+ assignRole: boolean;
47
+ suspend: boolean;
48
+ activate: boolean;
49
+ delete: boolean;
50
+ };
51
+
52
+ export function memberRowActions(input: {
53
+ item: TRow;
54
+ org: TRow;
55
+ /** The signed-in user's id. */
56
+ viewerId?: string;
57
+ /** The tab: "active", "suspended", or an app's extra tab. */
58
+ status: string;
59
+ assignRole: boolean;
60
+ canSuspend: boolean;
61
+ canActivate: boolean;
62
+ canDelete: boolean;
63
+ }): TMemberRowActions {
64
+ const owner = isOrgOwnerRow(input.item, input.org);
65
+ const viewer = idOf(input.viewerId);
66
+ const self = !!viewer && idOf(input.item?.user) === viewer;
67
+ const locked = owner || self;
68
+
69
+ const assignRole = input.assignRole && !owner;
70
+ const suspend = input.status === "active" && input.canSuspend && !locked;
71
+ const activate = input.status === "suspended" && input.canActivate && !owner;
72
+ const del = input.canDelete && !locked;
73
+ // As before: Delete alone opens the menu only on Active / Inactive.
74
+ const onStatusTab = input.status === "active" || input.status === "suspended";
75
+ const menu = assignRole || (onStatusTab && (suspend || activate || del));
76
+
77
+ return { menu, assignRole, suspend, activate, delete: del };
78
+ }
@@ -66,9 +66,17 @@ export function memberAccess(item: Record<string, any> | null | undefined, orgLe
66
66
  return { roles: text ? [text] : [], tone: chip?.tone ?? "info", scope, sites: [] };
67
67
  }
68
68
 
69
- /** Name on top, email underneath - the email only when it adds something. */
69
+ /**
70
+ * Name on top, email underneath - the email only when it adds something.
71
+ *
72
+ * The ACCOUNT's name (`userName`, from GET /api/members) first, then the
73
+ * membership's. A membership is often saved with the e-mail as its name (core
74
+ * `createMemberDirect`), while the account holds the name the person signed up
75
+ * with (DV-1857). Same order as the HID picker (`memberCandidateOf`).
76
+ */
70
77
  export function memberPerson(item: Record<string, any> | null | undefined): { name: string; email: string } {
71
- const name = typeof item?.name === "string" ? item.name.trim() : "";
78
+ const text = (value: unknown) => (typeof value === "string" ? value.trim() : "");
79
+ const name = text(item?.userName) || text(item?.name);
72
80
  const email = typeof item?.email === "string" ? item.email.trim() : "";
73
81
  if (!name) return { name: email, email: "" };
74
82
  return { name, email: email.toLowerCase() === name.toLowerCase() ? "" : email };
@@ -0,0 +1,48 @@
1
+ /**
2
+ * DV-1858: who holds a role, one entry per PERSON.
3
+ *
4
+ * The deletion preview returns one row per membership, and a person usually
5
+ * has two on the same role (Organisation and the app), so Delete Role listed
6
+ * them twice with two Reassign fields. Group by `user`; keep every membership
7
+ * id so one choice reassigns all of them (the API refuses a reassignment that
8
+ * leaves any membership on the deleted role).
9
+ */
10
+ export type TDeletionPerson = {
11
+ key: string;
12
+ name: string;
13
+ email: string;
14
+ memberIds: string[];
15
+ };
16
+
17
+ const idOf = (v: unknown) => String((v as any)?.toString?.() ?? v ?? "").trim();
18
+
19
+ export function groupDeletionMembers(
20
+ members: ReadonlyArray<Record<string, any>> | null | undefined,
21
+ ): TDeletionPerson[] {
22
+ const people = new Map<string, TDeletionPerson>();
23
+ for (const m of members ?? []) {
24
+ const memberId = idOf(m?._id);
25
+ const key = idOf(m?.user) || `member:${memberId}`;
26
+ const found = people.get(key);
27
+ if (found) {
28
+ found.memberIds.push(memberId);
29
+ if (!found.name && m?.name) found.name = String(m.name);
30
+ if (!found.email && m?.email) found.email = String(m.email);
31
+ continue;
32
+ }
33
+ people.set(key, {
34
+ key,
35
+ name: String(m?.name ?? ""),
36
+ email: String(m?.email ?? ""),
37
+ memberIds: [memberId],
38
+ });
39
+ }
40
+ return [...people.values()];
41
+ }
42
+
43
+ export function reassignmentsFor(
44
+ people: ReadonlyArray<TDeletionPerson>,
45
+ choice: Record<string, string>,
46
+ ): Array<{ memberId: string; roleId: string }> {
47
+ return people.flatMap((p) => p.memberIds.map((memberId) => ({ memberId, roleId: choice[p.key] })));
48
+ }