@openinc/parse-server-opendash 4.4.5 → 4.5.0
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/dist/featuremap.json +6 -7
- package/dist/features/config/index.d.ts +4 -1
- package/dist/features/config/index.js +6 -1
- package/dist/features/config/services/ensureConfigs.d.ts +29 -0
- package/dist/features/config/services/ensureConfigs.js +133 -0
- package/dist/features/config/types/ConfigKeys.d.ts +87 -7
- package/dist/features/config/types/ConfigKeys.js +112 -11
- package/dist/features/openservice/alarms/actionParams.d.ts +29 -0
- package/dist/features/openservice/alarms/actionParams.js +63 -0
- package/dist/features/openservice/alarms/index.d.ts +1 -1
- package/dist/features/openservice/alarms/index.js +2 -1
- package/dist/features/openservice/alarms/schedule/createAlarmSchedule.d.ts +1 -1
- package/dist/features/openservice/alarms/schedule/createAlarmSchedule.js +23 -1
- package/dist/features/openservice/alarms/schedule/ensureAlarmScheduleAction.d.ts +17 -0
- package/dist/features/openservice/alarms/schedule/ensureAlarmScheduleAction.js +83 -1
- package/dist/features/openservice/alarms/schedule/listAlarmTriggers.js +44 -22
- package/dist/features/openservice/alarms/ticket/createAlarmTicket.d.ts +1 -1
- package/dist/features/openservice/alarms/ticket/createAlarmTicket.js +10 -1
- package/dist/features/openservice/alarms/ticket/ensureAlarmTicketAction.js +18 -1
- package/dist/features/openservice/init.js +8 -3
- package/dist/features/openservice/serviceProviders/ProviderAccessTypes.d.ts +23 -0
- package/dist/features/openservice/serviceProviders/ProviderAccessTypes.js +17 -0
- package/dist/features/openservice/serviceProviders/grantProviderAccess.d.ts +35 -0
- package/dist/features/openservice/serviceProviders/grantProviderAccess.js +172 -0
- package/dist/features/openservice/serviceProviders/index.d.ts +5 -0
- package/dist/features/openservice/serviceProviders/index.js +12 -0
- package/dist/features/openservice/serviceProviders/providerRoleSetup.d.ts +63 -0
- package/dist/features/openservice/serviceProviders/providerRoleSetup.js +110 -0
- package/dist/features/openservice/setupStatus.d.ts +55 -0
- package/dist/features/openservice/setupStatus.js +139 -0
- package/dist/features/permissions/types/Permissions.d.ts +1 -0
- package/dist/features/permissions/types/Permissions.js +5 -0
- package/dist/functions/openinc-auth-login-passwordless.js +7 -2
- package/dist/functions/openinc-auth-validate-token.js +6 -0
- package/dist/functions/openinc-auth.common.js +13 -0
- package/dist/functions/openinc-openservice-provider-access.d.ts +22 -0
- package/dist/functions/openinc-openservice-provider-access.js +54 -0
- package/dist/functions/openinc-openservice-provider-setup.d.ts +19 -0
- package/dist/functions/openinc-openservice-provider-setup.js +57 -0
- package/dist/functions/openinc-openservice-setup.d.ts +24 -0
- package/dist/functions/openinc-openservice-setup.js +140 -0
- package/dist/hooks/Chat_Message.js +15 -1
- package/dist/hooks/Config_open_service.js +34 -10
- package/dist/hooks/Service_Equipment.js +6 -11
- package/dist/hooks/Service_Schedule_Execution.js +127 -7
- package/dist/scripts/migration/lib/articleMeta.d.ts +20 -7
- package/dist/scripts/migration/lib/articleMeta.js +20 -14
- package/dist/scripts/migration/passes/05-articles.d.ts +17 -8
- package/dist/scripts/migration/passes/05-articles.js +43 -24
- package/dist/types/BDE_Article.d.ts +27 -3
- package/dist/types/BDE_Article.js +48 -0
- package/dist/types/Service_MigrationMap.d.ts +26 -0
- package/dist/types/Service_MigrationMap.js +45 -0
- package/dist/types/Service_Occurrence.d.ts +31 -0
- package/dist/types/Service_Occurrence.js +51 -0
- package/dist/types/Service_Schedule_Execution.d.ts +6 -0
- package/dist/types/Service_Schedule_Execution.js +12 -0
- package/dist/types/index.d.ts +4 -4
- package/dist/types/index.js +5 -5
- package/package.json +1 -1
- package/schema/BDE_Article.json +41 -6
- package/schema/Service_FormConfig.json +10 -10
- package/schema/{Service_TriggerState.json → Service_Occurrence.json} +21 -9
- package/schema/Service_Schedule_Execution.json +8 -0
- package/dist/hooks/Service_TriggerState.d.ts +0 -1
- package/dist/hooks/Service_TriggerState.js +0 -17
- package/dist/types/Service_MeterReading.d.ts +0 -35
- package/dist/types/Service_MeterReading.js +0 -57
- package/dist/types/Service_TriggerState.d.ts +0 -31
- package/dist/types/Service_TriggerState.js +0 -51
- package/schema/Service_MeterReading.json +0 -54
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Permissions } from "../../permissions/types/Permissions.js";
|
|
2
|
+
import { Tenant } from "../../../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* The capabilities a service provider needs to be of any use once they have
|
|
5
|
+
* been assigned to a plan.
|
|
6
|
+
*
|
|
7
|
+
* Deliberately short. A provider opens the plugin, walks the plan and signs the
|
|
8
|
+
* protocol — nothing more. Creating plans, managing templates and deleting are
|
|
9
|
+
* the customer's own business, and a provider account is by definition one the
|
|
10
|
+
* customer does not control.
|
|
11
|
+
*
|
|
12
|
+
* `required: false` marks a capability that is a judgement call rather than a
|
|
13
|
+
* prerequisite: without it the provider can see the plan but not record what
|
|
14
|
+
* they did, which some customers want (the provider reports, the maintainer
|
|
15
|
+
* signs).
|
|
16
|
+
*/
|
|
17
|
+
export declare const PROVIDER_CAPABILITIES: readonly [{
|
|
18
|
+
readonly key: Permissions.SERVICE.schedule_access;
|
|
19
|
+
readonly required: true;
|
|
20
|
+
}, {
|
|
21
|
+
readonly key: Permissions.SERVICE.execution_perform;
|
|
22
|
+
readonly required: false;
|
|
23
|
+
}];
|
|
24
|
+
export interface ProviderCapabilityState {
|
|
25
|
+
key: string;
|
|
26
|
+
/** Whether the tenant's provider role can currently read this permission. */
|
|
27
|
+
granted: boolean;
|
|
28
|
+
/** Whether the permission row exists for this tenant at all. */
|
|
29
|
+
exists: boolean;
|
|
30
|
+
required: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface ProviderRoleStatus {
|
|
33
|
+
roleName: string;
|
|
34
|
+
/** `false` until somebody has been granted access for the first time. */
|
|
35
|
+
roleExists: boolean;
|
|
36
|
+
/** How many accounts are in the role. */
|
|
37
|
+
memberCount: number;
|
|
38
|
+
capabilities: ProviderCapabilityState[];
|
|
39
|
+
/** True when every `required` capability is granted — the "ready" light. */
|
|
40
|
+
ready: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* What the tenant's service-provider setup looks like right now.
|
|
44
|
+
*
|
|
45
|
+
* Exists because granting access deliberately does **not** hand out
|
|
46
|
+
* capabilities (that is a policy decision per customer), which leaves a gap
|
|
47
|
+
* nobody could see: the provider has an account, is assigned to the plan, and
|
|
48
|
+
* still cannot open the plugin. This is what makes that gap visible.
|
|
49
|
+
*/
|
|
50
|
+
export declare function providerRoleStatus(tenant: Tenant): Promise<ProviderRoleStatus>;
|
|
51
|
+
/**
|
|
52
|
+
* Grant or withdraw capabilities for the tenant's service-provider role.
|
|
53
|
+
*
|
|
54
|
+
* A capability here is an `OD3_Permission` row the role may **read** — that is
|
|
55
|
+
* the whole mechanism `hasPermission` checks. So granting is an ACL edit on an
|
|
56
|
+
* existing row, never creating one: the rows are registered per tenant at
|
|
57
|
+
* startup, and inventing a new one would produce a permission no part of the
|
|
58
|
+
* product asks about.
|
|
59
|
+
*
|
|
60
|
+
* Unknown keys are refused rather than ignored. Silently dropping one would
|
|
61
|
+
* leave the caller believing a capability was granted that never was.
|
|
62
|
+
*/
|
|
63
|
+
export declare function setProviderCapabilities(tenant: Tenant, keys: string[], granted: boolean): Promise<ProviderRoleStatus>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PROVIDER_CAPABILITIES = void 0;
|
|
7
|
+
exports.providerRoleStatus = providerRoleStatus;
|
|
8
|
+
exports.setProviderCapabilities = setProviderCapabilities;
|
|
9
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
10
|
+
const Permissions_js_1 = require("../../permissions/types/Permissions.js");
|
|
11
|
+
const index_js_1 = require("../../../types/index.js");
|
|
12
|
+
const ProviderAccessTypes_js_1 = require("./ProviderAccessTypes.js");
|
|
13
|
+
/**
|
|
14
|
+
* The capabilities a service provider needs to be of any use once they have
|
|
15
|
+
* been assigned to a plan.
|
|
16
|
+
*
|
|
17
|
+
* Deliberately short. A provider opens the plugin, walks the plan and signs the
|
|
18
|
+
* protocol — nothing more. Creating plans, managing templates and deleting are
|
|
19
|
+
* the customer's own business, and a provider account is by definition one the
|
|
20
|
+
* customer does not control.
|
|
21
|
+
*
|
|
22
|
+
* `required: false` marks a capability that is a judgement call rather than a
|
|
23
|
+
* prerequisite: without it the provider can see the plan but not record what
|
|
24
|
+
* they did, which some customers want (the provider reports, the maintainer
|
|
25
|
+
* signs).
|
|
26
|
+
*/
|
|
27
|
+
exports.PROVIDER_CAPABILITIES = [
|
|
28
|
+
{ key: Permissions_js_1.Permissions.SERVICE.schedule_access, required: true },
|
|
29
|
+
{ key: Permissions_js_1.Permissions.SERVICE.execution_perform, required: false },
|
|
30
|
+
];
|
|
31
|
+
/**
|
|
32
|
+
* What the tenant's service-provider setup looks like right now.
|
|
33
|
+
*
|
|
34
|
+
* Exists because granting access deliberately does **not** hand out
|
|
35
|
+
* capabilities (that is a policy decision per customer), which leaves a gap
|
|
36
|
+
* nobody could see: the provider has an account, is assigned to the plan, and
|
|
37
|
+
* still cannot open the plugin. This is what makes that gap visible.
|
|
38
|
+
*/
|
|
39
|
+
async function providerRoleStatus(tenant) {
|
|
40
|
+
const roleName = `${ProviderAccessTypes_js_1.PROVIDER_ROLE_PREFIX}${tenant.id}`;
|
|
41
|
+
const role = await new node_1.default.Query(node_1.default.Role)
|
|
42
|
+
.equalTo("name", roleName)
|
|
43
|
+
.first({ useMasterKey: true });
|
|
44
|
+
const memberCount = role
|
|
45
|
+
? await role.relation("users").query().count({ useMasterKey: true })
|
|
46
|
+
: 0;
|
|
47
|
+
const capabilities = [];
|
|
48
|
+
for (const { key, required } of exports.PROVIDER_CAPABILITIES) {
|
|
49
|
+
const permission = await findPermission(tenant, key);
|
|
50
|
+
capabilities.push({
|
|
51
|
+
key,
|
|
52
|
+
exists: !!permission,
|
|
53
|
+
// No role means nothing can be granted yet — report it as not granted
|
|
54
|
+
// rather than as an error, because that is exactly the starting state.
|
|
55
|
+
granted: !!role && !!permission?.getACL()?.getRoleReadAccess(roleName),
|
|
56
|
+
required,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
roleName,
|
|
61
|
+
roleExists: !!role,
|
|
62
|
+
memberCount,
|
|
63
|
+
capabilities,
|
|
64
|
+
ready: !!role &&
|
|
65
|
+
capabilities.every((capability) => !capability.required || capability.granted),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Grant or withdraw capabilities for the tenant's service-provider role.
|
|
70
|
+
*
|
|
71
|
+
* A capability here is an `OD3_Permission` row the role may **read** — that is
|
|
72
|
+
* the whole mechanism `hasPermission` checks. So granting is an ACL edit on an
|
|
73
|
+
* existing row, never creating one: the rows are registered per tenant at
|
|
74
|
+
* startup, and inventing a new one would produce a permission no part of the
|
|
75
|
+
* product asks about.
|
|
76
|
+
*
|
|
77
|
+
* Unknown keys are refused rather than ignored. Silently dropping one would
|
|
78
|
+
* leave the caller believing a capability was granted that never was.
|
|
79
|
+
*/
|
|
80
|
+
async function setProviderCapabilities(tenant, keys, granted) {
|
|
81
|
+
const allowed = new Set(exports.PROVIDER_CAPABILITIES.map((capability) => capability.key));
|
|
82
|
+
const unknown = keys.filter((key) => !allowed.has(key));
|
|
83
|
+
if (unknown.length > 0) {
|
|
84
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `Not a service provider capability: ${unknown.join(", ")}`);
|
|
85
|
+
}
|
|
86
|
+
const roleName = `${ProviderAccessTypes_js_1.PROVIDER_ROLE_PREFIX}${tenant.id}`;
|
|
87
|
+
const role = await new node_1.default.Query(node_1.default.Role)
|
|
88
|
+
.equalTo("name", roleName)
|
|
89
|
+
.first({ useMasterKey: true });
|
|
90
|
+
if (!role) {
|
|
91
|
+
throw new node_1.default.Error(node_1.default.Error.OBJECT_NOT_FOUND, `The role ${roleName} does not exist yet — grant one provider access first.`);
|
|
92
|
+
}
|
|
93
|
+
for (const key of keys) {
|
|
94
|
+
const permission = await findPermission(tenant, key);
|
|
95
|
+
if (!permission) {
|
|
96
|
+
throw new node_1.default.Error(node_1.default.Error.OBJECT_NOT_FOUND, `No permission row for ${key} in this tenant. It is registered at server startup — check that the service feature is enabled.`);
|
|
97
|
+
}
|
|
98
|
+
const acl = permission.getACL() ?? new node_1.default.ACL();
|
|
99
|
+
acl.setRoleReadAccess(roleName, granted);
|
|
100
|
+
permission.setACL(acl);
|
|
101
|
+
await permission.save(null, { useMasterKey: true });
|
|
102
|
+
}
|
|
103
|
+
return providerRoleStatus(tenant);
|
|
104
|
+
}
|
|
105
|
+
function findPermission(tenant, key) {
|
|
106
|
+
return new node_1.default.Query(index_js_1.Permission)
|
|
107
|
+
.equalTo("key", key)
|
|
108
|
+
.equalTo("tenant", tenant)
|
|
109
|
+
.first({ useMasterKey: true });
|
|
110
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Tenant } from "../../types/index.js";
|
|
2
|
+
/** One thing that has to be in place, and whether it is. */
|
|
3
|
+
export interface SetupCheck {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
ok: boolean;
|
|
7
|
+
/** Shown when `ok` is false — what to do about it. */
|
|
8
|
+
hint?: string;
|
|
9
|
+
/**
|
|
10
|
+
* `true` when the server creates this by itself at boot. A failing
|
|
11
|
+
* automatic check means something is wrong, not that somebody forgot.
|
|
12
|
+
*/
|
|
13
|
+
automatic: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** State of one config row. Never carries the value of a secret. */
|
|
16
|
+
export interface ConfigStatus {
|
|
17
|
+
key: string;
|
|
18
|
+
description: string;
|
|
19
|
+
exists: boolean;
|
|
20
|
+
/** `true` when the row holds a non-empty value. */
|
|
21
|
+
filled: boolean;
|
|
22
|
+
secret: boolean;
|
|
23
|
+
required: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The server generates this value, so it is read and replaced rather than
|
|
26
|
+
* typed in. A UI cannot infer it from `required` — Outlook is a secret that
|
|
27
|
+
* is not generated.
|
|
28
|
+
*/
|
|
29
|
+
generated: boolean;
|
|
30
|
+
/** Only for secrets: whether the row is readable by ordinary tenant users. */
|
|
31
|
+
exposed?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface OpenServiceSetupStatus {
|
|
34
|
+
tenantId: string;
|
|
35
|
+
tenantLabel?: string;
|
|
36
|
+
ready: boolean;
|
|
37
|
+
checks: SetupCheck[];
|
|
38
|
+
configs: ConfigStatus[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Whether open.SERVICE is actually set up for a tenant — and if not, what is
|
|
42
|
+
* missing.
|
|
43
|
+
*
|
|
44
|
+
* **Why this exists separately from the bootstrap.** `ensureConfigs()` and the
|
|
45
|
+
* `ensure*Action()` functions make most of the setup happen without anybody
|
|
46
|
+
* asking, but three things they cannot do: supply a customer's Outlook
|
|
47
|
+
* credentials, tell whether the alarm executor was ever pointed at us, and
|
|
48
|
+
* notice that an old row still carries a permissive ACL. Before this, the only
|
|
49
|
+
* way to find out was to trigger something and see whether it worked.
|
|
50
|
+
*
|
|
51
|
+
* Read-only, and it never returns a secret's value — only whether one is set.
|
|
52
|
+
* A status page that leaks the credential it is reporting on would be a poor
|
|
53
|
+
* trade.
|
|
54
|
+
*/
|
|
55
|
+
export declare function openServiceSetupStatus(tenant: Tenant): Promise<OpenServiceSetupStatus>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.openServiceSetupStatus = openServiceSetupStatus;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const index_js_1 = require("../../types/index.js");
|
|
9
|
+
const index_js_2 = require("../config/index.js");
|
|
10
|
+
const Permissions_js_1 = require("../permissions/types/Permissions.js");
|
|
11
|
+
const AlarmScheduleTypes_js_1 = require("./alarms/schedule/AlarmScheduleTypes.js");
|
|
12
|
+
const AlarmTicketTypes_js_1 = require("./alarms/ticket/AlarmTicketTypes.js");
|
|
13
|
+
/**
|
|
14
|
+
* Whether open.SERVICE is actually set up for a tenant — and if not, what is
|
|
15
|
+
* missing.
|
|
16
|
+
*
|
|
17
|
+
* **Why this exists separately from the bootstrap.** `ensureConfigs()` and the
|
|
18
|
+
* `ensure*Action()` functions make most of the setup happen without anybody
|
|
19
|
+
* asking, but three things they cannot do: supply a customer's Outlook
|
|
20
|
+
* credentials, tell whether the alarm executor was ever pointed at us, and
|
|
21
|
+
* notice that an old row still carries a permissive ACL. Before this, the only
|
|
22
|
+
* way to find out was to trigger something and see whether it worked.
|
|
23
|
+
*
|
|
24
|
+
* Read-only, and it never returns a secret's value — only whether one is set.
|
|
25
|
+
* A status page that leaks the credential it is reporting on would be a poor
|
|
26
|
+
* trade.
|
|
27
|
+
*/
|
|
28
|
+
async function openServiceSetupStatus(tenant) {
|
|
29
|
+
const configs = await configStatuses(tenant);
|
|
30
|
+
const checks = await setupChecks(tenant);
|
|
31
|
+
const requiredConfigsOk = configs
|
|
32
|
+
.filter((config) => config.required)
|
|
33
|
+
.every((config) => config.filled);
|
|
34
|
+
return {
|
|
35
|
+
tenantId: tenant.id,
|
|
36
|
+
tenantLabel: tenant.get("label"),
|
|
37
|
+
ready: requiredConfigsOk && checks.every((check) => check.ok),
|
|
38
|
+
checks,
|
|
39
|
+
configs,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async function configStatuses(tenant) {
|
|
43
|
+
const result = [];
|
|
44
|
+
for (const definition of index_js_2.OPENSERVICE_CONFIG_KEYS) {
|
|
45
|
+
// Runtime state is the worker's business; reporting it as "missing" would
|
|
46
|
+
// invite somebody to create it and break the very thing it tracks.
|
|
47
|
+
if (definition.runtimeState)
|
|
48
|
+
continue;
|
|
49
|
+
const row = await findConfig(tenant, definition);
|
|
50
|
+
const value = row?.get("value");
|
|
51
|
+
result.push({
|
|
52
|
+
key: definition.key,
|
|
53
|
+
description: definition.description,
|
|
54
|
+
exists: !!row,
|
|
55
|
+
filled: typeof value === "string" && value.trim() !== "",
|
|
56
|
+
secret: !!definition.secret,
|
|
57
|
+
required: !!definition.required,
|
|
58
|
+
generated: definition.generate === "secret",
|
|
59
|
+
exposed: definition.secret && row ? isExposed(row, tenant) : undefined,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
async function setupChecks(tenant) {
|
|
65
|
+
const [scheduleAction, ticketAction, webhook, permissionCount, alarmCount] = await Promise.all([
|
|
66
|
+
new node_1.default.Query(index_js_1.AlarmAction)
|
|
67
|
+
.equalTo("topic", AlarmScheduleTypes_js_1.ALARM_SCHEDULE_ACTION_ID)
|
|
68
|
+
.first({ useMasterKey: true }),
|
|
69
|
+
new node_1.default.Query(index_js_1.AlarmAction)
|
|
70
|
+
.equalTo("topic", AlarmTicketTypes_js_1.ALARM_TICKET_ACTION_ID)
|
|
71
|
+
.first({ useMasterKey: true }),
|
|
72
|
+
new node_1.default.Query(index_js_1.AlarmWebhook)
|
|
73
|
+
.contains("url", "openinc-openservice-alarm-create-schedule")
|
|
74
|
+
.first({ useMasterKey: true }),
|
|
75
|
+
new node_1.default.Query(index_js_1.Permission)
|
|
76
|
+
.equalTo("key", Permissions_js_1.Permissions.SERVICE.schedule_access)
|
|
77
|
+
.equalTo("tenant", tenant)
|
|
78
|
+
.count({ useMasterKey: true }),
|
|
79
|
+
new node_1.default.Query(index_js_1.Alarm)
|
|
80
|
+
.equalTo("tenant", tenant)
|
|
81
|
+
.equalTo("action.topic", AlarmScheduleTypes_js_1.ALARM_SCHEDULE_ACTION_ID)
|
|
82
|
+
.count({ useMasterKey: true }),
|
|
83
|
+
]);
|
|
84
|
+
const webhookPayload = webhook?.get("payload");
|
|
85
|
+
return [
|
|
86
|
+
{
|
|
87
|
+
id: "permissions",
|
|
88
|
+
label: "Berechtigungen registriert",
|
|
89
|
+
ok: permissionCount > 0,
|
|
90
|
+
automatic: true,
|
|
91
|
+
hint: "Werden beim Serverstart je Mandant angelegt. Fehlen sie, ist das Service-Feature für diesen Mandanten nicht aktiv.",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: "alarm-action-schedule",
|
|
95
|
+
label: 'Alarm-Aktion "Wartungstermin anlegen"',
|
|
96
|
+
ok: !!scheduleAction,
|
|
97
|
+
automatic: true,
|
|
98
|
+
hint: "Wird beim Serverstart angelegt. Ohne sie lässt sich die Aktion im Alarm-Dialog nicht auswählen.",
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: "alarm-action-ticket",
|
|
102
|
+
label: 'Alarm-Aktion "Ticket erstellen"',
|
|
103
|
+
ok: !!ticketAction,
|
|
104
|
+
automatic: true,
|
|
105
|
+
hint: "Wird beim Serverstart angelegt.",
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: "alarm-webhook",
|
|
109
|
+
label: "Webhook für Wartungstermine",
|
|
110
|
+
// An existing row with an empty payload is worse than none: it looks
|
|
111
|
+
// configured and delivers nothing.
|
|
112
|
+
ok: !!webhook &&
|
|
113
|
+
typeof webhookPayload === "string" &&
|
|
114
|
+
webhookPayload.includes("{{secret}}"),
|
|
115
|
+
automatic: true,
|
|
116
|
+
hint: "Wird beim Serverstart angelegt. Ist er vorhanden, aber ohne Payload-Vorlage, trägt der Aufruf weder Secret noch Ereignis.",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: "alarm-configured",
|
|
120
|
+
label: "Mindestens ein Alarm löst Wartung aus",
|
|
121
|
+
ok: alarmCount > 0,
|
|
122
|
+
automatic: false,
|
|
123
|
+
hint: 'In open.DASH einen Alarm anlegen und als Aktion "Wartungstermin anlegen" mit einer Vorlage wählen.',
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
}
|
|
127
|
+
function findConfig(tenant, definition) {
|
|
128
|
+
const query = new node_1.default.Query(index_js_1.Config).equalTo("key", definition.key);
|
|
129
|
+
return definition.scope === "tenant"
|
|
130
|
+
? query.equalTo("tenant", tenant).first({ useMasterKey: true })
|
|
131
|
+
: query.doesNotExist("tenant").first({ useMasterKey: true });
|
|
132
|
+
}
|
|
133
|
+
/** Whether ordinary tenant members can read this row. */
|
|
134
|
+
function isExposed(config, tenant) {
|
|
135
|
+
const acl = config.getACL();
|
|
136
|
+
if (!acl)
|
|
137
|
+
return true; // no ACL at all is as open as it gets
|
|
138
|
+
return acl.getRoleReadAccess(`od-tenant-user-${tenant.id}`);
|
|
139
|
+
}
|
|
@@ -19,6 +19,7 @@ export declare namespace Permissions {
|
|
|
19
19
|
kanban_view = "maintenance:can-update-kanban-view"
|
|
20
20
|
}
|
|
21
21
|
enum SERVICE {
|
|
22
|
+
admin_access = "service:can-access-admin",
|
|
22
23
|
ticket_read = "service:can-read-ticket",
|
|
23
24
|
ticket_create = "service:can-create-ticket",
|
|
24
25
|
ticket_edit = "service:can-edit-ticket",
|
|
@@ -30,6 +30,11 @@ var Permissions;
|
|
|
30
30
|
})(MAINTENANCE = Permissions.MAINTENANCE || (Permissions.MAINTENANCE = {}));
|
|
31
31
|
let SERVICE;
|
|
32
32
|
(function (SERVICE) {
|
|
33
|
+
// Access to the shared service administration (`/admin/service/**`) —
|
|
34
|
+
// master data, contacts, service providers. Deliberately not tied to the
|
|
35
|
+
// schedule plugin: a tenant running only tickets administers the same
|
|
36
|
+
// contacts and companies.
|
|
37
|
+
SERVICE["admin_access"] = "service:can-access-admin";
|
|
33
38
|
// Tickets
|
|
34
39
|
SERVICE["ticket_read"] = "service:can-read-ticket";
|
|
35
40
|
SERVICE["ticket_create"] = "service:can-create-ticket";
|
|
@@ -24,8 +24,13 @@ async function init(name) {
|
|
|
24
24
|
action: "login",
|
|
25
25
|
provider: "openinc-auth-login-passwordless",
|
|
26
26
|
});
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
// Route the caller's template through `createUrl`, like every other
|
|
28
|
+
// token mail does. Without it the endpoint mails an open.DASH-branded
|
|
29
|
+
// link to any host the caller names — carrying a live session token of
|
|
30
|
+
// the account being logged in. `ENFORCE_APP_URL` pins protocol and host
|
|
31
|
+
// to `APP_URL`; the path and query still come from the caller, which is
|
|
32
|
+
// what makes the parameter useful in the first place.
|
|
33
|
+
const url = (0, openinc_auth_common_js_1.createUrl)(urlTemplate, sessionToken);
|
|
29
34
|
await (0, index_js_1.sendTemplateEmail)({
|
|
30
35
|
template: "openinc-auth-login-passwordless",
|
|
31
36
|
subject: "Passwordless Login",
|
|
@@ -35,6 +35,12 @@ async function init(name) {
|
|
|
35
35
|
required: true,
|
|
36
36
|
type: String,
|
|
37
37
|
},
|
|
38
|
+
// Read since this endpoint was written, but never declared — so it was
|
|
39
|
+
// absent from the signature and, until now, from the check as well.
|
|
40
|
+
type: {
|
|
41
|
+
required: true,
|
|
42
|
+
type: String,
|
|
43
|
+
},
|
|
38
44
|
},
|
|
39
45
|
});
|
|
40
46
|
}
|
|
@@ -43,6 +43,19 @@ async function consumeToken(type, key, doNotConsume = false) {
|
|
|
43
43
|
if (!token) {
|
|
44
44
|
throw new node_1.default.Error(node_1.default.Error.OBJECT_NOT_FOUND, "Token not found.");
|
|
45
45
|
}
|
|
46
|
+
// The `type` argument used to be taken and ignored: the query matched on the
|
|
47
|
+
// key alone, so a token issued for one purpose could be redeemed at any of
|
|
48
|
+
// these endpoints. Nothing exploited it while every row here was a
|
|
49
|
+
// short-lived, single-use auth token, but the table is shared — the service
|
|
50
|
+
// provider links live in it too, and those are long-lived and handed to
|
|
51
|
+
// people outside the organisation.
|
|
52
|
+
//
|
|
53
|
+
// Checked before the token is consumed, so a mismatch cannot burn a token
|
|
54
|
+
// that belongs to another flow.
|
|
55
|
+
const payload = token.get("payload");
|
|
56
|
+
if (payload?.type !== type) {
|
|
57
|
+
throw new node_1.default.Error(node_1.default.Error.OBJECT_NOT_FOUND, "Token not found.");
|
|
58
|
+
}
|
|
46
59
|
if (!doNotConsume) {
|
|
47
60
|
token.used = true;
|
|
48
61
|
await token.save({ used: true }, { useMasterKey: true });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grant or withdraw one service provider's access to one maintenance plan.
|
|
3
|
+
*
|
|
4
|
+
* Params: `{ contactId, scheduleId, revoke? }`. Granting returns
|
|
5
|
+
* `ProviderGrantResult`; withdrawing returns `{ scheduleId, userId? }`.
|
|
6
|
+
*
|
|
7
|
+
* **The tenant comes from the caller's account, never from the parameters.**
|
|
8
|
+
* This endpoint is for a person in a browser session, and a session must not be
|
|
9
|
+
* able to name a tenant it does not belong to — otherwise granting access to a
|
|
10
|
+
* plan would become a way to reach into another customer's data.
|
|
11
|
+
*
|
|
12
|
+
* **Gated on `schedule_create`, not on a capability of its own.** Handing an
|
|
13
|
+
* address-book row an account that can log in is the same order of decision as
|
|
14
|
+
* creating a plan, and whoever may do one is trusted with the other. A separate
|
|
15
|
+
* key would have been a third thing to configure per tenant and, unconfigured,
|
|
16
|
+
* a feature nobody can reach.
|
|
17
|
+
*
|
|
18
|
+
* Note that this is the first `Service_*` endpoint that checks a capability
|
|
19
|
+
* server-side rather than relying on the UI hiding a button — see GRENZEN §2
|
|
20
|
+
* for the rest, which does not.
|
|
21
|
+
*/
|
|
22
|
+
export declare function init(name: string): Promise<void>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.init = init;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const index_js_1 = require("../features/openservice/serviceProviders/index.js");
|
|
9
|
+
const index_js_2 = require("../features/permissions/index.js");
|
|
10
|
+
const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
|
|
11
|
+
/**
|
|
12
|
+
* Grant or withdraw one service provider's access to one maintenance plan.
|
|
13
|
+
*
|
|
14
|
+
* Params: `{ contactId, scheduleId, revoke? }`. Granting returns
|
|
15
|
+
* `ProviderGrantResult`; withdrawing returns `{ scheduleId, userId? }`.
|
|
16
|
+
*
|
|
17
|
+
* **The tenant comes from the caller's account, never from the parameters.**
|
|
18
|
+
* This endpoint is for a person in a browser session, and a session must not be
|
|
19
|
+
* able to name a tenant it does not belong to — otherwise granting access to a
|
|
20
|
+
* plan would become a way to reach into another customer's data.
|
|
21
|
+
*
|
|
22
|
+
* **Gated on `schedule_create`, not on a capability of its own.** Handing an
|
|
23
|
+
* address-book row an account that can log in is the same order of decision as
|
|
24
|
+
* creating a plan, and whoever may do one is trusted with the other. A separate
|
|
25
|
+
* key would have been a third thing to configure per tenant and, unconfigured,
|
|
26
|
+
* a feature nobody can reach.
|
|
27
|
+
*
|
|
28
|
+
* Note that this is the first `Service_*` endpoint that checks a capability
|
|
29
|
+
* server-side rather than relying on the UI hiding a button — see GRENZEN §2
|
|
30
|
+
* for the rest, which does not.
|
|
31
|
+
*/
|
|
32
|
+
async function init(name) {
|
|
33
|
+
node_1.default.Cloud.define(name, async (request) => {
|
|
34
|
+
const user = request.user;
|
|
35
|
+
if (!user) {
|
|
36
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_SESSION_TOKEN, `${name} requires a logged-in user`);
|
|
37
|
+
}
|
|
38
|
+
await (0, index_js_2.requirePermission)({
|
|
39
|
+
sessionToken: user.getSessionToken(),
|
|
40
|
+
master: request.master,
|
|
41
|
+
}, Permissions_js_1.Permissions.SERVICE.schedule_create, "grant a service provider access to a maintenance plan");
|
|
42
|
+
const tenant = user.get("tenant");
|
|
43
|
+
if (!tenant?.id) {
|
|
44
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${name}: the calling user has no tenant`);
|
|
45
|
+
}
|
|
46
|
+
const { contactId, scheduleId, revoke } = request.params;
|
|
47
|
+
if (typeof contactId !== "string" || typeof scheduleId !== "string") {
|
|
48
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${name}: contactId and scheduleId are required`);
|
|
49
|
+
}
|
|
50
|
+
return revoke === true
|
|
51
|
+
? await (0, index_js_1.revokeProviderAccess)(tenant, contactId, scheduleId)
|
|
52
|
+
: await (0, index_js_1.grantProviderAccess)(tenant, contactId, scheduleId);
|
|
53
|
+
}, { requireUser: true });
|
|
54
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read and repair the tenant's service-provider setup.
|
|
3
|
+
*
|
|
4
|
+
* Params: `{ action: "status" }` or
|
|
5
|
+
* `{ action: "grant" | "revoke", keys: string[] }`.
|
|
6
|
+
*
|
|
7
|
+
* This exists because granting a provider access deliberately does not hand
|
|
8
|
+
* out capabilities — which rights a provider should have is a policy per
|
|
9
|
+
* customer. The cost of that decision is a gap nobody could see: the account
|
|
10
|
+
* exists, the assignment exists, and the provider still cannot open the plugin.
|
|
11
|
+
* Rather than guessing on their behalf, this makes the gap visible and gives
|
|
12
|
+
* the administrator one button for it.
|
|
13
|
+
*
|
|
14
|
+
* Gated on `masterdata_manage`, not on `schedule_create`: handing a role a
|
|
15
|
+
* capability is administration of the tenant, a step above assigning somebody
|
|
16
|
+
* to a plan. Whoever may set up access here may widen what *every* provider in
|
|
17
|
+
* the tenant can do.
|
|
18
|
+
*/
|
|
19
|
+
export declare function init(name: string): Promise<void>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.init = init;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const index_js_1 = require("../features/openservice/serviceProviders/index.js");
|
|
9
|
+
const index_js_2 = require("../features/permissions/index.js");
|
|
10
|
+
const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
|
|
11
|
+
/**
|
|
12
|
+
* Read and repair the tenant's service-provider setup.
|
|
13
|
+
*
|
|
14
|
+
* Params: `{ action: "status" }` or
|
|
15
|
+
* `{ action: "grant" | "revoke", keys: string[] }`.
|
|
16
|
+
*
|
|
17
|
+
* This exists because granting a provider access deliberately does not hand
|
|
18
|
+
* out capabilities — which rights a provider should have is a policy per
|
|
19
|
+
* customer. The cost of that decision is a gap nobody could see: the account
|
|
20
|
+
* exists, the assignment exists, and the provider still cannot open the plugin.
|
|
21
|
+
* Rather than guessing on their behalf, this makes the gap visible and gives
|
|
22
|
+
* the administrator one button for it.
|
|
23
|
+
*
|
|
24
|
+
* Gated on `masterdata_manage`, not on `schedule_create`: handing a role a
|
|
25
|
+
* capability is administration of the tenant, a step above assigning somebody
|
|
26
|
+
* to a plan. Whoever may set up access here may widen what *every* provider in
|
|
27
|
+
* the tenant can do.
|
|
28
|
+
*/
|
|
29
|
+
async function init(name) {
|
|
30
|
+
node_1.default.Cloud.define(name, async (request) => {
|
|
31
|
+
const user = request.user;
|
|
32
|
+
if (!user) {
|
|
33
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_SESSION_TOKEN, `${name} requires a logged-in user`);
|
|
34
|
+
}
|
|
35
|
+
await (0, index_js_2.requirePermission)({
|
|
36
|
+
sessionToken: user.getSessionToken(),
|
|
37
|
+
master: request.master,
|
|
38
|
+
}, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "manage the service provider setup");
|
|
39
|
+
const tenant = user.get("tenant");
|
|
40
|
+
if (!tenant?.id) {
|
|
41
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${name}: the calling user has no tenant`);
|
|
42
|
+
}
|
|
43
|
+
const { action, keys } = request.params;
|
|
44
|
+
if (action === undefined || action === "status") {
|
|
45
|
+
return (0, index_js_1.providerRoleStatus)(tenant);
|
|
46
|
+
}
|
|
47
|
+
if (action !== "grant" && action !== "revoke") {
|
|
48
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${name}: action must be "status", "grant" or "revoke"`);
|
|
49
|
+
}
|
|
50
|
+
if (!Array.isArray(keys) ||
|
|
51
|
+
keys.length === 0 ||
|
|
52
|
+
keys.some((key) => typeof key !== "string")) {
|
|
53
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${name}: keys must be a non-empty array of permission keys`);
|
|
54
|
+
}
|
|
55
|
+
return (0, index_js_1.setProviderCapabilities)(tenant, keys, action === "grant");
|
|
56
|
+
}, { requireUser: true });
|
|
57
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inspect and complete the open.SERVICE setup of the caller's tenant.
|
|
3
|
+
*
|
|
4
|
+
* Actions:
|
|
5
|
+
* - `status` (default) — what is in place and what is not. Never returns a
|
|
6
|
+
* secret's value.
|
|
7
|
+
* - `reveal` — the value of one secret config row, so it can be pasted into
|
|
8
|
+
* the alarm executor. The one call that hands a credential out, which is why
|
|
9
|
+
* it is a separate action rather than a field on `status`: a page rendering
|
|
10
|
+
* the overview should not be carrying secrets it does not display.
|
|
11
|
+
* - `regenerate` — replace a secret with a fresh one. Invalidates the old one
|
|
12
|
+
* immediately, so every executor holding it stops working until it is
|
|
13
|
+
* updated. The caller is expected to have said so out loud first.
|
|
14
|
+
* - `set` — write a config row a human has to supply (the Outlook
|
|
15
|
+
* credentials). Refuses keys the catalogue marks as generated, because
|
|
16
|
+
* pasting a secret by hand defeats generating one.
|
|
17
|
+
*
|
|
18
|
+
* Gated on `masterdata_manage`: this is tenant administration, a step above
|
|
19
|
+
* working with plans and tickets.
|
|
20
|
+
*
|
|
21
|
+
* **The tenant comes from the session, never from a parameter** — otherwise
|
|
22
|
+
* reading a secret would become a way to read another customer's.
|
|
23
|
+
*/
|
|
24
|
+
export declare function init(name: string): Promise<void>;
|