identity-admin 1.28.7 → 1.28.9

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.
@@ -4,5 +4,6 @@ import { IResourceFile } from '../types/IResourceFile';
4
4
  export default class ActionController {
5
5
  private resources;
6
6
  constructor(resources: IResourceFile[]);
7
+ sendDraftEmail(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
7
8
  execute(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
8
9
  }
@@ -29,12 +29,47 @@ const Repository_1 = __importDefault(require("../repositories/Repository"));
29
29
  const ResourceUtils_1 = require("../utils/ResourceUtils");
30
30
  const UserActionsLog_1 = __importDefault(require("../models/userActionsLog/UserActionsLog"));
31
31
  const PermissionResource_1 = require("../helpers/Permissions/PermissionResource");
32
+ const helpers_1 = require("../types/helpers");
32
33
  let ActionController = class ActionController {
33
34
  constructor(resources) {
34
35
  this.resources = resources;
35
36
  }
37
+ sendDraftEmail(req, res) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const record = req.body.record;
40
+ const modelName = req.body.modelName;
41
+ const resource = (0, ResourceUtils_1.getResource)(modelName, this.resources);
42
+ if (!resource) {
43
+ return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
44
+ }
45
+ const repository = new Repository_1.default(resource.properties.resource);
46
+ const sendDraftMail = resource.properties.sendDraftMail;
47
+ if (!sendDraftMail) {
48
+ return ResponseUtils_1.default.unprocessable(res, 'Mail sender is not defined in resource properties', []);
49
+ }
50
+ const oldRecord = yield repository.findById(record._id);
51
+ sendDraftMail(record);
52
+ const response = {
53
+ action: helpers_1.ActionNames.LIST,
54
+ path: StringUtils_1.default.lowerCaseFirstLetter(modelName),
55
+ };
56
+ const newRecord = yield repository.findById(record._id);
57
+ const userActionsLog = new UserActionsLog_1.default({
58
+ action: 'Send Draft',
59
+ modelName,
60
+ userId: req.user._id,
61
+ dataBefore: JSON.stringify(oldRecord),
62
+ dataAfter: JSON.stringify(newRecord),
63
+ resourceId: record._id,
64
+ });
65
+ yield userActionsLog.save();
66
+ return ResponseUtils_1.default.send(res, 200, 'Ok', {
67
+ response,
68
+ });
69
+ });
70
+ }
36
71
  execute(req, res) {
37
- var _a, _b;
72
+ var _a, _b, _c;
38
73
  return __awaiter(this, void 0, void 0, function* () {
39
74
  const record = req.body.record;
40
75
  const modelName = req.body.modelName;
@@ -52,8 +87,8 @@ let ActionController = class ActionController {
52
87
  resource: {
53
88
  name: modelName,
54
89
  path: StringUtils_1.default.lowerCaseFirstLetter(modelName),
55
- repository
56
- }
90
+ repository,
91
+ },
57
92
  };
58
93
  const extraActions = (_b = (_a = resource.properties.actions) === null || _a === void 0 ? void 0 : _a.extras) !== null && _b !== void 0 ? _b : [];
59
94
  const havePermission = yield PermissionResource_1.PermissionResource.havePermission(currentUser.permissionGroupId, actionKey);
@@ -63,27 +98,37 @@ let ActionController = class ActionController {
63
98
  for (var i = 0; i < extraActions.length; i++) {
64
99
  const extraAction = extraActions[i];
65
100
  if (extraAction.key === actionKey) {
66
- const oldRecord = yield repository.findById(record._id);
67
- response = yield extraAction.handler(req, res, data);
68
- const newRecord = yield repository.findById(record._id);
69
- const userActionsLog = new UserActionsLog_1.default({
70
- action: extraAction.name,
71
- modelName,
72
- userId: req.user._id,
73
- dataBefore: JSON.stringify(oldRecord),
74
- dataAfter: JSON.stringify(newRecord),
75
- resourceId: record._id,
76
- });
77
- yield userActionsLog.save();
101
+ if ((_c = resource.properties) === null || _c === void 0 ? void 0 : _c.enableLog) {
102
+ const oldRecord = yield repository.findById(record._id);
103
+ response = yield extraAction.handler(req, res, data);
104
+ const newRecord = yield repository.findById(record._id);
105
+ const userActionsLog = new UserActionsLog_1.default({
106
+ action: extraAction.name,
107
+ modelName,
108
+ userId: req.user._id,
109
+ dataBefore: JSON.stringify(oldRecord),
110
+ dataAfter: JSON.stringify(newRecord),
111
+ resourceId: record._id,
112
+ });
113
+ yield userActionsLog.save();
114
+ }
115
+ else {
116
+ response = yield extraAction.handler(req, res, data);
117
+ }
78
118
  break;
79
119
  }
80
120
  }
81
121
  return ResponseUtils_1.default.send(res, 200, 'Ok', {
82
- response
122
+ response,
83
123
  });
84
124
  });
85
125
  }
