@steedos/standard-permission 2.5.0-beta.13 → 2.5.0-beta.14

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.
@@ -0,0 +1,111 @@
1
+ name: copy
2
+ amis_schema: |-
3
+ {
4
+ "type": "service",
5
+ "body": [
6
+ {
7
+ "type": "button",
8
+ "label": "复制",
9
+ "id": "u:copy",
10
+ "onEvent": {
11
+ "click": {
12
+ "weight": 0,
13
+ "actions": [
14
+ {
15
+ "dialog": {
16
+ "type": "dialog",
17
+ "title": "复制 当前简档记录",
18
+ "body": [
19
+ {
20
+ "type": "form",
21
+ "title": "表单",
22
+ "body": [
23
+ {
24
+ "label": "显示名称",
25
+ "type": "input-text",
26
+ "value": "${record.label} 的副本",
27
+ "name": "label_input",
28
+ "id": "u:24e89a11d437",
29
+ "required": true
30
+ },
31
+ {
32
+ "type": "input-text",
33
+ "name": "name_input",
34
+ "value": "${record.name}_copy",
35
+ "label": "api名称",
36
+ "id": "u:27bd7cfe3e12",
37
+ "required": true
38
+ }
39
+ ],
40
+ "api": {
41
+ "url": "${context.rootUrl}/api/permission/permission_set/copy",
42
+ "method": "post",
43
+ "messages": {},
44
+ "requestAdaptor": "delete api.body.label_input;\ndelete api.body.name_input;",
45
+ "data": {
46
+ "&": "$$",
47
+ "label": "${label_input}",
48
+ "name": "${name_input}",
49
+ "originalPermissionSetId": "${record._id}"
50
+ },
51
+ "headers": {
52
+ "Authorization": "Bearer ${context.tenantId},${context.authToken}"
53
+ }
54
+ },
55
+ "onEvent": {
56
+ "submitSucc": {
57
+ "weight": 0,
58
+ "actions": [
59
+ {
60
+ "args": {
61
+ "url": "${context.rootUrl}/app/${appId}/${objectName}/view/${result.data.recordId}",
62
+ "blank": false
63
+ },
64
+ "actionType": "url"
65
+ }
66
+ ]
67
+ }
68
+ },
69
+ "id": "u:818f7b68417b",
70
+ "mode": "normal"
71
+ }
72
+ ],
73
+ "showCloseButton": true,
74
+ "showErrorMsg": true,
75
+ "showLoading": true,
76
+ "id": "u:9f9b042404a1",
77
+ "closeOnEsc": false,
78
+ "dataMapSwitch": false,
79
+ "size": "md"
80
+ },
81
+ "actionType": "dialog"
82
+ }
83
+ ]
84
+ }
85
+ }
86
+ }
87
+ ],
88
+ "regions": [
89
+ "body"
90
+ ],
91
+ "data": {
92
+ "context": {},
93
+ "app_id": "",
94
+ "tab_id": "",
95
+ "object_name": "",
96
+ "dataComponentId": "",
97
+ "record_id": "",
98
+ "record": {},
99
+ "permissions": {}
100
+ },
101
+ "bodyClassName": "p-0",
102
+ "id": "u:4b81eda72f12"
103
+ }
104
+ is_enable: true
105
+ label: 复制
106
+ 'on': record_only
107
+ type: amis_button
108
+ visible: !!js/function |
109
+ function (object_name, record_id, record_permissions, record) {
110
+ return record.record.type == 'profile';
111
+ }
@@ -2,7 +2,7 @@
2
2
  * @Author: sunhaolin@hotoa.com
3
3
  * @Date: 2022-05-26 16:56:54
4
4
  * @LastEditors: sunhaolin@hotoa.com
5
- * @LastEditTime: 2022-05-26 19:28:09
5
+ * @LastEditTime: 2023-04-25 17:13:09
6
6
  * @Description: 复制已有简档来创建新简档
7
7
  */
8
8
  'use strict';
