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.
pull/2484/head
Michael Desa 2017-12-05 12:29:57 -05:00
parent 83e3ef8e2e
commit 04f65d1c68
2 changed files with 48 additions and 0 deletions

View File

@ -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)
}
}

View File

@ -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)