forked from desertbit/wego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_user.go
259 lines (212 loc) · 7.68 KB
/
client_user.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
/**
* Copyright (c) 2023 Sebastian Borchers
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
package wego
import (
"context"
"encoding/json"
)
// GetCurrentUserID returns the id of the logged in user.
// This is an additional convenience method that has no pendant in the Wekan API.
func (c *Client) GetCurrentUserID() (id string) {
c.mx.Lock()
id = c.mxUserID
c.mx.Unlock()
return
}
// AddBoardMember performs a add_board_member request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#add_board_member
func (c *Client) AddBoardMember(ctx context.Context, boardID, userID string, data AddBoardMemberRequest) (err error) {
endpoint := c.endpoint("boards", boardID, "members", userID, "add")
req, err := c.newAuthenticatedPOSTRequest(ctx, endpoint, data)
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
// RemoveBoardMember performs a remove_board_member request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#remove_board_member
func (c *Client) RemoveBoardMember(ctx context.Context, boardID, userID string) (err error) {
endpoint := c.endpoint("boards", boardID, "members", userID, "remove")
req, err := c.newAuthenticatedPOSTRequest(ctx, endpoint, removeBoardMemberRequest{Action: "remove"})
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
// CreateUserToken performs a create_user_token request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#create_user_token
func (c *Client) CreateUserToken(ctx context.Context, userID string) (r CreateUserTokenResponse, err error) {
endpoint := c.endpoint("createtoken", userID)
req, err := c.newAuthenticatedPOSTRequest(ctx, endpoint, nil)
if err != nil {
return
}
err = c.doSimpleRequest(req, &r)
if err != nil {
return
}
return
}
// GetCurrentUser performs a get_current_user request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_current_user
func (c *Client) GetCurrentUser(ctx context.Context) (u User, err error) {
endpoint := c.endpoint("user")
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &u)
if err != nil {
return
}
return
}
// GetAllUsers performs a get_all_users request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_all_users
func (c *Client) GetAllUsers(ctx context.Context) (users []GetAllUser, err error) {
endpoint := c.endpoint("users")
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &users)
if err != nil {
return
}
return
}
// NewUser performs a new_user request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#new_user
func (c *Client) NewUser(ctx context.Context, data NewUserRequest) (r NewUserResponse, err error) {
endpoint := c.endpoint("users")
req, err := c.newAuthenticatedPOSTRequest(ctx, endpoint, data)
if err != nil {
return
}
err = c.doSimpleRequest(req, &r)
if err != nil {
return
}
return
}
// GetUser performs a get_user request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#get_user
func (c *Client) GetUser(ctx context.Context, userID string) (user User, err error) {
endpoint := c.endpoint("users", userID)
req, err := c.newAuthenticatedGETRequest(ctx, endpoint)
if err != nil {
return
}
err = c.doSimpleRequest(req, &user)
if err != nil {
return
}
return
}
// EditUser performs a edit_user request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#edit_user
//
// Note: Possible values for action:
// - takeOwnership: The admin takes the ownership of ALL boards of the user (archived and not archived) where the user is admin on.
// - disableLogin: Disable a user (the user is not allowed to login and his login tokens are purged)
// - enableLogin: Enable a user
func (c *Client) EditUser(ctx context.Context, userID, action string) (err error) {
endpoint := c.endpoint("users", userID)
req, err := c.newAuthenticatedPUTRequest(ctx, endpoint, editUserRequest{Action: action})
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
// DeleteUser performs a delete_user request against the Wekan server.
// See https://wekan.github.io/api/v5.13/#delete_user
func (c *Client) DeleteUser(ctx context.Context, userID string) (err error) {
endpoint := c.endpoint("users", userID)
req, err := c.newAuthenticatedDELETERequest(ctx, endpoint)
if err != nil {
return
}
return c.doSimpleRequest(req, nil)
}
//#############//
//### Types ###//
//#############//
type AddBoardMemberRequest struct {
Action string `json:"action"`
IsAdmin bool `json:"isAdmin"`
IsNoComments bool `json:"isNoComments"`
IsCommentOnly bool `json:"isCommentOnly"`
}
type removeBoardMemberRequest struct {
Action string `json:"action"`
}
type CreateUserTokenResponse struct {
ID string `json:"_id"`
}
type User struct {
Username string `json:"username"`
Emails []UserEmail `json:"emails"`
CreatedAt string `json:"createdAt"`
ModifiedAt string `json:"modifiedAt"`
Profile UserProfile `json:"profile"`
Services json.RawMessage `json:"services"`
Heartbeat string `json:"heartbeat"`
IsAdmin bool `json:"isAdmin"`
CreatedThroughApi bool `json:"createdThroughApi"`
LoginDisabled bool `json:"loginDisabled"`
AuthenticationMethod string `json:"authenticationMethod"`
SessionData UserSessionData `json:"sessionData"`
ImportUsernames []string `json:"importUsernames"`
}
type UserEmail struct {
Address string `json:"address"`
Verified bool `json:"verified"`
}
type UserSessionData struct {
TotalHits int `json:"totalHits"`
LastHit int `json:"lastHit"`
}
type UserProfile struct {
AvatarUrl string `json:"avatarUrl"`
EmailBuffer []string `json:"emailBuffer"`
Fullname string `json:"fullname"`
ShowDesktopDragHandles bool `json:"showDesktopDragHandles"`
HideCheckedItems bool `json:"hideCheckedItems"`
HiddenSystemMessages bool `json:"hiddenSystemMessages"`
HiddenMinicardLabelText bool `json:"hiddenMinicardLabelText"`
Initials string `json:"initials"`
InvitedBoards []string `json:"invitedBoards"`
Language string `json:"language"`
Notifications json.RawMessage `json:"notifications"`
Activity string `json:"activity"`
Read string `json:"read"`
ShowCardsCountAt int `json:"showCardsCountAt"`
StartDayOfWeek int `json:"startDayOfWeek"`
StarredBoards []string `json:"starredBoards"`
Icode string `json:"icode"`
BoardView string `json:"boardView"`
ListSortBy string `json:"listSortBy"`
TemplatesBoardID string `json:"templatesBoardId"`
CardTemplatesSwimlaneID string `json:"cardTemplatesSwimlaneId"`
ListTemplatesSwimlaneID string `json:"listTemplatesSwimlaneId"`
BoardTemplatesSwimlaneID string `json:"boardTemplatesSwimlaneId"`
}
type GetAllUser struct {
ID string `json:"_id"`
Username string `json:"username"`
}
type NewUserRequest struct {
Username string `json:"username"`
Password string `json:"password"`
Email string `json:"email"`
}
type NewUserResponse struct {
ID string `json:"_id"`
}
type editUserRequest struct {
Action string `json:"action"`
}