Only promote user to super admin in user org store
Add diff check to Organization UsersStore Add tests Previously, a users super admin status was disregarded in the Add facade. This was problematic when new users were added with a super admin status, because they would not be granted the status. This created an odd user experiece.pull/2552/head
parent
456488f0ac
commit
1298c2eedc
|
@ -142,6 +142,16 @@ func (s *UsersStore) Add(ctx context.Context, u *chronograf.User) (*chronograf.U
|
|||
// and the user that was found in the underlying store
|
||||
usr.Roles = append(roles, u.Roles...)
|
||||
|
||||
// u.SuperAdmin == true is logically equivalent to u.SuperAdmin, however
|
||||
// it is more clear on a conceptual level to check equality
|
||||
//
|
||||
// TODO(desa): this should go away with https://github.com/influxdata/chronograf/issues/2207
|
||||
// I do not like checking super admin here. The organization users store should only be
|
||||
// concerned about organizations.
|
||||
if u.SuperAdmin == true {
|
||||
usr.SuperAdmin = true
|
||||
}
|
||||
|
||||
// Update the user in the underlying store
|
||||
if err := s.store.Update(ctx, usr); err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -315,9 +315,62 @@ func TestUsersStore_Add(t *testing.T) {
|
|||
Scheme: "oauth2",
|
||||
Roles: []chronograf.Role{
|
||||
{
|
||||
Organization: "1337",
|
||||
Name: "editor",
|
||||
Organization: "1336",
|
||||
Name: "admin",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Add non-new user with Role. Stored user is not super admin. Provided user is super admin",
|
||||
fields: fields{
|
||||
UsersStore: &mocks.UsersStore{
|
||||
AddF: func(ctx context.Context, u *chronograf.User) (*chronograf.User, error) {
|
||||
return u, nil
|
||||
},
|
||||
UpdateF: func(ctx context.Context, u *chronograf.User) error {
|
||||
return nil
|
||||
},
|
||||
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
||||
return &chronograf.User{
|
||||
ID: 1234,
|
||||
Name: "docbrown",
|
||||
Provider: "github",
|
||||
Scheme: "oauth2",
|
||||
SuperAdmin: false,
|
||||
Roles: []chronograf.Role{
|
||||
{
|
||||
Organization: "1337",
|
||||
Name: "editor",
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
},
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
u: &chronograf.User{
|
||||
ID: 1234,
|
||||
Name: "docbrown",
|
||||
Provider: "github",
|
||||
Scheme: "oauth2",
|
||||
SuperAdmin: true,
|
||||
Roles: []chronograf.Role{
|
||||
{
|
||||
Organization: "1336",
|
||||
Name: "admin",
|
||||
},
|
||||
},
|
||||
},
|
||||
orgID: "1336",
|
||||
},
|
||||
want: &chronograf.User{
|
||||
Name: "docbrown",
|
||||
Provider: "github",
|
||||
Scheme: "oauth2",
|
||||
SuperAdmin: true,
|
||||
Roles: []chronograf.Role{
|
||||
{
|
||||
Organization: "1336",
|
||||
Name: "admin",
|
||||
|
@ -503,6 +556,9 @@ func TestUsersStore_Add(t *testing.T) {
|
|||
if got == nil && tt.want == nil {
|
||||
continue
|
||||
}
|
||||
if diff := cmp.Diff(got, tt.want, userCmpOptions...); diff != "" {
|
||||
t.Errorf("%q. UsersStore.Add():\n-got/+want\ndiff %s", tt.name, diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue