mirror of
https://github.com/grafana/grafana.git
synced 2026-08-18 17:15:08 -05:00
Various fixes to data access
This commit is contained in:
@@ -59,8 +59,8 @@ func TestAccountDataAccess(t *testing.T) {
|
||||
err := GetSignedInUser(&query)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(query.Result.AccountId, ShouldEqual, ac2.AccountId)
|
||||
So(query.Result.Email, ShouldEqual, "ac2@test.com")
|
||||
So(query.Result.AccountId, ShouldEqual, ac2.AccountId)
|
||||
So(query.Result.Name, ShouldEqual, "ac2 name")
|
||||
So(query.Result.Login, ShouldEqual, "ac2")
|
||||
So(query.Result.AccountRole, ShouldEqual, "Admin")
|
||||
@@ -76,6 +76,15 @@ func TestAccountDataAccess(t *testing.T) {
|
||||
So(len(query.Result), ShouldEqual, 2)
|
||||
})
|
||||
|
||||
Convey("Can get account users", func() {
|
||||
query := m.GetAccountUsersQuery{AccountId: ac1.AccountId}
|
||||
err := GetAccountUsers(&query)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(len(query.Result), ShouldEqual, 2)
|
||||
So(query.Result[0].Role, ShouldEqual, "Admin")
|
||||
})
|
||||
|
||||
Convey("Can set using account", func() {
|
||||
cmd := m.SetUsingAccountCommand{UserId: ac2.Id, AccountId: ac1.Id}
|
||||
err := SetUsingAccount(&cmd)
|
||||
|
||||
@@ -36,7 +36,8 @@ func GetAccountUsers(query *m.GetAccountUsersQuery) error {
|
||||
sess := x.Table("account_user")
|
||||
sess.Join("INNER", "user", "account_user.user_id=user.id")
|
||||
sess.Where("account_user.account_id=?", query.AccountId)
|
||||
sess.Cols("account_user.account_id", "account_user.user_id", "user.email", "user.login")
|
||||
sess.Cols("account_user.account_id", "account_user.user_id", "user.email", "user.login", "account_user.role")
|
||||
sess.Asc("user.email", "user.login")
|
||||
|
||||
err := sess.Find(&query.Result)
|
||||
return err
|
||||
|
||||
@@ -120,7 +120,16 @@ func SearchDashboards(query *m.SearchDashboardsQuery) error {
|
||||
}
|
||||
|
||||
func GetDashboardTags(query *m.GetDashboardTagsQuery) error {
|
||||
sess := x.Sql("select count(*) as count, term from dashboard_tag group by term")
|
||||
sql := `SELECT
|
||||
COUNT(*) as count,
|
||||
term
|
||||
FROM dashboard
|
||||
INNER JOIN dashboard_tag on dashboard_tag.dashboard_id = dashboard.id
|
||||
WHERE dashboard.account_id=?
|
||||
GROUP BY term`
|
||||
|
||||
query.Result = make([]*m.DashboardTagCloudItem, 0)
|
||||
sess := x.Sql(sql, query.AccountId)
|
||||
err := sess.Find(&query.Result)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ func TestDashboardDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Should be able to get dashboard tags", func() {
|
||||
query := m.GetDashboardTagsQuery{}
|
||||
query := m.GetDashboardTagsQuery{AccountId: 1}
|
||||
|
||||
err := GetDashboardTags(&query)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Reference in New Issue
Block a user