K8s: Dashboards: Fix multi-org provisioning flow (#102266)
This commit is contained in:
committed by
GitHub
parent
250cdbcd1a
commit
6019b21cc5
@@ -146,7 +146,7 @@ func (d *dashboardStore) GetProvisionedDashboardData(ctx context.Context, name s
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (d *dashboardStore) GetProvisionedDashboardsByName(ctx context.Context, name string) ([]*dashboards.Dashboard, error) {
|
||||
func (d *dashboardStore) GetProvisionedDashboardsByName(ctx context.Context, name string, orgID int64) ([]*dashboards.Dashboard, error) {
|
||||
ctx, span := tracer.Start(ctx, "dashboards.database.GetProvisionedDashboardsByName")
|
||||
defer span.End()
|
||||
|
||||
@@ -154,7 +154,7 @@ func (d *dashboardStore) GetProvisionedDashboardsByName(ctx context.Context, nam
|
||||
err := d.store.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
return sess.Table(`dashboard`).
|
||||
Join(`INNER`, `dashboard_provisioning`, `dashboard.id = dashboard_provisioning.dashboard_id`).
|
||||
Where(`dashboard_provisioning.name = ?`, name).Find(&dashes)
|
||||
Where(`dashboard_provisioning.name = ? AND dashboard.org_id = ?`, name, orgID).Find(&dashes)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -162,7 +162,7 @@ func (d *dashboardStore) GetProvisionedDashboardsByName(ctx context.Context, nam
|
||||
return dashes, nil
|
||||
}
|
||||
|
||||
func (d *dashboardStore) GetOrphanedProvisionedDashboards(ctx context.Context, notIn []string) ([]*dashboards.Dashboard, error) {
|
||||
func (d *dashboardStore) GetOrphanedProvisionedDashboards(ctx context.Context, notIn []string, orgID int64) ([]*dashboards.Dashboard, error) {
|
||||
ctx, span := tracer.Start(ctx, "dashboards.database.GetOrphanedProvisionedDashboards")
|
||||
defer span.End()
|
||||
|
||||
@@ -170,6 +170,7 @@ func (d *dashboardStore) GetOrphanedProvisionedDashboards(ctx context.Context, n
|
||||
err := d.store.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
return sess.Table(`dashboard`).
|
||||
Join(`INNER`, `dashboard_provisioning`, `dashboard.id = dashboard_provisioning.dashboard_id`).
|
||||
Where(`dashboard.org_id = ?`, orgID).
|
||||
NotIn(`dashboard_provisioning.name`, notIn).Find(&dashes)
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -293,16 +293,23 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
require.Equal(t, res[0], provisioningData)
|
||||
|
||||
// get dashboards within the provisioner
|
||||
dashs, err := dashboardStore.GetProvisionedDashboardsByName(context.Background(), "test")
|
||||
dashs, err := dashboardStore.GetProvisionedDashboardsByName(context.Background(), "test", 1)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, dashs, 1)
|
||||
dashs, err = dashboardStore.GetProvisionedDashboardsByName(context.Background(), "test", 2)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, dashs, 0)
|
||||
|
||||
// find dashboards not within that provisioner
|
||||
dashs, err = dashboardStore.GetOrphanedProvisionedDashboards(context.Background(), []string{"test"})
|
||||
dashs, err = dashboardStore.GetOrphanedProvisionedDashboards(context.Background(), []string{"test"}, 1)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, dashs, 1)
|
||||
dashs, err = dashboardStore.GetOrphanedProvisionedDashboards(context.Background(), []string{"test"}, 2)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, dashs, 0)
|
||||
|
||||
// if both are provided, nothing should be returned
|
||||
dashs, err = dashboardStore.GetOrphanedProvisionedDashboards(context.Background(), []string{"test", "orphaned"})
|
||||
dashs, err = dashboardStore.GetOrphanedProvisionedDashboards(context.Background(), []string{"test", "orphaned"}, 1)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, dashs, 0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user