@openinc/parse-server-opendash 4.13.0 → 4.14.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.
@@ -19,21 +19,18 @@ 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",
23
- ticket_read = "service:can-read-ticket",
24
- ticket_create = "service:can-create-ticket",
25
- ticket_edit = "service:can-edit-ticket",
26
- ticket_delete = "service:can-delete-ticket",
27
- ticket_assign = "service:can-assign-ticket",
22
+ admin_access = "openservice-core:can-access-admin",
23
+ masterdata_manage = "openservice-core:can-manage-masterdata",
24
+ tag_create = "openservice-core:can-create-tag",
25
+ ticket_access = "openservice-ticket:can-access-ticket-plugin",
26
+ ticket_create = "openservice-ticket:can-create-ticket",
27
+ ticket_delete = "openservice-ticket:can-delete-ticket",
28
28
  schedule_access = "openservice-schedule:can-access-schedule-plugin",
29
29
  schedule_create = "openservice-schedule:can-create-schedule",
30
30
  schedule_delete = "openservice-schedule:can-delete-schedule",
31
31
  execution_perform = "openservice-schedule:can-perform-execution",
32
32
  template_manage = "openservice-schedule:can-manage-template",
33
- masterdata_manage = "service:can-manage-masterdata",
34
- formconfig_manage = "service:can-manage-formconfig",
35
- tag_create = "service:can-create-tag",
36
- analytics_view = "service:can-view-analytics"
33
+ analytics_view = "openservice-schedule:can-view-analytics"
37
34
  }
38
35
  enum CORE {
39
36
  adminoverview = "opendash:can-access-admin-overview",
@@ -28,19 +28,32 @@ var Permissions;
28
28
  // Update
29
29
  MAINTENANCE["kanban_view"] = "maintenance:can-update-kanban-view";
30
30
  })(MAINTENANCE = Permissions.MAINTENANCE || (Permissions.MAINTENANCE = {}));
31
+ // The prefix names the plugin that owns a key, and it is the i18n namespace
32
+ // the role admin resolves the label (`<key>.label`) in — each plugin ships
33
+ // the texts for its own keys. Must stay in sync with `SERVICE_PERMISSIONS`
34
+ // in `@opendash/plugin-openservice-core`.
31
35
  let SERVICE;
32
36
  (function (SERVICE) {
37
+ // openservice-core — shared by the ticket and the schedule plugin.
38
+ //
33
39
  // Access to the shared service administration (`/admin/service/**`) —
34
40
  // master data, contacts, service providers. Deliberately not tied to the
35
41
  // schedule plugin: a tenant running only tickets administers the same
36
42
  // contacts and companies.
37
- SERVICE["admin_access"] = "service:can-access-admin";
38
- // Tickets
39
- SERVICE["ticket_read"] = "service:can-read-ticket";
40
- SERVICE["ticket_create"] = "service:can-create-ticket";
41
- SERVICE["ticket_edit"] = "service:can-edit-ticket";
42
- SERVICE["ticket_delete"] = "service:can-delete-ticket";
43
- SERVICE["ticket_assign"] = "service:can-assign-ticket";
43
+ SERVICE["admin_access"] = "openservice-core:can-access-admin";
44
+ SERVICE["masterdata_manage"] = "openservice-core:can-manage-masterdata";
45
+ // Narrow master-data capability: create a tag inline from a tag picker,
46
+ // without granting full master-data management.
47
+ SERVICE["tag_create"] = "openservice-core:can-create-tag";
48
+ // Ticket-Plugin
49
+ //
50
+ // No `read`, `edit` or `assign`: the ticket's ACL decides those per
51
+ // record. `create` has no record yet whose ACL could be asked. `delete`
52
+ // covers archiving, which is an update the ACL would grant to everybody
53
+ // assigned to the ticket.
54
+ SERVICE["ticket_access"] = "openservice-ticket:can-access-ticket-plugin";
55
+ SERVICE["ticket_create"] = "openservice-ticket:can-create-ticket";
56
+ SERVICE["ticket_delete"] = "openservice-ticket:can-delete-ticket";
44
57
  // Schedule-Plugin
45
58
  //
46
59
  // No `read` or `edit` here on purpose: both are decided per record by the
@@ -54,14 +67,7 @@ var Permissions;
54
67
  SERVICE["schedule_delete"] = "openservice-schedule:can-delete-schedule";
55
68
  SERVICE["execution_perform"] = "openservice-schedule:can-perform-execution";
56
69
  SERVICE["template_manage"] = "openservice-schedule:can-manage-template";
57
- // Catalog / master data / form config
58
- SERVICE["masterdata_manage"] = "service:can-manage-masterdata";
59
- SERVICE["formconfig_manage"] = "service:can-manage-formconfig";
60
- // Narrow master-data capability: create a tag inline from a tag picker,
61
- // without granting full master-data management.
62
- SERVICE["tag_create"] = "service:can-create-tag";
63
- // Analytics / monitoring
64
- SERVICE["analytics_view"] = "service:can-view-analytics";
70
+ SERVICE["analytics_view"] = "openservice-schedule:can-view-analytics";
65
71
  })(SERVICE = Permissions.SERVICE || (Permissions.SERVICE = {}));
