@openinc/parse-server-opendash 4.38.0 → 4.38.2

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.
@@ -3,5 +3,6 @@ export { Notifications } from "./types/Notifications.js";
3
3
  export { getAllNotifications, default as initNotifications, } from "./services/registerNotification.js";
4
4
  export { RegisteredNotification } from "./states/NotificationClass.js";
5
5
  export { EmailState } from "./states/EmailState.js";
6
+ export { MAIL_ADMIN_PERMISSION } from "./permissions.js";
6
7
  export { initEmailTransport } from "./services/initEmailTransport.js";
7
8
  export { sendSimpleEmail, sendTemplateEmail } from "./services/sendMails.js";
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sendTemplateEmail = exports.sendSimpleEmail = exports.initEmailTransport = exports.EmailState = exports.RegisteredNotification = exports.initNotifications = exports.getAllNotifications = exports.Notifications = void 0;
6
+ exports.sendTemplateEmail = exports.sendSimpleEmail = exports.initEmailTransport = exports.MAIL_ADMIN_PERMISSION = exports.EmailState = exports.RegisteredNotification = exports.initNotifications = exports.getAllNotifications = exports.Notifications = void 0;
7
7
  var Notifications_js_1 = require("./types/Notifications.js");
8
8
  Object.defineProperty(exports, "Notifications", { enumerable: true, get: function () { return Notifications_js_1.Notifications; } });
9
9
  var registerNotification_js_1 = require("./services/registerNotification.js");
@@ -13,6 +13,8 @@ var NotificationClass_js_1 = require("./states/NotificationClass.js");
13
13
  Object.defineProperty(exports, "RegisteredNotification", { enumerable: true, get: function () { return NotificationClass_js_1.RegisteredNotification; } });
14
14
  var EmailState_js_1 = require("./states/EmailState.js");
15
15
  Object.defineProperty(exports, "EmailState", { enumerable: true, get: function () { return EmailState_js_1.EmailState; } });
16
+ var permissions_js_1 = require("./permissions.js");
17
+ Object.defineProperty(exports, "MAIL_ADMIN_PERMISSION", { enumerable: true, get: function () { return permissions_js_1.MAIL_ADMIN_PERMISSION; } });
16
18
  var initEmailTransport_js_1 = require("./services/initEmailTransport.js");
17
19
  Object.defineProperty(exports, "initEmailTransport", { enumerable: true, get: function () { return initEmailTransport_js_1.initEmailTransport; } });
18
20
  var sendMails_js_1 = require("./services/sendMails.js");
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Access to the mail administration: reading the SMTP config and sending a
3
+ * test mail through the server's transport.
4
+ *
5
+ * Deliberately not part of the `Permissions` namespace: everything listed
6
+ * there is registered for every tenant on start and handed to its roles. This
7
+ * key is registered by the frontend's setup dialog instead, so only whoever is
8
+ * granted it there holds it (see 46d064a4).
9
+ */
10
+ export declare const MAIL_ADMIN_PERMISSION = "parse-admin:can-access-mail-admin";
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAIL_ADMIN_PERMISSION = void 0;
4
+ /**
5
+ * Access to the mail administration: reading the SMTP config and sending a
6
+ * test mail through the server's transport.
7
+ *
8
+ * Deliberately not part of the `Permissions` namespace: everything listed
9
+ * there is registered for every tenant on start and handed to its roles. This
10
+ * key is registered by the frontend's setup dialog instead, so only whoever is
11
+ * granted it there holds it (see 46d064a4).
12
+ */
13
+ exports.MAIL_ADMIN_PERMISSION = "parse-admin:can-access-mail-admin";
@@ -5,12 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.init = init;
7
7
  const node_1 = __importDefault(require("parse/node"));
