@steedos/service-core-objects 3.0.0-beta.138 → 3.0.0-beta.139

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.
@@ -1,142 +1,6 @@
1
1
  const objectql = require('@steedos/objectql');
2
- const auth = require('@steedos/auth');
3
2
  const _ = require('underscore');
4
3
 
5
- /**
6
- * 校验记录的 company 是否在指定授权范围内
7
- * @param {*} object_name
8
- * @param {*} userId
9
- * @param {*} doc
10
- */
11
- const checkCompany = async (object_name, userId, doc) => {
12
- const userSession = await auth.getSessionByUserId(userId, doc.space);
13
-
14
- if (!userSession || userSession.is_space_admin) {
15
- return;
16
- }
17
-
18
- let userObjectPermission = null;
19
-
20
- try {
21
- userObjectPermission = await objectql.getObject(object_name).getUserObjectPermission(userSession);
22
- } catch (error) {
23
- return;
24
- }
25
-
26
- if (userObjectPermission.modifyAllRecords) {
27
- return true;
28
- }
29
-
30
- let allowCompanyIds = [];
31
-
32
- //与client端保持一致,始终授权用户所属分部
33
- if (!_.isEmpty(userSession.company_ids)) {
34
- allowCompanyIds.push(...userSession.company_ids);
35
- }
36
- if (!_.isEmpty(userObjectPermission.modifyAssignCompanysRecords)) {
37
- allowCompanyIds.push(...userObjectPermission.modifyAssignCompanysRecords);
38
- }
39
-
40
- if (_.has(doc, "company_id")) {
41
- if (!_.include(allowCompanyIds, doc.company_id)) {
42
- throw new Error(`未获得分部授权`);
43
- }
44
- }
45
-
46
- if (_.has(doc, "company_ids")) {
47
- if (_.difference(doc.company_ids, allowCompanyIds).length > 0) {
48
- throw new Error(`未获得分部授权`);
49
- }
50
- }
51
- }
52
-
53
- const beforeInsertBase = async function () {
54
- const { doc, userId } = this;
55
- // 迁移到insert函数中提前执行了
56
- // doc.created = new Date();
57
- // doc.modified = new Date();
58
- // if (userId) {
59
- // if (!doc.owner) {
60
- // doc.owner = userId;
61
- // }
62
- // if (doc.owner === '{userId}') {
63
- // doc.owner = userId;
64
- // }
65
- // doc.created_by = userId;
66
- // doc.modified_by = userId;
67
- // }
68
- var extras = ["spaces", "company", "organizations", "users", "space_users"];
69
- if (extras.indexOf(this.object_name) < 0 && doc.space) {
70
- /* company_ids/company_id默认值逻辑*/
71
- if (!doc.company_id || !doc.company_ids) {
72
- var su;
73
- if (userId) {
74
- const spaceUsers = await objectql.getObject("space_users").find({ filters: [['space', '=', doc.space], ['user', '=', userId]], fields: ['company_id'] });
75
- su = spaceUsers.length > 0 ? spaceUsers[0] : null
76
- }
77
- if (!doc.company_id) {
78
- if (doc.company_ids && doc.company_ids.length) {
79
- /* 如果用户在界面上指定了company_ids,则取第一个值 */
80
- doc.company_id = doc.company_ids[0];
81
- }
82
- else if (su && su.company_id) {
83
- doc.company_id = su.company_id;
84
- }
85
- }
86
- if (!doc.company_ids) {
87
- if (doc.company_id) {
88
- /* 如果用户在界面上指定了company_id,则取其值输入 */
89
- doc.company_ids = [doc.company_id];
90
- }
91
- else if (su && su.company_id) {
92
- doc.company_ids = [su.company_id];
93
- }
94
- }
95
- }
96
- await checkCompany(this.object_name, userId, doc);
97
- }
98
- }
99
- const beforeUpdateBase = async function () {
100
- const { doc, userId } = this;
101
- if (!doc) {
102
- return;
103
- }
104
- // 迁移到update函数中提前执行了
105
- // doc.modified = new Date();
106
- // if (userId) {
107
- // doc.modified_by = userId;
108
- // }
109
- var extras = ["spaces", "company", "organizations", "users", "space_users"];
110
- if (extras.indexOf(this.object_name) < 0) {
111
- /* company_ids/company_id级联修改逻辑*/
112
- if (_.has(doc, "company_ids")) {
113
- /*
114
- 原则上应该将 company_ids 设置为可编辑,company_id 设置为只读。
115
- 当 company_ids 可编辑时,修改 company_ids 同时更新 company_id = company_ids[0]
116
- */
117
- var firstCompanyId = doc.company_ids ? doc.company_ids[0] : null;
118
- if (firstCompanyId) {
119
- doc.company_id = firstCompanyId;
120
- }
121
- else {
122
- doc.company_id = null;
123
- }
124
- }
125
- else if (_.has(doc, "company_id")) {
126
- /*
127
- 考虑到兼容老项目,允许将 company_id 设置为可编辑,此时 company_ids 必须只读。
128
- 当 company_id 可编辑时,修改 company_id 同时更新 company_ids = [company_id]
129
- */
130
- if (doc.company_id) {
131
- doc.company_ids = [doc.company_id];
132
- }
133
- else {
134
- doc.company_ids = null;
135
- }
136
- }
137
- await checkCompany(this.object_name, userId, doc);
138
- }
139
- }
140
4
  const afterDeleteBase = async function () {
141
5
  const { object_name, previousDoc } = this;
142
6
  if (!previousDoc) {
@@ -148,22 +12,21 @@ const afterDeleteBase = async function () {
148
12
  const fields = objectConfig.fields;
149
13
  const fieldsName = _.keys(previousDoc);
150
14
 
151
- _.each(fieldsName, function (fieldName) {
15
+ for (const fieldName of fieldsName) {
152
16
  const fieldProps = fields[fieldName];
153
17
  const indexOfType = fieldProps && ['file', 'image'].indexOf(fieldProps.type);
154
18
  if (indexOfType > -1 && previousDoc[fieldName] && previousDoc[fieldName].length) {
155
- const collection = [cfs.files, cfs.images][indexOfType];
19
+ const collection = ['cfs_files_filerecord', 'cfs_images_filerecord'][indexOfType];
156
20
  let ids = previousDoc[fieldName]
157
21
  if (typeof ids === 'string') {
158
22
  ids = [ids]
159
23
  }
160
- _.each(ids, function (id) {
161
- collection.remove({
162
- "_id": id
163
- });
164
- })
24
+ for (const id of ids) {
25
+ await objectql.getObject(collection).delete(id)
26
+ }
165
27
  }
166
- });
28
+ }
29
+
167
30
  if ("cms_files" != object_name) {
168
31
  // 删除附件
169
32
  const cmsFilesObj = objectql.getObject('cms_files')
@@ -13,7 +13,7 @@ module.exports = {
13
13
  return toastr.warning("请先启动对象");
14
14
  }
15
15
 
16
- window.open(Steedos.getRelativeUrl("/app/__preview/" + (record.name || this.record.name)));
16
+ window.open(Steedos.getRelativeUrl("/app/-/" + (record.name || this.record.name)));
17
17
  },
18
18
  show_objectVisible: function(object_name, record_id, record_permissions, data) {
19
19
  var record = data && data.record;
@@ -225,18 +225,17 @@ fields:
225
225
  visible_on: "{{global.mode ==='read' ? true : false}}"
226
226
  disabled: true
227
227
  list_views:
228
- default:
229
- columns:
230
- - name
231
- - report_type
232
- - object_name
233
- - is_system
234
228
  all:
235
229
  label: All Reports
236
230
  filter_scope: space
237
231
  filter_fields:
238
232
  - report_type
239
233
  - created
234
+ columns:
235
+ - name
236
+ - report_type
237
+ - object_name
238
+ - is_system
240
239
  # application:
241
240
  # label: Application Reports
242
241
  # filter_scope: space
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-core-objects",
3
- "version": "3.0.0-beta.138",
3
+ "version": "3.0.0-beta.139",
4
4
  "main": "package.service.js",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -9,12 +9,12 @@
9
9
  "steedos"
10
10
  ],
11
11
  "dependencies": {
12
- "@steedos/service-package-loader": "3.0.0-beta.138",
12
+ "@steedos/service-package-loader": "3.0.0-beta.139",
13
13
  "json2xls": "^0.1.2",
14
14
  "lodash": "^4.17.21"
15
15
  },
16
16
  "description": "steedos package",
17
17
  "repository": {},
18
18
  "license": "MIT",
19
- "gitHead": "7fb737dcbfd3ad7d7b8303e17ea3fff57f45da98"
19
+ "gitHead": "8d6ec68f7c87be83db0a0eba893300457f71657f"
20
20
  }
@@ -1,12 +0,0 @@
1
- /*
2
- * @Author: sunhaolin@hotoa.com
3
- * @Date: 2022-12-12 11:32:14
4
- * @LastEditors: sunhaolin@hotoa.com
5
- * @LastEditTime: 2022-12-12 13:44:53
6
- * @Description:
7
- */
8
- module.exports = {
9
- upgrade: function () {
10
- window.open(`https://www.steedos.com/pricing/platform`);
11
- }
12
- }
@@ -1,4 +0,0 @@
1
- name: upgrade
2
- label: Upgrade
3
- 'on': record
4
- visible: true