identity-admin 1.22.7 → 1.23.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.
@@ -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) {
@@ -383,7 +383,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
383
383
  });
384
384
  }
385
385
  deleteAll(req, res) {
386
- var _a, _b, _c;
386
+ var _a, _b, _c, _d;
387
387
  return __awaiter(this, void 0, void 0, function* () {
388
388
  if (!this.validateRequest(req, res)) {
389
389
  return;
@@ -404,12 +404,12 @@ let DashboardController = DashboardController_1 = class DashboardController {
404
404
  if (!permissionCheck) {
405
405
  return ResponseUtils_1.default.forbidden(res);
406
406
  }
407
- const actions = ActionsGenerator_1.default.generateActions(resource.properties.actions, resource, currentUser);
407
+ 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
408
  const bulkDeletePermission = actions.bulkDelete.isAccessible;
409
409
  if (!bulkDeletePermission) {
410
410
  return ResponseUtils_1.default.forbidden(res);
411
411
  }
412
- const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
412
+ const repository = (_d = this.repository) !== null && _d !== void 0 ? _d : new Repository_1.default(resource.properties.resource);
413
413
  for (var i = 0; i < recordIds.length; i++) {
414
414
  const recordId = recordIds[i];
415
415
  const record = yield repository.findById(recordId);
@@ -422,7 +422,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
422
422
  });
423
423
  }
424
424
  delete(req, res) {
425
- var _a, _b, _c;
425
+ var _a, _b, _c, _d;
426
426
  return __awaiter(this, void 0, void 0, function* () {
427
427
  if (!this.validateRequest(req, res)) {
428
428
  return;
@@ -443,12 +443,12 @@ let DashboardController = DashboardController_1 = class DashboardController {
443
443
  if (!permissionCheck) {
444
444
  return ResponseUtils_1.default.forbidden(res);
445
445
  }
446
- const actions = ActionsGenerator_1.default.generateActions(resource.properties.actions, resource, currentUser);
446
+ 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
447
  const deletePermission = actions.delete.isAccessible;
448
448
  if (!deletePermission) {
449
449
  return ResponseUtils_1.default.forbidden(res);
450
450
  }
451
- const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
451
+ const repository = (_d = this.repository) !== null && _d !== void 0 ? _d : new Repository_1.default(resource.properties.resource);
452
452
  const record = yield repository.findById(recordId);
453
453
  if (!record) {
454
454
  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,63 +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) {
65
+ static getActions(actions, currentUser, configuration) {
66
+ var _a, _b, _c, _d, _e, _f;
60
67
  var actionObject = {
61
- show: { isAccessible: true },
62
- new: { isAccessible: true },
63
- edit: { isAccessible: true },
64
- delete: { isAccessible: true },
65
- 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 },
66
73
  };
67
74
  if (!actions || Object.keys(actions).length === 0) {
68
75
  return actionObject;
69
76
  }
70
77
  for (const key in actions) {
71
- if ((actions[key].hasOwnProperty('isAccessible') || actions[key].hasOwnProperty('reloadAfterAction')) && key !== 'extras') {
78
+ if (actions[key].hasOwnProperty("isAccessible") && key !== "extras") {
72
79
  actionObject[key] = actions[key];
73
80
  }
74
- else if (actions[key].isAllowed && key !== 'extras') {
81
+ else if (actions[key].isAllowed && key !== "extras") {
75
82
  actionObject[key] = {
76
- isAccessible: actions[key].isAllowed(currentUser)
83
+ isAccessible: actions[key].isAllowed(currentUser),
77
84
  };
78
85
  }
79
- else if (key === 'extras') {
86
+ else if (key === "extras") {
80
87
  actionObject[key] = actions[key];
81
88
  }
89
+ actionObject[key].reloadAfterAction = (_f = actions[key]) === null || _f === void 0 ? void 0 : _f.reloadAfterAction;
82
90
  }
83
91
  return actionObject;
84
92
  }
85
93
  static appendActionValues(action, actionObject, translation) {
86
94
  switch (action) {
87
- case 'new':
88
- 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() });
89
99
  break;
90
- case 'edit':
91
- 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() });
92
104
  break;
93
- case 'delete':
94
- actionObject.value = translation ? translation : (0, i18n_1.__)({ phrase: "actions_delete", locale: i18n_1.default.getLocale() });
95
- actionObject.confirmationMessageTitle = (0, i18n_1.__)({ phrase: "actions_delete_confirmMessage_title", locale: i18n_1.default.getLocale() });
96
- actionObject.confirmationMessageBody = (0, i18n_1.__)({ phrase: "actions_delete_confirmMessage_body", locale: i18n_1.default.getLocale() });
97
- actionObject.confirmDeleteOption = (0, i18n_1.__)({ phrase: "actions_delete_options_yes", locale: i18n_1.default.getLocale() });
98
- 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
+ });
99
125
  break;
100
- case 'bulkDelete':
101
- actionObject.value = translation ? translation : (0, i18n_1.__)({ phrase: "actions_delete", locale: i18n_1.default.getLocale() });
102
- actionObject.confirmationMessageTitle = (0, i18n_1.__)({ phrase: "actions_bulkDelete_confirmMessage_title", locale: i18n_1.default.getLocale() });
103
- actionObject.confirmationMessageBody = (0, i18n_1.__)({ phrase: "actions_bulkDelete_confirmMessage_body", locale: i18n_1.default.getLocale() });
104
- actionObject.confirmDeleteOption = (0, i18n_1.__)({ phrase: "actions_delete_options_yes", locale: i18n_1.default.getLocale() });
105
- 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
+ });
106
146
  break;
107
147
  }
108
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.7",
3
+ "version": "1.23.0",
4
4
  "description": "",
5
5
  "main": "lib/Dashboard.js",
6
6
  "types": "lib/Dashbord.d.ts",