1
1
import { generateUrl } from '@nextcloud/router'
2
- import { OCSResult , AxiosOCSResult } from 'NC'
3
2
import axios from '@nextcloud/axios'
3
+ // eslint-disable-next-line n/no-unpublished-import
4
+ import type { OCSResponse } from '@nextcloud/typings/lib/ocs'
4
5
5
6
export interface Group {
6
7
gid : string ;
@@ -28,7 +29,6 @@ export interface ManageRuleProps {
28
29
displayname : string ;
29
30
}
30
31
31
-
32
32
export interface Folder {
33
33
id : number ;
34
34
mount_point : string ;
@@ -46,117 +46,98 @@ export class Api {
46
46
}
47
47
48
48
async listFolders ( ) : Promise < Folder [ ] > {
49
- return $ . getJSON ( this . getUrl ( 'folders' ) )
50
- . then ( ( data : OCSResult < Folder [ ] > ) => Object . keys ( data . ocs . data ) . map ( id => data . ocs . data [ id ] ) )
49
+ const response = await axios . get < OCSResponse < Folder [ ] > > ( this . getUrl ( 'folders' ) )
50
+ return Object . keys ( response . data . ocs . data ) . map ( id => response . data . ocs . data [ id ] )
51
51
}
52
52
53
53
// Returns all NC groups
54
54
async listGroups ( ) : Promise < Group [ ] > {
55
- return $ . getJSON ( this . getUrl ( 'delegation/groups' ) )
56
- . then ( ( data : OCSResult < Group [ ] > ) => data . ocs . data )
55
+ const response = await axios . get < OCSResponse < Group [ ] > > ( this . getUrl ( 'delegation/groups' ) )
56
+ return response . data . ocs . data
57
57
}
58
58
59
59
// Returns all visible NC circles
60
60
async listCircles ( ) : Promise < Circle [ ] > {
61
- return $ . getJSON ( this . getUrl ( 'delegation/circles' ) )
62
- . then ( ( data : OCSResult < Circle [ ] > ) => data . ocs . data )
61
+ const response = await axios . get < OCSResponse < Circle [ ] > > ( this . getUrl ( 'delegation/circles' ) )
62
+ return response . data . ocs . data
63
63
}
64
64
65
65
// Returns all groups that have been granted delegated admin or subadmin rights on groupfolders
66
66
async listDelegatedGroups ( classname : string ) : Promise < Group [ ] > {
67
- return axios . get ( this . getUrl ( '/delegation/authorized-groups' ) , { params : { classname } } )
68
- . then ( ( data : AxiosOCSResult < Group [ ] > ) => {
69
- // The admin group is always there. We don't want the user to remove it
70
- const groups = data . data . ocs . data . filter ( g => g . gid !== 'admin' )
71
- return groups
72
- } )
67
+ const response = await axios . get < OCSResponse < Group [ ] > > ( this . getUrl ( '/delegation/authorized-groups' ) , { params : { classname } } )
68
+ return response . data . ocs . data . filter ( g => g . gid !== 'admin' )
73
69
}
74
70
75
71
// Updates the list of groups that have been granted delegated admin or subadmin rights on groupfolders
76
72
async updateDelegatedGroups ( newGroups : Group [ ] , classname : string ) : Promise < void > {
77
- return axios . post ( generateUrl ( '/apps/settings/' ) + '/settings/authorizedgroups/saveSettings' , {
73
+ await axios . post ( generateUrl ( '/apps/settings/' ) + '/settings/authorizedgroups/saveSettings' , {
78
74
newGroups,
79
75
class : classname ,
80
- } ) . then ( ( data ) => data . data )
76
+ } )
81
77
}
82
78
83
79
async createFolder ( mountPoint : string ) : Promise < number > {
84
- return $ . post ( this . getUrl ( 'folders' ) , {
85
- mountpoint : mountPoint
86
- } , null , 'json' ) . then ( ( data : OCSResult < { id : number ; } > ) => data . ocs . data . id )
80
+ const response = await axios . post < OCSResponse < number > > ( this . getUrl ( 'folders' ) , { mountpoint : mountPoint } )
81
+ return response . data . ocs . data
87
82
}
88
83
89
84
async deleteFolder ( id : number ) : Promise < void > {
90
- return $ . ajax ( {
91
- url : this . getUrl ( `folders/${ id } ` ) ,
92
- type : 'DELETE'
93
- } )
85
+ await axios . delete ( this . getUrl ( `folders/${ id } ` ) )
94
86
}
95
87
96
88
async addGroup ( folderId : number , group : string ) : Promise < void > {
97
- return $ . post ( this . getUrl ( `folders/${ folderId } /groups` ) , {
98
- group
99
- } )
89
+ await axios . post ( this . getUrl ( `folders/${ folderId } /groups` ) , { group } )
100
90
}
101
91
102
92
async removeGroup ( folderId : number , group : string ) : Promise < void > {
103
- return $ . ajax ( {
104
- url : this . getUrl ( `folders/${ folderId } /groups/${ group } ` ) ,
105
- type : 'DELETE'
106
- } )
93
+ await axios . delete ( this . getUrl ( `folders/${ folderId } /groups/${ group } ` ) )
107
94
}
108
95
109
96
async setPermissions ( folderId : number , group : string , permissions : number ) : Promise < void > {
110
- return $ . post ( this . getUrl ( `folders/${ folderId } /groups/${ group } ` ) , {
111
- permissions
112
- } )
97
+ await axios . post ( this . getUrl ( `folders/${ folderId } /groups/${ group } ` ) , { permissions } )
113
98
}
114
99
115
100
async setManageACL ( folderId : number , type : string , id : string , manageACL : boolean ) : Promise < void > {
116
- return $ . post ( this . getUrl ( `folders/${ folderId } /manageACL` ) , {
101
+ await axios . post ( this . getUrl ( `folders/${ folderId } /manageACL` ) , {
117
102
mappingType : type ,
118
103
mappingId : id ,
119
- manageAcl : manageACL ? 1 : 0
104
+ manageAcl : manageACL ? 1 : 0 ,
120
105
} )
121
106
}
122
107
123
108
async setQuota ( folderId : number , quota : number ) : Promise < void > {
124
- return $ . post ( this . getUrl ( `folders/${ folderId } /quota` ) , {
125
- quota
126
- } )
109
+ await axios . post ( this . getUrl ( `folders/${ folderId } /quota` ) , { quota } )
127
110
}
128
111
129
112
async setACL ( folderId : number , acl : boolean ) : Promise < void > {
130
- return $ . post ( this . getUrl ( `folders/${ folderId } /acl` ) , {
131
- acl : acl ? 1 : 0
132
- } )
113
+ await axios . post ( this . getUrl ( `folders/${ folderId } /acl` ) , { acl : acl ? 1 : 0 } )
133
114
}
134
115
135
116
async renameFolder ( folderId : number , mountpoint : string ) : Promise < void > {
136
- return $ . post ( this . getUrl ( `folders/${ folderId } /mountpoint` ) , {
137
- mountpoint
138
- } )
117
+ await axios . post ( this . getUrl ( `folders/${ folderId } /mountpoint` ) , { mountpoint } )
139
118
}
140
119
141
- async aclMappingSearch ( folderId : number , search : string ) : Promise < { groups : ManageRuleProps [ ] , users : ManageRuleProps [ ] } > {
142
- return $ . getJSON ( this . getUrl ( `folders/${ folderId } /search?format=json&search=${ search } ` ) )
143
- . then ( ( data : OCSResult < { groups : OCSGroup [ ] ; users : OCSUser [ ] ; } > ) => {
120
+ async aclMappingSearch ( folderId : number , search : string ) : Promise < {
121
+ groups : ManageRuleProps [ ] ,
122
+ users : ManageRuleProps [ ]
123
+ } > {
124
+ const response = await axios . get < OCSResponse < { groups : OCSGroup [ ] , users : OCSUser [ ] } > > ( this . getUrl ( `folders/${ folderId } /search` ) , { params : { search } } )
125
+ return {
126
+ groups : Object . values ( response . data . ocs . data . groups ) . map ( ( item ) => {
144
127
return {
145
- groups : Object . values ( data . ocs . data . groups ) . map ( ( item ) => {
146
- return {
147
- type : 'group' ,
148
- id : item . gid ,
149
- displayname : item . displayname
150
- }
151
- } ) ,
152
- users : Object . values ( data . ocs . data . users ) . map ( ( item ) => {
153
- return {
154
- type : 'user' ,
155
- id : item . uid ,
156
- displayname : item . displayname
157
- }
158
- } )
128
+ type : 'group' ,
129
+ id : item . gid ,
130
+ displayname : item . displayname ,
159
131
}
160
- } )
132
+ } ) ,
133
+ users : Object . values ( response . data . ocs . data . users ) . map ( ( item ) => {
134
+ return {
135
+ type : 'user' ,
136
+ id : item . uid ,
137
+ displayname : item . displayname ,
138
+ }
139
+ } ) ,
140
+ }
161
141
}
142
+
162
143
}
0 commit comments