@openinc/parse-server-opendash 4.14.1 → 4.15.1
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/hooks/Meta_Entry.js
CHANGED
|
@@ -37,9 +37,57 @@ function allowSubjectUserWrite(object) {
|
|
|
37
37
|
acl.setWriteAccess(subjectId, true);
|
|
38
38
|
object.setACL(acl);
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* File an entry under the tenant of the object it is *about*, not under the
|
|
42
|
+
* tenant of whoever wrote it.
|
|
43
|
+
*
|
|
44
|
+
* `defaultHandler` can only answer "whose is this?" with the writer's own
|
|
45
|
+
* tenant — it knows nothing about `entryClassName` / `entryObjectId`. That was
|
|
46
|
+
* wrong for anyone who edits across tenants: an `od-admin` of tenant A adding
|
|
47
|
+
* meta to tenant B's equipment produced an entry owned by A, and since
|
|
48
|
+
* `defaultAclHandler` keys its grants on the entry's tenant, **B could not read
|
|
49
|
+
* the meta data on its own record** — only od-admin and tenant A could. The
|
|
50
|
+
* `afterSave` below then registered the context under A as well.
|
|
51
|
+
*
|
|
52
|
+
* Runs after `defaultHandler` on purpose: that function overwrites `tenant`
|
|
53
|
+
* with the writer's own for any caller without `opendash:can-admin-tenants`,
|
|
54
|
+
* so correcting it beforehand would be undone.
|
|
55
|
+
*
|
|
56
|
+
* Only on create, or on a master-key write — `immutableField` refuses a tenant
|
|
57
|
+
* change for everyone else, and a master-key re-save is therefore also the
|
|
58
|
+
* repair path for entries written before this existed.
|
|
59
|
+
*
|
|
60
|
+
* Every failure leaves `defaultHandler`'s answer in place: a linked object that
|
|
61
|
+
* does not exist, a class without a tenant column, an entry that names no
|
|
62
|
+
* object at all. The tenant is never cleared, only corrected.
|
|
63
|
+
*/
|
|
64
|
+
async function applyLinkedObjectTenant(request) {
|
|
65
|
+
if (request.original && !request.master)
|
|
66
|
+
return;
|
|
67
|
+
const className = request.object.entryClassName;
|
|
68
|
+
const objectId = request.object.entryObjectId;
|
|
69
|
+
if (!className || !objectId)
|
|
70
|
+
return;
|
|
71
|
+
try {
|
|
72
|
+
const linked = await new node_1.default.Query(className)
|
|
73
|
+
.equalTo("objectId", objectId)
|
|
74
|
+
.first({ useMasterKey: true });
|
|
75
|
+
const tenant = linked?.get("tenant");
|
|
76
|
+
if (!tenant)
|
|
77
|
+
return;
|
|
78
|
+
if (request.object.tenant?.id === tenant.id)
|
|
79
|
+
return;
|
|
80
|
+
request.object.tenant = tenant;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.error("[@openinc/parse-server-opendash][Meta_Entry] Failed to resolve the linked object's tenant", className, objectId, error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
40
86
|
async function init() {
|
|
41
87
|
(0, index_js_2.beforeSaveHook)(index_js_3.Meta_Entry, async (request) => {
|
|
42
88
|
await (0, index_js_2.defaultHandler)(request);
|
|
89
|
+
// Before the ACL handler: it derives every grant from `tenant`.
|
|
90
|
+
await applyLinkedObjectTenant(request);
|
|
43
91
|
await (0, index_js_2.defaultAclHandler)(request, {
|
|
44
92
|
// Meta entries are collaborative header data: the tenant's users are the
|
|
45
93
|
// ones filling them in from the ticket/equipment UI, so they need write
|
|
@@ -6,23 +6,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.init = init;
|
|
7
7
|
const node_1 = __importDefault(require("parse/node"));
|
|
8
8
|
const index_js_1 = require("../features/schema/index.js");
|
|
9
|
+
const index_js_2 = require("../features/permissions/index.js");
|
|
10
|
+
const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
|
|
9
11
|
const ticketSortKeys_js_1 = require("../helper/ticketSortKeys.js");
|
|
10
|
-
const
|
|
12
|
+
const index_js_3 = require("../types/index.js");
|
|
11
13
|
async function init() {
|
|
12
14
|
// Soft delete: tickets and meter readings point at equipment, so it is
|
|
13
15
|
// archived rather than destroyed. Archived rows are hidden from every client
|
|
14
16
|
// query (see hideSoftDeleted()).
|
|
15
|
-
(0, index_js_1.hideSoftDeleted)(
|
|
16
|
-
(0, index_js_1.beforeSaveHook)(
|
|
17
|
-
const { object, original
|
|
17
|
+
(0, index_js_1.hideSoftDeleted)(index_js_3.Service_Equipment, { field: "deleted" });
|
|
18
|
+
(0, index_js_1.beforeSaveHook)(index_js_3.Service_Equipment, async (request) => {
|
|
19
|
+
const { object, original } = request;
|
|
20
|
+
// Creating master data is a capability: there is no record yet whose ACL
|
|
21
|
+
// could be asked, and the class-level `create` is open to everybody. Editing
|
|
22
|
+
// an existing row needs no check here — `defaultAclHandler` below grants
|
|
23
|
+
// write to od-admin, the tenant admins and the creator, and nobody else.
|
|
24
|
+
//
|
|
25
|
+
// Passes `request`, not `request.user`: `defaultHandler` refetches the user
|
|
26
|
+
// in place, which drops its session token — so both checks run before it.
|
|
27
|
+
if (!original && !(0, index_js_1.isMigrationMode)()) {
|
|
28
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "create equipment");
|
|
29
|
+
}
|
|
30
|
+
// Archiving sets `deleted` — an update, which the ACL grants to the creator
|
|
31
|
+
// as well. Retiring equipment is a decision of its own, and restoring it is
|
|
32
|
+
// the same decision. Compared against `original`, so a client that resends
|
|
33
|
+
// the unchanged flag is not refused.
|
|
34
|
+
if (original &&
|
|
35
|
+
!(0, index_js_1.isMigrationMode)() &&
|
|
36
|
+
Boolean(object.get("deleted")) !== Boolean(original.get("deleted"))) {
|
|
37
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "archive equipment");
|
|
38
|
+
}
|
|
18
39
|
await (0, index_js_1.defaultHandler)(request);
|
|
19
40
|
await (0, index_js_1.defaultAclHandler)(request);
|
|
20
|
-
// TODO
|
|
21
41
|
});
|
|
22
42
|
// Tickets sort by `equipmentSortKey`, derived from this label when the ticket
|
|
23
43
|
// was saved. A rename therefore has to reach them, or they keep sorting under
|
|
24
44
|
// the old name until each one is touched by hand.
|
|
25
|
-
(0, index_js_1.afterSaveHook)(
|
|
45
|
+
(0, index_js_1.afterSaveHook)(index_js_3.Service_Equipment, async ({ object, original }) => {
|
|
26
46
|
if (!(0, ticketSortKeys_js_1.derivedValueChanged)(object, original, "label"))
|
|
27
47
|
return;
|
|
28
48
|
await (0, ticketSortKeys_js_1.pushSortKeyToTickets)("equipment", "equipmentSortKey", object, (0, ticketSortKeys_js_1.sortKeyOf)(object.get("label")));
|
|
@@ -30,8 +50,15 @@ async function init() {
|
|
|
30
50
|
// Block deleting equipment that is still referenced where it matters:
|
|
31
51
|
// active tickets, and meter readings (whose `equipment` pointer is required,
|
|
32
52
|
// so orphaning it would break them).
|
|
33
|
-
(0, index_js_1.beforeDeleteHook)(
|
|
34
|
-
const
|
|
53
|
+
(0, index_js_1.beforeDeleteHook)(index_js_3.Service_Equipment, async (request) => {
|
|
54
|
+
const { object } = request;
|
|
55
|
+
// Parse has no delete right of its own — an ACL `write` grant covers update
|
|
56
|
+
// *and* delete, so anyone allowed to edit equipment could otherwise remove
|
|
57
|
+
// it. Hiding the button in the UI does not change that.
|
|
58
|
+
if (!(0, index_js_1.isMigrationMode)()) {
|
|
59
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "delete equipment");
|
|
60
|
+
}
|
|
61
|
+
const tickets = await new node_1.default.Query(index_js_3.Service_Ticket)
|
|
35
62
|
.equalTo("equipment", object)
|
|
36
63
|
.notEqualTo("deleted", true)
|
|
37
64
|
.count({ useMasterKey: true });
|
|
@@ -2,23 +2,52 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.init = init;
|
|
4
4
|
const index_js_1 = require("../features/schema/index.js");
|
|
5
|
+
const index_js_2 = require("../features/permissions/index.js");
|
|
6
|
+
const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
|
|
5
7
|
const ticketSortKeys_js_1 = require("../helper/ticketSortKeys.js");
|
|
6
|
-
const
|
|
8
|
+
const index_js_3 = require("../types/index.js");
|
|
7
9
|
async function init() {
|
|
8
10
|
// Soft delete: tickets point at their project and draw their number from its
|
|
9
11
|
// counter, so a project is archived rather than destroyed. Archived rows are
|
|
10
12
|
// hidden from every client query (see hideSoftDeleted()).
|
|
11
|
-
(0, index_js_1.hideSoftDeleted)(
|
|
12
|
-
(0, index_js_1.beforeSaveHook)(
|
|
13
|
-
const { object, original
|
|
13
|
+
(0, index_js_1.hideSoftDeleted)(index_js_3.Service_Project, { field: "deleted" });
|
|
14
|
+
(0, index_js_1.beforeSaveHook)(index_js_3.Service_Project, async (request) => {
|
|
15
|
+
const { object, original } = request;
|
|
16
|
+
// Creating master data is a capability: there is no record yet whose ACL
|
|
17
|
+
// could be asked, and the class-level `create` is open to everybody. Editing
|
|
18
|
+
// an existing row needs no check here — `defaultAclHandler` below grants
|
|
19
|
+
// write to od-admin, the tenant admins and the creator, and nobody else.
|
|
20
|
+
//
|
|
21
|
+
// Both checks run before `defaultHandler`, which refetches the user in place
|
|
22
|
+
// and drops its session token.
|
|
23
|
+
if (!original && !(0, index_js_1.isMigrationMode)()) {
|
|
24
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "create a project");
|
|
25
|
+
}
|
|
26
|
+
// Archiving sets `deleted` — an update, which the ACL grants to the creator
|
|
27
|
+
// as well. Retiring a project is a decision of its own, and restoring it is
|
|
28
|
+
// the same decision. Compared against `original`, so a client that resends
|
|
29
|
+
// the unchanged flag is not refused.
|
|
30
|
+
if (original &&
|
|
31
|
+
!(0, index_js_1.isMigrationMode)() &&
|
|
32
|
+
Boolean(object.get("deleted")) !== Boolean(original.get("deleted"))) {
|
|
33
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "archive a project");
|
|
34
|
+
}
|
|
14
35
|
await (0, index_js_1.defaultHandler)(request);
|
|
15
36
|
await (0, index_js_1.defaultAclHandler)(request);
|
|
16
|
-
|
|
37
|
+
});
|
|
38
|
+
// Parse has no delete right of its own — an ACL `write` grant covers update
|
|
39
|
+
// *and* delete, so anyone allowed to edit a project could otherwise remove it.
|
|
40
|
+
// Tickets point at their project and draw their number from its counter, so
|
|
41
|
+
// the frontend archives instead; this covers the direct API call.
|
|
42
|
+
(0, index_js_1.beforeDeleteHook)(index_js_3.Service_Project, async (request) => {
|
|
43
|
+
if ((0, index_js_1.isMigrationMode)())
|
|
44
|
+
return;
|
|
45
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "delete a project");
|
|
17
46
|
});
|
|
18
47
|
// Tickets sort by `projectSortKey`, derived from this label when the ticket was
|
|
19
48
|
// saved. A rename therefore has to reach them, or they keep sorting under the
|
|
20
49
|
// old name until each one is touched by hand.
|
|
21
|
-
(0, index_js_1.afterSaveHook)(
|
|
50
|
+
(0, index_js_1.afterSaveHook)(index_js_3.Service_Project, async ({ object, original }) => {
|
|
22
51
|
if (!(0, ticketSortKeys_js_1.derivedValueChanged)(object, original, "label"))
|
|
23
52
|
return;
|
|
24
53
|
await (0, ticketSortKeys_js_1.pushSortKeyToTickets)("project", "projectSortKey", object, (0, ticketSortKeys_js_1.sortKeyOf)(object.get("label")));
|
|
@@ -6,31 +6,59 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.init = init;
|
|
7
7
|
const node_1 = __importDefault(require("parse/node"));
|
|
8
8
|
const index_js_1 = require("../features/schema/index.js");
|
|
9
|
+
const index_js_2 = require("../features/permissions/index.js");
|
|
10
|
+
const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
|
|
9
11
|
const ticketSortKeys_js_1 = require("../helper/ticketSortKeys.js");
|
|
10
|
-
const
|
|
12
|
+
const index_js_3 = require("../types/index.js");
|
|
11
13
|
async function init() {
|
|
12
14
|
// Soft delete: every ticket carries a required `status` pointer, so a status
|
|
13
15
|
// is archived rather than destroyed. Archived rows are hidden from every
|
|
14
16
|
// client query (see hideSoftDeleted() for the escape hatches).
|
|
15
|
-
(0, index_js_1.hideSoftDeleted)(
|
|
16
|
-
(0, index_js_1.beforeSaveHook)(
|
|
17
|
-
const { object, original
|
|
17
|
+
(0, index_js_1.hideSoftDeleted)(index_js_3.Service_Status, { field: "deleted" });
|
|
18
|
+
(0, index_js_1.beforeSaveHook)(index_js_3.Service_Status, async (request) => {
|
|
19
|
+
const { object, original } = request;
|
|
20
|
+
// A status is the ticket workflow: adding one changes what every ticket in
|
|
21
|
+
// the tenant can be set to. There is no record yet whose ACL could be asked
|
|
22
|
+
// and the class-level `create` is open to everybody, so it is a capability.
|
|
23
|
+
// Editing an existing row needs no check here — `defaultAclHandler` below
|
|
24
|
+
// grants write to od-admin, the tenant admins and the creator, nobody else.
|
|
25
|
+
//
|
|
26
|
+
// Both checks run before `defaultHandler`, which refetches the user in place
|
|
27
|
+
// and drops its session token.
|
|
28
|
+
if (!original && !(0, index_js_1.isMigrationMode)()) {
|
|
29
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "create a ticket status");
|
|
30
|
+
}
|
|
31
|
+
// Archiving sets `deleted` — an update, which the ACL grants to the creator
|
|
32
|
+
// as well. Retiring a status takes it out of every picker in the tenant, and
|
|
33
|
+
// restoring it is the same decision. Compared against `original`, so a
|
|
34
|
+
// client that resends the unchanged flag is not refused.
|
|
35
|
+
if (original &&
|
|
36
|
+
!(0, index_js_1.isMigrationMode)() &&
|
|
37
|
+
Boolean(object.get("deleted")) !== Boolean(original.get("deleted"))) {
|
|
38
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "archive a ticket status");
|
|
39
|
+
}
|
|
18
40
|
await (0, index_js_1.defaultHandler)(request);
|
|
19
41
|
await (0, index_js_1.defaultAclHandler)(request);
|
|
20
|
-
// TODO
|
|
21
42
|
});
|
|
22
43
|
// A ticket sorts by its status's workflow position, which it carries as
|
|
23
44
|
// `statusOrder`. Reordering the workflow has to reach the tickets, or the
|
|
24
45
|
// board keeps the old order until each one is touched by hand.
|
|
25
|
-
(0, index_js_1.afterSaveHook)(
|
|
46
|
+
(0, index_js_1.afterSaveHook)(index_js_3.Service_Status, async ({ object, original }) => {
|
|
26
47
|
if (!(0, ticketSortKeys_js_1.derivedValueChanged)(object, original, "order"))
|
|
27
48
|
return;
|
|
28
49
|
await (0, ticketSortKeys_js_1.pushSortKeyToTickets)("status", "statusOrder", object, object.get("order"));
|
|
29
50
|
});
|
|
30
51
|
// A ticket's `status` is required — deleting a status still in use by active
|
|
31
52
|
// tickets would orphan that required pointer. Block it.
|
|
32
|
-
(0, index_js_1.beforeDeleteHook)(
|
|
33
|
-
const
|
|
53
|
+
(0, index_js_1.beforeDeleteHook)(index_js_3.Service_Status, async (request) => {
|
|
54
|
+
const { object } = request;
|
|
55
|
+
// Parse has no delete right of its own — an ACL `write` grant covers update
|
|
56
|
+
// *and* delete, so anyone allowed to edit a status could otherwise remove
|
|
57
|
+
// it. Hiding the button in the UI does not change that.
|
|
58
|
+
if (!(0, index_js_1.isMigrationMode)()) {
|
|
59
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "delete a ticket status");
|
|
60
|
+
}
|
|
61
|
+
const inUse = await new node_1.default.Query(index_js_3.Service_Ticket)
|
|
34
62
|
.equalTo("status", object)
|
|
35
63
|
.notEqualTo("deleted", true)
|
|
36
64
|
.count({ useMasterKey: true });
|
|
@@ -6,19 +6,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.init = init;
|
|
7
7
|
const node_1 = __importDefault(require("parse/node"));
|
|
8
8
|
const index_js_1 = require("../features/schema/index.js");
|
|
9
|
-
const index_js_2 = require("../
|
|
9
|
+
const index_js_2 = require("../features/permissions/index.js");
|
|
10
|
+
const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
|
|
11
|
+
const index_js_3 = require("../types/index.js");
|
|
10
12
|
async function init() {
|
|
11
13
|
// Soft delete: tags are stored in the ancestor closures on tickets and
|
|
12
14
|
// equipment, so they are archived rather than destroyed. Archived rows are
|
|
13
15
|
// hidden from every client query (see hideSoftDeleted()).
|
|
14
|
-
(0, index_js_1.hideSoftDeleted)(
|
|
15
|
-
(0, index_js_1.beforeSaveHook)(
|
|
16
|
-
const { object, original
|
|
16
|
+
(0, index_js_1.hideSoftDeleted)(index_js_3.Service_Tag, { field: "deleted" });
|
|
17
|
+
(0, index_js_1.beforeSaveHook)(index_js_3.Service_Tag, async (request) => {
|
|
18
|
+
const { object, original } = request;
|
|
19
|
+
// Creating a tag is a capability: there is no record yet whose ACL could be
|
|
20
|
+
// asked, and the class-level `create` is open to everybody. Editing an
|
|
21
|
+
// existing tag needs no check here — `defaultAclHandler` below grants write
|
|
22
|
+
// to od-admin, the tenant admins and the creator, and nobody else.
|
|
23
|
+
//
|
|
24
|
+
// Runs before `defaultHandler`, which refetches the user in place and drops
|
|
25
|
+
// its session token.
|
|
26
|
+
if (!original && !(0, index_js_1.isMigrationMode)()) {
|
|
27
|
+
await requireTagCreate(request);
|
|
28
|
+
}
|
|
29
|
+
// Archiving sets `deleted` — an update, which the ACL grants to the creator
|
|
30
|
+
// as well. A tag is referenced by the ancestor closures on tickets and
|
|
31
|
+
// equipment, so retiring one reaches further than the row itself: that is
|
|
32
|
+
// master-data administration, not the narrow inline-create capability.
|
|
33
|
+
if (original &&
|
|
34
|
+
!(0, index_js_1.isMigrationMode)() &&
|
|
35
|
+
Boolean(object.get("deleted")) !== Boolean(original.get("deleted"))) {
|
|
36
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "archive a tag");
|
|
37
|
+
}
|
|
17
38
|
await (0, index_js_1.defaultHandler)(request);
|
|
18
39
|
await (0, index_js_1.defaultAclHandler)(request);
|
|
19
|
-
// TODO
|
|
20
40
|
});
|
|
21
|
-
(0, index_js_1.afterSaveHook)(
|
|
41
|
+
(0, index_js_1.afterSaveHook)(index_js_3.Service_Tag, async ({ object, original }) => {
|
|
22
42
|
// Entities store the *ancestor closure* of the tags picked on them (see the
|
|
23
43
|
// tags README). Re-parenting a tag changes those ancestors, so every
|
|
24
44
|
// equipment/ticket whose closure includes this tag must be rebuilt.
|
|
@@ -36,17 +56,45 @@ async function init() {
|
|
|
36
56
|
return; // parent unchanged → closures fine
|
|
37
57
|
await reconcileClosures(object, oldParentId, newParentId);
|
|
38
58
|
});
|
|
39
|
-
|
|
59
|
+
// Parse has no delete right of its own — an ACL `write` grant covers update
|
|
60
|
+
// *and* delete, so anyone allowed to edit a tag could otherwise remove it.
|
|
61
|
+
// Destroying a tag strips it from every ticket and equipment that references
|
|
62
|
+
// it (see `cleanupTagArrays`), which is master-data administration.
|
|
63
|
+
(0, index_js_1.beforeDeleteHook)(index_js_3.Service_Tag, async (request) => {
|
|
64
|
+
if ((0, index_js_1.isMigrationMode)())
|
|
65
|
+
return;
|
|
66
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "delete a tag");
|
|
67
|
+
});
|
|
68
|
+
(0, index_js_1.afterDeleteHook)(index_js_3.Service_Tag, async (request) => {
|
|
40
69
|
const { object } = request;
|
|
41
70
|
await cleanupTagArrays(object);
|
|
42
71
|
});
|
|
43
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Either capability may create a tag.
|
|
75
|
+
*
|
|
76
|
+
* `tag_create` is the narrow one the ticket editor's tag picker offers inline —
|
|
77
|
+
* someone who may file a ticket often needs a tag that does not exist yet,
|
|
78
|
+
* without being trusted with the whole master-data administration.
|
|
79
|
+
* `masterdata_manage` is that whole administration, and a superset of it: the
|
|
80
|
+
* Tag admin page's create button is gated on it, so a holder of it must be able
|
|
81
|
+
* to create a tag without also being granted the narrow key.
|
|
82
|
+
*/
|
|
83
|
+
async function requireTagCreate(request) {
|
|
84
|
+
if (request.master)
|
|
85
|
+
return;
|
|
86
|
+
if (request.sessionToken &&
|
|
87
|
+
(await (0, index_js_2.hasPermission)(request.sessionToken, Permissions_js_1.Permissions.SERVICE.tag_create))) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "create a tag");
|
|
91
|
+
}
|
|
44
92
|
async function cleanupTagArrays(object) {
|
|
45
93
|
if (!object.id)
|
|
46
94
|
return;
|
|
47
95
|
await Promise.all([
|
|
48
|
-
removeTagFromClass(
|
|
49
|
-
removeTagFromClass(
|
|
96
|
+
removeTagFromClass(index_js_3.Service_Ticket, object),
|
|
97
|
+
removeTagFromClass(index_js_3.Service_Equipment, object),
|
|
50
98
|
]);
|
|
51
99
|
}
|
|
52
100
|
async function removeTagFromClass(ObjectClass, tag) {
|
|
@@ -133,7 +181,7 @@ async function reconcileClosures(tag, oldParentId, newParentId) {
|
|
|
133
181
|
if (!tagId)
|
|
134
182
|
return;
|
|
135
183
|
const tenant = tag.tenant;
|
|
136
|
-
const query = new node_1.default.Query(
|
|
184
|
+
const query = new node_1.default.Query(index_js_3.Service_Tag);
|
|
137
185
|
if (tenant)
|
|
138
186
|
query.equalTo("tenant", tenant);
|
|
139
187
|
const allTags = await query.findAll({ useMasterKey: true });
|
|
@@ -146,8 +194,8 @@ async function reconcileClosures(tag, oldParentId, newParentId) {
|
|
|
146
194
|
const oldParents = new Map(newParents);
|
|
147
195
|
oldParents.set(tagId, oldParentId);
|
|
148
196
|
await Promise.all([
|
|
149
|
-
reconcileClass(
|
|
150
|
-
reconcileClass(
|
|
197
|
+
reconcileClass(index_js_3.Service_Ticket, tagId, tenant, oldParents, newParents),
|
|
198
|
+
reconcileClass(index_js_3.Service_Equipment, tagId, tenant, oldParents, newParents),
|
|
151
199
|
]);
|
|
152
200
|
}
|
|
153
201
|
async function reconcileClass(ObjectClass, tagId, tenant, oldParents, newParents) {
|