@pxp-nd/core 1.2.81 → 1.2.82
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
|
@@ -233,8 +233,8 @@ class Controller {
|
|
|
233
233
|
async ormMethodWrapper(params, req, next, res, methodName, readonly, permission = true, 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
|
}
|
|
@@ -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) => {
|