@@ -2,25 +2,52 @@ package client
22
33import "fmt"
44
5+ type Credentials struct {
6+ Permissions []string `json:"permissions,omitempty"`
7+ }
8+
9+ type Login struct {
10+ Credentials Credentials `json:"credentials,omitempty"`
11+ PersonalGit bool `json:"personalGit,omitempty"`
12+ Permissions []string `json:"permissions,omitempty"`
13+ IDP IDP `json:"idp,omitempty"`
14+ }
15+
16+ type ShortProfile struct {
17+ UserName string `json:"userName,omitempty"`
18+ }
19+
20+ type Personal struct {
21+ FirstName string `json:"firstName,omitempty"`
22+ LastName string `json:"lastName,omitempty"`
23+ CompanyName string `json:"companyName,omitempty"`
24+ PhoneNumber string `json:"phoneNumber,omitempty"`
25+ Country string `json:"country,omitempty"`
26+ }
27+
528type User struct {
6- ID string `json:"_id"`
29+ ID string `json:"_id,omitempty "`
730 UserName string `json:"userName"`
831 Email string `json:"email"`
9- Roles []interface {} `json:"roles"`
10- DefaultAccount int `json:"defaultAccount"`
11- Account []Account `json:"account"`
12- Status string `json:"status"`
13- RegisterDate string `json:"register_date"`
14- HasPassword bool `json:"hasPassword"`
15- Notifications []NotificationEvent `json:"notifications"`
16- ShortProfile struct {
17- UserName string `json:"userName"`
18- } `json:"shortProfile"`
19- Settings struct {
20- SendWeeklyReport bool `json:"sendWeeklyReport"`
21- } `json:"settings"`
22- Logins []interface {} `json:"logins"`
23- InviteURL string `json:"inviteUrl"`
32+ Personal Personal `json:"personal,omitempty"`
33+ Roles []string `json:"roles,omitempty"`
34+ DefaultAccount int `json:"defaultAccount,omitempty"`
35+ Account []Account `json:"account,omitempty"`
36+ Status string `json:"status,omitempty"`
37+ RegisterDate string `json:"register_date,omitempty"`
38+ HasPassword bool `json:"hasPassword,omitempty"`
39+ Notifications []NotificationEvent `json:"notifications,omitempty"`
40+ ShortProfile ShortProfile `json:"shortProfile,omitempty"`
41+ Logins []Login `json:"logins,omitempty"`
42+ InviteURL string `json:"inviteUrl,omitempty"`
43+ }
44+
45+ type NewUser struct {
46+ UserName string `json:"userName"`
47+ Email string `json:"email"`
48+ Logins []Login `json:"logins,omitempty"`
49+ Roles []string `json:"roles,omitempty"`
50+ Account []string `json:"account,omitempty"`
2451}
2552
2653func (client * Client ) AddNewUserToAccount (accountId , userName , userEmail string ) (* User , error ) {
@@ -50,6 +77,33 @@ func (client *Client) AddNewUserToAccount(accountId, userName, userEmail string)
5077 return & user , nil
5178}
5279
80+ func (client * Client ) AddPendingUser (user * NewUser ) (* User , error ) {
81+
82+ body , err := EncodeToJSON (user )
83+ if err != nil {
84+ return nil , err
85+ }
86+ opts := RequestOptions {
87+ Path : "/admin/accounts/addpendinguser" ,
88+ Method : "POST" ,
89+ Body : body ,
90+ }
91+
92+ resp , err := client .RequestAPI (& opts )
93+ if err != nil {
94+ return nil , err
95+ }
96+
97+ var respUser User
98+
99+ err = DecodeResponseInto (resp , & respUser )
100+ if err != nil {
101+ return nil , err
102+ }
103+
104+ return & respUser , nil
105+ }
106+
53107func (client * Client ) ActivateUser (userId string ) (* User , error ) {
54108
55109 opts := RequestOptions {
@@ -86,4 +140,57 @@ func (client *Client) SetUserAsAccountAdmin(accountId, userId string) error {
86140 }
87141
88142 return nil
89- }
143+ }
144+
145+ func (client * Client ) DeleteUserAsAccountAdmin (accountId , userId string ) error {
146+
147+ opts := RequestOptions {
148+ Path : fmt .Sprintf ("/accounts/%s/%s/admin" , accountId , userId ),
149+ Method : "DELETE" ,
150+ }
151+
152+ _ , err := client .RequestAPI (& opts )
153+ if err != nil {
154+ return err
155+ }
156+
157+ return nil
158+ }
159+
160+ func (client * Client ) ListUsers () (* []User , error ) {
161+
162+ opts := RequestOptions {
163+ Path : "/admin/user" ,
164+ Method : "GET" ,
165+ }
166+
167+ resp , err := client .RequestAPI (& opts )
168+ if err != nil {
169+ return nil , err
170+ }
171+
172+ var users []User
173+
174+ err = DecodeResponseInto (resp , & users )
175+ if err != nil {
176+ return nil , err
177+ }
178+
179+ return & users , nil
180+ }
181+
182+ func (client * Client ) DeleteUser (userName string ) error {
183+
184+ opts := RequestOptions {
185+ Path : fmt .Sprintf ("/admi/user/%s" , userName ),
186+ Method : "DELETE" ,
187+ }
188+
189+ _ , err := client .RequestAPI (& opts )
190+ if err != nil {
191+ return err
192+ }
193+
194+ return nil
195+ }
196+
0 commit comments