Remove RawUsers from DataStore
parent
00b79a45eb
commit
cf64b2e506
|
@ -32,11 +32,6 @@ func (s *Store) Users(ctx context.Context) chronograf.UsersStore {
|
|||
return s.UsersStore
|
||||
}
|
||||
|
||||
// TODO: remove me and put logic into Users Call
|
||||
func (s *Store) RawUsers(ctx context.Context) chronograf.UsersStore {
|
||||
return s.UsersStore
|
||||
}
|
||||
|
||||
func (s *Store) Organizations(ctx context.Context) chronograf.OrganizationsStore {
|
||||
return s.OrganizationsStore
|
||||
}
|
||||
|
|
11
server/me.go
11
server/me.go
|
@ -188,8 +188,10 @@ func (s *Service) Me(w http.ResponseWriter, r *http.Request) {
|
|||
// TODO: add real implementation
|
||||
ctx = context.WithValue(ctx, "organizationID", p.Organization)
|
||||
|
||||
// TODO: Change RawUsers to Users
|
||||
usr, err := s.Store.RawUsers(ctx).Get(ctx, chronograf.UserQuery{
|
||||
// TODO: add real implementation
|
||||
ctx = context.WithValue(ctx, "superadmin", true)
|
||||
|
||||
usr, err := s.Store.Users(ctx).Get(ctx, chronograf.UserQuery{
|
||||
Name: &p.Subject,
|
||||
Provider: &p.Issuer,
|
||||
Scheme: &scheme,
|
||||
|
@ -216,7 +218,10 @@ func (s *Service) Me(w http.ResponseWriter, r *http.Request) {
|
|||
Scheme: scheme,
|
||||
}
|
||||
|
||||
newUser, err := s.Store.RawUsers(ctx).Add(ctx, user)
|
||||
// TODO: add real implementation
|
||||
ctx = context.WithValue(ctx, "superadmin", true)
|
||||
|
||||
newUser, err := s.Store.Users(ctx).Add(ctx, user)
|
||||
if err != nil {
|
||||
msg := fmt.Errorf("error storing user %s: %v", user.Name, err)
|
||||
unknownErrorWithMessage(w, msg, s.Logger)
|
||||
|
|
|
@ -25,6 +25,21 @@ func hasOrganizationContext(ctx context.Context) (string, bool) {
|
|||
return orgID, true
|
||||
}
|
||||
|
||||
const superAdminKey = "superadmin"
|
||||
|
||||
func hasSuperAdminContext(ctx context.Context) (bool, bool) {
|
||||
// prevents panic in case of nil context
|
||||
if ctx == nil {
|
||||
return false, false
|
||||
}
|
||||
sa, ok := ctx.Value(superAdminKey).(bool)
|
||||
// should never happen
|
||||
if !ok {
|
||||
return false, false
|
||||
}
|
||||
return sa, true
|
||||
}
|
||||
|
||||
// TODO: Comment
|
||||
// DataSource is ...
|
||||
// Having this as an interface is useful for testing
|
||||
|
@ -33,8 +48,6 @@ type DataStore interface {
|
|||
Servers(ctx context.Context) chronograf.ServersStore
|
||||
Layouts(ctx context.Context) chronograf.LayoutsStore
|
||||
Users(ctx context.Context) chronograf.UsersStore
|
||||
// TODO: remove
|
||||
RawUsers(ctx context.Context) chronograf.UsersStore
|
||||
Organizations(ctx context.Context) chronograf.OrganizationsStore
|
||||
Dashboards(ctx context.Context) chronograf.DashboardsStore
|
||||
}
|
||||
|
@ -77,11 +90,15 @@ func (s *Store) Layouts(ctx context.Context) chronograf.LayoutsStore {
|
|||
}
|
||||
|
||||
func (s *Store) Users(ctx context.Context) chronograf.UsersStore {
|
||||
if superAdmin, ok := hasSuperAdminContext(ctx); ok && superAdmin {
|
||||
return s.UsersStore
|
||||
}
|
||||
if org, ok := hasOrganizationContext(ctx); ok {
|
||||
return organizations.NewUsersStore(s.UsersStore, org)
|
||||
}
|
||||
|
||||
return s.UsersStore
|
||||
// TODO: eventually have NoOpUserstore
|
||||
return organizations.NewUsersStore(s.UsersStore, "")
|
||||
}
|
||||
|
||||
func (s *Store) Dashboards(ctx context.Context) chronograf.DashboardsStore {
|
||||
|
@ -92,11 +109,6 @@ func (s *Store) Dashboards(ctx context.Context) chronograf.DashboardsStore {
|
|||
return s.DashboardsStore
|
||||
}
|
||||
|
||||
// TODO: remove me and put logic into Users Call
|
||||
func (s *Store) RawUsers(ctx context.Context) chronograf.UsersStore {
|
||||
return s.UsersStore
|
||||
}
|
||||
|
||||
func (s *Store) Organizations(ctx context.Context) chronograf.OrganizationsStore {
|
||||
return s.OrganizationsStore
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue