diff --git a/server/me.go b/server/me.go index adf144e2d6..8d343e7331 100644 --- a/server/me.go +++ b/server/me.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "sort" "golang.org/x/net/context" @@ -318,6 +319,10 @@ func (s *Service) usersOrganizations(ctx context.Context, u *chronograf.User) ([ orgs = append(orgs, *org) } + sort.Slice(orgs, func(i, j int) bool { + return orgs[i].ID < orgs[j].ID + }) + return orgs, nil } diff --git a/server/me_test.go b/server/me_test.go index 61b62e11fe..cf769f8750 100644 --- a/server/me_test.go +++ b/server/me_test.go @@ -349,7 +349,7 @@ func TestService_MeOrganizations(t *testing.T) { }, wantStatus: http.StatusOK, wantContentType: "application/json", - wantBody: `{"name":"me","roles":[{"name":"admin","organization":"1337"},{"name":"member","organization":"0"}],"provider":"github","scheme":"oauth2","links":{"self":"/chronograf/v1/users/0"},"organizations":[{"id":"1337","name":"The ShillBillThrilliettas"},{"id":"0","name":"Default"}],"currentOrganization":{"id":"1337","name":"The ShillBillThrilliettas"}}`, + wantBody: `{"name":"me","roles":[{"name":"admin","organization":"1337"},{"name":"member","organization":"0"}],"provider":"github","scheme":"oauth2","links":{"self":"/chronograf/v1/users/0"},"organizations":[{"id":"0","name":"Default"},{"id":"1337","name":"The ShillBillThrilliettas"}],"currentOrganization":{"id":"1337","name":"The ShillBillThrilliettas"}}`, }, { name: "Change the current User's organization", @@ -419,8 +419,7 @@ func TestService_MeOrganizations(t *testing.T) { }, wantStatus: http.StatusOK, wantContentType: "application/json", - wantBody: `{"name":"me","roles":[{"name":"admin","organization":"1337"},{"name":"member","organization":"0"}],"provider":"github","scheme":"oauth2","links":{"self":"/chronograf/v1/users/0"},"organizations":[{"id":"1337","name":"The ThrillShilliettos"},{"id":"0","name":"Default"}],"currentOrganization":{"id":"1337","name":"The ThrillShilliettos"}} -`, + wantBody: `{"name":"me","roles":[{"name":"admin","organization":"1337"},{"name":"member","organization":"0"}],"provider":"github","scheme":"oauth2","links":{"self":"/chronograf/v1/users/0"},"organizations":[{"id":"0","name":"Default"},{"id":"1337","name":"The ThrillShilliettos"}],"currentOrganization":{"id":"1337","name":"The ThrillShilliettos"}}`, }, { name: "Unable to find requested user in valid organization",