identity-admin 1.22.8 → 1.23.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.
@@ -225,7 +225,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
225
225
  });
226
226
  }
227
227
  create(req, res) {
228
- var _a, _b, _c;
228
+ var _a, _b, _c, _d;
229
229
  return __awaiter(this, void 0, void 0, function* () {
230
230
  if (!this.validateRequest(req, res)) {
231
231
  return;
@@ -245,12 +245,12 @@ let DashboardController = DashboardController_1 = class DashboardController {
245
245
  if (!permissionCheck) {
246
246
  return ResponseUtils_1.default.forbidden(res);
247
247
  }
248
- const actions = ActionsGenerator_1.default.generateActions(resource.properties.actions, resource, currentUser);
248
+ const actions = ActionsGenerator_1.default.generateActions(resource.properties.actions, resource, currentUser, (_c = this.modelConfigurations) === null || _c === void 0 ? void 0 : _c.get(resource.properties.modelName));
249
249
  const createPermission = actions.new.isAccessible;
250
250
  if (!createPermission) {
251
251
  return ResponseUtils_1.default.forbidden(res);
252
252
  }
253
- const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
253
+ const repository = (_d = this.repository) !== null && _d !== void 0 ? _d : new Repository_1.default(resource.properties.resource);
254
254
  var recordParams = req.body;
255
255
  recordParams = LocalizedStringHelper_1.default.mapLocalizableString(recordParams, resource);
256
256
  const crudOperations = resource.properties.crudOperations;
@@ -283,7 +283,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
283
283
  });
284
284
  }
285
285
  update(req, res) {
286
- var _a, _b, _c;
286
+ var _a, _b, _c, _d;
287
287
  return __awaiter(this, void 0, void 0, function* () {
288
288
  if (!this.validateRequest(req, res)) {
289
289
  return;
@@ -304,12 +304,12 @@ let DashboardController = DashboardController_1 = class DashboardController {
304
304
  if (!permissionCheck) {
305
305
  return ResponseUtils_1.default.forbidden(res);
306
306
  }
307
- const actions = ActionsGenerator_1.default.generateActions(resource.properties.actions, resource, currentUser);
307
+ const actions = ActionsGenerator_1.default.generateActions(resource.properties.actions, resource, currentUser, (_c = this.modelConfigurations) === null || _c === void 0 ? void 0 : _c.get(resource.properties.modelName));
308
308
  const editPermission = actions.edit.isAccessible;
309
309
  if (!editPermission) {
310
310
  return ResponseUtils_1.default.forbidden(res);
311
311
  }
312
- const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
312
+ const repository = (_d = this.repository) !== null && _d !== void 0 ? _d : new Repository_1.default(resource.properties.resource);
313
313
  const recordId = req.params.id;
314
314
  var record = yield repository.findById(recordId);
315
315
  if (!record) {
@@ -348,6 +348,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
348
348
  const recordId = req.params.id;
349
349
  const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
350
350
  const currentUser = req.user;
351
+ const model = resource === null || resource === void 0 ? void 0 : resource.properties.resource;
351
352
  if (!resource) {
352
353
  return ResponseUtils_1.default.notFound(res, "Resource not found", []);
353
354
  }
@@ -379,11 +380,25 @@ let DashboardController = DashboardController_1 = class DashboardController {
379
380
  if (afterMethod && record) {
380
381
  extras = yield afterMethod(req, record);
381
382
  }
382
- return ResponseUtils_1.default.ok(res, Object.assign(Object.assign({}, extras), { record: record ? record : null }));
383
+ const sortBy = modifiedResource.properties.defaultOrderBy;
384
+ const nextQuery = {};
385
+ const prevQuery = {};
386
+ const nextSortQuery = {};
387
+ const prevSortQuery = {};
388
+ nextQuery[sortBy] = { $gt: record[sortBy] };
389
+ prevQuery[sortBy] = { $lt: record[sortBy] };
390
+ nextSortQuery[sortBy] = 1;
391
+ prevSortQuery[sortBy] = -1;
392
+ const next = yield (model === null || model === void 0 ? void 0 : model.findOne(nextQuery).sort(nextSortQuery).limit(1));
393
+ const previous = yield (model === null || model === void 0 ? void 0 : model.findOne(prevQuery).sort(prevSortQuery).limit(1));
394
+ const hasNext = record && next && next._id ? true : false;
395
+ const hasPrevious = record && previous && previous._id ? true : false;
396
+ return ResponseUtils_1.default.ok(res, Object.assign(Object.assign({}, extras), { record: record ? record : null, hasNext,
397
+ hasPrevious, nextId: hasNext ? next === null || next === void 0 ? void 0 : next._id : undefined, previousId: hasPrevious ? previous === null || previous === void 0 ? void 0 : previous._id : undefined }));
383
398
  });
384
399
  }
385
400
  deleteAll(req, res) {
386
- var _a, _b, _c;
401
+ var _a, _b, _c, _d;
387
402
  return __awaiter(this, void 0, void 0, function* () {
388
403
  if (!this.validateRequest(req, res)) {
389
404
  return;
@@ -404,12 +419,12 @@ let DashboardController = DashboardController_1 = class DashboardController {
404
419
  if (!permissionCheck) {
405
420
  return ResponseUtils_1.default.forbidden(res);
406
421
  }
407
- const actions = ActionsGenerator_1.default.generateActions(resource.properties.actions, resource, currentUser);
422
+ const actions = ActionsGenerator_1.default.generateActions(resource.properties.actions, resource, currentUser, (_c = this.modelConfigurations) === null || _c === void 0 ? void 0 : _c.get(resource.properties.modelName));
408
423
  const bulkDeletePermission = actions.bulkDelete.isAccessible;
409
424
  if (!bulkDeletePermission) {
410
425
  return ResponseUtils_1.default.forbidden(res);
411
426
  }
412
- const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
427
+ const repository = (_d = this.repository) !== null && _d !== void 0 ? _d : new Repository_1.default(resource.properties.resource);
413
428
  for (var i = 0; i < recordIds.length; i++) {
414
429
  const recordId = recordIds[i];
415
430
  const record = yield repository.findById(recordId);
@@ -422,7 +437,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
422
437
  });
423
438
  }
424
439
  delete(req, res) {
425
- var _a, _b, _c;
440
+ var _a, _b, _c, _d;
426
441
  return __awaiter(this, void 0, void 0, function* () {
427
442
  if (!this.validateRequest(req, res)) {
428
443
  return;
@@ -443,12 +458,12 @@ let DashboardController = DashboardController_1 = class DashboardController {
443
458
  if (!permissionCheck) {
444
459
  return ResponseUtils_1.default.forbidden(res);
445
460
  }
446
- const actions = ActionsGenerator_1.default.generateActions(resource.properties.actions, resource, currentUser);
461
+ const actions = ActionsGenerator_1.default.generateActions(resource.properties.actions, resource, currentUser, (_c = this.modelConfigurations) === null || _c === void 0 ? void 0 : _c.get(resource.properties.modelName));
447
462
  const deletePermission = actions.delete.isAccessible;
448
463
  if (!deletePermission) {
449
464
  return ResponseUtils_1.default.forbidden(res);
450
465
  }
451
- const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
466
+ const repository = (_d = this.repository) !== null && _d !== void 0 ? _d : new Repository_1.default(resource.properties.resource);
452
467
  const record = yield repository.findById(recordId);
453
468
  if (!record) {
454
469
  return ResponseUtils_1.default.send(res, 404, "record Not Found");
@@ -1,7 +1,8 @@
1
1
  import { Document } from "mongoose";
2
2
  import { IResourceFile } from "../types/IResourceFile";
3
+ import { IModelConfigurationDocument } from "../models/modelConfiguration/IModelConfigurations";
3
4
  export default class ActionsGenerator {
4
- static generateActions(actionsCheck: any, resource: IResourceFile, currentUser: Document): {
5
+ static generateActions(actionsCheck: any, resource: IResourceFile, currentUser: Document, configuration?: IModelConfigurationDocument): {
5
6
  [key: string]: any;
6
7
  };
7
8
  private static addExtraActions;
@@ -29,13 +29,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const i18n_1 = __importStar(require("i18n"));
30
30
  const helpers_1 = require("../types/helpers");
31
31
  const ResourceHelper_1 = __importDefault(require("./ResourceHelper"));
32
- var pluralize = require('pluralize');
32
+ var pluralize = require("pluralize");
33
33
  class ActionsGenerator {
34
- static generateActions(actionsCheck, resource, currentUser) {
35
- const actions = this.getActions(actionsCheck ? resource.properties.actions : undefined, currentUser); //resource.properties.actions? ResourcesHelper.getActions(JSON.parse(JSON.stringify(resource.properties.actions))): ResourcesHelper.getActions(undefined)
34
+ static generateActions(actionsCheck, resource, currentUser, configuration) {
35
+ const actions = this.getActions(actionsCheck ? resource.properties.actions : undefined, currentUser, configuration); //resource.properties.actions? ResourcesHelper.getActions(JSON.parse(JSON.stringify(resource.properties.actions))): ResourcesHelper.getActions(undefined)
36
36
  for (const key in actions) {
37
- if (key === 'extras') {
38
- actions.extras = actions.extras ? this.addExtraActions(JSON.parse(JSON.stringify(resource.properties.actions.extras))) : actions.extras;
37
+ if (key === "extras") {
38
+ actions.extras = actions.extras
39
+ ? this.addExtraActions(JSON.parse(JSON.stringify(resource.properties.actions.extras)))
40
+ : actions.extras;
39
41
  continue;
40
42
  }
41
43
  const translation = ResourceHelper_1.default.checkActionTranslation(resource, key);
@@ -46,65 +48,101 @@ class ActionsGenerator {
46
48
  static addExtraActions(extraActions) {
47
49
  var extraActionsObject = {
48
50
  record: {},
49
- resource: {}
51
+ resource: {},
50
52
  };
51
53
  extraActions.forEach((action) => {
52
54
  action.keys = action.isVisible ? Object.keys(action.isVisible) : [];
53
55
  action.name = (0, i18n_1.__)({ phrase: action.name, locale: i18n_1.default.getLocale() });
54
- action.handlerStrategy = action.handlerStrategy ? action.handlerStrategy : helpers_1.HandlerStrategy.NORMAL;
55
- action.actionType ? extraActionsObject[action.actionType][action.key] = action : '';
56
+ action.handlerStrategy = action.handlerStrategy
57
+ ? action.handlerStrategy
58
+ : helpers_1.HandlerStrategy.NORMAL;
59
+ action.actionType
60
+ ? (extraActionsObject[action.actionType][action.key] = action)
61
+ : "";
56
62
  });
57
63
  return extraActionsObject;
58
64
  }
59
- static getActions(actions, currentUser) {
60
- var _a;
65
+ static getActions(actions, currentUser, configuration) {
66
+ var _a, _b, _c, _d, _e, _f;
61
67
  var actionObject = {
62
- show: { isAccessible: true },
63
- new: { isAccessible: true },
64
- edit: { isAccessible: true },
65
- delete: { isAccessible: true },
66
- bulkDelete: { isAccessible: false },
68
+ show: { isAccessible: ((_a = configuration === null || configuration === void 0 ? void 0 : configuration.actions) === null || _a === void 0 ? void 0 : _a.show) === false ? false : true },
69
+ new: { isAccessible: ((_b = configuration === null || configuration === void 0 ? void 0 : configuration.actions) === null || _b === void 0 ? void 0 : _b.new) === false ? false : true },
70
+ edit: { isAccessible: ((_c = configuration === null || configuration === void 0 ? void 0 : configuration.actions) === null || _c === void 0 ? void 0 : _c.edit) === false ? false : true },
71
+ delete: { isAccessible: ((_d = configuration === null || configuration === void 0 ? void 0 : configuration.actions) === null || _d === void 0 ? void 0 : _d.delete) === false ? false : true },
72
+ bulkDelete: { isAccessible: ((_e = configuration === null || configuration === void 0 ? void 0 : configuration.actions) === null || _e === void 0 ? void 0 : _e.bulkDelete) === true ? true : false },
67
73
  };
68
74
  if (!actions || Object.keys(actions).length === 0) {
69
75
  return actionObject;
70
76
  }
71
77
  for (const key in actions) {
72
- if (actions[key].hasOwnProperty('isAccessible') && key !== 'extras') {
78
+ if (actions[key].hasOwnProperty("isAccessible") && key !== "extras") {
73
79
  actionObject[key] = actions[key];
74
80
  }
75
- else if (actions[key].isAllowed && key !== 'extras') {
81
+ else if (actions[key].isAllowed && key !== "extras") {
76
82
  actionObject[key] = {
77
- isAccessible: actions[key].isAllowed(currentUser)
83
+ isAccessible: actions[key].isAllowed(currentUser),
78
84
  };
79
85
  }
80
- else if (key === 'extras') {
86
+ else if (key === "extras") {
81
87
  actionObject[key] = actions[key];
82
88
  }
83
- actionObject[key].reloadAfterAction = (_a = actions[key]) === null || _a === void 0 ? void 0 : _a.reloadAfterAction;
89
+ actionObject[key].reloadAfterAction = (_f = actions[key]) === null || _f === void 0 ? void 0 : _f.reloadAfterAction;
84
90
  }
85
91
  return actionObject;
86
92
  }
87
93
  static appendActionValues(action, actionObject, translation) {
88
94
  switch (action) {
89
- case 'new':
90
- actionObject.value = translation ? translation : (0, i18n_1.__)({ phrase: "actions_new", locale: i18n_1.default.getLocale() });
95
+ case "new":
96
+ actionObject.value = translation
97
+ ? translation
98
+ : (0, i18n_1.__)({ phrase: "actions_new", locale: i18n_1.default.getLocale() });
91
99
  break;
92
- case 'edit':
93
- actionObject.value = translation ? translation : (0, i18n_1.__)({ phrase: "actions_edit", locale: i18n_1.default.getLocale() });
100
+ case "edit":
101
+ actionObject.value = translation
102
+ ? translation
103
+ : (0, i18n_1.__)({ phrase: "actions_edit", locale: i18n_1.default.getLocale() });
94
104
  break;
95
- case 'delete':
96
- actionObject.value = translation ? translation : (0, i18n_1.__)({ phrase: "actions_delete", locale: i18n_1.default.getLocale() });
97
- actionObject.confirmationMessageTitle = (0, i18n_1.__)({ phrase: "actions_delete_confirmMessage_title", locale: i18n_1.default.getLocale() });
98
- actionObject.confirmationMessageBody = (0, i18n_1.__)({ phrase: "actions_delete_confirmMessage_body", locale: i18n_1.default.getLocale() });
99
- actionObject.confirmDeleteOption = (0, i18n_1.__)({ phrase: "actions_delete_options_yes", locale: i18n_1.default.getLocale() });
100
- actionObject.cancelDeleteOption = (0, i18n_1.__)({ phrase: "actions_delete_options_no", locale: i18n_1.default.getLocale() });
105
+ case "delete":
106
+ actionObject.value = translation
107
+ ? translation
108
+ : (0, i18n_1.__)({ phrase: "actions_delete", locale: i18n_1.default.getLocale() });
109
+ actionObject.confirmationMessageTitle = (0, i18n_1.__)({
110
+ phrase: "actions_delete_confirmMessage_title",
111
+ locale: i18n_1.default.getLocale(),
112
+ });
113
+ actionObject.confirmationMessageBody = (0, i18n_1.__)({
114
+ phrase: "actions_delete_confirmMessage_body",
115
+ locale: i18n_1.default.getLocale(),
116
+ });
117
+ actionObject.confirmDeleteOption = (0, i18n_1.__)({
118
+ phrase: "actions_delete_options_yes",
119
+ locale: i18n_1.default.getLocale(),
120
+ });
121
+ actionObject.cancelDeleteOption = (0, i18n_1.__)({
122
+ phrase: "actions_delete_options_no",
123
+ locale: i18n_1.default.getLocale(),
124
+ });
101
125
  break;
102
- case 'bulkDelete':
103
- actionObject.value = translation ? translation : (0, i18n_1.__)({ phrase: "actions_delete", locale: i18n_1.default.getLocale() });
104
- actionObject.confirmationMessageTitle = (0, i18n_1.__)({ phrase: "actions_bulkDelete_confirmMessage_title", locale: i18n_1.default.getLocale() });
105
- actionObject.confirmationMessageBody = (0, i18n_1.__)({ phrase: "actions_bulkDelete_confirmMessage_body", locale: i18n_1.default.getLocale() });
106
- actionObject.confirmDeleteOption = (0, i18n_1.__)({ phrase: "actions_delete_options_yes", locale: i18n_1.default.getLocale() });
107
- actionObject.cancelDeleteOption = (0, i18n_1.__)({ phrase: "actions_delete_options_no", locale: i18n_1.default.getLocale() });
126
+ case "bulkDelete":
127
+ actionObject.value = translation
128
+ ? translation
129
+ : (0, i18n_1.__)({ phrase: "actions_delete", locale: i18n_1.default.getLocale() });
130
+ actionObject.confirmationMessageTitle = (0, i18n_1.__)({
131
+ phrase: "actions_bulkDelete_confirmMessage_title",
132
+ locale: i18n_1.default.getLocale(),
133
+ });
134
+ actionObject.confirmationMessageBody = (0, i18n_1.__)({
135
+ phrase: "actions_bulkDelete_confirmMessage_body",
136
+ locale: i18n_1.default.getLocale(),
137
+ });
138
+ actionObject.confirmDeleteOption = (0, i18n_1.__)({
139
+ phrase: "actions_delete_options_yes",
140
+ locale: i18n_1.default.getLocale(),
141
+ });
142
+ actionObject.cancelDeleteOption = (0, i18n_1.__)({
143
+ phrase: "actions_delete_options_no",
144
+ locale: i18n_1.default.getLocale(),
145
+ });
108
146
  break;
109
147
  }
110
148
  return actionObject;
@@ -157,7 +157,7 @@ class ResourceGenerator {
157
157
  modifiedResource.properties.filters.scopes.options =
158
158
  ResourceHelper_1.default.setScopeFilterOptions(modelName, options);
159
159
  }
160
- const actions = ActionsGenerator_1.default.generateActions(actionsCheck, resource, currentUser);
160
+ const actions = ActionsGenerator_1.default.generateActions(actionsCheck, resource, currentUser, modelConfiguration);
161
161
  modifiedResource.properties.actions = actions;
162
162
  return modifiedResource;
163
163
  }
@@ -1,5 +1,12 @@
1
1
  import { Document, Model, Types } from 'mongoose';
2
2
  import { RowArrangeType, RowsPerPageOptions } from './ModelConfiguration';
3
+ export interface IModelConfigurationActions {
4
+ new?: boolean;
5
+ edit?: boolean;
6
+ show?: boolean;
7
+ delete?: boolean;
8
+ bulkDelete?: boolean;
9
+ }
3
10
  export interface IModelConfigurationProps {
4
11
  _id?: Types.ObjectId;
5
12
  modelName: string;
@@ -7,6 +14,7 @@ export interface IModelConfigurationProps {
7
14
  defaultOrderBy?: string;
8
15
  defaultOrder?: RowArrangeType;
9
16
  defaultrowsPerPage?: RowsPerPageOptions;
17
+ actions?: IModelConfigurationActions;
10
18
  listProperties?: string[];
11
19
  showProperties?: string[];
12
20
  filterProperties?: string[];
@@ -15,6 +15,28 @@ var RowsPerPageOptions;
15
15
  RowsPerPageOptions["FIFTY"] = "50";
16
16
  RowsPerPageOptions["ONE_HUNDRED"] = "100";
17
17
  })(RowsPerPageOptions = exports.RowsPerPageOptions || (exports.RowsPerPageOptions = {}));
18
+ const ActionSchema = new mongoose_1.Schema({
19
+ new: {
20
+ type: Boolean,
21
+ required: true,
22
+ },
23
+ edit: {
24
+ type: Boolean,
25
+ required: true,
26
+ },
27
+ show: {
28
+ type: Boolean,
29
+ required: false,
30
+ },
31
+ delete: {
32
+ type: Boolean,
33
+ required: false,
34
+ },
35
+ bulkDelete: {
36
+ type: Boolean,
37
+ required: false,
38
+ },
39
+ }, { _id: false });
18
40
  function getModelConfiguartionSchema(schemaOptions) {
19
41
  return new mongoose_1.Schema({
20
42
  modelName: {
@@ -40,6 +62,10 @@ function getModelConfiguartionSchema(schemaOptions) {
40
62
  enum: Object.values(RowsPerPageOptions),
41
63
  required: false,
42
64
  },
65
+ actions: {
66
+ type: ActionSchema,
67
+ required: false
68
+ },
43
69
  listProperties: [
44
70
  {
45
71
  type: String,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "identity-admin",
3
- "version": "1.22.8",
3
+ "version": "1.23.1",
4
4
  "description": "",
5
5
  "main": "lib/Dashboard.js",
6
6
  "types": "lib/Dashbord.d.ts",