forked from tj/go-dropbox
/
sharing.go
354 lines (302 loc) · 10.9 KB
/
sharing.go
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
package dropbox
import (
"context"
"encoding/json"
"time"
)
// Sharing client.
type Sharing struct {
*Client
}
// NewSharing client.
func NewSharing(config *Config) *Sharing {
return &Sharing{
Client: &Client{
Config: config,
},
}
}
// CreateSharedLinkInput request input.
type CreateSharedLinkInput struct {
Path string `json:"path"`
ShortURL bool `json:"short_url"`
}
// CreateSharedLinkOutput request output.
type CreateSharedLinkOutput struct {
URL string `json:"url"`
Path string `json:"path"`
VisibilityModel struct {
Tag VisibilityType `json:".tag"`
} `json:"visibility"`
Expires time.Time `json:"expires,omitempty"`
}
// VisibilityType determines who can access the link.
type VisibilityType string
// Visibility types supported.
const (
Public VisibilityType = "public"
TeamOnly = "team_only"
Password = "password"
TeamAndPassword = "team_and_password"
SharedFolderOnly = "shared_folder_only"
)
// CreateSharedLink returns a shared link.
func (c *Sharing) CreateSharedLink(ctx context.Context, in *CreateSharedLinkInput) (out *CreateSharedLinkOutput, err error) {
body, err := c.call(ctx, "/sharing/create_shared_link", in)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// ListSharedFileMembersInput request input.
type ListSharedFileMembersInput struct {
File string `json:"file"`
Actions []MemberAction `json:"actions"`
IncludeInherited bool `json:"include_inherited"`
Limit uint32 `json:"limit"`
}
// ListSharedFolderMembersInput request input.
type ListSharedFolderMembersInput struct {
SharedFolderID string `json:"shared_folder_id"`
Actions []MemberAction `json:"actions"`
Limit uint64 `json:"limit"`
}
// ListSharedMembersOutput enumerates shared file/folder user and group membership.
type ListSharedMembersOutput struct {
Users []UserMembershipInfo `json:"users"`
Groups []GroupMembershipInfo `json:"groups"`
Invitees []InviteeMembershipInfo `json:"invitees"`
Cursor string `json:"cursor"`
}
// ListSharedMembersContinueInput is the input for continuing listing file/folder members.
type ListSharedMembersContinueInput struct {
Cursor string `json:"cursor"`
}
// UserMembershipInfo is information about a user member of the shared folder.
type UserMembershipInfo struct {
AccessType struct {
Tag AccessType `json:".tag"`
} `json:"access_type"`
User UserInfo `json:"user"`
Permissions []MemberPermission `json:"permissions,omitempty"`
Initials string `json:"initials,omitempty"`
IsInherited bool `json:"is_inherited"`
}
// UserInfo is the account information for the membership user.
type UserInfo struct {
AccountID string `json:"account_id"`
SameTeam bool `json:"same_team"`
TeamMemberID string `json:"team_member_id"`
}
// MemberPermission indicates whether the user is allowed to take the action on the associated member.
type MemberPermission struct {
Action MemberAction `json:"action"`
Allow bool `json:"allow"`
Reason PermissionDeniedReason `json:"reason,omitempty"`
}
// MemberAction indicates the action that the user may wish to take on the member.
type MemberAction string
// MemberAction possible values.
const (
MemberActionMakeEditor MemberAction = "make_editor"
MemberActionMakeOwner = "make_owner"
MemberActionMakeViewer = "make_viewer"
MemberActionRemove = "remove"
)
// PermissionDeniedReason is the reason the user is denied a permission.
type PermissionDeniedReason string
// PermissionDeniedReason possible values
const (
UserNotOnSameTeamAsOwner PermissionDeniedReason = "user_not_same_team_as_owner"
UserNotAllowedByOwner = "user_not_allowed_by_owner"
TargetIsIndirectmember = "target_is_indirect_member"
TargetIsOwner = "target_is_owner"
TargetIsSelf = "target_is_self"
TargetNotActive = "target_not_active"
)
// GroupMembershipInfo is information about a group member of the shared folder.
type GroupMembershipInfo struct {
AccessType struct {
Tag AccessType `json:".tag"`
} `json:"access_type"`
Group GroupInfo `json:"group"`
Permissions []MemberPermission `json:"permissions,omitempty"`
Initials *string `json:"initials,omitempty"`
IsInherited bool `json:"is_inherited"`
}
// GroupInfo defines information about the membership group.
type GroupInfo struct {
GroupName string `json:"group_name"`
GroupID string `json:"group_id"`
GroupType struct {
Tag GroupType `json:".tag"`
} `json:"group_type"`
IsOwner bool `json:"is_owner"`
SameTeam bool `json:"same_team"`
GroupExternalID string `json:"group_external_id,omitempty"`
MemberCount *uint32 `json:"member_count,omitempty"`
}
// GroupType determines how a group is created and managed.
type GroupType string
// GroupType possible values.
const (
GroupTypeTeam GroupType = "team"
GroupTypeUserManaged = "user_managed"
)
// InviteeMembershipInfo is information about an invited member of a shared folder.
type InviteeMembershipInfo struct {
AccessType struct {
Tag AccessType `json:".tag"`
} `json:"access_type"`
Invitee InviteeInfo `json:"invitee"`
Permissions []MemberPermission `json:"permissions,omitempty"`
Initials *string `json:"initials,omitempty"`
IsInherited bool `json:"is_inherited"`
}
// InviteeInfo contains information about the recipient of a shared folder invitation.
type InviteeInfo struct {
Email string `json:"email"`
}
// ListSharedFileMembers returns shared file membership by its file ID.
func (c *Sharing) ListSharedFileMembers(ctx context.Context, in *ListSharedFileMembersInput) (out *ListSharedMembersOutput, err error) {
body, err := c.call(ctx, "/sharing/list_file_members", in)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// ListSharedFileMembersContinue returns shared file membership by its file ID.
func (c *Sharing) ListSharedFileMembersContinue(ctx context.Context, in *ListSharedMembersContinueInput) (out *ListSharedMembersOutput, err error) {
body, err := c.call(ctx, "/sharing/list_file_members/continue", in)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// ListSharedFolderMembers returns shared folder membership by its folder ID.
func (c *Sharing) ListSharedFolderMembers(ctx context.Context, in *ListSharedFolderMembersInput) (out *ListSharedMembersOutput, err error) {
body, err := c.call(ctx, "/sharing/list_folder_members", in)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// ListSharedFolderMembersContinue returns shared folder membership by its folder ID.
func (c *Sharing) ListSharedFolderMembersContinue(ctx context.Context, in *ListSharedMembersContinueInput) (out *ListSharedMembersOutput, err error) {
body, err := c.call(ctx, "/sharing/list_folder_members/continue", in)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// ListSharedFolderInput request input.
type ListSharedFolderInput struct {
Limit uint64 `json:"limit"`
Actions []FolderAction `json:"actions,omitempty"`
}
// FolderAction defines actions that may be taken on shared folders.
type FolderAction struct {
ChangeOptions string
}
// ListSharedFolderOutput lists metadata about shared folders with a cursor to retrieve the next page.
type ListSharedFolderOutput struct {
Entries []SharedFolderMetadata `json:"entries"`
Cursor string `json:"cursor"`
}
// ListSharedFolders returns the list of all shared folders the current user has access to.
func (c *Sharing) ListSharedFolders(ctx context.Context, in *ListSharedFolderInput) (out *ListSharedFolderOutput, err error) {
body, err := c.call(ctx, "/sharing/list_folders", in)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// ListSharedFolderContinueInput request input.
type ListSharedFolderContinueInput struct {
Cursor string `json:"cursor"`
}
// ListSharedFoldersContinue returns the list of all shared folders the current user has access to.
func (c *Sharing) ListSharedFoldersContinue(ctx context.Context, in *ListSharedFolderContinueInput) (out *ListSharedFolderOutput, err error) {
body, err := c.call(ctx, "/sharing/list_folders/continue", in)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// SharedFolderMetadata includes basic information about the shared folder.
type SharedFolderMetadata struct {
AccessType struct {
Tag AccessType `json:".tag"`
} `json:"access_type"`
IsTeamFolder bool `json:"is_team_folder"`
Policy FolderPolicy `json:"policy"`
Name string `json:"name"`
SharedFolderID string `json:"shared_folder_id"`
TimeInvited time.Time `json:"time_invited"`
OwnerTeam struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"owner_team"`
ParentSharedFolderID string `json:"parent_shared_folder_id"`
PathLower string `json:"path_lower"`
Permissions []string `json:"permissions"`
}
// FolderPolicy enumerates the policies governing this shared folder.
type FolderPolicy struct {
ACLUpdatePolicy struct {
Tag ACLUpdatePolicy `json:".tag"`
} `json:"acl_update_policy"`
SharedLinkPolicy struct {
Tag SharedLinkPolicy `json:".tag"`
} `json:"shared_link_policy"`
MemberPolicy struct {
Tag MemberPolicy `json:".tag"`
} `json:"member_policy"`
ResolvedMemberPolicy struct {
Tag MemberPolicy `json:".tag"`
} `json:"resolved_member_policy"`
}
// AccessType determines the level of access to a shared folder.
type AccessType string
// Access types supported.
const (
Owner AccessType = "owner"
Editor = "editor"
Viewer = "viewer"
ViewerNoComment = "viewer_no_comment"
)
// ACLUpdatePolicy determines who can add and remove members from this shared folder.
type ACLUpdatePolicy string
// ACLUpdatePolicy types supported.
const (
ACLUpdatePolicyOwner ACLUpdatePolicy = "owner"
ACLUpdatePolicyEditors = "editors"
)
// SharedLinkPolicy governs who can view shared links.
type SharedLinkPolicy string
// SharedLinkPolicy types supported.
const (
SharedLinkPolicyAnyone SharedLinkPolicy = "anyone"
SharedLinkPolicyMembers = "members"
)
// MemberPolicy determines who can be a member of this shared folder, as set on the folder itself.
type MemberPolicy string
// MemberPolicy types supported.
const (
MemberPolicyTeam MemberPolicy = "team"
MemberPolicyAnyone = "anyone"
)