Repository navigation
Expand file tree
/
Copy pathinitial_state.go
More file actions
117 lines (106 loc) · 3.56 KB
/
Copy pathinitial_state.go
File metadata and controls
117 lines (106 loc) · 3.56 KB
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
package web
import (
"github.com/resonatecoop/id/config"
"github.com/resonatecoop/id/session"
"github.com/resonatecoop/user-api-client/models"
"github.com/resonatecoop/user-api/model"
)
// Profile user public profile
type Profile struct {
ID string `json:"id"`
Role string `json:"role"`
LegacyID int32 `json:"legacyID"`
DisplayName string `json:"displayName"`
Email string `json:"email"`
Credits string `json:"credits"`
// FullName string `json:"fullName"`
// FirstName string `json:"firstName"`
// LastName string `json:"lastName"`
Country string `json:"country"`
NewsletterNotification bool `json:"newsletterNotification"`
EmailConfirmed bool `json:"emailConfirmed"`
Member bool `json:"member"`
Complete bool `json:"complete"`
Usergroups []*models.UserUserGroupPrivateResponse `json:"usergroups"`
}
// NewProfile
func NewProfile(
user *model.User,
usergroups []*models.UserUserGroupPrivateResponse,
isUserAccountComplete bool,
credits string,
role string,
) *Profile {
displayName := ""
if len(usergroups) > 0 {
displayName = usergroups[0].DisplayName
}
return &Profile{
ID: user.ID.String(),
Complete: isUserAccountComplete,
Country: user.Country,
Credits: credits,
DisplayName: displayName,
Role: role,
Email: user.Username,
EmailConfirmed: user.EmailConfirmed,
LegacyID: user.LegacyID,
Member: user.Member,
NewsletterNotification: user.NewsletterNotification,
Usergroups: usergroups,
}
}
type InitialState struct {
ApplicationName string `json:"applicationName"`
ClientID string `json:"clientID"`
UserGroup string `json:"usergroup"`
Token string `json:"token"`
Clients []config.ClientConfig `json:"clients"`
Profile *Profile `json:"profile"`
Memberships []Membership `json:"memberships"`
Shares []Share `json:"shares"`
Products []Product `json:"products"`
CSRFToken string `json:"csrfToken"`
CountryList []Country `json:"countries"`
}
func NewInitialState(
cnf *config.Config,
client *model.Client,
user *model.User,
userSession *session.UserSession,
isUserAccountComplete bool,
credits string,
usergroups []*models.UserUserGroupPrivateResponse,
memberships []Membership,
shares []Share,
products []Product,
csrfToken string,
countryList []Country,
) *InitialState {
accessToken := ""
if userSession != nil {
accessToken = userSession.AccessToken
}
profile := NewProfile(
user,
usergroups,
isUserAccountComplete,
credits,
userSession.Role,
)
if len(usergroups) > 0 {
profile.DisplayName = usergroups[0].DisplayName
}
return &InitialState{
ApplicationName: client.ApplicationName.String,
ClientID: client.Key,
Clients: cnf.Clients,
Profile: profile,
Token: accessToken,
Memberships: memberships,
Shares: shares,
Products: products,
CSRFToken: csrfToken,
CountryList: countryList,
}
}