midway-fatcms 0.0.1-beta.54 → 0.0.1-beta.55

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.
@@ -23,8 +23,9 @@ export declare class AuthService {
23
23
  /**
24
24
  * 创建一个toC端的UserSession
25
25
  * @param consumerUserInfo
26
+ * @param loadRoleCodes
26
27
  */
27
- createUserSessionForConsumer(consumerUserInfo: IConsumerUserInfo): Promise<{
28
+ createUserSessionForConsumer(consumerUserInfo: IConsumerUserInfo, loadRoleCodes?: boolean): Promise<{
28
29
  sessionId: string;
29
30
  loginName: string;
30
31
  accountId: string;
@@ -69,14 +69,22 @@ let AuthService = class AuthService {
69
69
  /**
70
70
  * 创建一个toC端的UserSession
71
71
  * @param consumerUserInfo
72
+ * @param loadRoleCodes
72
73
  */
73
- async createUserSessionForConsumer(consumerUserInfo) {
74
+ async createUserSessionForConsumer(consumerUserInfo, loadRoleCodes) {
74
75
  const sessionId = (0, functions_1.createUniqueId)();
76
+ const accountId = consumerUserInfo.accountId;
77
+ let roleCodes = [];
78
+ let functionCodes = [];
79
+ if (loadRoleCodes === true) {
80
+ roleCodes = await this.queryUserRoleCodeList(accountId);
81
+ functionCodes = await this.queryFunctionCodeList(roleCodes);
82
+ }
75
83
  const sessionInfo = {
76
84
  nickName: consumerUserInfo.nickName,
77
85
  avatar: consumerUserInfo.avatar,
78
- roleCodes: [],
79
- functionCodes: [],
86
+ roleCodes: roleCodes,
87
+ functionCodes: functionCodes,
80
88
  loginName: consumerUserInfo.loginName,
81
89
  sessionId,
82
90
  accountId: consumerUserInfo.accountId,
@@ -28,6 +28,8 @@ export declare class CrudStdService extends ApiBaseService {
28
28
  * 执行普通CRUD
29
29
  */
30
30
  executeStdQuery(stdAction: ICrudStdActionParams, params: IRequestModelCrudProExt, sqlSimpleName: KeysOfSimpleSQL): Promise<ExecuteContext>;
31
+ private handleResult;
32
+ private handleResultDataPermissionBySettingKey;
31
33
  /**
32
34
  * 获取appInfo 并且拿到当前settingKey相关的信息
33
35
  * @param appCode
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CrudStdService = exports.SPECIAL_SETTING_KEY = void 0;
13
13
  /* eslint-disable prettier/prettier */
14
14
  const _ = require("lodash");
15
+ const ejs = require("ejs");
15
16
  const core_1 = require("@midwayjs/core");
16
17
  const CurdMixService_1 = require("../curd/CurdMixService");
17
18
  const keys_1 = require("../../libs/crud-pro/models/keys");
@@ -80,10 +81,57 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
80
81
  // 业务系统自定义的修改:查询前的查询条件:cfgModel
81
82
  await global_config_1.GLOBAL_STATIC_CONFIG.getConfig().bizUpdateCfgModelForCrudStd(params, cfgModel, appInfo, this.ctx);
82
83
  const crudExeCtx = await this.curdMixService.executeCrudByCfg(params, cfgModel);
84
+ // 处理结果
85
+ await this.handleResult(stdAction, params, cfgModel, appInfo, crudExeCtx);
83
86
  // 业务系统自定义的修改:查询后的返回值。
84
87
  await global_config_1.GLOBAL_STATIC_CONFIG.getConfig().bizUpdateExecuteContextForCrudStd(params, cfgModel, appInfo, this.ctx, crudExeCtx);
85
88
  return crudExeCtx;
86
89
  }
90
+ async handleResult(stdAction, params, cfgModel, appInfo, crudExeCtx) {
91
+ await this.handleResultDataPermissionBySettingKey(stdAction, params, cfgModel, appInfo, crudExeCtx);
92
+ }
93
+ async handleResultDataPermissionBySettingKey(stdAction, params, cfgModel, appInfo, crudExeCtx) {
94
+ const { settingKey } = stdAction || {};
95
+ if (settingKey !== exports.SPECIAL_SETTING_KEY.QUERY_LIST && settingKey !== exports.SPECIAL_SETTING_KEY.QUERY_ONE) {
96
+ return;
97
+ }
98
+ const rows = crudExeCtx.getResRows();
99
+ if (!Array.isArray(rows)) {
100
+ return;
101
+ }
102
+ const actionColumns = _.get(appInfo, 'stdCrudCfgObj.actionColumns');
103
+ const checkDataPermissionObjBySettingKey = (record) => {
104
+ var _a;
105
+ const permissionObj = {};
106
+ let count = 0;
107
+ const sessionInfo = (_a = this.ctx.userSession) === null || _a === void 0 ? void 0 : _a.getSessionInfo();
108
+ for (let index = 0; index < actionColumns.length; index++) {
109
+ const column = actionColumns[index];
110
+ const rowAuthCfg = (0, functions_1.parseJsonObject)(column.rowAuthCfg);
111
+ if (rowAuthCfg && typeof rowAuthCfg.authByExpress === 'string') {
112
+ const authByExpress = rowAuthCfg.authByExpress.trim();
113
+ if (authByExpress) {
114
+ const authResult = ejs.render(authByExpress, { record, sessionInfo, params, _ });
115
+ permissionObj[column.settingKey] = authResult;
116
+ count++;
117
+ }
118
+ }
119
+ }
120
+ if (count > 0) {
121
+ return permissionObj;
122
+ }
123
+ return null;
124
+ };
125
+ if (Array.isArray(actionColumns) && actionColumns.length > 0) {
126
+ for (let index = 0; index < rows.length; index++) {
127
+ const row = rows[index];
128
+ const dataPermissionObjBySettingKey = checkDataPermissionObjBySettingKey(row);
129
+ if (dataPermissionObjBySettingKey) {
130
+ row['__dataPermissionObjBySettingKey'] = dataPermissionObjBySettingKey;
131
+ }
132
+ }
133
+ }
134
+ }
87
135
  /**
88
136
  * 获取appInfo 并且拿到当前settingKey相关的信息
89
137
  * @param appCode
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "midway-fatcms",
3
- "version": "0.0.1-beta.54",
3
+ "version": "0.0.1-beta.55",
4
4
  "description": "This is a midway component sample",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -44,6 +44,7 @@
44
44
  "@midwayjs/upload": "^3.16.1",
45
45
  "@midwayjs/validate": "^3.16.1",
46
46
  "@midwayjs/view-ejs": "^3.20.4",
47
+ "@types/ejs": "3.1.5",
47
48
  "@types/humps": "2.0.6",
48
49
  "@types/jest": "^29.2.0",
49
50
  "@types/koa": "^2.13.4",
@@ -73,7 +74,8 @@
73
74
  "ts-jest": "^29.0.3",
74
75
  "typescript": "~4.8.0",
75
76
  "urlsafe-base64": "^1.0.0",
76
- "fast-csv": "^5.0.2"
77
+ "fast-csv": "^5.0.2",
78
+ "ejs": "^3.1.10"
77
79
  },
78
80
  "dependencies": {}
79
81
  }