66
72
  let CORE;
67
73
  (function (CORE) {
@@ -14,6 +14,28 @@ const index_js_4 = require("../types/index.js");
14
14
  async function init() {
15
15
  (0, index_js_1.beforeSaveHook)(index_js_4.Service_Schedule, async (request) => {
16
16
  const { object, original, user } = request;
17
+ // Creating a plan is a capability: there is no record yet whose ACL could
18
+ // be asked, and the class-level `create` is open to everybody. The
19
+ // frontend hides its create button without it; this makes it hold for
20
+ // every other write path. A migration replays history, and master-key
21
+ // writes (alarm plans, the calendar sync) are the server's own.
22
+ //
23
+ // Passes `request`, not `request.user`: `defaultHandler` below refetches
24
+ // the user in place, which drops its session token (see the execution
25
+ // hook for the details).
26
+ if (!original && !(0, index_js_1.isMigrationMode)()) {
27
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.schedule_create, "create a maintenance schedule");
28
+ }
29
+ // Archiving sets `deletedAt` — an update, which the plan's ACL grants to
30
+ // the creator and everybody assigned. The beforeDelete below only covers
31
+ // the hard delete, which no client uses; this is the path the frontend
32
+ // and the admin table take. Restoring is the same decision. Compared by
33
+ // presence, so a client resending the unchanged date is not refused.
34
+ if (original &&
35
+ !(0, index_js_1.isMigrationMode)() &&
36
+ !!object.get("deletedAt") !== !!original.get("deletedAt")) {
37
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.schedule_delete, "archive a maintenance schedule");
38
+ }
17
39
  await (0, index_js_1.defaultHandler)(request);
18
40
  // The creator, recorded once and never rewritten: it is who the plan
19
41
  // belongs to, and `defaultAclHandler` turns it into a read+write grant.
@@ -1,13 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.init = init;
4
- const index_js_1 = require("../features/schema/index.js");
4
+ const index_js_1 = require("../features/permissions/index.js");
5
+ const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
6
+ const index_js_2 = require("../features/schema/index.js");
5
7
  const assignmentAcl_js_1 = require("../features/openservice/serviceSchedules/assignmentAcl.js");
6
- const index_js_2 = require("../types/index.js");
8
+ const index_js_3 = require("../types/index.js");
7
9
  async function init() {
8
- (0, index_js_1.beforeSaveHook)(index_js_2.Service_Schedule_Template, async (request) => {
10
+ (0, index_js_2.beforeSaveHook)(index_js_3.Service_Schedule_Template, async (request) => {
9
11
  const { object, original, user } = request;
10
- await (0, index_js_1.defaultHandler)(request);
12
+ // The template catalog is one capability — creating, editing and
13
+ // archiving alike, which is how the frontend gates it. The class-level
14
+ // permissions are open to everybody and the template's ACL would let its
15
+ // assigned roles change it. A migration replays history; master-key writes
16
+ // (the ACL sync in afterSave) are the server's own.
17
+ //
18
+ // Passes `request`, not `request.user`: `defaultHandler` below refetches
19
+ // the user in place, which drops its session token.
20
+ if (!(0, index_js_2.isMigrationMode)()) {
21
+ await (0, index_js_1.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.template_manage, "change a maintenance template");
22
+ }
23
+ await (0, index_js_2.defaultHandler)(request);
11
24
  // The creator, recorded once and never rewritten — a template stays visible
12
25
  // to whoever built it, whatever happens to its assigned roles later.
13
26
  if (!original && user && !object.get("user")) {
@@ -16,17 +29,22 @@ async function init() {
16
29
  // A template is private like a plan: its creator, the roles it is assigned
17
30
  // to, and administrators. Without `denyTenantUserRead` the whole tenant
18
31
  // reads every template and assigning roles would mean nothing.
19
- await (0, index_js_1.defaultAclHandler)(request, {
32
+ await (0, index_js_2.defaultAclHandler)(request, {
20
33
  allowCustomACL: true,
21
34
  denyTenantUserRead: true,
22
35
  });
23
36
  });
24
- (0, index_js_1.afterSaveHook)(index_js_2.Service_Schedule_Template, async (request) => {
37
+ (0, index_js_2.beforeDeleteHook)(index_js_3.Service_Schedule_Template, async (request) => {
38
+ if ((0, index_js_2.isMigrationMode)())
39
+ return;
40
+ await (0, index_js_1.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.template_manage, "delete a maintenance template");
41
+ });
42
+ (0, index_js_2.afterSaveHook)(index_js_3.Service_Schedule_Template, async (request) => {
25
43
  const { object, context } = request;
26
44
  // The v1 → v2 migration writes the ACL this hook would derive itself; the
27
45
  // sync would re-save the template under the master key without
28
46
  // `skipChangelog`. See helper/migrationMode.ts.
29
- if ((0, index_js_1.isMigrationMode)())
47
+ if ((0, index_js_2.isMigrationMode)())
30
48
  return;
31
49
  // Our own ACL write — the assignments already match.
32
50
  if (context?.[assignmentAcl_js_1.ASSIGNMENT_ACL_CONTEXT_FLAG])
@@ -40,10 +40,12 @@ exports.init = init;
40
40
  const node_1 = __importStar(require("parse/node"));
41
41
  const i18next_1 = __importDefault(require("i18next"));
42
42
  const index_js_1 = require("../features/schema/index.js");
43
+ const index_js_2 = require("../features/permissions/index.js");
44
+ const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
43
45
  const appLinks_js_1 = require("../helper/appLinks.js");
44
46
  const pointerIds_js_1 = require("../helper/pointerIds.js");
45
47
  const getUserLanguage_js_1 = require("../helper/getUserLanguage.js");
46
- const index_js_2 = require("../types/index.js");
48
+ const index_js_3 = require("../types/index.js");
47
49
  const ruleset_core_1 = require("@opendash/ruleset-core");
48
50
  async function init() {
49
51
  // Soft delete: a ticket is referenced by chat messages, meta entries,
@@ -51,10 +53,31 @@ async function init() {
51
53
  // destroying. Archived rows are hidden from every client query here — see
52
54
  // hideSoftDeleted() for the escape hatches (master key, an explicit
53
55
  // constraint on `deleted`, and queries naming object ids).
54
- (0, index_js_1.hideSoftDeleted)(index_js_2.Service_Ticket, { field: "deleted" });
56
+ (0, index_js_1.hideSoftDeleted)(index_js_3.Service_Ticket, { field: "deleted" });
55
57
  (0, index_js_1.beforeSaveHook)("OD3_Service_Ticket", async (request) => {
56
58
  const { object, original, user } = request;
57
59
  const isNew = object.isNew();
60
+ // Creating a ticket is a capability: there is no record yet whose ACL
61
+ // could be asked, and the class-level `create` is open to everybody. The
62
+ // frontend hides its create buttons without it; this is what makes it
63
+ // hold for every other write path. A migration replays history, and
64
+ // master-key writes (alarm tickets) are the server's own.
65
+ //
66
+ // Passes `request`, not `request.user`: `defaultHandler` below refetches
67
+ // the user in place, which drops its session token (see the execution
68
+ // hook for the details).
69
+ if (isNew && !(0, index_js_1.isMigrationMode)()) {
70
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.ticket_create, "create a ticket");
71
+ }
72
+ // Archiving sets `deleted` — an update, which `setTicketACL` grants to the
73
+ // creator and everybody assigned. Retiring a ticket is a decision of its
74
+ // own, and restoring one is the same decision. Compared against
75
+ // `original`, so a client that resends the unchanged flag is not refused.
76
+ if (original &&
77
+ !(0, index_js_1.isMigrationMode)() &&
78
+ Boolean(object.get("deleted")) !== Boolean(original.get("deleted"))) {
79
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.ticket_delete, "archive a ticket");
80
+ }
58
81
  if (isNew && !object.get("createdBy") && user)
59
82
  object.set("createdBy", user);
60
83
  await (0, index_js_1.defaultHandler)(request);
@@ -84,11 +107,19 @@ async function init() {
84
107
  await assignTicketNumber(object);
85
108
  }
86
109
  });
87
- (0, index_js_1.afterDeleteHook)(index_js_2.Service_Ticket, async ({ object }) => {
110
+ // A hard delete takes the ticket's chat, meta entries and notifications with
111
+ // it (see the cascade below) — at least the decision archiving is. Parse has
112
+ // no delete right of its own: the ACL's write grant covers delete as well.
113
+ (0, index_js_1.beforeDeleteHook)(index_js_3.Service_Ticket, async (request) => {
114
+ if ((0, index_js_1.isMigrationMode)())
115
+ return;
116
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.ticket_delete, "delete a ticket");
117
+ });
118
+ (0, index_js_1.afterDeleteHook)(index_js_3.Service_Ticket, async ({ object }) => {
88
119
  if (object.id)
89
120
  await cleanupTicketRelations(object.id);
90
121
  });
91
- (0, index_js_1.afterSaveHook)(index_js_2.Service_Ticket, async ({ object, original, user }) => {
122
+ (0, index_js_1.afterSaveHook)(index_js_3.Service_Ticket, async ({ object, original, user }) => {
92
123
  // A bulk import would otherwise notify every assignee once per migrated
93
124
  // ticket (~10k per tenant). See helper/migrationMode.ts.
94
125
  if ((0, index_js_1.isMigrationMode)())
@@ -131,20 +162,20 @@ const RELATED_DELETE_LIMIT = 10000;
131
162
  */
132
163
  async function cleanupTicketRelations(ticketId) {
133
164
  const [metaEntries, chatMessages, notifications] = await Promise.all([
134
- new node_1.default.Query(index_js_2.Meta_Entry)
135
- .equalTo("entryClassName", index_js_2.Service_Ticket.className)
165
+ new node_1.default.Query(index_js_3.Meta_Entry)
166
+ .equalTo("entryClassName", index_js_3.Service_Ticket.className)
136
167
  .equalTo("entryObjectId", ticketId)
137
168
  .limit(RELATED_DELETE_LIMIT)
138
169
  .find({ useMasterKey: true }),
139
170
  // Chat context is stored as `contextToString(["service","ticket",id])`,
140
171
  // i.e. a JSON.stringify of the tuple — match it exactly.
141
- new node_1.default.Query(index_js_2.Chat_Message)
172
+ new node_1.default.Query(index_js_3.Chat_Message)
142
173
  .equalTo("context", JSON.stringify(["service", "ticket", ticketId]))
143
174
  .limit(RELATED_DELETE_LIMIT)
144
175
  .find({ useMasterKey: true }),
145
176
  // `data` is a JSON Object column; Parse supports dot-notation into it. Query
146
177
  // by class name (untyped) so the `data.ticketId` path key is accepted.
147
- new node_1.default.Query(index_js_2.Notification.className)
178
+ new node_1.default.Query(index_js_3.Notification.className)
148
179
  .equalTo("data.ticketId", ticketId)
149
180
  .limit(RELATED_DELETE_LIMIT)
150
181
  .find({ useMasterKey: true }),
@@ -482,7 +513,7 @@ async function notifyWatchers(ticket, notified, assignerName) {
482
513
  async function loadWatcherRules(tenant) {
483
514
  if (!tenant)
484
515
  return [];
485
- const config = await new node_1.default.Query(index_js_2.Config)
516
+ const config = await new node_1.default.Query(index_js_3.Config)
486
517
  .equalTo("key", ASSIGNMENT_NOTIFICATION_CONFIG_KEY)
487
518
  .equalTo("tenant", tenant)
488
519
  .first({ useMasterKey: true });
@@ -549,7 +580,7 @@ async function sendAssignmentNotification(user, ticket, options) {
549
580
  await i18next_1.default.changeLanguage(await (0, getUserLanguage_js_1.getUserLanguage)(user));
550
581
  const base = `openservice:ticket.assignment.${options.variant}`;
551
582
  const ticketName = ticket.get("title");
552
- await new index_js_2.Notification({
583
+ await new index_js_3.Notification({
553
584
  title: i18next_1.default.t(`${base}.title`),
554
585
  description: i18next_1.default.t(`${base}.description`, {
555
586
  username: options.assignerName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "4.13.0",
3
+ "version": "4.14.0",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@12.8.1",
6
6
  "keywords": [