@7365admin1/layer-common 4.0.1 → 4.0.3-staging.220
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 +101 -0
- package/components/AccessCardQrTagging.vue +0 -4
- package/components/AccessManagement.vue +0 -4
- package/components/BuildingManagement/buildings.vue +0 -4
- package/components/BulletinBoardManagement.vue +0 -3
- package/components/CameraForm.vue +2 -5
- package/components/CameraMain.vue +3 -6
- package/components/ClientDetailForm.vue +65 -5
- package/components/ClientMain.vue +201 -59
- package/components/DashboardMain.vue +27 -8
- package/components/DocumentManagement.vue +0 -4
- package/components/HidAccessLogDashboard.vue +114 -34
- package/components/HidReaderManagement.vue +34 -11
- package/components/HidReaderUserRoster.vue +376 -0
- package/components/HidUserEnrollment.vue +6 -0
- package/components/HidUserMapping.vue +583 -0
- package/components/IncidentReport/Authorities.vue +0 -4
- package/components/IncidentReport/IncidentInformation.vue +0 -4
- package/components/IncidentReport/IncidentInformationDownload.vue +0 -4
- package/components/IncidentReport/affectedEntities.vue +0 -4
- package/components/MemberMain.vue +20 -2
- package/components/RolePermissionFormCreate.vue +6 -1
- package/components/RolePermissionFormPreviewUpdate.vue +22 -11
- package/components/RolePermissionMain.vue +39 -4
- package/components/VehicleManagement.vue +0 -4
- package/components/VisitorManagement.vue +0 -3
- package/components/VisitorsReportPreview.vue +0 -3
- package/composables/useBulletinBoardPermission.ts +6 -1
- package/composables/useConsoleTier.ts +73 -0
- package/composables/useHidAmico.ts +18 -1
- package/composables/useHidNavigation.ts +8 -1
- package/composables/useMember.ts +0 -5
- package/composables/useSettingsPermission.ts +7 -1
- package/package.json +2 -2
- package/pages/[org]/[site]/access-mgmt/hid-user-mapping/index.vue +23 -0
- package/pages/[org]/[site]/access-mgmt/hid-users/index.vue +1 -1
- package/utils/client-subscription.test.ts +95 -0
- package/utils/console-tier.test.ts +87 -0
- package/utils/console-tier.ts +67 -0
- package/utils/data.test.ts +84 -0
- package/utils/data.ts +92 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHICH SEVEN365 TIER THE SIGNED-IN PERSON IS, MIRRORED FROM THE SERVER'S RULE.
|
|
3
|
+
*
|
|
4
|
+
* Owner decision 9 splits Seven365 staff powers in two. Ordinary staff may view
|
|
5
|
+
* clients, set up subscriptions and manage promo codes. **Only the owner may
|
|
6
|
+
* suspend a client** - an action that stops that client's staff, residents and
|
|
7
|
+
* guards signing in.
|
|
8
|
+
*
|
|
9
|
+
* ## The server is the authority. This file only decides what to DRAW.
|
|
10
|
+
*
|
|
11
|
+
* `iservice365-core` `src/utils/super-admin.util.ts` answers the same question
|
|
12
|
+
* on the server, from the session id alone:
|
|
13
|
+
*
|
|
14
|
+
* isSuperAdmin(userId) -> a `members` row `{ type: "admin" }` whose role
|
|
15
|
+
* document is also `type: "admin"`
|
|
16
|
+
* isPlatformOwner(userId) -> the same, AND that role has `default === true`
|
|
17
|
+
*
|
|
18
|
+
* `requirePlatformOwner` (`console-authz.util.ts`) runs `isPlatformOwner`
|
|
19
|
+
* inside `PATCH /api/organizations/:id/status` before it writes anything, and
|
|
20
|
+
* it reads the session - never the request body, never a header the browser
|
|
21
|
+
* chose. So a browser that lies to itself about its tier gets a button it can
|
|
22
|
+
* press and a 401 when it does. Hiding the control is a courtesy, not a lock.
|
|
23
|
+
*
|
|
24
|
+
* ## Why `role.default`, and why nothing here invents a new marker
|
|
25
|
+
*
|
|
26
|
+
* `default` is the only property of a platform-staff role that no API caller
|
|
27
|
+
* can set: `role.controller.ts` validates create/update with Joi object schemas
|
|
28
|
+
* that do not list it (Joi rejects unknown keys), `role.repo.ts` never writes
|
|
29
|
+
* it, and `MRole` defaults it to `false`. Exactly one server path sets it on an
|
|
30
|
+
* `admin`-typed role - `user.service.ts createDefaultUser()` at API boot. Every
|
|
31
|
+
* additional staff account is invited onto a role made through the admin app,
|
|
32
|
+
* which cannot carry it.
|
|
33
|
+
*
|
|
34
|
+
* ## Fail closed
|
|
35
|
+
*
|
|
36
|
+
* Anything this function cannot positively prove is `"none"`. A missing member
|
|
37
|
+
* row, a role that failed to load, a request that threw - all of them draw the
|
|
38
|
+
* ordinary-staff console with no suspend control, which is the recoverable
|
|
39
|
+
* mistake. The other direction is not.
|
|
40
|
+
*
|
|
41
|
+
* Both fields come back from endpoints the app already calls, unprojected:
|
|
42
|
+
* `GET /api/members/user/:id/app/admin` and `GET /api/roles/id/:id`. Nothing
|
|
43
|
+
* new had to be added to the API for this.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
export type TConsoleTier = "owner" | "staff" | "none";
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* One divergence from the server, stated rather than hidden: `isSuperAdmin`
|
|
50
|
+
* matches `status: { $ne: "deleted" }` on the member row, and the endpoint the
|
|
51
|
+
* browser uses (`member.repo.ts getByUserIdType`) matches only `{ user, type }`.
|
|
52
|
+
* So a deleted staff membership can still be handed to this function. It is
|
|
53
|
+
* excluded here too, which keeps the drawn console and the server's answer the
|
|
54
|
+
* same for that case.
|
|
55
|
+
*/
|
|
56
|
+
export function consoleTier(
|
|
57
|
+
member: Record<string, any> | null | undefined,
|
|
58
|
+
role: Record<string, any> | null | undefined,
|
|
59
|
+
): TConsoleTier {
|
|
60
|
+
if (member?.type !== "admin") return "none";
|
|
61
|
+
if (member?.status === "deleted") return "none";
|
|
62
|
+
if (role?.type !== "admin") return "none";
|
|
63
|
+
|
|
64
|
+
// `=== true` exactly as the server writes it. A role document that omits
|
|
65
|
+
// `default` (every role the admin app can create) is staff, not owner.
|
|
66
|
+
return role?.default === true ? "owner" : "staff";
|
|
67
|
+
}
|
package/utils/data.test.ts
CHANGED
|
@@ -93,3 +93,87 @@ test("a non-array levels value is counted as zero, not as its own length", () =>
|
|
|
93
93
|
assert.equal(levelCount({ levels: 7 as unknown as [] }), 0);
|
|
94
94
|
assert.equal(levelCount({ levels: "12" as unknown as [] }), 0);
|
|
95
95
|
});
|
|
96
|
+
|
|
97
|
+
import { cameraErrorConverter } from "./data.ts";
|
|
98
|
+
|
|
99
|
+
/** Shape of an ofetch failure: the status and body live under `response`. */
|
|
100
|
+
const apiError = (status: number, message?: string) => ({
|
|
101
|
+
response: { status, _data: message === undefined ? {} : { message } },
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("a duplicate reads as a duplicate", () => {
|
|
105
|
+
assert.match(
|
|
106
|
+
cameraErrorConverter(apiError(400, "ANPR already exist."), "ip"),
|
|
107
|
+
/already exists on this site/
|
|
108
|
+
);
|
|
109
|
+
assert.match(
|
|
110
|
+
cameraErrorConverter(apiError(409), "ip"),
|
|
111
|
+
/already exists on this site/
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("a failure that is NOT a duplicate never says duplicate", () => {
|
|
116
|
+
const notDuplicate = [
|
|
117
|
+
cameraErrorConverter(apiError(401), "ip"),
|
|
118
|
+
cameraErrorConverter(apiError(403), "ip"),
|
|
119
|
+
cameraErrorConverter(apiError(404), "ip"),
|
|
120
|
+
cameraErrorConverter(apiError(429), "ip"),
|
|
121
|
+
cameraErrorConverter(apiError(500, "Failed to create ANPR."), "ip"),
|
|
122
|
+
cameraErrorConverter(new Error("Network request failed"), "ip"),
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
for (const message of notDuplicate) {
|
|
126
|
+
assert.doesNotMatch(message, /already exist/i, message);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("each cause gets its own message", () => {
|
|
131
|
+
assert.match(cameraErrorConverter(apiError(401), "ip"), /session has expired/);
|
|
132
|
+
assert.match(
|
|
133
|
+
cameraErrorConverter(apiError(403), "ip"),
|
|
134
|
+
/do not have permission/
|
|
135
|
+
);
|
|
136
|
+
assert.match(cameraErrorConverter(apiError(404), "ip"), /no longer exists/);
|
|
137
|
+
assert.match(cameraErrorConverter(apiError(429), "ip"), /Too many attempts/);
|
|
138
|
+
assert.match(
|
|
139
|
+
cameraErrorConverter(apiError(500, "Failed to create ANPR."), "ip"),
|
|
140
|
+
/could not save this CCTV camera/
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("no response at all reads as a connection problem, not a server refusal", () => {
|
|
145
|
+
assert.match(
|
|
146
|
+
cameraErrorConverter(new Error("Failed to fetch"), "ip"),
|
|
147
|
+
/Could not reach the server/
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("a rejected field is named the way the form names it", () => {
|
|
152
|
+
assert.equal(
|
|
153
|
+
cameraErrorConverter(apiError(400, '"host" is required'), "ip"),
|
|
154
|
+
"URL is required."
|
|
155
|
+
);
|
|
156
|
+
assert.equal(
|
|
157
|
+
cameraErrorConverter(apiError(400, '"name" is not allowed to be empty'), "ip"),
|
|
158
|
+
"Camera Name cannot be empty."
|
|
159
|
+
);
|
|
160
|
+
// A field with no friendly label still reads as a sentence.
|
|
161
|
+
assert.equal(
|
|
162
|
+
cameraErrorConverter(apiError(400, '"guardPost" must be a number'), "ip"),
|
|
163
|
+
"guardPost must be a number."
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("a plain 400 sentence from the API is passed through unchanged", () => {
|
|
168
|
+
assert.equal(
|
|
169
|
+
cameraErrorConverter(apiError(400, "Invalid _id format"), "ip"),
|
|
170
|
+
"Invalid _id format"
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("the camera type decides the wording", () => {
|
|
175
|
+
assert.match(cameraErrorConverter(apiError(404), "anpr"), /ANPR camera/);
|
|
176
|
+
assert.match(cameraErrorConverter(apiError(404), "ip"), /CCTV camera/);
|
|
177
|
+
// Unknown/absent type falls back to CCTV, which is what the panel defaults to.
|
|
178
|
+
assert.match(cameraErrorConverter(apiError(404)), /CCTV camera/);
|
|
179
|
+
});
|
package/utils/data.ts
CHANGED
|
@@ -30,6 +30,98 @@ export const errorConverter = (data: any): string => {
|
|
|
30
30
|
return error;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Field names the camera API validates, in the wording the camera form uses,
|
|
35
|
+
* so a rejection reads as the label the person is looking at.
|
|
36
|
+
*/
|
|
37
|
+
const CAMERA_FIELD_LABELS: Record<string, string> = {
|
|
38
|
+
host: "URL",
|
|
39
|
+
name: "Camera Name",
|
|
40
|
+
username: "User",
|
|
41
|
+
password: "Password",
|
|
42
|
+
direction: "Type",
|
|
43
|
+
category: "Category",
|
|
44
|
+
site: "Site",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Joi phrasing -> everyday phrasing. Anything unmapped is passed through. */
|
|
48
|
+
const CAMERA_VALIDATION_PHRASES: Array<[RegExp, string]> = [
|
|
49
|
+
[/^is required$/, "is required."],
|
|
50
|
+
[/^is not allowed to be empty$/, "cannot be empty."],
|
|
51
|
+
[/^must be a string$/, "is not valid."],
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Turns a save/delete failure on a site camera into a sentence the person
|
|
56
|
+
* setting up the camera can act on.
|
|
57
|
+
*
|
|
58
|
+
* The camera panel used to report every `type: "ip"` failure as "CCTV camera
|
|
59
|
+
* already exist", whatever actually went wrong - a signed-out session, a
|
|
60
|
+
* missing permission, a rejected field and a server outage all read as a
|
|
61
|
+
* duplicate. This maps the cases the API really returns instead.
|
|
62
|
+
*/
|
|
63
|
+
export const cameraErrorConverter = (error: any, type?: string): string => {
|
|
64
|
+
const camera = type === "anpr" ? "ANPR camera" : "CCTV camera";
|
|
65
|
+
|
|
66
|
+
const status =
|
|
67
|
+
error?.response?.status ?? error?.statusCode ?? error?.status ?? null;
|
|
68
|
+
|
|
69
|
+
const serverMessage = String(
|
|
70
|
+
error?.response?._data?.message ?? error?.data?.message ?? ""
|
|
71
|
+
).trim();
|
|
72
|
+
|
|
73
|
+
// No response at all: the request never reached the API.
|
|
74
|
+
if (!status) {
|
|
75
|
+
return `Could not reach the server, so this ${camera} was not saved. Check your internet connection and try again.`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (status === 401) {
|
|
79
|
+
return `Your session has expired. Sign in again, then save this ${camera}.`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (status === 403) {
|
|
83
|
+
return `You do not have permission to change cameras on this site. Ask your iService365 administrator for access.`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (status === 404) {
|
|
87
|
+
return `This ${camera} no longer exists. Refresh the list and try again.`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (status === 429) {
|
|
91
|
+
return "Too many attempts in a short time. Wait a moment and try again.";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// The API reports a clash from the unique index as "ANPR already exist.",
|
|
95
|
+
// which is the same message for a CCTV record.
|
|
96
|
+
if (status === 409 || /already exist|duplicate/i.test(serverMessage)) {
|
|
97
|
+
return `A ${camera} with this URL already exists on this site. Check the list before adding it again.`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (status >= 500) {
|
|
101
|
+
return `The server could not save this ${camera}. Try again, and contact support if it keeps happening.`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (status === 400 && serverMessage) {
|
|
105
|
+
// Joi rejections arrive as `"host" is required`.
|
|
106
|
+
const field = serverMessage.match(/^"(\w+)"\s+(.+?)\.?$/);
|
|
107
|
+
|
|
108
|
+
if (field) {
|
|
109
|
+
const label = CAMERA_FIELD_LABELS[field[1]] ?? field[1];
|
|
110
|
+
const phrase =
|
|
111
|
+
CAMERA_VALIDATION_PHRASES.find(([pattern]) =>
|
|
112
|
+
pattern.test(field[2])
|
|
113
|
+
)?.[1] ?? `${field[2]}.`;
|
|
114
|
+
|
|
115
|
+
return `${label} ${phrase}`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return serverMessage;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return errorConverter(error);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
|
|
33
125
|
/**
|
|
34
126
|
* A service-provider account can only be shown ITS OWN work orders, feedbacks
|
|
35
127
|
* and key logs, so every one of those screens scopes its request by the
|