forked from appwrite/sdk-for-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteams.go
140 lines (112 loc) · 4.37 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
package appwrite
import (
"strings"
)
// Teams service
type Teams struct {
client Client
}
func NewTeams(clt Client) Teams {
service := Teams{
client: clt,
}
return service
}
// List get a list of all the current user teams. You can use the query params
// to filter your results. On admin mode, this endpoint will return a list of
// all of the project teams. [Learn more about different API
// modes](/docs/admin).
func (srv *Teams) List(Search string, Limit int, Offset int, OrderType string) (map[string]interface{}, error) {
path := "/teams"
params := map[string]interface{}{
"search": Search,
"limit": Limit,
"offset": Offset,
"orderType": OrderType,
}
return srv.client.Call("GET", path, nil, params)
}
// Create create a new team. The user who creates the team will automatically
// be assigned as the owner of the team. The team owner can invite new
// members, who will be able add new owners and update or delete the team from
// your project.
func (srv *Teams) Create(Name string, Roles []interface{}) (map[string]interface{}, error) {
path := "/teams"
params := map[string]interface{}{
"name": Name,
"roles": Roles,
}
return srv.client.Call("POST", path, nil, params)
}
// Get get team by its unique ID. All team members have read access for this
// resource.
func (srv *Teams) Get(TeamId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{teamId}", TeamId)
path := r.Replace("/teams/{teamId}")
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// Update update team by its unique ID. Only team owners have write access for
// this resource.
func (srv *Teams) Update(TeamId string, Name string) (map[string]interface{}, error) {
r := strings.NewReplacer("{teamId}", TeamId)
path := r.Replace("/teams/{teamId}")
params := map[string]interface{}{
"name": Name,
}
return srv.client.Call("PUT", path, nil, params)
}
// Delete delete team by its unique ID. Only team owners have write access for
// this resource.
func (srv *Teams) Delete(TeamId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{teamId}", TeamId)
path := r.Replace("/teams/{teamId}")
params := map[string]interface{}{
}
return srv.client.Call("DELETE", path, nil, params)
}
// GetMemberships get team members by the team unique ID. All team members
// have read access for this list of resources.
func (srv *Teams) GetMemberships(TeamId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{teamId}", TeamId)
path := r.Replace("/teams/{teamId}/memberships")
params := map[string]interface{}{
}
return srv.client.Call("GET", path, nil, params)
}
// CreateMembership use this endpoint to invite a new member to join your
// team. An email with a link to join the team will be sent to the new member
// email address if the member doesn't exist in the project it will be created
// automatically.
//
// 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/teams#updateMembershipStatus) endpoint to allow the user to
// accept the invitation to the team.
//
// Please note that in order to avoid a [Redirect
// Attacks](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
// added your platforms in the console interface.
func (srv *Teams) CreateMembership(TeamId string, Email string, Roles []interface{}, Url string, Name string) (map[string]interface{}, error) {
r := strings.NewReplacer("{teamId}", TeamId)
path := r.Replace("/teams/{teamId}/memberships")
params := map[string]interface{}{
"email": Email,
"name": Name,
"roles": Roles,
"url": Url,
}
return srv.client.Call("POST", path, nil, 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 he didn't accept it.
func (srv *Teams) DeleteMembership(TeamId string, InviteId string) (map[string]interface{}, error) {
r := strings.NewReplacer("{teamId}", TeamId, "{inviteId}", InviteId)
path := r.Replace("/teams/{teamId}/memberships/{inviteId}")
params := map[string]interface{}{
}
return srv.client.Call("DELETE", path, nil, params)
}