-
Notifications
You must be signed in to change notification settings - Fork 29
/
organization_user.go
126 lines (103 loc) · 3.67 KB
/
organization_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
// Package aiven provides a client for using the Aiven API.
package aiven
import (
"context"
"time"
)
type (
// OrganizationUserHandler is the client which interacts with the Organization Users API on Aiven.
OrganizationUserHandler struct {
// client is the API client to use.
client *Client
}
// OrganizationUserList is a response from Aiven for a list of organization users.
OrganizationUserList struct {
APIResponse
// Users is a list of organization users.
Users []OrganizationMemberInfo `json:"users"`
}
// OrganizationMemberInfo is a struct that represents a user's membership in an organization.
OrganizationMemberInfo struct {
APIResponse
// UserID is the unique identifier of the user.
UserID string `json:"user_id"`
// JoinTime is the time when the user joined the organization.
JoinTime *time.Time `json:"join_time"`
// UserInfo is the information of the user.
UserInfo OrganizationUserInfo `json:"user_info"`
}
// OrganizationUserInfo is a struct that represents a user in an organization.
OrganizationUserInfo struct {
// UserEmail is the email of the user.
UserEmail string `json:"user_email"`
// RealName is the real name of the user.
RealName string `json:"real_name"`
// State is the state of the user.
State string `json:"state"`
// JobTitle is the job title of the user.
JobTitle string `json:"job_title"`
// Country is the country of the user.
Country string `json:"country"`
// Department is the department of the user.
Department string `json:"department"`
}
// OrganizationUserUpdateRequest are the parameters to update an organization user.
OrganizationUserUpdateRequest struct {
// IsSuperAdmin alters super admin state of the organization user.
IsSuperAdmin *bool `json:"is_super_admin,omitempty"`
// RealName is the real name of the user.
RealName *string `json:"real_name,omitempty"`
// JobTitle is the job title of the user.
JobTitle *string `json:"job_title,omitempty"`
// Department is the department of the user.
Department *string `json:"department,omitempty"`
// Country is the country of the user.
Country *string `json:"country,omitempty"`
// City is the city of the user.
City *string `json:"city,omitempty"`
}
)
// Update updates an organization user.
func (h *OrganizationUserHandler) Update(
ctx context.Context,
id string,
userID string,
req OrganizationUserUpdateRequest,
) (*OrganizationMemberInfo, error) {
path := buildPath("organization", id, "user", userID)
bts, err := h.client.doPatchRequest(ctx, path, req)
if err != nil {
return nil, err
}
var r OrganizationMemberInfo
return &r, checkAPIResponse(bts, &r)
}
// List returns a list of all organization user invitations.
func (h *OrganizationUserHandler) List(ctx context.Context, id string) (*OrganizationUserList, error) {
path := buildPath("organization", id, "user")
bts, err := h.client.doGetRequest(ctx, path, nil)
if err != nil {
return nil, err
}
var r OrganizationUserList
return &r, checkAPIResponse(bts, &r)
}
// Get returns a single organization user invitation.
func (h *OrganizationUserHandler) Get(ctx context.Context, id, userID string) (*OrganizationMemberInfo, error) {
path := buildPath("organization", id, "user", userID)
bts, err := h.client.doGetRequest(ctx, path, nil)
if err != nil {
return nil, err
}
var r OrganizationMemberInfo
return &r, checkAPIResponse(bts, &r)
}
// Delete deletes a single organization user invitation.
func (h *OrganizationUserHandler) Delete(ctx context.Context, id, userID string) error {
path := buildPath("organization", id, "user", userID)
bts, err := h.client.doDeleteRequest(ctx, path, nil)
if err != nil {
return err
}
return checkAPIResponse(bts, nil)
}