move GetDashboardUIDById out of sqlstore and into dashboard service (#49170)
* sqlstore: move GetDashboardUIDById to dashboard service * winding change through the rest of the codebase
This commit is contained in:
@@ -889,3 +889,18 @@ func (d *DashboardStore) GetDashboard(ctx context.Context, query *models.GetDash
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (d *DashboardStore) GetDashboardUIDById(ctx context.Context, query *models.GetDashboardRefByIdQuery) error {
|
||||
return d.sqlStore.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
var rawSQL = `SELECT uid, slug from dashboard WHERE Id=?`
|
||||
us := &models.DashboardRef{}
|
||||
exists, err := sess.SQL(rawSQL, query.Id).Get(us)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !exists {
|
||||
return models.ErrDashboardNotFound
|
||||
}
|
||||
query.Result = us
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -109,6 +109,14 @@ func TestDashboardDataAccess(t *testing.T) {
|
||||
require.False(t, query.Result.IsFolder)
|
||||
})
|
||||
|
||||
t.Run("Should be able to get a dashboard UID by ID", func(t *testing.T) {
|
||||
setup()
|
||||
query := models.GetDashboardRefByIdQuery{Id: savedDash.Id}
|
||||
err := dashboardStore.GetDashboardUIDById(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, query.Result.Uid, savedDash.Uid)
|
||||
})
|
||||
|
||||
t.Run("Shouldn't be able to get a dashboard with just an OrgID", func(t *testing.T) {
|
||||
setup()
|
||||
query := models.GetDashboardQuery{
|
||||
|
||||
Reference in New Issue
Block a user