@7365admin1/layer-common 4.97.1-staging.524 → 4.97.1-staging.525

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.
@@ -584,6 +584,70 @@
584
584
  </p>
585
585
  </template>
586
586
 
587
+ <!-- EDITING SOMEBODY WHO IS ON SEVERAL READERS.
588
+ The same list, for the same reason, except the readers are the
589
+ ones that already hold this person rather than the ones that would
590
+ take them. Said before the save because of the PIN: a changed PIN
591
+ that reaches two readers of three leaves this person holding two
592
+ PINs, so the operator needs to know the change travels. -->
593
+ <template v-else-if="editPlaces.length > 1 || readerOutcomes.length">
594
+ <div class="field-label">
595
+ {{ readerOutcomes.length ? "Updating on" : "Also on" }}
596
+ </div>
597
+
598
+ <div class="hid-fanout mb-1">
599
+ <div
600
+ v-for="outcome in editRows"
601
+ :key="outcome.readerId"
602
+ class="hid-fanout__row"
603
+ :class="`hid-fanout__row--${outcome.step}`"
604
+ >
605
+ <v-icon
606
+ :icon="
607
+ outcome.step === 'done'
608
+ ? 'mdi-check-circle-outline'
609
+ : outcome.step === 'failed'
610
+ ? 'mdi-alert-circle-outline'
611
+ : outcome.step === 'working'
612
+ ? 'mdi-progress-upload'
613
+ : outcome.step === 'target'
614
+ ? 'mdi-check'
615
+ : 'mdi-clock-outline'
616
+ "
617
+ size="17"
618
+ />
619
+ <div class="hid-fanout__body">
620
+ <strong>{{ outcome.name }}</strong>
621
+ <span v-if="outcome.message">{{ outcome.message }}</span>
622
+ </div>
623
+ </div>
624
+ </div>
625
+
626
+ <p v-if="fanOutProgress && fanOutRunning" class="field-hint mb-3">
627
+ {{ fanOutProgress }}
628
+ </p>
629
+ <p
630
+ v-else-if="editResult"
631
+ class="field-hint mb-3"
632
+ :class="{ 'field-hint--error': editResult.tone !== 'success' }"
633
+ >
634
+ {{ editResult.message }}
635
+ </p>
636
+ <!-- Registration is the one field that does NOT travel: each reader
637
+ allocates its own, and one number written to all would collide. -->
638
+ <p v-else class="field-hint mb-3">
639
+ Name, photo, PIN and password are updated on every reader. The
640
+ registration number is each reader's own.
641
+ </p>
642
+ </template>
643
+
644
+ <p
645
+ v-else-if="editPlacesLoading"
646
+ class="field-hint mb-3"
647
+ >
648
+ Checking which readers hold this person...
649
+ </p>
650
+
587
651
  <div class="field-label">Name</div>
588
652
  <AppField
589
653
  v-model="form.name"
@@ -1031,20 +1095,76 @@
1031
1095
  </v-card>
1032
1096
  </v-dialog>
1033
1097
 
1034
- <v-dialog v-model="deleteDialog" max-width="360" persistent>
1098
+ <v-dialog v-model="deleteDialog" max-width="420" persistent>
1035
1099
  <v-card class="screen-modal">
1036
1100
  <v-card-title>Delete</v-card-title>
1037
1101
  <v-card-text class="screen-modal__body text-body-2">
1038
1102
  Are you sure you want to permanently delete this HID user?
