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