@7365admin1/layer-common 4.2.21-staging.282 → 4.2.21-staging.284
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.
|
@@ -184,19 +184,6 @@ function isActionSelected(resource: string, action: string) {
|
|
|
184
184
|
return holdsPermission(definedModel.value, `${resource}:${action}`);
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
/**
|
|
188
|
-
* Is this box ticked?
|
|
189
|
-
*
|
|
190
|
-
* The same grant is stored under more than one spelling. An exact `includes()`
|
|
191
|
-
* showed a role holding `work-orders:see-all-work-orders` as NOT having
|
|
192
|
-
* `workOrder:see-all-work-orders`, so the dialog reported a grant the role
|
|
193
|
-
* really holds as absent -- and unticking a box then cleared nothing. Ticks are
|
|
194
|
-
* alias-aware, and so is the untick below.
|
|
195
|
-
*/
|
|
196
|
-
function isActionSelected(resource: string, action: string) {
|
|
197
|
-
return holdsPermission(definedModel.value, `${resource}:${action}`);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
187
|
function selectedActionCount(resource: string) {
|
|
201
188
|
const actions = safePermissions.value[resource];
|
|
202
189
|
if (actions) {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where each line of business lives.
|
|
3
|
+
*
|
|
4
|
+
* An organisation's `nature` says which of the seven vertical apps it belongs
|
|
5
|
+
* to, and every one of those apps' base URLs is already in this layer's
|
|
6
|
+
* runtime config. Without this map each app had to carry its own copy, which is
|
|
7
|
+
* how a switcher ends up able to LIST an organisation it cannot open.
|
|
8
|
+
*
|
|
9
|
+
* `real_estate_developer` is deliberately absent: it is an allowed nature with
|
|
10
|
+
* no app of its own, and `appUrl` answers "" for it rather than guessing.
|
|
11
|
+
*/
|
|
12
|
+
const APP_URL_KEY_BY_NATURE: Record<string, string> = {
|
|
13
|
+
security_agency: "APP_SECURITY",
|
|
14
|
+
property_management_agency: "APP_PROPERTY_MANAGEMENT",
|
|
15
|
+
cleaning_services: "APP_HYGIENE",
|
|
16
|
+
mechanical_electrical_services: "APP_MECHANICAL_ELECTRICAL",
|
|
17
|
+
pest_control_services: "APP_PEST_CONTROL",
|
|
18
|
+
landscaping_services: "APP_LANDSCAPING",
|
|
19
|
+
pool_maintenance_services: "APP_POOL_MAINTENANCE",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default function useAppLinks() {
|
|
23
|
+
const config = useRuntimeConfig().public as unknown as Record<string, string>;
|
|
24
|
+
|
|
25
|
+
/** The base URL of the app this nature belongs to, or "" when there is none. */
|
|
26
|
+
function appUrl(nature = ""): string {
|
|
27
|
+
const key = APP_URL_KEY_BY_NATURE[nature];
|
|
28
|
+
|
|
29
|
+
return key ? config[key] || "" : "";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Where to land somebody switching into `org`. Returns "" when the app is
|
|
34
|
+
* unknown or unconfigured, so a caller can fall back to navigating locally
|
|
35
|
+
* rather than sending them to a broken URL.
|
|
36
|
+
*/
|
|
37
|
+
function appDashboardUrl(nature = "", org = "", site = ""): string {
|
|
38
|
+
const base = appUrl(nature);
|
|
39
|
+
|
|
40
|
+
return base ? `${base}/${org}/${site || "site"}/dashboard` : "";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return { appUrl, appDashboardUrl, APP_URL_KEY_BY_NATURE };
|
|
44
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHICH SITE to open an organisation at.
|
|
3
|
+
*
|
|
4
|
+
* `organizations.defaultSite` is the intended answer - `customer-site.service`
|
|
5
|
+
* sets it to the first site an organisation is ever given - but it is not a
|
|
6
|
+
* guarantee:
|
|
7
|
+
*
|
|
8
|
+
* - an organisation abandoned before the site step has none at all, and the
|
|
9
|
+
* switcher can list it, because the list is every organisation you belong
|
|
10
|
+
* to rather than every one that is finished;
|
|
11
|
+
* - a `defaultSite` can name a site that has since been removed or is no
|
|
12
|
+
* longer active, and the sites list is the only thing that knows.
|
|
13
|
+
*
|
|
14
|
+
* Both used to end the same way: the app built `…/<org>/site/dashboard` with
|
|
15
|
+
* the literal word "site" where an id belongs. So the stored answer is CHECKED
|
|
16
|
+
* against the list, and the first live site stands in when it does not hold up.
|
|
17
|
+
*/
|
|
18
|
+
export default function useOrgSite() {
|
|
19
|
+
const { getAll } = useCustomerSite();
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The site id to open `org` at, or "" when it has no usable site.
|
|
23
|
+
*
|
|
24
|
+
* `preferred` is tried first and kept only if the organisation really has it.
|
|
25
|
+
* A failed lookup falls back to `preferred` rather than blocking the switch -
|
|
26
|
+
* a stale id is still a better guess than a placeholder.
|
|
27
|
+
*/
|
|
28
|
+
async function resolveOrgSite(org = "", preferred = ""): Promise<string> {
|
|
29
|
+
if (!org) return "";
|
|
30
|
+
|
|
31
|
+
const clean = preferred && preferred !== "site" ? preferred : "";
|
|
32
|
+
|
|
33
|
+
const response: any = await getAll({ org, limit: 50 }).catch(() => null);
|
|
34
|
+
|
|
35
|
+
if (!response) return clean;
|
|
36
|
+
|
|
37
|
+
const items: any[] = response?.items ?? [];
|
|
38
|
+
|
|
39
|
+
// Customer-site rows carry the site id in `.site`; a raw site document
|
|
40
|
+
// carries its own `._id`. Accept either, the same way onboarding does.
|
|
41
|
+
const ids = items
|
|
42
|
+
.map((item) => String(item?.site || item?._id || ""))
|
|
43
|
+
.filter(Boolean);
|
|
44
|
+
|
|
45
|
+
if (clean && ids.includes(clean)) return clean;
|
|
46
|
+
|
|
47
|
+
return ids[0] || "";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { resolveOrgSite };
|
|
51
|
+
}
|
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.
|
|
5
|
+
"version": "4.2.21-staging.284",
|
|
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.",
|