1103
+
1104
+ <div v-if="deletePlacesLoading" class="text-caption text-medium-emphasis mt-2">
1105
+ Checking which readers hold this person...
1106
+ </div>
1107
+ <div v-else class="text-caption text-medium-emphasis mt-2">
1108
+ {{ deleteReach }}
1109
+ </div>
1110
+
1111
+ <!-- Only a choice when there is one to make. On one reader the radios
1112
+ would ask the operator to confirm the only possible answer. -->
1113
+ <v-radio-group
1114
+ v-if="deleteScopeOptions.length > 1"
1115
+ v-model="deleteScope"
1116
+ class="mt-2"
1117
+ density="compact"
1118
+ hide-details
1119
+ :disabled="deleting"
1120
+ >
1121
+ <v-radio
1122
+ v-for="choice in deleteScopeOptions"
1123
+ :key="choice.value"
1124
+ :label="choice.label"
1125
+ :value="choice.value"
1126
+ density="compact"
1127
+ />
1128
+ </v-radio-group>
1129
+
1130
+ <!-- Per-reader, so a reader that refused is named rather than hidden
1131
+ behind a single failure message. -->
1132
+ <div v-if="deleteOutcomes.length > 1" class="mt-3">
1133
+ <div
1134
+ v-for="outcome in deleteOutcomes"
1135
+ :key="outcome.readerId"
1136
+ class="d-flex align-center justify-space-between text-caption"
1137
+ >
1138
+ <span>{{ outcome.name }}</span>
1139
+ <span
1140
+ :class="outcome.step === 'failed'
1141
+ ? 'text-error'
1142
+ : 'text-medium-emphasis'"
1143
+ >
1144
+ {{ outcome.step === "done" ? "Deleted"
1145
+ : outcome.step === "failed" ? (outcome.message || "Failed")
1146
+ : outcome.step === "working" ? "Deleting..." : "Waiting" }}
1147
+ </span>
1148
+ </div>
1149
+ </div>
1150
+
1151
+ <div
1152
+ v-if="deleteSummary && deleteSummary.tone !== 'success'"
1153
+ class="text-caption text-error mt-2"
1154
+ >
1155
+ {{ deleteSummary.message }}
1156
+ </div>
1157
+
1039
1158
  <div class="text-caption text-medium-emphasis mt-2">
1040
- This action will remove the user from the HID reader and mark the
1041
- identity as deleted.
1159
+ This removes the user from the reader and marks the identity as
1160
+ deleted, which also takes away the access that let them through.
1042
1161
  </div>
1043
1162
  </v-card-text>
1044
1163
  <v-card-actions class="screen-modal__footer">
1045
1164
  <v-btn
1046
1165
  class="text-none screen-btn-ghost"
1047
1166
  variant="flat"
1167
+ :disabled="deleting"
1048
1168
  @click="deleteDialog = false"
1049
1169
  >
1050
1170
  Cancel
@@ -1052,10 +1172,12 @@
1052
1172
  <v-btn
1053
1173
  class="text-none screen-btn-primary"
1054
1174
  variant="flat"
1055
- :loading="deleting"
1175
+ :loading="deleting || deletePlacesLoading"
1056
1176
  @click="deleteUser"
1057
1177
  >
1058
- Delete
1178
+ {{ deleteSummary && deleteSummary.tone === "partial"
1179
+ ? "Try again"
1180
+ : "Delete" }}
1059
1181
  </v-btn>
1060
1182
  </v-card-actions>
1061
1183
  </v-card>