86
126
  };
127
+ __decorate([
128
+ (0, inversify_express_utils_1.httpPost)('/execute/send_draft_email'),
129
+ __param(0, (0, inversify_express_utils_1.request)()),
130
+ __param(1, (0, inversify_express_utils_1.response)())
131
+ ], ActionController.prototype, "sendDraftEmail", null);
87
132
  __decorate([
88
133
  (0, inversify_express_utils_1.httpPost)('/execute/:actionKey'),
89
134
  __param(0, (0, inversify_express_utils_1.request)()),
@@ -6,4 +6,5 @@ export default class ModelNames {
6
6
  static AdminPermission: string;
7
7
  static UserActionsLog: string;
8
8
  static AdminNotification: string;
9
+ static MailLog: string;
9
10
  }
@@ -10,3 +10,4 @@ ModelNames.PermissionGroup = 'PermissionGroup';
10
10
  ModelNames.AdminPermission = 'AdminPermission';
11
11
  ModelNames.UserActionsLog = 'UserActionsLog';
12
12
  ModelNames.AdminNotification = 'AdminNotification';
13
+ ModelNames.MailLog = 'MailLog';
@@ -0,0 +1,14 @@
1
+ import { Document, Model, Types } from 'mongoose';
2
+ export interface IMailLogProps {
3
+ _id?: Types.ObjectId;
4
+ to: string;
5
+ subject: string;
6
+ html: string;
7
+ }
8
+ export interface IMailLogDocument extends IMailLogProps, Document {
9
+ _id: Types.ObjectId;
10
+ createdAt: Date;
11
+ updatedAt: Date;
12
+ }
13
+ export default interface IMailLogModel extends Model<IMailLogDocument> {
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import IMailLogModel from './IMailLog';
2
+ declare const MailLog: IMailLogModel;
3
+ export default MailLog;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const mongoose_1 = require("mongoose");
7
+ const ModelNames_1 = __importDefault(require("../ModelNames"));
8
+ const MailLogSchema = new mongoose_1.Schema({
9
+ to: {
10
+ type: String,
11
+ required: true,
12
+ },
13
+ subject: {
14
+ type: String,
15
+ required: true,
16
+ },
17
+ html: {
18
+ type: String,
19
+ required: true,
20
+ },
21
+ }, { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } });
22
+ const MailLog = (0, mongoose_1.model)(ModelNames_1.default.MailLog, MailLogSchema);
23
+ exports.default = MailLog;
@@ -680,6 +680,15 @@ export interface IResourceFile {
680
680
  extras?: {
681
681
  [key: string]: any;
682
682
  };
683
+ /**
684
+ * Used for sending draft mails in mail log
685
+ * @default undefined
686
+ */
687
+ sendDraftMail?: (data: {
688
+ to: string;
689
+ subject: string;
690
+ html: string;
691
+ }) => Promise<void>;
683
692
  };
684
693
  /**
685
694
  * Array of properties that should be appeared in the list action.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "identity-admin",
3
- "version": "1.28.7",
3
+ "version": "1.28.9",
4
4
  "description": "",
5
5
  "main": "lib/Dashboard.js",
6
6
  "types": "lib/Dashbord.d.ts",