From 04f65d1c68e050d90152d6b3087a7fa2de26c9f8 Mon Sep 17 00:00:00 2001 From: Michael Desa Date: Tue, 5 Dec 2017 12:29:57 -0500 Subject: [PATCH] Allow empty Organization on Layouts in Org store Previously, canned dashboards were global to the application. When organizations were introduced, we scoped layouts under a specific organization. This was done without consideration to the `canned` layouts which are more global than a specific organization and likely apply an an application level. Since the layout did not have any organization associated with it, it was filtered out of the list of results that one would see for `GET /mappings`. This commit allows users to retrieve layouts that are stored in the canned store that do not have an organization associated when the user requests `All` layouts for an organization. Future work for this is outlined as a comment in the commit. --- organizations/layouts.go | 11 +++++++++++ organizations/layouts_test.go | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/organizations/layouts.go b/organizations/layouts.go index f79a49c0e..2f744c1e3 100644 --- a/organizations/layouts.go +++ b/organizations/layouts.go @@ -43,6 +43,17 @@ func (s *LayoutsStore) All(ctx context.Context) ([]chronograf.Layout, error) { layouts := ds[:0] for _, d := range ds { if d.Organization == s.organization { + // If the layout belongs to the organization add it to the list + layouts = append(layouts, d) + } + + // Layouts stored in the canned layouts store do not + // have an organization associated with them and as a result + // would be filtered out without this. It may be worth while + // to add a `*` organization to check for instead, since this + // change has implications elsewhere or possibly a Global + // attribute on the layout. + if d.Organization == "" { layouts = append(layouts, d) } } diff --git a/organizations/layouts_test.go b/organizations/layouts_test.go index 02095227c..1d182405a 100644 --- a/organizations/layouts_test.go +++ b/organizations/layouts_test.go @@ -75,6 +75,43 @@ func TestLayouts_All(t *testing.T) { }, }, }, + { + name: "All Layouts with empty organization", + fields: fields{ + LayoutsStore: &mocks.LayoutsStore{ + AllF: func(ctx context.Context) ([]chronograf.Layout, error) { + return []chronograf.Layout{ + { + Application: "howdy", + Organization: "1337", + }, + { + Application: "doody", + Organization: "1338", + }, + { + Application: "noorg", + Organization: "", + }, + }, nil + }, + }, + }, + args: args{ + organization: "1337", + ctx: context.Background(), + }, + want: []chronograf.Layout{ + { + Application: "howdy", + Organization: "1337", + }, + { + Application: "noorg", + Organization: "", + }, + }, + }, } for _, tt := range tests { s := organizations.NewLayoutsStore(tt.fields.LayoutsStore, tt.args.organization)