PublicDashboards: refactor service (#57372)
This commit is contained in:
@@ -258,8 +258,8 @@ func (d *PublicDashboardStoreImpl) UpdatePublicDashboardConfig(ctx context.Conte
|
||||
return err
|
||||
}
|
||||
|
||||
// Responds true if public dashboard for a dashboard exists and isEnabled
|
||||
func (d *PublicDashboardStoreImpl) PublicDashboardEnabled(ctx context.Context, dashboardUid string) (bool, error) {
|
||||
// EnabledPublicDashboardExistsByDashboardUid Responds true if there is an enabled public dashboard for a dashboard uid
|
||||
func (d *PublicDashboardStoreImpl) PublicDashboardEnabledExistsByDashboardUid(ctx context.Context, dashboardUid string) (bool, error) {
|
||||
hasPublicDashboard := false
|
||||
err := d.sqlStore.WithDbSession(ctx, func(dbSession *db.Session) error {
|
||||
sql := "SELECT COUNT(*) FROM dashboard_public WHERE dashboard_uid=? AND is_enabled=true"
|
||||
@@ -276,9 +276,8 @@ func (d *PublicDashboardStoreImpl) PublicDashboardEnabled(ctx context.Context, d
|
||||
return hasPublicDashboard, err
|
||||
}
|
||||
|
||||
// Responds true if accessToken exists and isEnabled. May be renamed in the
|
||||
// future
|
||||
func (d *PublicDashboardStoreImpl) AccessTokenExists(ctx context.Context, accessToken string) (bool, error) {
|
||||
// EnabledPublicDashboardExistsByAccessToken Responds true if accessToken exists and isEnabled
|
||||
func (d *PublicDashboardStoreImpl) PublicDashboardEnabledExistsByAccessToken(ctx context.Context, accessToken string) (bool, error) {
|
||||
hasPublicDashboard := false
|
||||
err := d.sqlStore.WithDbSession(ctx, func(dbSession *db.Session) error {
|
||||
sql := "SELECT COUNT(*) FROM dashboard_public WHERE access_token=? AND is_enabled=true"
|
||||
|
||||
@@ -88,8 +88,7 @@ func TestIntegrationGetDashboard(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// AccessTokenExists
|
||||
func TestIntegrationAccessTokenExists(t *testing.T) {
|
||||
func TestIntegrationEnabledPublicDashboardExistsByAccessToken(t *testing.T) {
|
||||
var sqlStore db.DB
|
||||
var cfg *setting.Cfg
|
||||
var dashboardStore *dashboardsDB.DashboardStore
|
||||
@@ -102,7 +101,7 @@ func TestIntegrationAccessTokenExists(t *testing.T) {
|
||||
publicdashboardStore = ProvideStore(sqlStore)
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||
}
|
||||
t.Run("AccessTokenExists will return true when at least one public dashboard has a matching access token", func(t *testing.T) {
|
||||
t.Run("PublicDashboardEnabledExistsByAccessToken will return true when at least one public dashboard has a matching access token", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
err := publicdashboardStore.SavePublicDashboardConfig(context.Background(), SavePublicDashboardConfigCommand{
|
||||
@@ -118,13 +117,13 @@ func TestIntegrationAccessTokenExists(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err := publicdashboardStore.AccessTokenExists(context.Background(), "accessToken")
|
||||
res, err := publicdashboardStore.PublicDashboardEnabledExistsByAccessToken(context.Background(), "accessToken")
|
||||
require.NoError(t, err)
|
||||
|
||||
require.True(t, res)
|
||||
})
|
||||
|
||||
t.Run("AccessTokenExists will return false when IsEnabled=false", func(t *testing.T) {
|
||||
t.Run("PublicDashboardEnabledExistsByAccessToken will return false when IsEnabled=false", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
err := publicdashboardStore.SavePublicDashboardConfig(context.Background(), SavePublicDashboardConfigCommand{
|
||||
@@ -140,24 +139,23 @@ func TestIntegrationAccessTokenExists(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err := publicdashboardStore.AccessTokenExists(context.Background(), "accessToken")
|
||||
res, err := publicdashboardStore.PublicDashboardEnabledExistsByAccessToken(context.Background(), "accessToken")
|
||||
require.NoError(t, err)
|
||||
|
||||
require.False(t, res)
|
||||
})
|
||||
|
||||
t.Run("AccessTokenExists will return false when no public dashboard has matching access token", func(t *testing.T) {
|
||||
t.Run("PublicDashboardEnabledExistsByAccessToken will return false when no public dashboard has matching access token", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
res, err := publicdashboardStore.AccessTokenExists(context.Background(), "accessToken")
|
||||
res, err := publicdashboardStore.PublicDashboardEnabledExistsByAccessToken(context.Background(), "accessToken")
|
||||
|
||||
require.NoError(t, err)
|
||||
require.False(t, res)
|
||||
})
|
||||
}
|
||||
|
||||
// PublicDashboardEnabled
|
||||
func TestIntegrationPublicDashboardEnabled(t *testing.T) {
|
||||
func TestIntegrationEnabledPublicDashboardExistsByDashboardUid(t *testing.T) {
|
||||
var sqlStore db.DB
|
||||
var cfg *setting.Cfg
|
||||
var dashboardStore *dashboardsDB.DashboardStore
|
||||
@@ -171,7 +169,7 @@ func TestIntegrationPublicDashboardEnabled(t *testing.T) {
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||
}
|
||||
|
||||
t.Run("PublicDashboardEnabled Will return true when dashboard has at least one enabled public dashboard", func(t *testing.T) {
|
||||
t.Run("PublicDashboardEnabledExistsByDashboardUid Will return true when dashboard has at least one enabled public dashboard", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
err := publicdashboardStore.SavePublicDashboardConfig(context.Background(), SavePublicDashboardConfigCommand{
|
||||
@@ -187,13 +185,13 @@ func TestIntegrationPublicDashboardEnabled(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err := publicdashboardStore.PublicDashboardEnabled(context.Background(), savedDashboard.Uid)
|
||||
res, err := publicdashboardStore.PublicDashboardEnabledExistsByDashboardUid(context.Background(), savedDashboard.Uid)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.True(t, res)
|
||||
})
|
||||
|
||||
t.Run("PublicDashboardEnabled will return false when dashboard has public dashboards but they are not enabled", func(t *testing.T) {
|
||||
t.Run("PublicDashboardEnabledExistsByDashboardUid will return false when dashboard has public dashboards but they are not enabled", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
err := publicdashboardStore.SavePublicDashboardConfig(context.Background(), SavePublicDashboardConfigCommand{
|
||||
@@ -209,7 +207,7 @@ func TestIntegrationPublicDashboardEnabled(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err := publicdashboardStore.PublicDashboardEnabled(context.Background(), savedDashboard.Uid)
|
||||
res, err := publicdashboardStore.PublicDashboardEnabledExistsByDashboardUid(context.Background(), savedDashboard.Uid)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.False(t, res)
|
||||
|
||||
Reference in New Issue
Block a user