-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathApi.ts
More file actions
148 lines (120 loc) Β· 4.58 KB
/
Api.ts
File metadata and controls
148 lines (120 loc) Β· 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { generateUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import { confirmPassword } from '@nextcloud/password-confirmation'
// eslint-disable-next-line n/no-unpublished-import
import type { OCSResponse } from '@nextcloud/typings/lib/ocs'
import type { Folder, Group, User, AclManage, DelegationCircle, DelegationGroup, Circle } from '../types'
export class Api {
getUrl(endpoint: string): string {
return generateUrl(`apps/groupfolders/${endpoint}`)
}
async listFolders(offset = 0, limit?: number, orderBy?: string, order?: string): Promise<Folder[]> {
const response = await axios.get<OCSResponse<Folder[]>>(this.getUrl('folders'), {
params: {
offset,
limit,
orderBy,
order,
},
})
return Object.values(response.data.ocs.data)
}
// Returns all NC groups
async listGroups(): Promise<DelegationGroup[]> {
const response = await axios.get<OCSResponse<DelegationGroup[]>>(this.getUrl('delegation/groups'))
return response.data.ocs.data
}
// Returns all visible NC circles
async listCircles(): Promise<DelegationCircle[]> {
const response = await axios.get<OCSResponse<DelegationCircle[]>>(this.getUrl('delegation/circles'))
return response.data.ocs.data
}
// Returns all groups that have been granted delegated admin or subadmin rights on groupfolders
async listDelegatedGroups(classname: string): Promise<DelegationGroup[]> {
const response = await axios.get<OCSResponse<DelegationGroup[]>>(this.getUrl('/delegation/authorized-groups'), { params: { classname } })
return response.data.ocs.data.filter(g => g.gid !== 'admin')
}
// Updates the list of groups that have been granted delegated admin or subadmin rights on groupfolders
async updateDelegatedGroups(newGroups: DelegationGroup[], classname: string): Promise<void> {
await confirmPassword()
await axios.post(generateUrl('/apps/settings/') + '/settings/authorizedgroups/saveSettings', {
newGroups,
class: classname,
})
}
async createFolder(mountPoint: string): Promise<Folder> {
await confirmPassword()
const response = await axios.post<OCSResponse<Folder>>(this.getUrl('folders'), { mountpoint: mountPoint })
return response.data.ocs.data
}
async deleteFolder(id: number): Promise<void> {
await confirmPassword()
await axios.delete(this.getUrl(`folders/${id}`))
}
async addGroup(folderId: number, group: string): Promise<void> {
await confirmPassword()
await axios.post(this.getUrl(`folders/${folderId}/groups`), { group })
}
async removeGroup(folderId: number, group: string): Promise<void> {
await confirmPassword()
await axios.delete(this.getUrl(`folders/${folderId}/groups/${group}`))
}
async setPermissions(folderId: number, group: string, permissions: number): Promise<void> {
await confirmPassword()
await axios.post(this.getUrl(`folders/${folderId}/groups/${group}`), { permissions })
}
async setManageACL(folderId: number, type: string, id: string, manageACL: boolean): Promise<void> {
await confirmPassword()
await axios.post(this.getUrl(`folders/${folderId}/manageACL`), {
mappingType: type,
mappingId: id,
manageAcl: manageACL ? 1 : 0,
})
}
async setQuota(folderId: number, quota: number): Promise<void> {
await confirmPassword()
await axios.post(this.getUrl(`folders/${folderId}/quota`), { quota })
}
async setACL(folderId: number, acl: boolean): Promise<void> {
await confirmPassword()
await axios.post(this.getUrl(`folders/${folderId}/acl`), { acl: acl ? 1 : 0 })
}
async renameFolder(folderId: number, mountpoint: string): Promise<void> {
await confirmPassword()
await axios.post(this.getUrl(`folders/${folderId}/mountpoint`), { mountpoint })
}
async aclMappingSearch(folderId: number, search: string): Promise<{
groups: AclManage[],
users: AclManage[],
circles: AclManage[],
}> {
const response = await axios.get<OCSResponse<{groups: Group[], users: User[], circles: Circle[]}>>(this.getUrl(`folders/${folderId}/search`), { params: { search } })
return {
groups: Object.values(response.data.ocs.data.groups).map((item) => {
return {
type: 'group',
id: item.gid,
displayname: item.displayname,
}
}),
users: Object.values(response.data.ocs.data.users).map((item) => {
return {
type: 'user',
id: item.uid,
displayname: item.displayname,
}
}),
circles: Object.values(response.data.ocs.data.circles).map((item) => {
return {
type: 'circle',
id: item.sid,
displayname: item.displayname,
}
}),
}
}
}