forked from lokalise/go-lokalise-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svc_teamusergroup.go
172 lines (140 loc) · 5.81 KB
/
svc_teamusergroup.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
package lokalise
import (
"fmt"
"path"
"strconv"
)
type TeamUserGroupService struct {
BaseService
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service entity objects
// _____________________________________________________________________________________________________________________
type TeamUserGroup struct {
WithCreationTime
WithTeamID
GroupID int64 `json:"group_id"`
Name string `json:"name"`
Permissions *Permission `json:"permissions"`
Projects []string `json:"projects"`
Members []int64 `json:"members"`
}
type Permission struct {
IsAdmin bool `json:"is_admin"`
IsReviewer bool `json:"is_reviewer"`
Languages []Language `json:"languages,omitempty"`
// Possible values are upload, activity, download, settings, statistics, keys, screenshots, contributors, languages
AdminRights []string `json:"admin_rights,omitempty"` // todo make admin rights as constants available in the lib
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service request/response objects
// _____________________________________________________________________________________________________________________
type NewGroupLanguages struct {
Reference []int64 `json:"reference"`
Contributable []int64 `json:"contributable"`
}
type NewGroup struct {
Name string `json:"name"`
IsAdmin bool `json:"is_admin"`
IsReviewer bool `json:"is_reviewer"`
AdminRights []string `json:"admin_rights,omitempty"`
Languages NewGroupLanguages `json:"languages,omitempty"`
}
type TeamUserGroupsResponse struct {
Paged
WithTeamID
UserGroups []TeamUserGroup `json:"user_groups"`
}
type CreateGroupResponse struct {
WithTeamID
Group TeamUserGroup `json:"group"`
}
type DeleteGroupResponse struct {
WithTeamID
IsDeleted bool `json:"group_deleted"`
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service methods
// _____________________________________________________________________________________________________________________
func (c *TeamUserGroupService) List(teamID int64) (r TeamUserGroupsResponse, err error) {
resp, err := c.getWithOptions(c.Ctx(), pathTeamUserGroups(teamID), &r, c.PageOpts())
if err != nil {
return
}
applyPaged(resp, &r.Paged)
return r, apiError(resp)
}
func (c *TeamUserGroupService) Create(teamID int64, group NewGroup) (r CreateGroupResponse, err error) {
resp, err := c.post(c.Ctx(), pathTeamUserGroups(teamID), &r, group)
if err != nil {
return r, err
}
return r, apiError(resp)
}
func (c *TeamUserGroupService) Retrieve(teamID, groupID int64) (r TeamUserGroup, err error) {
url := path.Join(pathTeamUserGroups(teamID), strconv.FormatInt(groupID, 10))
resp, err := c.get(c.Ctx(), url, &r)
if err != nil {
return r, err
}
return r, apiError(resp)
}
func (c *TeamUserGroupService) Update(teamID, groupID int64, group NewGroup) (r CreateGroupResponse, err error) {
url := path.Join(pathTeamUserGroups(teamID), strconv.FormatInt(groupID, 10))
resp, err := c.put(c.Ctx(), url, &r, group)
if err != nil {
return r, err
}
return r, apiError(resp)
}
func (c *TeamUserGroupService) AddProjects(teamID, groupID int64, projects []string) (r CreateGroupResponse, err error) {
url := path.Join(pathTeamUserGroups(teamID), strconv.FormatInt(groupID, 10), "projects", "add")
resp, err := c.put(c.Ctx(), url, &r, map[string]interface{}{
"projects": projects,
})
if err != nil {
return r, err
}
return r, apiError(resp)
}
func (c *TeamUserGroupService) RemoveProjects(teamID, groupID int64, projects []string) (r CreateGroupResponse, err error) {
url := path.Join(pathTeamUserGroups(teamID), strconv.FormatInt(groupID, 10), "projects", "remove")
resp, err := c.put(c.Ctx(), url, &r, map[string]interface{}{
"projects": projects,
})
if err != nil {
return r, err
}
return r, apiError(resp)
}
func (c *TeamUserGroupService) AddMembers(teamID, groupID int64, users []int64) (r CreateGroupResponse, err error) {
url := path.Join(pathTeamUserGroups(teamID), strconv.FormatInt(groupID, 10), "members", "add")
resp, err := c.put(c.Ctx(), url, &r, map[string]interface{}{
"users": users,
})
if err != nil {
return r, err
}
return r, apiError(resp)
}
func (c *TeamUserGroupService) RemoveMembers(teamID, groupID int64, users []int64) (r CreateGroupResponse, err error) {
url := path.Join(pathTeamUserGroups(teamID), strconv.FormatInt(groupID, 10), "members", "remove")
resp, err := c.put(c.Ctx(), url, &r, map[string]interface{}{
"users": users,
})
if err != nil {
return r, err
}
return r, apiError(resp)
}
func (c *TeamUserGroupService) Delete(teamID, groupID int64) (r DeleteGroupResponse, err error) {
url := path.Join(pathTeamUserGroups(teamID), strconv.FormatInt(groupID, 10))
resp, err := c.delete(c.Ctx(), url, &r)
if err != nil {
return r, err
}
return r, apiError(resp)
}
func pathTeamUserGroups(teamID int64) string {
return fmt.Sprintf("%s/%d/groups", pathTeams, teamID)
}