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.
- package/lib/controllers/ActionController.d.ts +1 -0
- package/lib/controllers/ActionController.js +61 -16
- package/lib/models/ModelNames.d.ts +1 -0
- package/lib/models/ModelNames.js +1 -0
- package/lib/models/mailLog/IMailLog.d.ts +14 -0
- package/lib/models/mailLog/IMailLog.js +2 -0
- package/lib/models/mailLog/MailLog.d.ts +3 -0
- package/lib/models/mailLog/MailLog.js +23 -0
- package/lib/types/IResourceFile.d.ts +9 -0
- package/package.json +1 -1
|
@@ -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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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)()),
|
package/lib/models/ModelNames.js
CHANGED
|
@@ -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,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.
|