@@ -1092,6 +1214,10 @@ import {
1092
1214
  what is worth offering and where an enrolment lands. */
1093
1215
  import {
1094
1216
  availableEnrolmentSubjects,
1217
+ deleteFanOutSummary,
1218
+ deleteReachText,
1219
+ deleteScopeChoices,
1220
+ editFanOutSummary,
1095
1221
  fanOutProgressText,
1096
1222
  fanOutSummary,
1097
1223
  partitionEnrolmentTargets,
@@ -1243,7 +1369,36 @@ const saving = ref(false);
1243
1369
  const deleting = ref(false);
1244
1370
  const formDialog = ref(false);
1245
1371
  const viewDialog = ref(false);
1372
+ /** One reader that holds this person, and the ids that reader knows them by. */
1373
+ type TPersonPlace = {
1374
+ readerId: string;
1375
+ name: string;
1376
+ identityId: string;
1377
+ hidUserId: string;
1378
+ };
1379
+
1246
1380
  const deleteDialog = ref(false);
1381
+ /* Where this person actually is, resolved when the dialog opens so the operator
1382
+ chooses the scope knowing the reach rather than after the fact. */
1383
+ const deletePlaces = ref<TPersonPlace[]>([]);
1384
+ const deletePlacesLoading = ref(false);
1385
+ const deleteScope = ref<"here" | "all">("here");
1386
+ /* Kept apart from the enrolment fan-out's outcomes on purpose: that list drives
1387
+ a Retry that RE-ENROLS, which is the wrong action for a reader a delete could
1388
+ not reach. */
1389
+ const deleteOutcomes = ref<THidReaderOutcome[]>([]);
1390
+ const deleteReach = computed(
1391
+ () => deleteReachText(deletePlaces.value, selectedReaderId.value),
1392
+ );
1393
+ const deleteScopeOptions = computed(() => deleteScopeChoices(
1394
+ deletePlaces.value.length,
1395
+ selectedReader.value?.name || "this reader",
1396
+ ));
1397
+ const deleteSummary = computed(() =>
1398
+ deleteOutcomes.value.length && !deleting.value
1399
+ ? deleteFanOutSummary(deleteOutcomes.value)
1400
+ : null
1401
+ );
1247
1402
  const cardDialog = ref(false);
1248
1403
  const selectedUser = ref<HidUser | null>(null);
1249
1404
  const cardUser = ref<HidUser | null>(null);
@@ -1537,6 +1692,39 @@ const fanOutResult = computed(() =>
1537
1692
  const failedReaders = computed(() =>
1538
1693
  readerOutcomes.value.filter((outcome) => outcome.step === "failed")
1539
1694
  );
1695
+ /* Where an edit will land, resolved when the form opens so the dialog can say
1696
+ it BEFORE the operator changes a PIN - "this also changes the gym" is only
1697
+ useful in advance. */
1698
+ const editPlaces = ref<TPersonPlace[]>([]);
1699
+ const editPlacesLoading = ref(false);
1700
+ /* Before a save, the readers that hold this person; during and after it, those
1701
+ same readers with each one's own state. One list either way, so the rows do
1702
+ not move when the save starts. */
1703
+ type TEditRow = {
1704
+ readerId: string;
1705
+ name: string;
1706
+ /* "target" is this list's own state and not a fan-out step: a reader that
1707
+ holds this person but has not been asked to do anything yet. */
1708
+ step: THidReaderStep | "target";
1709
+ message?: string;
1710
+ };
1711
+ const editRows = computed<TEditRow[]>(() => (
1712
+ readerOutcomes.value.length
1713
+ ? readerOutcomes.value
1714
+ : editPlaces.value.map((place) => ({
1715
+ readerId: place.readerId,
1716
+ name: place.name,
1717
+ step: "target" as const,
1718
+ }))
1719
+ ));
1720
+ /* The edit's own summary: it has to speak about the PIN, which an enrolment's
1721
+ does not - a PIN that reached some readers and not others is worse than one
1722
+ that reached none. */
1723
+ const editResult = computed(() =>
1724
+ readerOutcomes.value.length && !fanOutRunning.value
1725
+ ? editFanOutSummary(readerOutcomes.value, Boolean(form.accessPin))
1726
+ : null
1727
+ );
1540
1728
 
1541
1729
  function setReaderStep(
1542
1730
  readerId: string,
@@ -2827,8 +3015,22 @@ async function openEdit(user: HidUser) {
2827
3015
  if (form.unit) await loadUnitPeople();
2828
3016
  selectedPhotoFile.value = null;
2829
3017
  removePhotoRequested.value = false;
3018
+ readerOutcomes.value = [];
3019
+ editPlaces.value = [];
2830
3020
  formDialog.value = true;
2831
3021
 
3022
+ // After the dialog is up, like the candidate lists: it is several requests and
3023
+ // the form must not wait on them. A failure leaves the list empty and `saveUser`
3024
+ // resolves it again rather than skipping readers.
3025
+ editPlacesLoading.value = true;
3026
+ try {
3027
+ editPlaces.value = await findPersonReaders(user);
3028
+ } catch (error: unknown) {
3029
+ console.error("Unable to work out which readers hold this person:", error);
3030
+ } finally {
3031
+ editPlacesLoading.value = false;
3032
+ }
3033
+
2832
3034
  try {
2833
3035
  const hidUserId = toHidNumericId(user.hidUserId);
2834
3036
  const [pinStatus, passwordStatus] = await Promise.all([
@@ -2847,9 +3049,26 @@ function openView(user: HidUser) {
2847
3049
  viewDialog.value = true;
2848
3050
  }
2849
3051
 
2850
- function openDelete(user: HidUser) {
3052
+ async function openDelete(user: HidUser) {
2851
3053
  selectedUser.value = user;
3054
+ // Always reopened narrow. A scope carried over from the last delete would
3055
+ // widen a delete the operator did not widen.
3056
+ deleteScope.value = "here";
3057
+ deleteOutcomes.value = [];
3058
+ deletePlaces.value = [];
2852
3059
  deleteDialog.value = true;
3060
+
3061
+ deletePlacesLoading.value = true;
3062
+ try {
3063
+ deletePlaces.value = await findPersonReaders(user);
3064
+ } catch (error: unknown) {
3065
+ // The reach is what the scope choice is FOR, so without it the dialog
3066
+ // offers only this reader rather than guessing at "all".
3067
+ console.error("Unable to work out which readers hold this person:", error);
3068
+ deletePlaces.value = [];
3069
+ } finally {
3070
+ deletePlacesLoading.value = false;
3071
+ }
2853
3072
  }
2854
3073
 
2855
3074
  function triggerPhotoInput() {
@@ -3011,19 +3230,75 @@ async function saveUser() {
3011
3230
  };
3012
3231
 
3013
3232
  if (selectedUser.value) {
3014
- await updateHidUserOnReader(readerId, hidUser);
3015
- const facialResult = await syncFacialImage(readerId, hidUser.id);
3016
- applyFacialResult(payload.metadata, facialResult);
3017
- payload.metadata.pinEnrolled = await syncAccessPin(readerId, hidUser.id);
3018
- payload.metadata.passwordSet = await syncPassword(readerId, hidUser.id);
3019
- if (selectedUser.value._id) {
3020
- await updateIdentity(selectedUser.value._id, payload);
3021
- } else if (form.subjectId) {
3022
- await saveIdentityOnReader(readerId, payload);
3233
+ /*
3234
+ * AN EDIT REACHES EVERY READER THIS PERSON IS ON.
3235
+ *
3236
+ * After a fan-out they are on several, and a change applied to one leaves
3237
+ * the others wrong in a way nothing on screen would show: a PIN changed at
3238
+ * the lobby and not at the gym means the person has two PINs and no way to
3239
+ * know which door wants which.
3240
+ *
3241
+ * Each reader knows them by its OWN HID user id, so the id comes from that
3242
+ * reader's identity rather than from the row on screen.
3243
+ *
3244
+ * REGISTRATION IS NOT FANNED OUT. Each reader allocates its own from its
3245
+ * own numbering, and one number written to all of them would collide with
3246
+ * whatever else holds it there.
3247
+ */
3248
+ const places = editPlaces.value.length
3249
+ ? editPlaces.value
3250
+ : await findPersonReaders(selectedUser.value);
3251
+ readerOutcomes.value = places.map((place) => ({
3252
+ readerId: place.readerId,
3253
+ name: place.name,
3254
+ step: "waiting" as const,
3255
+ }));
3256
+ fanOutRunning.value = true;
3257
+ for (const place of places) {
3258
+ setReaderStep(place.readerId, "working");
3259
+ try {
3260
+ const readerUser = toHidUserObject({
3261
+ hidUserId: place.hidUserId,
3262
+ name: form.name,
3263
+ // This reader's own, left exactly as it is.
3264
+ registration: "",
3265
+ });
3266
+ if (!readerUser.id) throw new Error("This reader has no usable HID user ID for this person.");
3267
+ await updateHidUserOnReader(place.readerId, {
3268
+ ...readerUser,
3269
+ registration: "",
3270
+ });
3271
+ const perReader = { ...payload, metadata: { ...payload.metadata } };
3272
+ applyFacialResult(
3273
+ perReader.metadata,
3274
+ await syncFacialImage(place.readerId, readerUser.id),
3275
+ );
3276
+ perReader.metadata.pinEnrolled = await syncAccessPin(place.readerId, readerUser.id);
3277
+ perReader.metadata.passwordSet = await syncPassword(place.readerId, readerUser.id);
3278
+ if (place.identityId) {
3279
+ await updateIdentity(place.identityId, {
3280
+ ...perReader,
3281
+ hidUserId: place.hidUserId,
3282
+ // Untouched: see above.
3283
+ registration: undefined as unknown as string,
3284
+ });
3285
+ }
3286
+ setReaderStep(place.readerId, "done");
3287
+ } catch (error: unknown) {
3288
+ setReaderStep(place.readerId, "failed", {
3289
+ message: getHidErrorMessage(error),
3290
+ retryable: false,
3291
+ });
3292
+ console.error(`Unable to update this person on reader ${place.readerId}:`, error);
3293
+ }
3023
3294
  }
3024
- // else: a user the reader holds and we have never linked. The photo, PIN
3025
- // and password above are already on the device; creating an identity for
3026
- // it would need a subject we deliberately no longer ask for here.
3295
+ fanOutRunning.value = false;
3296
+
3297
+ const summary = editFanOutSummary(readerOutcomes.value, Boolean(form.accessPin));
3298
+ await loadUsers();
3299
+ if (summary.tone === "success") formDialog.value = false;
3300
+ showToast(summary.message, summary.tone === "success" ? "success" : "error");
3301
+ return;
3027
3302
  } else {
3028
3303
  /*
3029
3304
  * EVERY READER THAT SERVES THIS PERSON, one at a time.
@@ -3213,6 +3488,70 @@ async function enrolledAccountId() {
3213
3488
  }
3214
3489
  }
3215
3490
 
3491
+ /**
3492
+ * EVERY READER THAT HOLDS THIS PERSON.
3493
+ *
3494
+ * Needed by both editing and deleting, because after a fan-out a person is on
3495
+ * several readers and each one knows them by a DIFFERENT HID user id. Acting on
3496
+ * the id from the reader on screen would write to the wrong user on every other
3497
+ * reader - or to nobody, which is worse because it looks like it worked.
3498
+ *
3499
+ * Matched on the ACCOUNT, not the subject record. `listIdentities` checks
3500
+ * `person`, `member`, `serviceProvider` and `user`, and the account is the one
3501
+ * field every row carries however it was written - an enrolment, a bulk grant or
3502
+ * a reconcile. A row written by the reconcile may hold no subject at all.
3503
+ *
3504
+ * Falls back to the reader on screen when there is no account to match: a device
3505
+ * user we have never linked exists on that reader and nowhere else we can prove.
3506
+ */
3507
+ async function findPersonReaders(user: HidUser): Promise<TPersonPlace[]> {
3508
+ const here = {
3509
+ readerId: selectedReaderId.value,
3510
+ name: selectedReader.value?.name || "this reader",
3511
+ identityId: await findIdentityIdForUser(selectedReaderId.value, user),
3512
+ hidUserId: String(user.hidUserId ?? ""),
3513
+ };
3514
+
3515
+ const current = await findExistingIdentityOnReader(selectedReaderId.value, {
3516
+ hidUserId: String(user.hidUserId ?? ""),
3517
+ registration: String(user.registration ?? ""),
3518
+ cardNo: String(user.cardNo ?? ""),
3519
+ metadata: {},
3520
+ }).catch(() => null);
3521
+ const accountId = String(current?.user ?? "").trim();
3522
+ if (!accountId) return [here];
3523
+
3524
+ const found: TPersonPlace[] = [];
3525
+ for (const reader of readers.value) {
3526
+ const readerId = String(reader._id ?? "");
3527
+ if (!readerId) continue;
3528
+ try {
3529
+ const response = await getIdentities(readerId, {
3530
+ page: 1,
3531
+ // A person should hold one per reader; a few are asked for so a stray
3532
+ // duplicate is seen rather than hidden behind the first row.
3533
+ limit: 5,
3534
+ subject: accountId,
3535
+ });
3536
+ const items = readCandidatePage(response).items.map(toHidUser);
3537
+ for (const identity of items) {
3538
+ if (!identity._id) continue;
3539
+ found.push({
3540
+ readerId,
3541
+ name: String(reader.name ?? "") || "HID Reader",
3542
+ identityId: identity._id,
3543
+ hidUserId: String(identity.hidUserId ?? ""),
3544
+ });
3545
+ }
3546
+ } catch (error: unknown) {
3547
+ // One unreachable reader must not hide the others. It is reported as a
3548
+ // failure when acted on, not silently dropped from the count.
3549
+ console.error(`Unable to check reader ${readerId} for this person:`, error);
3550
+ }
3551
+ }
3552
+ return found.length ? found : [here];
3553
+ }
3554
+
3216
3555
  async function retryReader(outcome: THidReaderOutcome) {
3217
3556
  if (fanOutRunning.value) return;
3218
3557
  fanOutRunning.value = true;
@@ -3375,41 +3714,84 @@ async function findIdentityIdForUser(readerId: string, user: HidUser) {
3375
3714
  }
3376
3715
  }
3377
3716
 
3717
+ /**
3718
+ * Remove this person from ONE reader: the admin role, the PIN, the device user,
3719
+ * then our own row.
3720
+ *
3721
+ * Order matters. The identity id is resolved by the caller before anything is
3722
+ * destroyed, because it is read from our own records and a failure there costs
3723
+ * nothing - whereas a device user destroyed with no row left to clear is the
3724
+ * orphan that `findIdentityIdForUser` exists to prevent.
3725
+ */
3726
+ async function deleteOnReader(place: TPersonPlace) {
3727
+ const hidUserId = toHidNumericId(place.hidUserId);
3728
+ await syncHidUserRole(place.readerId, hidUserId, false);
3729
+ await deleteUserPin(place.readerId, hidUserId);
3730
+ await deleteHidUserFromReader(place.readerId, place.hidUserId);
3731
+ if (place.identityId) {
3732
+ // Soft-deletes the row AND removes the access grant that let this person
3733
+ // through, which is what stops the next reconcile rebuilding them.
3734
+ await deleteIdentity(place.identityId);
3735
+ }
3736
+ }
3737
+
3378
3738
  async function deleteUser() {
3379
3739
  if (!selectedUser.value) return;
3380
3740
 
3381
- deleting.value = true;
3382
- try {
3383
- // Resolved BEFORE the device user is destroyed: this reads our own records,
3384
- // and doing it first means a failure here costs nothing.
3385
- const identityId = await findIdentityIdForUser(
3741
+ const here: TPersonPlace = {
3742
+ readerId: selectedReaderId.value,
3743
+ name: selectedReader.value?.name || "this reader",
3744
+ identityId: await findIdentityIdForUser(
3386
3745
  selectedReaderId.value,
3387
3746
  selectedUser.value
3388
- );
3389
- await syncHidUserRole(
3390
- selectedReaderId.value,
3391
- toHidNumericId(selectedUser.value.hidUserId),
3392
- false
3393
- );
3394
- await deleteUserPin(
3395
- selectedReaderId.value,
3396
- toHidNumericId(selectedUser.value.hidUserId)
3397
- );
3398
- await deleteHidUserFromReader(selectedReaderId.value, selectedUser.value);
3399
- if (identityId) {
3400
- // Soft-deletes the row AND removes the access grant that let this person
3401
- // through, which is what stops the next reconcile rebuilding them.
3402
- await deleteIdentity(identityId);
3747
+ ),
3748
+ hidUserId: String(selectedUser.value.hidUserId ?? ""),
3749
+ };
3750
+ const places = deleteScope.value === "all" && deletePlaces.value.length
3751
+ ? deletePlaces.value
3752
+ : [deletePlaces.value.find((p) => p.readerId === here.readerId) ?? here];
3753
+
3754
+ deleting.value = true;
3755
+ deleteOutcomes.value = places.map((place) => ({
3756
+ readerId: place.readerId,
3757
+ name: place.name,
3758
+ step: "waiting" as const,
3759
+ }));
3760
+ try {
3761
+ for (const place of places) {
3762
+ setDeleteStep(place.readerId, "working");
3763
+ try {
3764
+ await deleteOnReader(place);
3765
+ setDeleteStep(place.readerId, "done");
3766
+ } catch (error: unknown) {
3767
+ // One reader refusing must not leave the others untouched - the point of
3768
+ // "all readers" is that the person loses the doors that CAN be reached.
3769
+ setDeleteStep(place.readerId, "failed", {
3770
+ message: getHidErrorMessage(error),
3771
+ });
3772
+ console.error(`Unable to delete this person from reader ${place.readerId}:`, error);
3773
+ }
3403
3774
  }
3404
- deleteDialog.value = false;
3405
- await loadUsers();
3406
- showToast("HID user deleted from reader.");
3407
- } catch (error: unknown) {
3408
- console.error("Unable to delete HID user:", error);
3409
- showToast(getHidErrorMessage(error), "error");
3410
3775
  } finally {
3411
3776
  deleting.value = false;
3412
3777
  }
3778
+
3779
+ const summary = deleteFanOutSummary(deleteOutcomes.value);
3780
+ await loadUsers();
3781
+ // A reader still holding this person keeps the dialog open, with its name on
3782
+ // screen, so the operator can see which door is still live and try again.
3783
+ if (summary.tone === "success") deleteDialog.value = false;
3784
+ showToast(summary.message, summary.tone === "success" ? "success" : "error");
3785
+ }
3786
+
3787
+ function setDeleteStep(
3788
+ readerId: string,
3789
+ step: THidReaderStep,
3790
+ extra: { message?: string } = {},
3791
+ ) {
3792
+ deleteOutcomes.value = deleteOutcomes.value.map((outcome) => (
3793
+ outcome.readerId === readerId ? { ...outcome, step, ...extra } : outcome
3794
+ ));
3413
3795
  }
3414
3796
 
3415
3797
  async function saveIdentityOnReader(
@@ -3525,8 +3907,8 @@ async function updateHidUserOnReader(
3525
3907
  });
3526
3908
  }
3527
3909
 
3528
- async function deleteHidUserFromReader(readerId: string, user: HidUser) {
3529
- const id = toHidNumericId(user.hidUserId);
3910
+ async function deleteHidUserFromReader(readerId: string, hidUserId: unknown) {
3911
+ const id = toHidNumericId(hidUserId);
3530
3912
  if (!readerId || !id) return;
3531
3913
 
3532
3914
  await runObjectOperation(readerId, {
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.97.1-staging.524",
5
+ "version": "4.97.1-staging.525",
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.",
@@ -436,3 +436,122 @@ export function fanOutSummary(outcomes: ReadonlyArray<THidReaderOutcome>): {
436
436
  message: `Enrolled on ${done} of ${total} readers. ${failed} can be retried — the person does not need to be present.`,
437
437
  };
438
438
  }
439
+
440
+ /**
441
+ * What to say after an EDIT has been applied across readers.
442
+ *
443
+ * Different from an enrolment's summary in one way that matters: a PIN.
444
+ *
445
+ * A face that reached three readers of four is incomplete - the person opens
446
+ * three doors. A PIN that reached three of four is WORSE than incomplete: the
447
+ * old PIN still works on the fourth, so they hold two PINs and have no way to
448
+ * know which door wants which. That is the one partial state worth naming
449
+ * explicitly rather than folding into "2 of 3".
450
+ */
451
+ export function editFanOutSummary(
452
+ outcomes: ReadonlyArray<THidReaderOutcome>,
453
+ pinChanged: boolean,
454
+ ): { tone: "success" | "partial" | "error"; message: string } {
455
+ const total = outcomes.length;
456
+ const done = outcomes.filter((o) => o.step === "done").length;
457
+ const failed = outcomes.filter((o) => o.step === "failed").length;
458
+
459
+ if (!total) return { tone: "error", message: "This person is not on any reader." };
460
+ if (!failed) {
461
+ return {
462
+ tone: "success",
463
+ message: total === 1
464
+ ? "Updated on this reader."
465
+ : `Updated on all ${total} readers.`,
466
+ };
467
+ }
468
+ if (!done) {
469
+ return {
470
+ tone: "error",
471
+ message: `Could not update any of the ${total} ${total === 1 ? "reader" : "readers"}.`,
472
+ };
473
+ }
474
+
475
+ const stale = outcomes.filter((o) => o.step === "failed").map((o) => o.name).join(", ");
476
+ return {
477
+ tone: "partial",
478
+ message: pinChanged
479
+ ? `Updated on ${done} of ${total} readers. ${stale} still ${failed === 1 ? "has" : "have"} the OLD PIN —`
480
+ + " this person now has two different PINs. Save again to finish."
481
+ : `Updated on ${done} of ${total} readers. ${stale} ${failed === 1 ? "was" : "were"} not reached. Save again to finish.`,
482
+ };
483
+ }
484
+
485
+ /* ── DELETING SOMEBODY WHO IS ON SEVERAL READERS ───────────────────────── */
486
+
487
+ /**
488
+ * A delete used to be read as "remove this row", which was true when a person
489
+ * lived on one reader. Once enrolment fans out, the same person is on several,
490
+ * and "delete" is ambiguous in the one direction that matters: removing them
491
+ * everywhere when the operator meant one door is an access change they did not
492
+ * ask for and cannot see from this screen.
493
+ *
494
+ * So the dialog asks, and the default is the narrow one - this reader. Widening
495
+ * is a deliberate click.
496
+ */
497
+ export function deleteScopeChoices(
498
+ readerCount: number,
499
+ hereName: string,
500
+ ): Array<{ label: string; value: "here" | "all" }> {
501
+ const here = { label: `This reader only (${hereName || "this reader"})`, value: "here" as const };
502
+ if (readerCount < 2) return [here];
503
+ return [here, { label: `All ${readerCount} readers`, value: "all" as const }];
504
+ }
505
+
506
+ /** "This person is also on Gym and Car Park." - said before, not after. */
507
+ export function deleteReachText(
508
+ places: ReadonlyArray<{ readerId: string; name: string }>,
509
+ hereReaderId: string,
510
+ ): string {
511
+ const others = places
512
+ .filter((p) => p.readerId !== hereReaderId)
513
+ .map((p) => p.name || "a reader");
514
+ if (!others.length) return "This person is only on this reader.";
515
+ const names = others.length === 1
516
+ ? others[0]
517
+ : `${others.slice(0, -1).join(", ")} and ${others[others.length - 1]}`;
518
+ return `This person is also on ${names}.`;
519
+ }
520
+
521
+ /**
522
+ * What to say after a delete has run across readers.
523
+ *
524
+ * The failure here is the mirror of the edit's: a delete that reached three
525
+ * readers of four leaves the person still able to open the fourth door. Naming
526
+ * that reader is the whole message - "2 of 3" alone tells an operator a door is
527
+ * still open without telling them which.
528
+ */
529
+ export function deleteFanOutSummary(
530
+ outcomes: ReadonlyArray<THidReaderOutcome>,
531
+ ): { tone: "success" | "partial" | "error"; message: string } {
532
+ const total = outcomes.length;
533
+ const done = outcomes.filter((o) => o.step === "done").length;
534
+ const failed = outcomes.filter((o) => o.step === "failed");
535
+
536
+ if (!total) return { tone: "error", message: "There was nothing to delete." };
537
+ if (!failed.length) {
538
+ return {
539
+ tone: "success",
540
+ message: total === 1
541
+ ? "Deleted from this reader."
542
+ : `Deleted from all ${total} readers.`,
543
+ };
544
+ }
545
+ if (!done) {
546
+ return {
547
+ tone: "error",
548
+ message: `Could not delete from any of the ${total} ${total === 1 ? "reader" : "readers"}.`,
549
+ };
550
+ }
551
+ const left = failed.map((o) => o.name).join(", ");
552
+ return {
553
+ tone: "partial",
554
+ message: `Deleted from ${done} of ${total} readers. This person can STILL open`
555
+ + ` ${left}. Delete again to finish.`,
556
+ };
557
+ }