@terreno/admin-backend 57.1.0 → 57.3.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/.ai/guidelines/core.md +12 -4
- package/.claude/CLAUDE.local.md +17 -2
- package/.cursor/rules/00-root.mdc +17 -2
- package/.github/copilot-instructions.md +17 -2
- package/AGENTS.md +17 -2
- package/README.md +3 -1
- package/dist/adminApp.d.ts +15 -1
- package/dist/adminApp.js +406 -175
- package/dist/aggregateAdmin.js +5 -1
- package/dist/documentStorageApp.js +1 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/resolvedAdminModel.js +1 -0
- package/package.json +5 -5
- package/src/adminApp.models.test.ts +429 -4
- package/src/adminApp.ts +285 -121
- package/src/adminUiV2.test.ts +71 -1
- package/src/aggregateAdmin.ts +6 -4
- package/src/documentStorageApp.ts +1 -3
- package/src/index.ts +1 -1
- package/src/resolvedAdminModel.ts +1 -0
package/dist/adminApp.js
CHANGED
|
@@ -46,6 +46,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
50
|
+
var t = {};
|
|
51
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
52
|
+
t[p] = s[p];
|
|
53
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
54
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
55
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
56
|
+
t[p[i]] = s[p[i]];
|
|
57
|
+
}
|
|
58
|
+
return t;
|
|
59
|
+
};
|
|
49
60
|
var __values = (this && this.__values) || function(o) {
|
|
50
61
|
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
51
62
|
if (m) return m.call(o);
|
|
@@ -86,7 +97,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
86
97
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
87
98
|
};
|
|
88
99
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
89
|
-
exports.AdminApp = exports.getArrayEmbeddedSchemaType = void 0;
|
|
100
|
+
exports.AdminApp = exports.getArrayEmbeddedSchemaType = exports.adminOwnedBy = void 0;
|
|
90
101
|
var api_1 = require("@terreno/api");
|
|
91
102
|
var express_1 = __importDefault(require("express"));
|
|
92
103
|
var luxon_1 = require("luxon");
|
|
@@ -97,6 +108,20 @@ var adminUiV2_1 = require("./adminUiV2");
|
|
|
97
108
|
var aggregateAdmin_1 = require("./aggregateAdmin");
|
|
98
109
|
var filterParser_1 = require("./filterParser");
|
|
99
110
|
var scriptCli_1 = require("./scriptCli");
|
|
111
|
+
/**
|
|
112
|
+
* Builds an ownership check for writeOwned admin access. The field may contain an id
|
|
113
|
+
* directly or a populated document with `_id`.
|
|
114
|
+
*/
|
|
115
|
+
var adminOwnedBy = function (field) {
|
|
116
|
+
return function (_a) {
|
|
117
|
+
var _b;
|
|
118
|
+
var instance = _a.instance, user = _a.user;
|
|
119
|
+
var value = instance === null || instance === void 0 ? void 0 : instance[field];
|
|
120
|
+
var ownerId = (_b = value === null || value === void 0 ? void 0 : value._id) !== null && _b !== void 0 ? _b : value;
|
|
121
|
+
return ownerId != null && String(ownerId) === String(user.id);
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
exports.adminOwnedBy = adminOwnedBy;
|
|
100
125
|
var buildAllModelAdminsMap = function (models) {
|
|
101
126
|
var e_1, _a;
|
|
102
127
|
var map = {};
|
|
@@ -294,52 +319,14 @@ var getArrayEmbeddedSchemaType = function (schemaPath) {
|
|
|
294
319
|
return compatiblePath.caster;
|
|
295
320
|
};
|
|
296
321
|
exports.getArrayEmbeddedSchemaType = getArrayEmbeddedSchemaType;
|
|
297
|
-
var
|
|
298
|
-
var
|
|
299
|
-
var
|
|
300
|
-
var fields =
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
fields[key] = {
|
|
306
|
-
default: prop.default,
|
|
307
|
-
description: prop.description,
|
|
308
|
-
enum: prop.enum,
|
|
309
|
-
ref: prop.$ref ? prop.$ref.replace("#/components/schemas/", "") : undefined,
|
|
310
|
-
required: required.includes(key),
|
|
311
|
-
searchable: fieldType === "string" && !prop.enum,
|
|
312
|
-
type: fieldType,
|
|
313
|
-
};
|
|
314
|
-
// For array fields, extract item sub-field metadata
|
|
315
|
-
if (prop.type === "array" && ((_c = prop.items) === null || _c === void 0 ? void 0 : _c.properties)) {
|
|
316
|
-
var itemRequired = (_d = prop.items.required) !== null && _d !== void 0 ? _d : [];
|
|
317
|
-
fields[key].items = extractFieldMeta(prop.items.properties, itemRequired);
|
|
318
|
-
}
|
|
319
|
-
// For array fields of primitives, capture the item type and enum
|
|
320
|
-
if (prop.type === "array" && prop.items && !prop.items.properties) {
|
|
321
|
-
var itemProp = prop.items;
|
|
322
|
-
if (itemProp.type) {
|
|
323
|
-
fields[key].itemType = itemProp.type;
|
|
324
|
-
}
|
|
325
|
-
if (itemProp.enum) {
|
|
326
|
-
fields[key].itemEnum = itemProp.enum;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
// Check for ObjectId references in the raw property
|
|
330
|
-
if (!fields[key].ref && prop.type === "string" && prop.format === "objectid") {
|
|
331
|
-
// mongoose-to-swagger may not preserve ref directly; we'll handle this in register()
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
336
|
-
finally {
|
|
337
|
-
try {
|
|
338
|
-
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
339
|
-
}
|
|
340
|
-
finally { if (e_5) throw e_5.error; }
|
|
341
|
-
}
|
|
342
|
-
return fields;
|
|
322
|
+
var extractFieldMetaFromDescription = function (model, hiddenFields) {
|
|
323
|
+
var hiddenFieldSet = new Set(hiddenFields);
|
|
324
|
+
var description = (0, api_1.describeModel)(model);
|
|
325
|
+
var fields = (0, api_1.modelDescriptionToAdminFields)(description);
|
|
326
|
+
return Object.fromEntries(Object.entries(fields).filter(function (_a) {
|
|
327
|
+
var _b = __read(_a, 1), key = _b[0];
|
|
328
|
+
return !hiddenFieldSet.has(key);
|
|
329
|
+
}));
|
|
343
330
|
};
|
|
344
331
|
var asMiddlewareList = function (middleware) {
|
|
345
332
|
if (middleware === undefined) {
|
|
@@ -403,7 +390,7 @@ var AdminApp = /** @class */ (function () {
|
|
|
403
390
|
}
|
|
404
391
|
AdminApp.prototype.adminAccessPermissions = function () {
|
|
405
392
|
if (this.options.accessControl) {
|
|
406
|
-
return [this.options.accessControl.permission({ admin: [
|
|
393
|
+
return [this.options.accessControl.permission({ admin: [api_1.ADMIN_PAGE_ACTION] })];
|
|
407
394
|
}
|
|
408
395
|
return [api_1.Permissions.IsAdmin];
|
|
409
396
|
};
|
|
@@ -447,18 +434,136 @@ var AdminApp = /** @class */ (function () {
|
|
|
447
434
|
});
|
|
448
435
|
});
|
|
449
436
|
};
|
|
450
|
-
AdminApp.prototype.
|
|
437
|
+
AdminApp.prototype.canAnyResourceAction = function (user, resource, actions, instance) {
|
|
438
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
439
|
+
var accessControl, actions_1, actions_1_1, action, result, e_5_1;
|
|
440
|
+
var e_5, _a, _b;
|
|
441
|
+
return __generator(this, function (_c) {
|
|
442
|
+
switch (_c.label) {
|
|
443
|
+
case 0:
|
|
444
|
+
accessControl = this.options.accessControl;
|
|
445
|
+
if (!accessControl || !user) {
|
|
446
|
+
return [2 /*return*/, Boolean(user === null || user === void 0 ? void 0 : user.admin)];
|
|
447
|
+
}
|
|
448
|
+
_c.label = 1;
|
|
449
|
+
case 1:
|
|
450
|
+
_c.trys.push([1, 6, 7, 8]);
|
|
451
|
+
actions_1 = __values(actions), actions_1_1 = actions_1.next();
|
|
452
|
+
_c.label = 2;
|
|
453
|
+
case 2:
|
|
454
|
+
if (!!actions_1_1.done) return [3 /*break*/, 5];
|
|
455
|
+
action = actions_1_1.value;
|
|
456
|
+
return [4 /*yield*/, accessControl.can({
|
|
457
|
+
doc: instance,
|
|
458
|
+
permissions: (_b = {}, _b[resource] = [action], _b),
|
|
459
|
+
user: user,
|
|
460
|
+
})];
|
|
461
|
+
case 3:
|
|
462
|
+
result = _c.sent();
|
|
463
|
+
if (result.allowed) {
|
|
464
|
+
return [2 /*return*/, true];
|
|
465
|
+
}
|
|
466
|
+
_c.label = 4;
|
|
467
|
+
case 4:
|
|
468
|
+
actions_1_1 = actions_1.next();
|
|
469
|
+
return [3 /*break*/, 2];
|
|
470
|
+
case 5: return [3 /*break*/, 8];
|
|
471
|
+
case 6:
|
|
472
|
+
e_5_1 = _c.sent();
|
|
473
|
+
e_5 = { error: e_5_1 };
|
|
474
|
+
return [3 /*break*/, 8];
|
|
475
|
+
case 7:
|
|
476
|
+
try {
|
|
477
|
+
if (actions_1_1 && !actions_1_1.done && (_a = actions_1.return)) _a.call(actions_1);
|
|
478
|
+
}
|
|
479
|
+
finally { if (e_5) throw e_5.error; }
|
|
480
|
+
return [7 /*endfinally*/];
|
|
481
|
+
case 8: return [2 /*return*/, false];
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
};
|
|
486
|
+
AdminApp.prototype.adminResource = function (config) {
|
|
451
487
|
var _a;
|
|
488
|
+
var accessControl = this.options.accessControl;
|
|
489
|
+
var explicit = (_a = config.adminAccess) === null || _a === void 0 ? void 0 : _a.resource;
|
|
490
|
+
if (explicit) {
|
|
491
|
+
return explicit;
|
|
492
|
+
}
|
|
493
|
+
var standard = "admin".concat(config.model.modelName);
|
|
494
|
+
if (accessControl === null || accessControl === void 0 ? void 0 : accessControl.statements[standard]) {
|
|
495
|
+
return standard;
|
|
496
|
+
}
|
|
497
|
+
return "".concat(config.model.modelName.charAt(0).toLowerCase()).concat(config.model.modelName.slice(1));
|
|
498
|
+
};
|
|
499
|
+
AdminApp.prototype.isAdminModelOwned = function (config, user, instance) {
|
|
500
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
501
|
+
var owner, ownerId;
|
|
502
|
+
var _a, _b;
|
|
503
|
+
return __generator(this, function (_c) {
|
|
504
|
+
if ((_a = config.adminAccess) === null || _a === void 0 ? void 0 : _a.isOwned) {
|
|
505
|
+
return [2 /*return*/, config.adminAccess.isOwned({ instance: instance, user: user })];
|
|
506
|
+
}
|
|
507
|
+
owner = instance === null || instance === void 0 ? void 0 : instance.ownerId;
|
|
508
|
+
ownerId = (_b = owner === null || owner === void 0 ? void 0 : owner._id) !== null && _b !== void 0 ? _b : owner;
|
|
509
|
+
return [2 /*return*/, ownerId != null && String(ownerId) === String(user.id)];
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
};
|
|
513
|
+
AdminApp.prototype.resourceActionPermissions = function (config, action) {
|
|
514
|
+
var _a;
|
|
515
|
+
var _this = this;
|
|
516
|
+
var _b;
|
|
452
517
|
var shell = this.adminAccessPermissions();
|
|
453
518
|
var accessControl = this.options.accessControl;
|
|
454
519
|
if (!accessControl) {
|
|
455
520
|
return shell;
|
|
456
521
|
}
|
|
457
|
-
|
|
522
|
+
if ((_b = config.adminAccess) === null || _b === void 0 ? void 0 : _b.authorize) {
|
|
523
|
+
return __spreadArray(__spreadArray([], __read(shell), false), [
|
|
524
|
+
function (_method, user, instance) { return __awaiter(_this, void 0, void 0, function () { var _a, _b, _c; return __generator(this, function (_d) {
|
|
525
|
+
return [2 /*return*/, (_c = (_b = (_a = config.adminAccess) === null || _a === void 0 ? void 0 : _a.authorize) === null || _b === void 0 ? void 0 : _b.call(_a, { action: action, instance: instance, user: user })) !== null && _c !== void 0 ? _c : false];
|
|
526
|
+
}); }); },
|
|
527
|
+
], false);
|
|
528
|
+
}
|
|
529
|
+
var resource = this.adminResource(config);
|
|
458
530
|
var knownActions = accessControl.statements[resource];
|
|
459
531
|
if (!knownActions) {
|
|
460
532
|
return [];
|
|
461
533
|
}
|
|
534
|
+
var hasStandardAccess = knownActions.includes("write") || knownActions.includes("writeOwned");
|
|
535
|
+
if (hasStandardAccess) {
|
|
536
|
+
return __spreadArray(__spreadArray([], __read(shell), false), [
|
|
537
|
+
function (_method, user, instance) { return __awaiter(_this, void 0, void 0, function () {
|
|
538
|
+
return __generator(this, function (_a) {
|
|
539
|
+
switch (_a.label) {
|
|
540
|
+
case 0:
|
|
541
|
+
if (!user) {
|
|
542
|
+
return [2 /*return*/, false];
|
|
543
|
+
}
|
|
544
|
+
if (action === "list" || action === "read") {
|
|
545
|
+
return [2 /*return*/, this.canAnyResourceAction(user, resource, ["read"], instance)];
|
|
546
|
+
}
|
|
547
|
+
return [4 /*yield*/, this.canAnyResourceAction(user, resource, ["write"], instance)];
|
|
548
|
+
case 1:
|
|
549
|
+
if (_a.sent()) {
|
|
550
|
+
return [2 /*return*/, true];
|
|
551
|
+
}
|
|
552
|
+
return [4 /*yield*/, this.canAnyResourceAction(user, resource, ["writeOwned"], instance)];
|
|
553
|
+
case 2:
|
|
554
|
+
if (!(_a.sent())) {
|
|
555
|
+
return [2 /*return*/, false];
|
|
556
|
+
}
|
|
557
|
+
// writeOwned always allows create. Ownership applies to update/delete.
|
|
558
|
+
if (action === "create" || instance === undefined) {
|
|
559
|
+
return [2 /*return*/, true];
|
|
560
|
+
}
|
|
561
|
+
return [2 /*return*/, this.isAdminModelOwned(config, user, instance)];
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
}); },
|
|
565
|
+
], false);
|
|
566
|
+
}
|
|
462
567
|
return __spreadArray(__spreadArray([], __read(shell), false), [accessControl.permission((_a = {}, _a[resource] = [action], _a))], false);
|
|
463
568
|
};
|
|
464
569
|
/**
|
|
@@ -522,122 +627,68 @@ var AdminApp = /** @class */ (function () {
|
|
|
522
627
|
source: config.source,
|
|
523
628
|
}); }));
|
|
524
629
|
var configModels = modelConfigs.map(function (config, configIndex) {
|
|
525
|
-
var e_8, _a
|
|
526
|
-
var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q
|
|
527
|
-
var
|
|
528
|
-
var
|
|
529
|
-
var filteredProperties = Object.fromEntries(Object.entries(properties).filter(function (_a) {
|
|
530
|
-
var _b = __read(_a, 1), key = _b[0];
|
|
531
|
-
return !hiddenFieldSet.has(key);
|
|
532
|
-
}));
|
|
533
|
-
var filteredRequired = required.filter(function (key) { return !hiddenFieldSet.has(key); });
|
|
534
|
-
// Extract ref information directly from the Mongoose schema
|
|
535
|
-
var fields = extractFieldMeta(filteredProperties, filteredRequired);
|
|
536
|
-
try {
|
|
537
|
-
for (var _w = __values(Object.entries(fields)), _x = _w.next(); !_x.done; _x = _w.next()) {
|
|
538
|
-
var _y = __read(_x.value, 2), key = _y[0], field = _y[1];
|
|
539
|
-
var schemaPath = config.model.schema.path(key);
|
|
540
|
-
if (schemaPath) {
|
|
541
|
-
var pathOptions = schemaPath.options;
|
|
542
|
-
if (pathOptions === null || pathOptions === void 0 ? void 0 : pathOptions.ref) {
|
|
543
|
-
field.ref = pathOptions.ref;
|
|
544
|
-
}
|
|
545
|
-
// Handle array of refs (legacy: also set ref for back-compat)
|
|
546
|
-
if (Array.isArray(pathOptions === null || pathOptions === void 0 ? void 0 : pathOptions.type) && ((_d = pathOptions.type[0]) === null || _d === void 0 ? void 0 : _d.ref)) {
|
|
547
|
-
field.ref = pathOptions.type[0].ref;
|
|
548
|
-
}
|
|
549
|
-
// For arrays, use the public embedded schema type to infer the primitive item type/ref.
|
|
550
|
-
if (schemaPath.instance === "Array") {
|
|
551
|
-
var embeddedSchemaType = (0, exports.getArrayEmbeddedSchemaType)(schemaPath);
|
|
552
|
-
if ((embeddedSchemaType === null || embeddedSchemaType === void 0 ? void 0 : embeddedSchemaType.instance) && !field.items) {
|
|
553
|
-
var instanceToType = {
|
|
554
|
-
Boolean: "boolean",
|
|
555
|
-
Number: "number",
|
|
556
|
-
ObjectID: "objectid",
|
|
557
|
-
ObjectId: "objectid",
|
|
558
|
-
SchemaObjectId: "objectid",
|
|
559
|
-
String: "string",
|
|
560
|
-
};
|
|
561
|
-
var mapped = instanceToType[embeddedSchemaType.instance];
|
|
562
|
-
if (mapped) {
|
|
563
|
-
field.itemType = mapped;
|
|
564
|
-
}
|
|
565
|
-
if ((_e = embeddedSchemaType.options) === null || _e === void 0 ? void 0 : _e.ref) {
|
|
566
|
-
field.itemRef = embeddedSchemaType.options.ref;
|
|
567
|
-
}
|
|
568
|
-
if (Array.isArray((_f = embeddedSchemaType.options) === null || _f === void 0 ? void 0 : _f.enum)) {
|
|
569
|
-
field.itemEnum = embeddedSchemaType.options.enum;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
577
|
-
finally {
|
|
578
|
-
try {
|
|
579
|
-
if (_x && !_x.done && (_a = _w.return)) _a.call(_w);
|
|
580
|
-
}
|
|
581
|
-
finally { if (e_8) throw e_8.error; }
|
|
582
|
-
}
|
|
630
|
+
var e_8, _a;
|
|
631
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
632
|
+
var hiddenFieldSet = new Set((_b = config.hiddenFields) !== null && _b !== void 0 ? _b : []);
|
|
633
|
+
var fields = extractFieldMetaFromDescription(config.model, __spreadArray([], __read(hiddenFieldSet), false));
|
|
583
634
|
// Apply field overrides (e.g., widget: "markdown")
|
|
584
635
|
if (config.fieldOverrides) {
|
|
585
636
|
try {
|
|
586
|
-
for (var
|
|
587
|
-
var
|
|
637
|
+
for (var _r = __values(Object.entries(config.fieldOverrides)), _s = _r.next(); !_s.done; _s = _r.next()) {
|
|
638
|
+
var _t = __read(_s.value, 2), key = _t[0], override = _t[1];
|
|
588
639
|
if (fields[key] && override.widget) {
|
|
589
640
|
fields[key].widget = override.widget;
|
|
590
641
|
}
|
|
591
642
|
}
|
|
592
643
|
}
|
|
593
|
-
catch (
|
|
644
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
594
645
|
finally {
|
|
595
646
|
try {
|
|
596
|
-
if (
|
|
647
|
+
if (_s && !_s.done && (_a = _r.return)) _a.call(_r);
|
|
597
648
|
}
|
|
598
|
-
finally { if (
|
|
649
|
+
finally { if (e_8) throw e_8.error; }
|
|
599
650
|
}
|
|
600
651
|
}
|
|
601
|
-
var readonlyFields = (
|
|
652
|
+
var readonlyFields = (_c = config.readonlyFields) !== null && _c !== void 0 ? _c : [];
|
|
602
653
|
var listFields = config.listFields.filter(function (field) { return !hiddenFieldSet.has(field); });
|
|
603
|
-
var listDisplay = (
|
|
654
|
+
var listDisplay = (_d = config.listDisplay) !== null && _d !== void 0 ? _d : listFields;
|
|
604
655
|
var derivedSearchFields = listFields.filter(function (field) { var _a; return (_a = fields[field]) === null || _a === void 0 ? void 0 : _a.searchable; });
|
|
605
|
-
var searchFields = (
|
|
656
|
+
var searchFields = (_e = config.searchFields) !== null && _e !== void 0 ? _e : derivedSearchFields;
|
|
606
657
|
var sortableFields = resolveAdminSortableFields({
|
|
607
658
|
defaultSort: config.defaultSort,
|
|
608
659
|
listDisplay: listDisplay,
|
|
609
660
|
sortableFields: config.sortableFields,
|
|
610
661
|
});
|
|
611
662
|
var schemaPathKeys = new Set(Object.keys(config.model.schema.paths));
|
|
612
|
-
var bulkPatchAllowlist = (
|
|
663
|
+
var bulkPatchAllowlist = (_f = config.bulkPatchAllowlist) !== null && _f !== void 0 ? _f : (0, adminUiV2_1.defaultBulkPatchAllowlistFrom)({
|
|
613
664
|
hiddenFieldSet: hiddenFieldSet,
|
|
614
665
|
listFields: listFields,
|
|
615
666
|
readonlyFields: readonlyFields,
|
|
616
667
|
schemaPaths: schemaPathKeys,
|
|
617
668
|
});
|
|
618
669
|
return {
|
|
619
|
-
actions: (
|
|
670
|
+
actions: (_g = config.actions) !== null && _g !== void 0 ? _g : [],
|
|
620
671
|
bulkPatchAllowlist: bulkPatchAllowlist,
|
|
621
|
-
defaultSort: (
|
|
672
|
+
defaultSort: (_h = config.defaultSort) !== null && _h !== void 0 ? _h : "-created",
|
|
622
673
|
displayName: config.displayName,
|
|
623
674
|
fieldOrder: config.fieldOrder,
|
|
624
675
|
fields: fields,
|
|
625
676
|
fieldsets: config.fieldsets,
|
|
626
|
-
filters: (
|
|
677
|
+
filters: (_j = config.filters) !== null && _j !== void 0 ? _j : [],
|
|
627
678
|
group: config.group,
|
|
628
679
|
hiddenFields: __spreadArray([], __read(hiddenFieldSet), false),
|
|
629
680
|
listDisplay: listDisplay,
|
|
630
|
-
listDisplayLinks: (
|
|
681
|
+
listDisplayLinks: (_k = config.listDisplayLinks) !== null && _k !== void 0 ? _k : [],
|
|
631
682
|
listFields: listFields,
|
|
632
|
-
name: (
|
|
683
|
+
name: (_l = configNames[configIndex]) !== null && _l !== void 0 ? _l : config.model.modelName,
|
|
633
684
|
pageSize: config.pageSize,
|
|
634
685
|
permissions: {
|
|
635
|
-
create: ((
|
|
636
|
-
delete: ((
|
|
637
|
-
update: ((
|
|
686
|
+
create: ((_m = config.permissions) === null || _m === void 0 ? void 0 : _m.create) !== false,
|
|
687
|
+
delete: ((_o = config.permissions) === null || _o === void 0 ? void 0 : _o.delete) !== false,
|
|
688
|
+
update: ((_p = config.permissions) === null || _p === void 0 ? void 0 : _p.update) !== false,
|
|
638
689
|
},
|
|
639
690
|
readonlyFields: readonlyFields,
|
|
640
|
-
realtime: (
|
|
691
|
+
realtime: (_q = config.realtime) !== null && _q !== void 0 ? _q : false,
|
|
641
692
|
recordTitleField: config.recordTitleField,
|
|
642
693
|
routePath: "".concat(basePath).concat(config.routePath),
|
|
643
694
|
searchFields: searchFields,
|
|
@@ -654,9 +705,8 @@ var AdminApp = /** @class */ (function () {
|
|
|
654
705
|
name: script.name,
|
|
655
706
|
});
|
|
656
707
|
});
|
|
657
|
-
var
|
|
658
|
-
var
|
|
659
|
-
var configResponse = {
|
|
708
|
+
var mergedScreens = __spreadArray(__spreadArray([], __read(aggregated.customScreens), false), __read(((_f = this.options.customScreens) !== null && _f !== void 0 ? _f : [])), false);
|
|
709
|
+
var baseConfigResponse = {
|
|
660
710
|
capabilities: {
|
|
661
711
|
actions: true,
|
|
662
712
|
fieldsets: true,
|
|
@@ -666,10 +716,127 @@ var AdminApp = /** @class */ (function () {
|
|
|
666
716
|
customScreens: mergedScreens,
|
|
667
717
|
home: (0, adminUiV2_1.normalizeAdminHome)(this.options.home),
|
|
668
718
|
models: configModels,
|
|
719
|
+
platformTools: {
|
|
720
|
+
configuration: true,
|
|
721
|
+
roles: true,
|
|
722
|
+
runScripts: true,
|
|
723
|
+
scripts: true,
|
|
724
|
+
version: true,
|
|
725
|
+
viewScripts: true,
|
|
726
|
+
},
|
|
669
727
|
schemaVersion: adminUiV2_1.ADMIN_SCHEMA_VERSION,
|
|
670
728
|
scripts: configScripts,
|
|
671
729
|
widgetIds: aggregated.widgetIds,
|
|
672
730
|
};
|
|
731
|
+
var buildAuthorizedConfig = function (user) { return __awaiter(_this, void 0, void 0, function () {
|
|
732
|
+
var authorizedModels, authorizedScreens, canReadConfiguration, canReadRoles, canRunScripts, canViewScripts, canUseScripts;
|
|
733
|
+
var _this = this;
|
|
734
|
+
return __generator(this, function (_a) {
|
|
735
|
+
switch (_a.label) {
|
|
736
|
+
case 0: return [4 /*yield*/, Promise.all(configModels.map(function (modelMeta, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
737
|
+
var config, canRead, canCreate, _a, canDelete, _b, canUpdate, _c;
|
|
738
|
+
return __generator(this, function (_d) {
|
|
739
|
+
switch (_d.label) {
|
|
740
|
+
case 0:
|
|
741
|
+
config = modelConfigs[index];
|
|
742
|
+
if (!config) {
|
|
743
|
+
return [2 /*return*/, null];
|
|
744
|
+
}
|
|
745
|
+
return [4 /*yield*/, (0, api_1.checkPermissions)("list", this.resourceActionPermissions(config, "list"), user)];
|
|
746
|
+
case 1:
|
|
747
|
+
canRead = _d.sent();
|
|
748
|
+
if (!canRead) {
|
|
749
|
+
return [2 /*return*/, null];
|
|
750
|
+
}
|
|
751
|
+
_a = modelMeta.permissions.create;
|
|
752
|
+
if (!_a) return [3 /*break*/, 3];
|
|
753
|
+
return [4 /*yield*/, (0, api_1.checkPermissions)("create", this.resourceActionPermissions(config, "create"), user)];
|
|
754
|
+
case 2:
|
|
755
|
+
_a = (_d.sent());
|
|
756
|
+
_d.label = 3;
|
|
757
|
+
case 3:
|
|
758
|
+
canCreate = _a;
|
|
759
|
+
_b = modelMeta.permissions.delete;
|
|
760
|
+
if (!_b) return [3 /*break*/, 5];
|
|
761
|
+
return [4 /*yield*/, (0, api_1.checkPermissions)("delete", this.resourceActionPermissions(config, "delete"), user)];
|
|
762
|
+
case 4:
|
|
763
|
+
_b = (_d.sent());
|
|
764
|
+
_d.label = 5;
|
|
765
|
+
case 5:
|
|
766
|
+
canDelete = _b;
|
|
767
|
+
_c = modelMeta.permissions.update;
|
|
768
|
+
if (!_c) return [3 /*break*/, 7];
|
|
769
|
+
return [4 /*yield*/, (0, api_1.checkPermissions)("update", this.resourceActionPermissions(config, "update"), user)];
|
|
770
|
+
case 6:
|
|
771
|
+
_c = (_d.sent());
|
|
772
|
+
_d.label = 7;
|
|
773
|
+
case 7:
|
|
774
|
+
canUpdate = _c;
|
|
775
|
+
return [2 /*return*/, __assign(__assign({}, modelMeta), { permissions: { create: canCreate, delete: canDelete, update: canUpdate } })];
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
}); }))];
|
|
779
|
+
case 1:
|
|
780
|
+
authorizedModels = (_a.sent()).filter(function (model) { return model !== null; });
|
|
781
|
+
return [4 /*yield*/, Promise.all(mergedScreens.map(function (screen) { return __awaiter(_this, void 0, void 0, function () {
|
|
782
|
+
var allowed_1, allowed;
|
|
783
|
+
var _a, _b;
|
|
784
|
+
return __generator(this, function (_c) {
|
|
785
|
+
switch (_c.label) {
|
|
786
|
+
case 0:
|
|
787
|
+
if (!screen.adminAccess) {
|
|
788
|
+
return [2 /*return*/, screen];
|
|
789
|
+
}
|
|
790
|
+
if (!screen.adminAccess.authorize) return [3 /*break*/, 2];
|
|
791
|
+
return [4 /*yield*/, screen.adminAccess.authorize({
|
|
792
|
+
action: (_a = screen.adminAccess.action) !== null && _a !== void 0 ? _a : "read",
|
|
793
|
+
user: user,
|
|
794
|
+
})];
|
|
795
|
+
case 1:
|
|
796
|
+
allowed_1 = _c.sent();
|
|
797
|
+
return [2 /*return*/, allowed_1 ? screen : null];
|
|
798
|
+
case 2:
|
|
799
|
+
if (!screen.adminAccess.resource) {
|
|
800
|
+
return [2 /*return*/, screen];
|
|
801
|
+
}
|
|
802
|
+
return [4 /*yield*/, this.canAnyResourceAction(user, screen.adminAccess.resource, [
|
|
803
|
+
(_b = screen.adminAccess.action) !== null && _b !== void 0 ? _b : "read",
|
|
804
|
+
])];
|
|
805
|
+
case 3:
|
|
806
|
+
allowed = _c.sent();
|
|
807
|
+
return [2 /*return*/, allowed ? screen : null];
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
}); }))];
|
|
811
|
+
case 2:
|
|
812
|
+
authorizedScreens = (_a.sent()).filter(function (screen) { return screen !== null; });
|
|
813
|
+
return [4 /*yield*/, this.hasConfigurationPermission(user, "read")];
|
|
814
|
+
case 3:
|
|
815
|
+
canReadConfiguration = _a.sent();
|
|
816
|
+
return [4 /*yield*/, this.canAnyResourceAction(user, "rbac", ["read"])];
|
|
817
|
+
case 4:
|
|
818
|
+
canReadRoles = _a.sent();
|
|
819
|
+
return [4 /*yield*/, this.hasScriptPermission(user, "runScripts")];
|
|
820
|
+
case 5:
|
|
821
|
+
canRunScripts = _a.sent();
|
|
822
|
+
return [4 /*yield*/, this.hasScriptPermission(user, "viewBackgroundTasks")];
|
|
823
|
+
case 6:
|
|
824
|
+
canViewScripts = _a.sent();
|
|
825
|
+
canUseScripts = canRunScripts || canViewScripts;
|
|
826
|
+
return [2 /*return*/, __assign(__assign({}, baseConfigResponse), { customScreens: authorizedScreens.map(function (_a) {
|
|
827
|
+
var _adminAccess = _a.adminAccess, screen = __rest(_a, ["adminAccess"]);
|
|
828
|
+
return screen;
|
|
829
|
+
}), models: authorizedModels, platformTools: {
|
|
830
|
+
configuration: canReadConfiguration,
|
|
831
|
+
roles: canReadRoles,
|
|
832
|
+
runScripts: canRunScripts,
|
|
833
|
+
scripts: canUseScripts,
|
|
834
|
+
version: canReadConfiguration,
|
|
835
|
+
viewScripts: canViewScripts,
|
|
836
|
+
}, scripts: canUseScripts ? configScripts : [] })];
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
}); };
|
|
673
840
|
var adminConfigOpenApi = openApiMw
|
|
674
841
|
? (0, api_1.createOpenApiBuilder)({ openApi: openApiMw })
|
|
675
842
|
.withTags(["admin"])
|
|
@@ -697,6 +864,17 @@ var AdminApp = /** @class */ (function () {
|
|
|
697
864
|
},
|
|
698
865
|
home: { type: "object" },
|
|
699
866
|
models: { type: "array" },
|
|
867
|
+
platformTools: {
|
|
868
|
+
properties: {
|
|
869
|
+
configuration: { type: "boolean" },
|
|
870
|
+
roles: { type: "boolean" },
|
|
871
|
+
runScripts: { type: "boolean" },
|
|
872
|
+
scripts: { type: "boolean" },
|
|
873
|
+
version: { type: "boolean" },
|
|
874
|
+
viewScripts: { type: "boolean" },
|
|
875
|
+
},
|
|
876
|
+
type: "object",
|
|
877
|
+
},
|
|
700
878
|
schemaVersion: { type: "number" },
|
|
701
879
|
scripts: {
|
|
702
880
|
items: {
|
|
@@ -715,14 +893,17 @@ var AdminApp = /** @class */ (function () {
|
|
|
715
893
|
: undefined;
|
|
716
894
|
// GET /admin/config
|
|
717
895
|
app.get.apply(app, __spreadArray(__spreadArray(["".concat(basePath, "/config"), (0, api_1.authenticateMiddleware)()], __read(asMiddlewareList(adminConfigOpenApi)), false), [(0, api_1.asyncHandler)(function (req, res) { return __awaiter(_this, void 0, void 0, function () {
|
|
718
|
-
|
|
719
|
-
|
|
896
|
+
var _a, _b;
|
|
897
|
+
return __generator(this, function (_c) {
|
|
898
|
+
switch (_c.label) {
|
|
720
899
|
case 0: return [4 /*yield*/, (0, api_1.checkPermissions)("read", this.adminAccessPermissions(), req.user)];
|
|
721
900
|
case 1:
|
|
722
|
-
if (!(
|
|
901
|
+
if (!(_c.sent())) {
|
|
723
902
|
throw new api_1.APIError({ status: 403, title: "Admin access required" });
|
|
724
903
|
}
|
|
725
|
-
|
|
904
|
+
_b = (_a = res).json;
|
|
905
|
+
return [4 /*yield*/, buildAuthorizedConfig(req.user)];
|
|
906
|
+
case 2: return [2 /*return*/, _b.apply(_a, [_c.sent()])];
|
|
726
907
|
}
|
|
727
908
|
});
|
|
728
909
|
}); })], false));
|
|
@@ -842,7 +1023,7 @@ var AdminApp = /** @class */ (function () {
|
|
|
842
1023
|
}); }));
|
|
843
1024
|
app.put(versionConfigPath, (0, api_1.authenticateMiddleware)(), (0, api_1.asyncHandler)(function (req, res) { return __awaiter(_this, void 0, void 0, function () {
|
|
844
1025
|
var raw, allowedFields, setFields, unsetFields, allowedFields_1, allowedFields_1_1, field, updateOp, doc;
|
|
845
|
-
var
|
|
1026
|
+
var e_9, _a;
|
|
846
1027
|
return __generator(this, function (_b) {
|
|
847
1028
|
switch (_b.label) {
|
|
848
1029
|
case 0: return [4 /*yield*/, this.hasConfigurationPermission(req.user, "update")];
|
|
@@ -873,12 +1054,12 @@ var AdminApp = /** @class */ (function () {
|
|
|
873
1054
|
}
|
|
874
1055
|
}
|
|
875
1056
|
}
|
|
876
|
-
catch (
|
|
1057
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
877
1058
|
finally {
|
|
878
1059
|
try {
|
|
879
1060
|
if (allowedFields_1_1 && !allowedFields_1_1.done && (_a = allowedFields_1.return)) _a.call(allowedFields_1);
|
|
880
1061
|
}
|
|
881
|
-
finally { if (
|
|
1062
|
+
finally { if (e_9) throw e_9.error; }
|
|
882
1063
|
}
|
|
883
1064
|
updateOp = {};
|
|
884
1065
|
if (Object.keys(setFields).length > 0) {
|
|
@@ -900,7 +1081,7 @@ var AdminApp = /** @class */ (function () {
|
|
|
900
1081
|
});
|
|
901
1082
|
}); }));
|
|
902
1083
|
var _loop_1 = function (config) {
|
|
903
|
-
var
|
|
1084
|
+
var e_10, _t;
|
|
904
1085
|
// Determine searchable fields from the actual Mongoose schema type,
|
|
905
1086
|
// not the OpenAPI type (which reports ObjectId as "string")
|
|
906
1087
|
var searchableFields = [];
|
|
@@ -908,7 +1089,7 @@ var AdminApp = /** @class */ (function () {
|
|
|
908
1089
|
var modelMeta = (0, adminConfigIdentity_1.findAdminModelMetaByRoutePath)(configModels, "".concat(basePath).concat(config.routePath));
|
|
909
1090
|
if (modelMeta) {
|
|
910
1091
|
try {
|
|
911
|
-
for (var _u = (
|
|
1092
|
+
for (var _u = (e_10 = void 0, __values(Object.keys(modelMeta.fields))), _v = _u.next(); !_v.done; _v = _u.next()) {
|
|
912
1093
|
var key = _v.value;
|
|
913
1094
|
var schemaPath = config.model.schema.path(key);
|
|
914
1095
|
if (schemaPath && schemaPath.instance === "String" && !modelMeta.fields[key].enum) {
|
|
@@ -919,12 +1100,12 @@ var AdminApp = /** @class */ (function () {
|
|
|
919
1100
|
}
|
|
920
1101
|
}
|
|
921
1102
|
}
|
|
922
|
-
catch (
|
|
1103
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
923
1104
|
finally {
|
|
924
1105
|
try {
|
|
925
1106
|
if (_v && !_v.done && (_t = _u.return)) _t.call(_u);
|
|
926
1107
|
}
|
|
927
|
-
finally { if (
|
|
1108
|
+
finally { if (e_10) throw e_10.error; }
|
|
928
1109
|
}
|
|
929
1110
|
}
|
|
930
1111
|
app.get("".concat(basePath).concat(config.routePath, "/search"), (0, api_1.authenticateMiddleware)(), (0, api_1.asyncHandler)(function (req, res) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -932,7 +1113,7 @@ var AdminApp = /** @class */ (function () {
|
|
|
932
1113
|
var _a;
|
|
933
1114
|
return __generator(this, function (_b) {
|
|
934
1115
|
switch (_b.label) {
|
|
935
|
-
case 0: return [4 /*yield*/, (0, api_1.checkPermissions)("list", this.resourceActionPermissions(config
|
|
1116
|
+
case 0: return [4 /*yield*/, (0, api_1.checkPermissions)("list", this.resourceActionPermissions(config, "list"), req.user)];
|
|
936
1117
|
case 1:
|
|
937
1118
|
if (!(_b.sent())) {
|
|
938
1119
|
throw new api_1.APIError({
|
|
@@ -1021,66 +1202,66 @@ var AdminApp = /** @class */ (function () {
|
|
|
1021
1202
|
if (allowed === false) {
|
|
1022
1203
|
return [];
|
|
1023
1204
|
}
|
|
1024
|
-
return _this.resourceActionPermissions(config
|
|
1205
|
+
return _this.resourceActionPermissions(config, action);
|
|
1025
1206
|
};
|
|
1026
|
-
var updatePermissions = this_1.resourceActionPermissions(config
|
|
1207
|
+
var updatePermissions = this_1.resourceActionPermissions(config, "update");
|
|
1027
1208
|
var stripProtectedFromBody = function (body) {
|
|
1028
|
-
var
|
|
1209
|
+
var e_11, _a, e_12, _b, e_13, _c, e_14, _d;
|
|
1029
1210
|
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
1030
1211
|
return {};
|
|
1031
1212
|
}
|
|
1032
1213
|
var next = __assign({}, body);
|
|
1033
1214
|
try {
|
|
1034
|
-
for (var readonlySet_1 = (
|
|
1215
|
+
for (var readonlySet_1 = (e_11 = void 0, __values(readonlySet)), readonlySet_1_1 = readonlySet_1.next(); !readonlySet_1_1.done; readonlySet_1_1 = readonlySet_1.next()) {
|
|
1035
1216
|
var key = readonlySet_1_1.value;
|
|
1036
1217
|
delete next[key];
|
|
1037
1218
|
}
|
|
1038
1219
|
}
|
|
1039
|
-
catch (
|
|
1220
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
1040
1221
|
finally {
|
|
1041
1222
|
try {
|
|
1042
1223
|
if (readonlySet_1_1 && !readonlySet_1_1.done && (_a = readonlySet_1.return)) _a.call(readonlySet_1);
|
|
1043
1224
|
}
|
|
1044
|
-
finally { if (
|
|
1225
|
+
finally { if (e_11) throw e_11.error; }
|
|
1045
1226
|
}
|
|
1046
1227
|
try {
|
|
1047
|
-
for (var hiddenFieldSet_1 = (
|
|
1228
|
+
for (var hiddenFieldSet_1 = (e_12 = void 0, __values(hiddenFieldSet)), hiddenFieldSet_1_1 = hiddenFieldSet_1.next(); !hiddenFieldSet_1_1.done; hiddenFieldSet_1_1 = hiddenFieldSet_1.next()) {
|
|
1048
1229
|
var key = hiddenFieldSet_1_1.value;
|
|
1049
1230
|
delete next[key];
|
|
1050
1231
|
}
|
|
1051
1232
|
}
|
|
1052
|
-
catch (
|
|
1233
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
1053
1234
|
finally {
|
|
1054
1235
|
try {
|
|
1055
1236
|
if (hiddenFieldSet_1_1 && !hiddenFieldSet_1_1.done && (_b = hiddenFieldSet_1.return)) _b.call(hiddenFieldSet_1);
|
|
1056
1237
|
}
|
|
1057
|
-
finally { if (
|
|
1238
|
+
finally { if (e_12) throw e_12.error; }
|
|
1058
1239
|
}
|
|
1059
1240
|
try {
|
|
1060
|
-
for (var excludeFieldSet_1 = (
|
|
1241
|
+
for (var excludeFieldSet_1 = (e_13 = void 0, __values(excludeFieldSet)), excludeFieldSet_1_1 = excludeFieldSet_1.next(); !excludeFieldSet_1_1.done; excludeFieldSet_1_1 = excludeFieldSet_1.next()) {
|
|
1061
1242
|
var key = excludeFieldSet_1_1.value;
|
|
1062
1243
|
delete next[key];
|
|
1063
1244
|
}
|
|
1064
1245
|
}
|
|
1065
|
-
catch (
|
|
1246
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
1066
1247
|
finally {
|
|
1067
1248
|
try {
|
|
1068
1249
|
if (excludeFieldSet_1_1 && !excludeFieldSet_1_1.done && (_c = excludeFieldSet_1.return)) _c.call(excludeFieldSet_1);
|
|
1069
1250
|
}
|
|
1070
|
-
finally { if (
|
|
1251
|
+
finally { if (e_13) throw e_13.error; }
|
|
1071
1252
|
}
|
|
1072
1253
|
try {
|
|
1073
|
-
for (var SYSTEM_ADMIN_FIELDS_1 = (
|
|
1254
|
+
for (var SYSTEM_ADMIN_FIELDS_1 = (e_14 = void 0, __values(adminUiV2_1.SYSTEM_ADMIN_FIELDS)), SYSTEM_ADMIN_FIELDS_1_1 = SYSTEM_ADMIN_FIELDS_1.next(); !SYSTEM_ADMIN_FIELDS_1_1.done; SYSTEM_ADMIN_FIELDS_1_1 = SYSTEM_ADMIN_FIELDS_1.next()) {
|
|
1074
1255
|
var key = SYSTEM_ADMIN_FIELDS_1_1.value;
|
|
1075
1256
|
delete next[key];
|
|
1076
1257
|
}
|
|
1077
1258
|
}
|
|
1078
|
-
catch (
|
|
1259
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
1079
1260
|
finally {
|
|
1080
1261
|
try {
|
|
1081
1262
|
if (SYSTEM_ADMIN_FIELDS_1_1 && !SYSTEM_ADMIN_FIELDS_1_1.done && (_d = SYSTEM_ADMIN_FIELDS_1.return)) _d.call(SYSTEM_ADMIN_FIELDS_1);
|
|
1082
1263
|
}
|
|
1083
|
-
finally { if (
|
|
1264
|
+
finally { if (e_14) throw e_14.error; }
|
|
1084
1265
|
}
|
|
1085
1266
|
// Self-service never writes these fields. Admin CRUD may set `admin`.
|
|
1086
1267
|
// When RBAC is enabled, `roles` must go through RoleManager.assign and
|
|
@@ -1171,7 +1352,7 @@ var AdminApp = /** @class */ (function () {
|
|
|
1171
1352
|
};
|
|
1172
1353
|
var restoreUserFieldsAfterFailedRoleAssign = function (value, prev, cleanedBody) { return __awaiter(_this, void 0, void 0, function () {
|
|
1173
1354
|
var record, prevRecord, body, restore, _a, _b, key;
|
|
1174
|
-
var
|
|
1355
|
+
var e_15, _c;
|
|
1175
1356
|
return __generator(this, function (_d) {
|
|
1176
1357
|
switch (_d.label) {
|
|
1177
1358
|
case 0:
|
|
@@ -1197,12 +1378,12 @@ var AdminApp = /** @class */ (function () {
|
|
|
1197
1378
|
}
|
|
1198
1379
|
}
|
|
1199
1380
|
}
|
|
1200
|
-
catch (
|
|
1381
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
1201
1382
|
finally {
|
|
1202
1383
|
try {
|
|
1203
1384
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1204
1385
|
}
|
|
1205
|
-
finally { if (
|
|
1386
|
+
finally { if (e_15) throw e_15.error; }
|
|
1206
1387
|
}
|
|
1207
1388
|
if (Object.keys(restore).length === 0) {
|
|
1208
1389
|
return [2 /*return*/];
|
|
@@ -1397,6 +1578,51 @@ var AdminApp = /** @class */ (function () {
|
|
|
1397
1578
|
}
|
|
1398
1579
|
request.terrenoAllowUserAdminWrite = true;
|
|
1399
1580
|
};
|
|
1581
|
+
var addRecordCapabilities = function (value, request) { return __awaiter(_this, void 0, void 0, function () {
|
|
1582
|
+
var scrubbed, sourceItems, scrubbedItems, withCapabilities;
|
|
1583
|
+
var _this = this;
|
|
1584
|
+
return __generator(this, function (_a) {
|
|
1585
|
+
switch (_a.label) {
|
|
1586
|
+
case 0:
|
|
1587
|
+
scrubbed = scrubAdminResponse(value, config, allModelAdmins);
|
|
1588
|
+
sourceItems = Array.isArray(value) ? value : [value];
|
|
1589
|
+
scrubbedItems = Array.isArray(scrubbed) ? scrubbed : [scrubbed];
|
|
1590
|
+
return [4 /*yield*/, Promise.all(scrubbedItems.map(function (item, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
1591
|
+
var instance, canUpdate, _a, canDelete, _b;
|
|
1592
|
+
var _c, _d;
|
|
1593
|
+
return __generator(this, function (_e) {
|
|
1594
|
+
switch (_e.label) {
|
|
1595
|
+
case 0:
|
|
1596
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
1597
|
+
return [2 /*return*/, item];
|
|
1598
|
+
}
|
|
1599
|
+
instance = sourceItems[index];
|
|
1600
|
+
_a = ((_c = config.permissions) === null || _c === void 0 ? void 0 : _c.update) !== false;
|
|
1601
|
+
if (!_a) return [3 /*break*/, 2];
|
|
1602
|
+
return [4 /*yield*/, (0, api_1.checkPermissions)("update", this.resourceActionPermissions(config, "update"), request.user, instance)];
|
|
1603
|
+
case 1:
|
|
1604
|
+
_a = (_e.sent());
|
|
1605
|
+
_e.label = 2;
|
|
1606
|
+
case 2:
|
|
1607
|
+
canUpdate = _a;
|
|
1608
|
+
_b = ((_d = config.permissions) === null || _d === void 0 ? void 0 : _d.delete) !== false;
|
|
1609
|
+
if (!_b) return [3 /*break*/, 4];
|
|
1610
|
+
return [4 /*yield*/, (0, api_1.checkPermissions)("delete", this.resourceActionPermissions(config, "delete"), request.user, instance)];
|
|
1611
|
+
case 3:
|
|
1612
|
+
_b = (_e.sent());
|
|
1613
|
+
_e.label = 4;
|
|
1614
|
+
case 4:
|
|
1615
|
+
canDelete = _b;
|
|
1616
|
+
return [2 /*return*/, __assign(__assign({}, item), { _adminCapabilities: { delete: canDelete, update: canUpdate } })];
|
|
1617
|
+
}
|
|
1618
|
+
});
|
|
1619
|
+
}); }))];
|
|
1620
|
+
case 1:
|
|
1621
|
+
withCapabilities = _a.sent();
|
|
1622
|
+
return [2 /*return*/, (Array.isArray(scrubbed) ? withCapabilities : withCapabilities[0])];
|
|
1623
|
+
}
|
|
1624
|
+
});
|
|
1625
|
+
}); };
|
|
1400
1626
|
// noExplicitAny: matches the Model<any> from AdminModelConfig above.
|
|
1401
1627
|
// biome-ignore lint/suspicious/noExplicitAny: matches the Model<any> from AdminModelConfig above.
|
|
1402
1628
|
var routerOptions = __assign(__assign(__assign(__assign(__assign({}, (openApiMw ? { openApi: openApiMw } : {})), (this_1.options.accessControl ? { accessControl: this_1.options.accessControl } : {})), { defaultLimit: (_l = config.pageSize) !== null && _l !== void 0 ? _l : 100, maxLimit: 500, permissions: {
|
|
@@ -1450,9 +1676,14 @@ var AdminApp = /** @class */ (function () {
|
|
|
1450
1676
|
return [2 /*return*/, body];
|
|
1451
1677
|
}
|
|
1452
1678
|
record = body;
|
|
1679
|
+
return [4 /*yield*/, (0, api_1.checkPermissions)("create", this.resourceActionPermissions(config, "create"), req.user, record)];
|
|
1680
|
+
case 1:
|
|
1681
|
+
if (!(_a.sent())) {
|
|
1682
|
+
throw new api_1.APIError({ status: 403, title: "Admin create access denied" });
|
|
1683
|
+
}
|
|
1453
1684
|
takePendingUserRoles(record, req);
|
|
1454
1685
|
return [4 /*yield*/, assertCanWriteUserAdminFlag(record, req)];
|
|
1455
|
-
case
|
|
1686
|
+
case 2:
|
|
1456
1687
|
_a.sent();
|
|
1457
1688
|
markAuthorizedUserAdminWrite(record, req);
|
|
1458
1689
|
return [2 /*return*/, stripProtectedFromBody(body)];
|
|
@@ -1483,15 +1714,15 @@ var AdminApp = /** @class */ (function () {
|
|
|
1483
1714
|
listDisplay: config.listDisplay,
|
|
1484
1715
|
listFields: config.listFields,
|
|
1485
1716
|
searchFields: (_q = modelMeta === null || modelMeta === void 0 ? void 0 : modelMeta.searchFields) !== null && _q !== void 0 ? _q : config.searchFields,
|
|
1486
|
-
}), queryFilter: buildAdminListQueryFilter(config, modelMeta === null || modelMeta === void 0 ? void 0 : modelMeta.searchFields), responseHandler: function (value, _method,
|
|
1487
|
-
return [2 /*return*/,
|
|
1717
|
+
}), queryFilter: buildAdminListQueryFilter(config, modelMeta === null || modelMeta === void 0 ? void 0 : modelMeta.searchFields), responseHandler: function (value, _method, request) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
1718
|
+
return [2 /*return*/, addRecordCapabilities(value, request)];
|
|
1488
1719
|
}); }); }, sort: (_r = config.defaultSort) !== null && _r !== void 0 ? _r : "-created" }), (config.populatePaths ? { populatePaths: config.populatePaths } : {})), (auditHooks.postDelete ? { postDelete: auditHooks.postDelete } : {}));
|
|
1489
1720
|
var modelBase = express_1.default.Router();
|
|
1490
1721
|
modelBase.use(validateAdminSortParam((_s = modelMeta === null || modelMeta === void 0 ? void 0 : modelMeta.sortableFields) !== null && _s !== void 0 ? _s : []));
|
|
1491
1722
|
modelBase.post.apply(modelBase, __spreadArray(__spreadArray(["/bulk-patch",
|
|
1492
1723
|
(0, api_1.authenticateMiddleware)()], __read(asMiddlewareList(bulkPatchOpenApi)), false), [(0, api_1.asyncHandler)(function (req, res) { return __awaiter(_this, void 0, void 0, function () {
|
|
1493
|
-
var body, ids, rawPatch, unknownKeys, patch, pendingRoles, updated, failures, actor, ids_1, ids_1_1, id, doc, previousPatch, _a, _b, key, roleError_1, err_4, message,
|
|
1494
|
-
var
|
|
1724
|
+
var body, ids, rawPatch, unknownKeys, patch, pendingRoles, updated, failures, actor, ids_1, ids_1_1, id, doc, previousPatch, _a, _b, key, roleError_1, err_4, message, e_16_1;
|
|
1725
|
+
var e_16, _c, e_17, _d;
|
|
1495
1726
|
var _e, _f;
|
|
1496
1727
|
return __generator(this, function (_g) {
|
|
1497
1728
|
switch (_g.label) {
|
|
@@ -1577,17 +1808,17 @@ var AdminApp = /** @class */ (function () {
|
|
|
1577
1808
|
_g.sent();
|
|
1578
1809
|
previousPatch = {};
|
|
1579
1810
|
try {
|
|
1580
|
-
for (_a = (
|
|
1811
|
+
for (_a = (e_17 = void 0, __values(Object.keys(patch))), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1581
1812
|
key = _b.value;
|
|
1582
1813
|
previousPatch[key] = doc[key];
|
|
1583
1814
|
}
|
|
1584
1815
|
}
|
|
1585
|
-
catch (
|
|
1816
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
1586
1817
|
finally {
|
|
1587
1818
|
try {
|
|
1588
1819
|
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
1589
1820
|
}
|
|
1590
|
-
finally { if (
|
|
1821
|
+
finally { if (e_17) throw e_17.error; }
|
|
1591
1822
|
}
|
|
1592
1823
|
if (!(Object.keys(patch).length > 0)) return [3 /*break*/, 9];
|
|
1593
1824
|
return [4 /*yield*/, doc.updateOne({ $set: patch })];
|
|
@@ -1631,14 +1862,14 @@ var AdminApp = /** @class */ (function () {
|
|
|
1631
1862
|
return [3 /*break*/, 3];
|
|
1632
1863
|
case 18: return [3 /*break*/, 21];
|
|
1633
1864
|
case 19:
|
|
1634
|
-
|
|
1635
|
-
|
|
1865
|
+
e_16_1 = _g.sent();
|
|
1866
|
+
e_16 = { error: e_16_1 };
|
|
1636
1867
|
return [3 /*break*/, 21];
|
|
1637
1868
|
case 20:
|
|
1638
1869
|
try {
|
|
1639
1870
|
if (ids_1_1 && !ids_1_1.done && (_c = ids_1.return)) _c.call(ids_1);
|
|
1640
1871
|
}
|
|
1641
|
-
finally { if (
|
|
1872
|
+
finally { if (e_16) throw e_16.error; }
|
|
1642
1873
|
return [7 /*endfinally*/];
|
|
1643
1874
|
case 21: return [2 /*return*/, res.json({ failures: failures.length > 0 ? failures : undefined, updated: updated })];
|
|
1644
1875
|
}
|
|
@@ -1732,7 +1963,7 @@ var AdminApp = /** @class */ (function () {
|
|
|
1732
1963
|
// POST /admin/scripts/:name/run — Execute a script
|
|
1733
1964
|
router.post("/:name/run", (0, api_1.asyncHandler)(function (req, res) { return __awaiter(_this, void 0, void 0, function () {
|
|
1734
1965
|
var user, _a, script, isWetRun, argValues, _b, _c, _d, key, value, rawBody, bodyValues, _e, _f, _g, key, value, _h, args, argErrors, now, task, err_5, detail, ctx;
|
|
1735
|
-
var
|
|
1966
|
+
var e_18, _j, e_19, _k;
|
|
1736
1967
|
var _this = this;
|
|
1737
1968
|
var _l, _m;
|
|
1738
1969
|
return __generator(this, function (_o) {
|
|
@@ -1764,12 +1995,12 @@ var AdminApp = /** @class */ (function () {
|
|
|
1764
1995
|
argValues[key] = value;
|
|
1765
1996
|
}
|
|
1766
1997
|
}
|
|
1767
|
-
catch (
|
|
1998
|
+
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
1768
1999
|
finally {
|
|
1769
2000
|
try {
|
|
1770
2001
|
if (_c && !_c.done && (_j = _b.return)) _j.call(_b);
|
|
1771
2002
|
}
|
|
1772
|
-
finally { if (
|
|
2003
|
+
finally { if (e_18) throw e_18.error; }
|
|
1773
2004
|
}
|
|
1774
2005
|
rawBody = req.body && typeof req.body === "object" && !Array.isArray(req.body)
|
|
1775
2006
|
? req.body
|
|
@@ -1786,12 +2017,12 @@ var AdminApp = /** @class */ (function () {
|
|
|
1786
2017
|
argValues[key] = value;
|
|
1787
2018
|
}
|
|
1788
2019
|
}
|
|
1789
|
-
catch (
|
|
2020
|
+
catch (e_19_1) { e_19 = { error: e_19_1 }; }
|
|
1790
2021
|
finally {
|
|
1791
2022
|
try {
|
|
1792
2023
|
if (_f && !_f.done && (_k = _e.return)) _k.call(_e);
|
|
1793
2024
|
}
|
|
1794
|
-
finally { if (
|
|
2025
|
+
finally { if (e_19) throw e_19.error; }
|
|
1795
2026
|
}
|
|
1796
2027
|
_h = (0, api_1.createScriptArgs)({
|
|
1797
2028
|
defs: (_l = script.args) !== null && _l !== void 0 ? _l : [],
|