-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
user.go
48 lines (42 loc) · 1.21 KB
/
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
package presenters
import (
"time"
"github.com/smartcontractkit/chainlink/v2/core/sessions"
)
// UserResource represents a User JSONAPI resource.
type UserResource struct {
JAID
Email string `json:"email"`
Role sessions.UserRole `json:"role"`
HasActiveApiToken string `json:"hasActiveApiToken"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// GetName implements the api2go EntityNamer interface
func (r UserResource) GetName() string {
return "users"
}
// NewUserResource constructs a new UserResource.
//
// A User does not have an ID primary key, so we must use the email
func NewUserResource(u sessions.User) *UserResource {
hasToken := "false"
if u.TokenKey.Valid {
hasToken = "true"
}
return &UserResource{
JAID: NewJAID(u.Email),
Email: u.Email,
Role: sessions.UserRole(u.Role),
HasActiveApiToken: hasToken,
CreatedAt: u.CreatedAt,
UpdatedAt: u.UpdatedAt,
}
}
func NewUserResources(users []sessions.User) []UserResource {
us := []UserResource{}
for _, user := range users {
us = append(us, *NewUserResource(user))
}
return us
}