@@ -39,6 +39,9 @@ router.post('/api/permission/permission_set/copy', core.requireAuthentication, a
39
39
  const psObj = objectql.getObject('permission_set');
40
40
  const poObj = objectql.getObject('permission_objects');
41
41
  const pfObj = objectql.getObject('permission_fields');
42
+ const ptObj = objectql.getObject('permission_tabs');
43
+
44
+ // const originalPermissionSet = (await psObj.find({ filters:[ ['name', '=', originalPermissionSetId], ['space', '=', spaceId] ] }, userSession))[0]
42
45
 
43
46
  const originalPermissionSet = await psObj.findOne(originalPermissionSetId, {}, userSession);
44
47
  if (!originalPermissionSet) {
@@ -60,15 +63,20 @@ router.post('/api/permission/permission_set/copy', core.requireAuthentication, a
60
63
  };
61
64
 
62
65
  // 创建新简档
63
- delete originalPermissionSet._id;
64
- const newPermissionSet = await psObj.insert({
66
+ let newPermissionSetData = {
65
67
  ...originalPermissionSet,
66
- ...baseInfo,
68
+ ...baseInfo,
69
+ is_system: false,
67
70
  name,
68
71
  label
69
- });
72
+ };
70
73
 
71
- // 创建对象权限
74
+ delete newPermissionSetData._id;
75
+ delete newPermissionSetData.record_permissions;
76
+ const newPermissionSet = await psObj.insert(newPermissionSetData);
77
+
78
+
79
+ // 创建对象权限和选项卡权限
72
80
  if (newPermissionSet) {
73
81
  const orininalPermissionSetName = originalPermissionSet.name;
74
82
  const { _id: newPermissionSetId, name: newPermissionSetName } = newPermissionSet;
@@ -77,7 +85,7 @@ router.post('/api/permission/permission_set/copy', core.requireAuthentication, a
77
85
  for (const poDoc of originalPermissionObjects) {
78
86
  // 创建新的对象权限
79
87
  delete poDoc._id;
80
- const newPermissionObject = await poObj.insert({
88
+ const newPermissionObject = await poObj.directInsert({
81
89
  ...poDoc,
82
90
  ...baseInfo,
83
91
  permission_set_id: newPermissionSetId,
@@ -101,9 +109,26 @@ router.post('/api/permission/permission_set/copy', core.requireAuthentication, a
101
109
  // }
102
110
  }
103
111
 
112
+
113
+ // 创建选项卡权限
114
+ const originalPermissionTabs = await ptObj.find({ filters: [['space', '=', spaceId], ['permission_set', '=', originalPermissionSet.name]] }, userSession);
115
+ // 遍历原有的选项卡权限
116
+ for (const ptDoc of originalPermissionTabs) {
117
+ delete ptDoc._id;
118
+ ptDoc.permission_set = name;
119
+ const newPermissionTabs = await ptObj.directInsert({
120
+ ...ptDoc,
121
+ ...baseInfo,
122
+ });
123
+ }
124
+
104
125
  }
105
126
 
106
- res.status(200).send({ message: 'success' });
127
+ res.status(200).send({
128
+ message: 'success' ,
129
+ recordId: newPermissionSet._id
130
+ });
131
+
107
132
  } catch (error) {
108
133
  console.error(error);
109
134
  res.status(500).send({ error: error.message });
@@ -91,6 +91,21 @@ module.exports = {
91
91
  this.data.values.push(doc);
92
92
  }
93
93
  })
94
+
95
+ // 为了解决默认简档自定义后生成新的_id,导致无法查询到数据的问题
96
+ const filtersStr = this.query.filters;
97
+ const regex = /(?<=permission_set_id eq ')\w+(?=')/g;
98
+ const matches = filtersStr.match(regex);
99
+ if (matches) {
100
+ const permissionSetId = matches[0];
101
+ // 查找permissionSetId对应的permissionSet
102
+ const permissionSetDoc = await objectql.getObject('permission_set').findOne(permissionSetId);
103
+ if (permissionSetDoc) {
104
+ // 替换this.query.filters中全部的的permission_set_id为permissionSetDoc.name
105
+ this.query.filters = this.query.filters.replace(regex, permissionSetDoc.name).replace(`permission_set_id eq '${permissionSetDoc.name}'`, `(permission_set_id eq '${permissionSetDoc.name}') or (permission_set_id eq '${permissionSetId}')`);
106
+ }
107
+ }
108
+
94
109
  const records = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
95
110
  if (records.length > 0) {
96
111
  this.data.values = records;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/standard-permission",
3
- "version": "2.5.0-beta.13",
3
+ "version": "2.5.0-beta.14",
4
4
  "main": "package.service.js",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -12,5 +12,5 @@
12
12
  "description": "steedos package",
13
13
  "repository": {},
14
14
  "license": "MIT",
15
- "gitHead": "7027a5e2cff04814d2284fc63a1d738e32c90feb"
15
+ "gitHead": "cf9e5f923a350dc11801e32ab9103f688349be14"
16
16
  }