@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.
@@ -48,5 +48,6 @@ export interface IConfigPxpApp {
48
48
  enableSocket?: boolean;
49
49
  expressJsonConfig?: IConfigExpress;
50
50
  expressUrlEncodedConfig?: IConfigExpress;
51
+ permissionFunction?: boolean | ((user: any, transaction: string) => Promise<boolean>);
51
52
  }
52
53
  export {};
@@ -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 && this.user.roles && this.user.roles.length === 0) {
237
- const hasPermission = await index_1.__(index_1.userHasPermission(this.config.entities.Role)(this.user.userId, this.transactionCode));
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: (Role: any) => (userId: number, transaction: string) => Promise<boolean>;
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 = (Role) => async (userId, transaction) => {
25
- const user = await typeorm_1.getManager()
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
- return user.count === '0' ? false : true;
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) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pxp-nd/core",
3
- "version": "1.2.81",
3
+ "version": "1.2.82",
4
4
  "description": "Contains main files for pxp-nd",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",