Remove RawUsers from DataStore
parent
00b79a45eb
commit
cf64b2e506
|
@ -32,11 +32,6 @@ func (s *Store) Users(ctx context.Context) chronograf.UsersStore {
|
||||||
return s.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 {
|
func (s *Store) Organizations(ctx context.Context) chronograf.OrganizationsStore {
|
||||||
return s.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
|
// TODO: add real implementation
|
||||||
ctx = context.WithValue(ctx, "organizationID", p.Organization)
|
ctx = context.WithValue(ctx, "organizationID", p.Organization)
|
||||||
|
|
||||||
// TODO: Change RawUsers to Users
|
// TODO: add real implementation
|
||||||
usr, err := s.Store.RawUsers(ctx).Get(ctx, chronograf.UserQuery{
|
ctx = context.WithValue(ctx, "superadmin", true)
|
||||||
|
|
||||||
|
usr, err := s.Store.Users(ctx).Get(ctx, chronograf.UserQuery{
|
||||||
Name: &p.Subject,
|
Name: &p.Subject,
|
||||||
Provider: &p.Issuer,
|
Provider: &p.Issuer,
|
||||||
Scheme: &scheme,
|
Scheme: &scheme,
|
||||||
|
@ -216,7 +218,10 @@ func (s *Service) Me(w http.ResponseWriter, r *http.Request) {
|
||||||
Scheme: scheme,
|
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 {
|
if err != nil {
|
||||||
msg := fmt.Errorf("error storing user %s: %v", user.Name, err)
|
msg := fmt.Errorf("error storing user %s: %v", user.Name, err)
|
||||||
unknownErrorWithMessage(w, msg, s.Logger)
|
unknownErrorWithMessage(w, msg, s.Logger)
|
||||||
|
|
|
@ -25,6 +25,21 @@ func hasOrganizationContext(ctx context.Context) (string, bool) {
|
||||||
return orgID, true
|
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
|
// TODO: Comment
|
||||||
// DataSource is ...
|
// DataSource is ...
|
||||||
// Having this as an interface is useful for testing
|
// Having this as an interface is useful for testing
|
||||||
|
@ -33,8 +48,6 @@ type DataStore interface {
|
||||||
Servers(ctx context.Context) chronograf.ServersStore
|
Servers(ctx context.Context) chronograf.ServersStore
|
||||||
Layouts(ctx context.Context) chronograf.LayoutsStore
|
Layouts(ctx context.Context) chronograf.LayoutsStore
|
||||||
Users(ctx context.Context) chronograf.UsersStore
|
Users(ctx context.Context) chronograf.UsersStore
|
||||||
// TODO: remove
|
|
||||||
RawUsers(ctx context.Context) chronograf.UsersStore
|
|
||||||
Organizations(ctx context.Context) chronograf.OrganizationsStore
|
Organizations(ctx context.Context) chronograf.OrganizationsStore
|
||||||
Dashboards(ctx context.Context) chronograf.DashboardsStore
|
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 {
|
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 {
|
if org, ok := hasOrganizationContext(ctx); ok {
|
||||||
return organizations.NewUsersStore(s.UsersStore, org)
|
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 {
|
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
|
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 {
|
func (s *Store) Organizations(ctx context.Context) chronograf.OrganizationsStore {
|
||||||
return s.OrganizationsStore
|
return s.OrganizationsStore
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue