/
teams.go
215 lines (179 loc) · 6.92 KB
/
teams.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
package appwrite
import (
"strings"
)
// Teams service
type Teams struct {
client Client
}
func NewTeams(clt Client) *Teams {
return &Teams{
client: clt,
}
}
// List get a list of all the teams in which the current user is a member. You
// can use the parameters to filter your results.
func (srv *Teams) List(Queries []interface{}, Search string) (*ClientResponse, error) {
path := "/teams"
params := map[string]interface{}{
"queries": Queries,
"search": Search,
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("GET", path, headers, params)
}
// Create create a new team. The user who creates the team will automatically
// be assigned as the owner of the team. Only the users with the owner role
// can invite new members, add new owners and delete or update the team.
func (srv *Teams) Create(TeamId string, Name string, Roles []interface{}) (*ClientResponse, error) {
path := "/teams"
params := map[string]interface{}{
"teamId": TeamId,
"name": Name,
"roles": Roles,
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("POST", path, headers, params)
}
// Get get a team by its ID. All team members have read access for this
// resource.
func (srv *Teams) Get(TeamId string) (*ClientResponse, error) {
r := strings.NewReplacer("{teamId}", TeamId)
path := r.Replace("/teams/{teamId}")
params := map[string]interface{}{
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("GET", path, headers, params)
}
// Update update a team using its ID. Only members with the owner role can
// update the team.
func (srv *Teams) Update(TeamId string, Name string) (*ClientResponse, error) {
r := strings.NewReplacer("{teamId}", TeamId)
path := r.Replace("/teams/{teamId}")
params := map[string]interface{}{
"name": Name,
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("PUT", path, headers, params)
}
// Delete delete a team using its ID. Only team members with the owner role
// can delete the team.
func (srv *Teams) Delete(TeamId string) (*ClientResponse, error) {
r := strings.NewReplacer("{teamId}", TeamId)
path := r.Replace("/teams/{teamId}")
params := map[string]interface{}{
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("DELETE", path, headers, params)
}
// ListMemberships use this endpoint to list a team's members using the team's
// ID. All team members have read access to this endpoint.
func (srv *Teams) ListMemberships(TeamId string, Queries []interface{}, Search string) (*ClientResponse, error) {
r := strings.NewReplacer("{teamId}", TeamId)
path := r.Replace("/teams/{teamId}/memberships")
params := map[string]interface{}{
"queries": Queries,
"search": Search,
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("GET", path, headers, params)
}
// CreateMembership invite a new member to join your team. If initiated from
// the client SDK, an email with a link to join the team will be sent to the
// member's email address and an account will be created for them should they
// not be signed up already. If initiated from server-side SDKs, the new
// member will automatically be added to the team.
//
// Use the 'url' parameter to redirect the user from the invitation email back
// to your app. When the user is redirected, use the [Update Team Membership
// Status](/docs/client/teams#teamsUpdateMembershipStatus) endpoint to allow
// the user to accept the invitation to the team.
//
// Please note that to avoid a [Redirect
// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
// the only valid redirect URL's are the once from domains you have set when
// adding your platforms in the console interface.
func (srv *Teams) CreateMembership(TeamId string, Email string, Roles []interface{}, Url string, Name string) (*ClientResponse, error) {
r := strings.NewReplacer("{teamId}", TeamId)
path := r.Replace("/teams/{teamId}/memberships")
params := map[string]interface{}{
"email": Email,
"roles": Roles,
"url": Url,
"name": Name,
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("POST", path, headers, params)
}
// GetMembership get a team member by the membership unique id. All team
// members have read access for this resource.
func (srv *Teams) GetMembership(TeamId string, MembershipId string) (*ClientResponse, error) {
r := strings.NewReplacer("{teamId}", TeamId, "{membershipId}", MembershipId)
path := r.Replace("/teams/{teamId}/memberships/{membershipId}")
params := map[string]interface{}{
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("GET", path, headers, params)
}
// UpdateMembershipRoles modify the roles of a team member. Only team members
// with the owner role have access to this endpoint. Learn more about [roles
// and permissions](/docs/permissions).
func (srv *Teams) UpdateMembershipRoles(TeamId string, MembershipId string, Roles []interface{}) (*ClientResponse, error) {
r := strings.NewReplacer("{teamId}", TeamId, "{membershipId}", MembershipId)
path := r.Replace("/teams/{teamId}/memberships/{membershipId}")
params := map[string]interface{}{
"roles": Roles,
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("PATCH", path, headers, params)
}
// DeleteMembership this endpoint allows a user to leave a team or for a team
// owner to delete the membership of any other team member. You can also use
// this endpoint to delete a user membership even if it is not accepted.
func (srv *Teams) DeleteMembership(TeamId string, MembershipId string) (*ClientResponse, error) {
r := strings.NewReplacer("{teamId}", TeamId, "{membershipId}", MembershipId)
path := r.Replace("/teams/{teamId}/memberships/{membershipId}")
params := map[string]interface{}{
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("DELETE", path, headers, params)
}
// UpdateMembershipStatus use this endpoint to allow a user to accept an
// invitation to join a team after being redirected back to your app from the
// invitation email received by the user.
//
// If the request is successful, a session for the user is automatically
// created.
//
func (srv *Teams) UpdateMembershipStatus(TeamId string, MembershipId string, UserId string, Secret string) (*ClientResponse, error) {
r := strings.NewReplacer("{teamId}", TeamId, "{membershipId}", MembershipId)
path := r.Replace("/teams/{teamId}/memberships/{membershipId}/status")
params := map[string]interface{}{
"userId": UserId,
"secret": Secret,
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("PATCH", path, headers, params)
}