1
1
/*
2
2
3
3
* @Date : 2022-06-15 15:49:44
4
- * @LastEditors : sunhaolin@hotoa .com
5
- * @LastEditTime : 2022-11-07 20:55:13
4
+ * @LastEditors : baozhoutao@steedos .com
5
+ * @LastEditTime : 2022-12-06 10:31:30
6
6
* @Description :
7
7
*/
8
8
@@ -17,7 +17,7 @@ import { getSteedosSchema, getUserLocale } from '../../..';
17
17
import { getQueryFields } from "./getQueryFields" ;
18
18
import { getPrimaryFieldType } from "./getPrimaryFieldType" ;
19
19
20
- import { BASIC_TYPE_MAPPING , EXPAND_SUFFIX , DISPLAY_PREFIX , RELATED_PREFIX , GRAPHQL_ACTION_PREFIX , UI_PREFIX } from "./consts" ;
20
+ import { BASIC_TYPE_MAPPING , EXPAND_SUFFIX , DISPLAY_PREFIX , RELATED_PREFIX , GRAPHQL_ACTION_PREFIX , UI_PREFIX , PERMISSIONS_PREFIX } from "./consts" ;
21
21
22
22
export function generateActionGraphqlProp ( actionName : string , objectConfig : SteedosObjectTypeConfig ) {
23
23
let gplObj : any = { } ;
@@ -76,6 +76,26 @@ export function generateActionGraphqlProp(actionName: string, objectConfig: Stee
76
76
return gplObj ;
77
77
}
78
78
79
+ const callObjectServiceAction = async function ( actionName , userSession , data ?) {
80
+ const broker = getSteedosSchema ( ) . broker ;
81
+ return broker . call ( actionName , data , { meta : { user : userSession } } )
82
+ }
83
+
84
+ const formatFileSize = function ( fileSize ) {
85
+ var rev , unit ;
86
+ rev = fileSize / 1024.00 ;
87
+ unit = 'KB' ;
88
+ if ( rev > 1024.00 ) {
89
+ rev = rev / 1024.00 ;
90
+ unit = 'MB' ;
91
+ }
92
+ if ( rev > 1024.00 ) {
93
+ rev = rev / 1024.00 ;
94
+ unit = 'GB' ;
95
+ }
96
+ return rev . toFixed ( 2 ) + unit ;
97
+ } ;
98
+
79
99
export function generateSettingsGraphql ( objectConfig : SteedosObjectTypeConfig ) {
80
100
let objectName = objectConfig . name ;
81
101
let fields = objectConfig . fields ;
@@ -194,6 +214,27 @@ export function generateSettingsGraphql(objectConfig: SteedosObjectTypeConfig) {
194
214
${ type }
195
215
` ;
196
216
217
+ // _permissions
218
+ let _permissions_type_name = `${ PERMISSIONS_PREFIX } _${ objectName } ` ;
219
+ type += `${ PERMISSIONS_PREFIX } : ${ _permissions_type_name } ` ;
220
+ resolvers [ objectName ] [ PERMISSIONS_PREFIX ] = {
221
+ action : `${ getObjectServiceName (
222
+ objectName
223
+ ) } .${ GRAPHQL_ACTION_PREFIX } ${ PERMISSIONS_PREFIX } `,
224
+ rootParams : {
225
+ _id : "_id"
226
+ } ,
227
+ params : {
228
+ '__objectName' : objectName
229
+ } ,
230
+ } ;
231
+ // define _permissions_type
232
+ let _permissions_type = _getPermissionsType ( _permissions_type_name , fields ) ;
233
+ type = gql `
234
+ ${ _permissions_type }
235
+ ${ type }
236
+ ` ;
237
+
197
238
// _related
198
239
if ( objectConfig . enable_files ) {
199
240
let relatedObjName = "cms_files" ;
@@ -478,6 +519,17 @@ export function getGraphqlActions(objectConfig: SteedosObjectTypeConfig) {
478
519
} ,
479
520
} ;
480
521
522
+ actions [ `${ GRAPHQL_ACTION_PREFIX } ${ PERMISSIONS_PREFIX } ` ] = {
523
+ handler : async function ( ctx ) {
524
+ let params = ctx . params ;
525
+ let { __objectName } = params ;
526
+ let userSession = ctx . meta . user ;
527
+ return await callObjectServiceAction ( `@${ __objectName } .getRecordPermissionsById` , userSession , {
528
+ recordId : params . _id
529
+ } ) ; ;
530
+ } ,
531
+ } ;
532
+
481
533
return actions ;
482
534
}
483
535
@@ -988,6 +1040,8 @@ async function translateToUI(objectName, doc, userSession: any, selectorFieldNam
988
1040
}
989
1041
}
990
1042
displayObj [ name ] = fileValue ;
1043
+ } else if ( fType == "filesize" ) {
1044
+ displayObj [ name ] = formatFileSize ( doc [ name ] ) ;
991
1045
} else {
992
1046
displayObj [ name ] = formatBasicFieldValue ( fType , field , doc [ name ] , objConfig , userSession ) ;
993
1047
}
@@ -1049,6 +1103,35 @@ function _getUIType(typeName, fields) {
1049
1103
return type ;
1050
1104
}
1051
1105
1106
+ function _getPermissionsType ( typeName , fields ) {
1107
+ return `
1108
+ type ${ typeName } {
1109
+ allowCreate: Boolean
1110
+ allowCreateFiles: Boolean
1111
+ allowDelete: Boolean
1112
+ allowDeleteFiles: Boolean
1113
+ allowEdit: Boolean
1114
+ allowEditFiles: Boolean
1115
+ allowRead: Boolean
1116
+ allowReadFiles: Boolean
1117
+ disabled_actions: [String]
1118
+ disabled_list_views: [String]
1119
+ field_permissions: JSON
1120
+ modifyAllFiles: Boolean
1121
+ modifyAllRecords: Boolean
1122
+ modifyAssignCompanysRecords: [String]
1123
+ modifyCompanyRecords: Boolean
1124
+ uneditable_fields: [String]
1125
+ unreadable_fields: [String]
1126
+ unrelated_objects: [String]
1127
+ viewAllFiles: Boolean
1128
+ viewAllRecords: Boolean
1129
+ viewAssignCompanysRecords: [String]
1130
+ viewCompanyRecords: Boolean
1131
+ }
1132
+ `
1133
+ }
1134
+
1052
1135
// 获取object元数据
1053
1136
export function getLocalService ( objectApiName : string ) {
1054
1137
let steedosSchema = getSteedosSchema ( ) ;
0 commit comments