@@ -24,6 +24,10 @@ function withPermissionAccess(targets: string[], access?: PermissionAccess) {
2424 return Array . from ( new Set ( targets . map ( ( target ) => applyPermissionAccess ( target , access ) ) ) )
2525}
2626
27+ function uniqueTargets ( targets : string [ ] ) {
28+ return Array . from ( new Set ( targets ) )
29+ }
30+
2731export function permissionPatternMatches ( pattern : string , requiredPermission : string ) {
2832 if ( pattern === '*' ) {
2933 return true
@@ -82,6 +86,54 @@ export function dataSourcePermissionTargets(
8286 )
8387}
8488
89+ export function projectDataSourcePermissionTargets (
90+ projectId : string ,
91+ sourceId : string | '*' ,
92+ access ?: PermissionAccess ,
93+ ) {
94+ const targets = [
95+ `project.manage.${ projectId } .datasources` ,
96+ `project.manage.${ projectId } .datasources.*` ,
97+ ]
98+
99+ if ( sourceId !== '*' ) {
100+ targets . push ( `project.manage.${ projectId } .datasources.${ sourceId } ` )
101+ }
102+
103+ return withPermissionAccess ( targets , access )
104+ }
105+
106+ export function dataSourceReadPermissionTargets ( projectId : string , sourceId : string | '*' ) {
107+ return uniqueTargets ( [
108+ ...projectDataSourcePermissionTargets ( projectId , sourceId , 'read' ) ,
109+ ...projectDataSourcePermissionTargets ( projectId , sourceId , 'write' ) ,
110+ ...dataSourcePermissionTargets ( projectId , sourceId , 'view' , 'read' ) ,
111+ ...dataSourcePermissionTargets ( projectId , sourceId , 'query' , 'read' ) ,
112+ ...dataSourcePermissionTargets ( projectId , sourceId , 'query' , 'write' ) ,
113+ ...dataSourcePermissionTargets ( projectId , sourceId , 'manage' , 'write' ) ,
114+ ...dataSourcePermissionTargets ( projectId , sourceId , 'table.edit' , 'write' ) ,
115+ ...projectPermissionTargets ( projectId , 'manage' , 'write' ) ,
116+ ] )
117+ }
118+
119+ export function dataSourceWritePermissionTargets ( projectId : string , sourceId : string | '*' ) {
120+ return uniqueTargets ( [
121+ ...projectDataSourcePermissionTargets ( projectId , sourceId , 'write' ) ,
122+ ...dataSourcePermissionTargets ( projectId , sourceId , 'query' , 'write' ) ,
123+ ...dataSourcePermissionTargets ( projectId , sourceId , 'manage' , 'write' ) ,
124+ ...dataSourcePermissionTargets ( projectId , sourceId , 'table.edit' , 'write' ) ,
125+ ...projectPermissionTargets ( projectId , 'manage' , 'write' ) ,
126+ ] )
127+ }
128+
129+ export function dataSourceConfigPermissionTargets ( projectId : string , sourceId : string | '*' ) {
130+ return uniqueTargets ( [
131+ ...projectDataSourcePermissionTargets ( projectId , sourceId , 'write' ) ,
132+ ...dataSourcePermissionTargets ( projectId , sourceId , 'manage' , 'write' ) ,
133+ ...projectPermissionTargets ( projectId , 'manage' , 'write' ) ,
134+ ] )
135+ }
136+
85137export function adminPermissionTargets (
86138 action : 'access' | 'users' | 'roles' | 'apiKeys' ,
87139 access ?: PermissionAccess ,
0 commit comments