8
+ const index_js_1 = require("../features/notifications/index.js");
9
+ const index_js_2 = require("../features/permissions/index.js");
8
10
  async function init(name) {
9
11
  node_1.default.Cloud.define(name, async (request) => {
10
- console.log(request);
11
- if (!request.user) {
12
- return { message: "Unauthorized" };
13
- }
12
+ await (0, index_js_2.requirePermission)({
13
+ sessionToken: request.user?.getSessionToken(),
14
+ master: request.master,
15
+ }, index_js_1.MAIL_ADMIN_PERMISSION, "read the mail server config");
14
16
  if (process.env.OPENINC_PARSE_SMTP_ENABLED !== undefined &&
15
17
  /true/.test(process.env.OPENINC_PARSE_SMTP_ENABLED)) {
16
18
  // Return your mail server config
@@ -1 +1,6 @@
1
+ /**
2
+ * Sends a fixed test mail through the server's SMTP transport, so an admin can
3
+ * check the mail setup. Returns the saved `Core_Email` including the SMTP
4
+ * response — that is the diagnostic the caller is after.
5
+ */
1
6
  export declare function init(name: string): Promise<void>;
@@ -6,16 +6,36 @@ 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/notifications/index.js");
9
+ const index_js_2 = require("../features/permissions/index.js");
10
+ // One plain address. nodemailer would also take a comma-separated list, an
11
+ // array or an address object with a free-text name — any of which turns a
12
+ // test mail into a relay to as many recipients as fit in the request.
13
+ const SINGLE_ADDRESS = /^[^\s@,;<>"()[\]\\]+@[^\s@,;<>"()[\]\\]+\.[^\s@,;<>"()[\]\\]+$/;
14
+ /**
15
+ * Sends a fixed test mail through the server's SMTP transport, so an admin can
16
+ * check the mail setup. Returns the saved `Core_Email` including the SMTP
17
+ * response — that is the diagnostic the caller is after.
18
+ */
9
19
  async function init(name) {
10
- // sendTestEmail - Sends a test email
11
20
  node_1.default.Cloud.define(name, async (request) => {
12
- if (!request.user) {
13
- return { message: "Unauthorized" };
21
+ await (0, index_js_2.requirePermission)({
22
+ sessionToken: request.user?.getSessionToken(),
23
+ master: request.master,
24
+ }, index_js_1.MAIL_ADMIN_PERMISSION, "send a test mail");
25
+ const to = request.params.to;
26
+ if (typeof to !== "string" ||
27
+ to.length > 254 ||
28
+ !SINGLE_ADDRESS.test(to.trim())) {
29
+ throw new node_1.default.Error(node_1.default.Error.INVALID_EMAIL_ADDRESS, "Expected a single email address in `to`");
14
30
  }
15
- const { to } = request.params;
16
- const mail = await (0, index_js_1.sendSimpleEmail)(to, "open.INC Test Mail", "This is a test email from open.INC Stack.");
17
- return mail;
31
+ return await (0, index_js_1.sendSimpleEmail)(to.trim(), "open.INC Test Mail", "This is a test email from open.INC Stack.");
18
32
  }, {
19
33
  requireUser: true,
34
+ // Per client IP; the master key is exempt.
35
+ rateLimit: {
36
+ requestTimeWindow: 60 * 1000,
37
+ requestCount: 5,
38
+ errorResponseMessage: "Too many test mails, try again in a minute.",
39
+ },
20
40
  });
21
41
  }
@@ -74,6 +74,22 @@ async function init() {
74
74
  if (object.isNew()) {
75
75
  await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.execution_perform, "perform a maintenance execution");
76
76
  }
77
+ // The capability says *that* somebody may perform maintenance, not *which*
78
+ // plans. That is decided by the plan's ACL — creator and assignments — so
79
+ // the plan an execution points at has to be one the acting user can read.
80
+ //
81
+ // Without this, anyone holding `can-perform-execution` could record a run
82
+ // of a plan they were never assigned to, given its objectId (which every
83
+ // tenant-readable execution of that plan carries). It would count towards
84
+ // the plan's due dates, and `freezeSteps` above — which reads with the
85
+ // master key — would copy the private plan's steps into a record the whole
86
+ // tenant can read.
87
+ //
88
+ // Checked whenever `schedule` changes, not only on create: re-pointing an
89
+ // open execution at another plan is the same question.
90
+ if (object.dirty("schedule")) {
91
+ await requireReadableSchedule(object, request.sessionToken);
92
+ }
77
93
  // Who performed it is established by the server from the session, not
78
94
  // accepted from the client. A protocol that names somebody else is worth
79
95
  // less than no protocol at all.
@@ -126,6 +142,25 @@ async function init() {
126
142
  // already owns notification timing and recipients.
127
143
  });
128
144
  }
145
+ /**
146
+ * Refuse an execution whose plan the acting user cannot read.
147
+ *
148
+ * Queried with the user's session token, so Parse applies the plan's ACL. A
149
+ * plan the user may not read and one that does not exist look the same here,
150
+ * and both are refused the same way — telling them apart would confirm that a
151
+ * guessed id belongs to somebody else's plan.
152
+ */
153
+ async function requireReadableSchedule(execution, sessionToken) {
154
+ const schedule = execution.get("schedule");
155
+ if (!schedule?.id)
156
+ return;
157
+ const readable = await new node_1.default.Query(index_js_3.Service_Schedule)
158
+ .equalTo("objectId", schedule.id)
159
+ .first({ sessionToken: sessionToken ?? undefined });
160
+ if (!readable) {
161
+ throw new node_1.default.Error(node_1.default.Error.OPERATION_FORBIDDEN, "Maintenance plan not found, or not assigned to you.");
162
+ }
163
+ }
129
164
  /**
130
165
  * Copy the plan's steps onto the execution.
131
166
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "4.38.0",
3
+ "version": "4.38.2",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@12.16.1",
6
6
  "keywords": [