@pxp-nd/core 1.2.81 → 1.2.83
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/dist/interfaces.d.ts
CHANGED
|
@@ -219,7 +219,7 @@ class Controller {
|
|
|
219
219
|
}
|
|
220
220
|
});
|
|
221
221
|
}
|
|
222
|
-
async genericMethodWrapper(params, req, next, res, methodName, dbsettings, readonly, permission =
|
|
222
|
+
async genericMethodWrapper(params, req, next, res, methodName, dbsettings, readonly, permission = false, log = true, logConfig = {}, isHtml, isFile) {
|
|
223
223
|
if (dbsettings === 'Orm') {
|
|
224
224
|
await index_1.__(this.ormMethodWrapper(params, req, next, res, methodName, readonly, permission, log, logConfig, isHtml, isFile));
|
|
225
225
|
}
|
|
@@ -230,11 +230,11 @@ class Controller {
|
|
|
230
230
|
await this.sqlMethodWrapper(params, next, res, methodName, readonly, permission, log, logConfig);
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
|
-
async ormMethodWrapper(params, req, next, res, methodName, readonly, permission =
|
|
233
|
+
async ormMethodWrapper(params, req, next, res, methodName, readonly, permission = false, log = true, logConfig = {}, isHtml = false, isFile = false) {
|
|
234
234
|
let metResponse;
|
|
235
235
|
if (permission) {
|
|
236
|
-
if (this.user
|
|
237
|
-
const hasPermission = await index_1.__(index_1.userHasPermission(this.
|
|
236
|
+
if (this.user) {
|
|
237
|
+
const hasPermission = await index_1.__(index_1.userHasPermission(this.user, this.transactionCode, this.config.permissionFunction));
|
|
238
238
|
if (!hasPermission) {
|
|
239
239
|
throw new index_1.PxpError(403, 'Access denied to execute this method');
|
|
240
240
|
}
|
|
@@ -108,7 +108,7 @@ const IsFile = (isFile = false) => (target, propertyKey) => setProperty(target,
|
|
|
108
108
|
exports.IsFile = IsFile;
|
|
109
109
|
const DbSettings = (modelType) => (target, propertyKey) => setProperty(target, propertyKey)(modelType, 'dbsettings');
|
|
110
110
|
exports.DbSettings = DbSettings;
|
|
111
|
-
const Permission = (permission =
|
|
111
|
+
const Permission = (permission = false) => (target, propertyKey) => setProperty(target, propertyKey)(permission, 'permission');
|
|
112
112
|
exports.Permission = Permission;
|
|
113
113
|
const Log = (log = true, config = {}) => {
|
|
114
114
|
return (target, propertyKey) => {
|
|
@@ -17,7 +17,7 @@ interface ScriptInterface {
|
|
|
17
17
|
scriptCode: string;
|
|
18
18
|
scriptFunction: (manager: EntityManager) => void;
|
|
19
19
|
}
|
|
20
|
-
declare const userHasPermission: (
|
|
20
|
+
declare const userHasPermission: (user: any, transaction: string, permissionFunction: boolean | ((user: any, transaction: string) => Promise<boolean>)) => Promise<boolean>;
|
|
21
21
|
declare const insertLog: (username: string, macaddres: string, ip: string, logType: string, desc: string, proc: string, trans: string, query: string, req: Record<string, unknown>, resp: string, err: string, timeEx: number, logConfig: Record<string, unknown>) => Promise<number>;
|
|
22
22
|
export { userHasPermission, insertLog };
|
|
23
23
|
export type { ScriptInterface };
|
|
@@ -21,18 +21,25 @@ require("reflect-metadata");
|
|
|
21
21
|
const typeorm_1 = require("typeorm");
|
|
22
22
|
// import { Role } from '@pxp-nd/entities';
|
|
23
23
|
const Log_1 = __importDefault(require("../../../entities/Log"));
|
|
24
|
-
const userHasPermission =
|
|
25
|
-
|
|
24
|
+
const userHasPermission = async (user, transaction, permissionFunction) => {
|
|
25
|
+
if (typeof permissionFunction === 'function') {
|
|
26
|
+
return await permissionFunction(user, transaction);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
/*const userRes = await getManager()
|
|
26
30
|
.createQueryBuilder(Role, 'role')
|
|
27
31
|
.innerJoinAndSelect('role.uis', 'ui')
|
|
28
32
|
.innerJoin('role.users', 'user')
|
|
29
33
|
.innerJoin('ui.transactions', 'uiTran')
|
|
30
34
|
.innerJoin('uiTran.transaction', 'transac')
|
|
31
35
|
.select('COUNT(*) AS count')
|
|
32
|
-
.where('"user".user_id = :userId', { userId })
|
|
36
|
+
.where('"user".user_id = :userId', { userId: user.userId })
|
|
33
37
|
.andWhere('transac.code= :codeTrans', { codeTrans: transaction })
|
|
34
38
|
.getRawOne();
|
|
35
|
-
|
|
39
|
+
|
|
40
|
+
return userRes.count === '0' ? false : true;*/
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
36
43
|
};
|
|
37
44
|
exports.userHasPermission = userHasPermission;
|
|
38
45
|
const insertLog = async (username, macaddres, ip, logType, desc, proc, trans, query, req, resp, err, timeEx, logConfig) => {
|