identity-admin 1.28.15 → 1.28.17

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.
@@ -41,4 +41,5 @@ export default class DashboardController {
41
41
  deleteAll(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
42
42
  delete(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
43
43
  getNeighbors(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
44
+ import(req: any, res: Response): Promise<void>;
44
45
  }
@@ -43,6 +43,10 @@ const UserActionsLog_1 = __importDefault(require("../models/userActionsLog/UserA
43
43
  const PermissionResource_1 = require("../helpers/Permissions/PermissionResource");
44
44
  const RecordsCounter_1 = require("../helpers/RecordsCounter");
45
45
  const FilterQueryHelper_1 = require("../helpers/FilterQueryHelper");
46
+ const multer = require('multer');
47
+ const upload = multer({ dest: 'uploads/' });
48
+ var fs = require('fs');
49
+ const xlsx = require('node-xlsx');
46
50
  let DashboardController = DashboardController_1 = class DashboardController {
47
51
  constructor(resource, repository, resources, modelConfigurations) {
48
52
  this.resource = resource;
@@ -730,6 +734,37 @@ let DashboardController = DashboardController_1 = class DashboardController {
730
734
  });
731
735
  });
732
736
  }
737
+ import(req, res) {
738
+ var _a, _b;
739
+ return __awaiter(this, void 0, void 0, function* () {
740
+ if (!this.validateRequest(req, res)) {
741
+ return;
742
+ }
743
+ const filePath = req.file.path;
744
+ const modelName = req.params.resource;
745
+ const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
746
+ const currentUser = req.user;
747
+ if (!resource) {
748
+ return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
749
+ }
750
+ if (!currentUser) {
751
+ return ResponseUtils_1.default.unauthorized(res);
752
+ }
753
+ var data = [];
754
+ const sheets = xlsx.parse(fs.readFileSync(filePath));
755
+ if (!sheets.length)
756
+ data = [];
757
+ else
758
+ data = sheets[0].data || [];
759
+ if (resource && resource.properties.afterImport) {
760
+ yield resource.properties.afterImport(req, currentUser, data);
761
+ }
762
+ fs.rmSync(req.file.path, {
763
+ force: true,
764
+ });
765
+ return ResponseUtils_1.default.created(res, {});
766
+ });
767
+ }
733
768
  };
734
769
  DashboardController.DEFAULT_PAGE = 1;
735
770
  DashboardController.DEFAULT_PER_PAGE = 30;
@@ -777,6 +812,11 @@ __decorate([
777
812
  __param(0, (0, inversify_express_utils_1.request)()),
778
813
  __param(1, (0, inversify_express_utils_1.response)())
779
814
  ], DashboardController.prototype, "getNeighbors", null);
815
+ __decorate([
816
+ (0, inversify_express_utils_1.httpPost)('/import', upload.single('file')),
817
+ __param(0, (0, inversify_express_utils_1.request)()),
818
+ __param(1, (0, inversify_express_utils_1.response)())
819
+ ], DashboardController.prototype, "import", null);
780
820
  DashboardController = DashboardController_1 = __decorate([
781
821
  (0, inversify_1.injectable)(),
782
822
  __param(0, (0, inversify_1.unmanaged)()),
@@ -1,6 +1,6 @@
1
- import { Document } from "mongoose";
2
- import { IResourceFile } from "../types/IResourceFile";
3
- import { IModelConfigurationDocument } from "../models/modelConfiguration/IModelConfigurations";
1
+ import { Document } from 'mongoose';
2
+ import { IResourceFile } from '../types/IResourceFile';
3
+ import { IModelConfigurationDocument } from '../models/modelConfiguration/IModelConfigurations';
4
4
  export default class ActionsGenerator {
5
5
  static generateActions(actionsCheck: any, resource: IResourceFile, currentUser: Document, configuration?: IModelConfigurationDocument): {
6
6
  [key: string]: any;
@@ -29,15 +29,13 @@ 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
34
  static generateActions(actionsCheck, resource, currentUser, configuration) {
35
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
39
- ? this.addExtraActions(JSON.parse(JSON.stringify(resource.properties.actions.extras)))
40
- : actions.extras;
37
+ if (key === 'extras') {
38
+ actions.extras = actions.extras ? this.addExtraActions(JSON.parse(JSON.stringify(resource.properties.actions.extras))) : actions.extras;
41
39
  continue;
42
40
  }
43
41
  const translation = ResourceHelper_1.default.checkActionTranslation(resource, key);
@@ -53,30 +51,20 @@ class ActionsGenerator {
53
51
  extraActions.forEach((action) => {
54
52
  action.keys = action.isVisible ? Object.keys(action.isVisible) : [];
55
53
  action.name = (0, i18n_1.__)({ phrase: action.name, locale: i18n_1.default.getLocale() });
56
- action.guardTitle = action.guardTitle
57
- ? (0, i18n_1.__)({ phrase: action.guardTitle, locale: i18n_1.default.getLocale() })
58
- : undefined;
59
- action.guard = action.guard
60
- ? (0, i18n_1.__)({ phrase: action.guard, locale: i18n_1.default.getLocale() })
61
- : undefined;
62
- action.message = action.message
63
- ? (0, i18n_1.__)({ phrase: action.message, locale: i18n_1.default.getLocale() })
64
- : undefined;
65
- action.handlerStrategy = action.handlerStrategy
66
- ? action.handlerStrategy
67
- : helpers_1.HandlerStrategy.NORMAL;
68
- action.actionType
69
- ? (extraActionsObject[action.actionType][action.key] = action)
70
- : "";
54
+ action.guardTitle = action.guardTitle ? (0, i18n_1.__)({ phrase: action.guardTitle, locale: i18n_1.default.getLocale() }) : undefined;
55
+ action.guard = action.guard ? (0, i18n_1.__)({ phrase: action.guard, locale: i18n_1.default.getLocale() }) : undefined;
56
+ action.message = action.message ? (0, i18n_1.__)({ phrase: action.message, locale: i18n_1.default.getLocale() }) : undefined;
57
+ action.handlerStrategy = action.handlerStrategy ? action.handlerStrategy : helpers_1.HandlerStrategy.NORMAL;
58
+ action.actionType ? (extraActionsObject[action.actionType][action.key] = action) : '';
71
59
  });
72
60
  return extraActionsObject;
73
61
  }
74
62
  static getActions(actions, currentUser, configuration) {
75
- var _a, _b, _c, _d, _e, _f, _g, _h;
63
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
76
64
  var actionObject = {
77
65
  show: {
78
66
  isAccessible: ((_a = configuration === null || configuration === void 0 ? void 0 : configuration.actions) === null || _a === void 0 ? void 0 : _a.show) === false ? false : true,
79
- isMainAction: true
67
+ isMainAction: true,
80
68
  },
81
69
  new: {
82
70
  isAccessible: ((_b = configuration === null || configuration === void 0 ? void 0 : configuration.actions) === null || _b === void 0 ? void 0 : _b.new) === false ? false : true,
@@ -86,97 +74,90 @@ class ActionsGenerator {
86
74
  },
87
75
  edit: {
88
76
  isAccessible: ((_d = configuration === null || configuration === void 0 ? void 0 : configuration.actions) === null || _d === void 0 ? void 0 : _d.edit) === false ? false : true,
89
- isMainAction: true
77
+ isMainAction: true,
90
78
  },
91
79
  delete: {
92
80
  isAccessible: ((_e = configuration === null || configuration === void 0 ? void 0 : configuration.actions) === null || _e === void 0 ? void 0 : _e.delete) === false ? false : true,
93
81
  },
82
+ import: {
83
+ isAccessible: ((_f = configuration === null || configuration === void 0 ? void 0 : configuration.actions) === null || _f === void 0 ? void 0 : _f.import) === true ? true : false,
84
+ },
94
85
  bulkDelete: {
95
- isAccessible: ((_f = configuration === null || configuration === void 0 ? void 0 : configuration.actions) === null || _f === void 0 ? void 0 : _f.bulkDelete) === true ? true : false,
86
+ isAccessible: ((_g = configuration === null || configuration === void 0 ? void 0 : configuration.actions) === null || _g === void 0 ? void 0 : _g.bulkDelete) === true ? true : false,
96
87
  },
97
88
  };
98
89
  if (!actions || Object.keys(actions).length === 0) {
99
90
  return actionObject;
100
91
  }
101
92
  for (const key in actions) {
102
- if (actions[key].hasOwnProperty("isAccessible") && key !== "extras") {
93
+ if (actions[key].hasOwnProperty('isAccessible') && key !== 'extras') {
103
94
  actionObject[key] = actions[key];
104
95
  }
105
- else if (actions[key].isAllowed && key !== "extras") {
96
+ else if (actions[key].isAllowed && key !== 'extras') {
106
97
  actionObject[key] = {
107
98
  isAccessible: actions[key].isAllowed(currentUser),
108
99
  };
109
100
  }
110
- else if (key === "extras") {
101
+ else if (key === 'extras') {
111
102
  actionObject[key] = actions[key];
112
103
  }
113
- actionObject[key].reloadAfterAction = (_g = actions[key]) === null || _g === void 0 ? void 0 : _g.reloadAfterAction;
114
- actionObject[key].isMainAction =
115
- (_h = actions[key].isMainAction) !== null && _h !== void 0 ? _h : (key === "edit" || key === "show");
104
+ actionObject[key].reloadAfterAction = (_h = actions[key]) === null || _h === void 0 ? void 0 : _h.reloadAfterAction;
105
+ actionObject[key].isMainAction = (_j = actions[key].isMainAction) !== null && _j !== void 0 ? _j : (key === 'edit' || key === 'show');
116
106
  }
117
107
  return actionObject;
118
108
  }
119
109
  static appendActionValues(action, actionObject, translation) {
120
110
  switch (action) {
121
- case "new":
122
- actionObject.value = translation
123
- ? translation
124
- : (0, i18n_1.__)({ phrase: "actions_new", locale: i18n_1.default.getLocale() });
111
+ case 'new':
112
+ actionObject.value = translation ? translation : (0, i18n_1.__)({ phrase: 'actions_new', locale: i18n_1.default.getLocale() });
113
+ break;
114
+ case 'duplicate':
115
+ actionObject.value = translation ? translation : (0, i18n_1.__)({ phrase: 'actions_duplicate', locale: i18n_1.default.getLocale() });
125
116
  break;
126
- case "duplicate":
127
- actionObject.value = translation
128
- ? translation
129
- : (0, i18n_1.__)({ phrase: "actions_duplicate", locale: i18n_1.default.getLocale() });
117
+ case 'edit':
118
+ actionObject.value = translation ? translation : (0, i18n_1.__)({ phrase: 'actions_edit', locale: i18n_1.default.getLocale() });
130
119
  break;
131
- case "edit":
132
- actionObject.value = translation
133
- ? translation
134
- : (0, i18n_1.__)({ phrase: "actions_edit", locale: i18n_1.default.getLocale() });
120
+ case 'show':
121
+ actionObject.value = translation ? translation : (0, i18n_1.__)({ phrase: 'actions_show', locale: i18n_1.default.getLocale() });
135
122
  break;
136
- case "show":
137
- actionObject.value = translation
138
- ? translation
139
- : (0, i18n_1.__)({ phrase: "actions_show", locale: i18n_1.default.getLocale() });
123
+ case 'import':
124
+ actionObject.value = translation ? translation : (0, i18n_1.__)({ phrase: 'actions_import', locale: i18n_1.default.getLocale() });
140
125
  break;
141
- case "delete":
142
- actionObject.value = translation
143
- ? translation
144
- : (0, i18n_1.__)({ phrase: "actions_delete", locale: i18n_1.default.getLocale() });
126
+ case 'delete':
127
+ actionObject.value = translation ? translation : (0, i18n_1.__)({ phrase: 'actions_delete', locale: i18n_1.default.getLocale() });
145
128
  actionObject.confirmationMessageTitle = (0, i18n_1.__)({
146
- phrase: "actions_delete_confirmMessage_title",
129
+ phrase: 'actions_delete_confirmMessage_title',
147
130
  locale: i18n_1.default.getLocale(),
148
131
  });
149
132
  actionObject.confirmationMessageBody = (0, i18n_1.__)({
150
- phrase: "actions_delete_confirmMessage_body",
133
+ phrase: 'actions_delete_confirmMessage_body',
151
134
  locale: i18n_1.default.getLocale(),
152
135
  });
153
136
  actionObject.confirmDeleteOption = (0, i18n_1.__)({
154
- phrase: "actions_delete_options_yes",
137
+ phrase: 'actions_delete_options_yes',
155
138
  locale: i18n_1.default.getLocale(),
156
139
  });
157
140
  actionObject.cancelDeleteOption = (0, i18n_1.__)({
158
- phrase: "actions_delete_options_no",
141
+ phrase: 'actions_delete_options_no',
159
142
  locale: i18n_1.default.getLocale(),
160
143
  });
161
144
  break;
162
- case "bulkDelete":
163
- actionObject.value = translation
164
- ? translation
165
- : (0, i18n_1.__)({ phrase: "actions_delete", locale: i18n_1.default.getLocale() });
145
+ case 'bulkDelete':
146
+ actionObject.value = translation ? translation : (0, i18n_1.__)({ phrase: 'actions_delete', locale: i18n_1.default.getLocale() });
166
147
  actionObject.confirmationMessageTitle = (0, i18n_1.__)({
167
- phrase: "actions_bulkDelete_confirmMessage_title",
148
+ phrase: 'actions_bulkDelete_confirmMessage_title',
168
149
  locale: i18n_1.default.getLocale(),
169
150
  });
170
151
  actionObject.confirmationMessageBody = (0, i18n_1.__)({
171
- phrase: "actions_bulkDelete_confirmMessage_body",
152
+ phrase: 'actions_bulkDelete_confirmMessage_body',
172
153
  locale: i18n_1.default.getLocale(),
173
154
  });
174
155
  actionObject.confirmDeleteOption = (0, i18n_1.__)({
175
- phrase: "actions_delete_options_yes",
156
+ phrase: 'actions_delete_options_yes',
176
157
  locale: i18n_1.default.getLocale(),
177
158
  });
178
159
  actionObject.cancelDeleteOption = (0, i18n_1.__)({
179
- phrase: "actions_delete_options_no",
160
+ phrase: 'actions_delete_options_no',
180
161
  locale: i18n_1.default.getLocale(),
181
162
  });
182
163
  break;
@@ -6,6 +6,7 @@ export interface IModelConfigurationActions {
6
6
  show?: boolean;
7
7
  delete?: boolean;
8
8
  bulkDelete?: boolean;
9
+ import?: boolean;
9
10
  }
10
11
  export interface IModelConfigurationProps {
11
12
  _id?: Types.ObjectId;
@@ -32,6 +32,10 @@ const ActionSchema = new mongoose_1.Schema({
32
32
  type: Boolean,
33
33
  required: false,
34
34
  },
35
+ import: {
36
+ type: Boolean,
37
+ required: false,
38
+ },
35
39
  bulkDelete: {
36
40
  type: Boolean,
37
41
  required: false,
@@ -41,13 +41,13 @@ interface Action {
41
41
  /**
42
42
  * Specify if this action is accessible or not.
43
43
  * @default True for show, edit, delete, and new.
44
- * @default false for bulk delete.
45
- * You can ovveride any of these values here.
44
+ * @default false for bulk delete and import.
45
+ * You can override any of these values here.
46
46
  */
47
47
  isAccessible?: boolean;
48
48
  /**
49
49
  * Specify if the page requires to be reloaded after executing the action
50
- * @default Fale for show, edit, delete, and new.
50
+ * @default False for show, edit, delete, and new.
51
51
  */
52
52
  reloadAfterAction?: boolean;
53
53
  /**
@@ -377,13 +377,13 @@ export interface IFieldValue {
377
377
  */
378
378
  relatedFields?: string[];
379
379
  /**
380
- * Used to add the disableImageOptimization option in the field. Only used when the type of the field is image
381
- * @default false
382
- */
380
+ * Used to add the disableImageOptimization option in the field. Only used when the type of the field is image
381
+ * @default false
382
+ */
383
383
  disableImageOptimization?: boolean;
384
384
  /**
385
- * Only used if the field type is REFERENCE. Used to filter the list of referenced items.
386
- */
385
+ * Only used if the field type is REFERENCE. Used to filter the list of referenced items.
386
+ */
387
387
  filter?: {
388
388
  formList?: Record<string, any>;
389
389
  filterList?: Record<string, any>;
@@ -444,6 +444,7 @@ interface ActionOptions {
444
444
  new?: Action;
445
445
  edit?: Action;
446
446
  delete?: Action;
447
+ import?: Action;
447
448
  bulkDelete?: Action;
448
449
  /**
449
450
  * Any extra action to be added.
@@ -694,6 +695,11 @@ export interface IResourceFile {
694
695
  subject: string;
695
696
  html: string;
696
697
  }) => Promise<void>;
698
+ /**
699
+ * The function called after importing the data from the imported file
700
+ * @default undefined
701
+ */
702
+ afterImport?: (req: IRequest, currentUser: Document, data: string[][]) => Promise<any>;
697
703
  };
698
704
  /**
699
705
  * Array of properties that should be appeared in the list action.
@@ -59,6 +59,7 @@ interface IAction {
59
59
  edit: IActionMin;
60
60
  new: IActionMin;
61
61
  show: IActionMin;
62
+ import: IActionMin;
62
63
  extras?: IExtras;
63
64
  }
64
65
  interface IExtras {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "identity-admin",
3
- "version": "1.28.15",
3
+ "version": "1.28.17",
4
4
  "description": "",
5
5
  "main": "lib/Dashboard.js",
6
6
  "types": "lib/Dashbord.d.ts",
@@ -52,6 +52,7 @@
52
52
  "express-session": "^1.17.3",
53
53
  "lodash": "^4.17.21",
54
54
  "memory-cache": "^0.2.0",
55
+ "multer": "^2.0.2",
55
56
  "node-xlsx": "^0.21.0",
56
57
  "passport": "^0.6.0",
57
58
  "passport-local": "^1.0.0",