mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Various fixes to data access
This commit is contained in:
parent
0a695ba17a
commit
4ea5d80099
2
grafana
2
grafana
@ -1 +1 @@
|
|||||||
Subproject commit 590c3b4b50195cacf02fbd0456d55ef69db16b79
|
Subproject commit d9a33680a686ac6bc1239797278ad03b3c784d1c
|
@ -17,7 +17,7 @@ func Search(c *middleware.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(queryText, "tags!:") {
|
if strings.HasPrefix(queryText, "tags!:") {
|
||||||
query := m.GetDashboardTagsQuery{}
|
query := m.GetDashboardTagsQuery{AccountId: c.AccountId}
|
||||||
err := bus.Dispatch(&query)
|
err := bus.Dispatch(&query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JsonApiErr(500, "Failed to get tags from database", err)
|
c.JsonApiErr(500, "Failed to get tags from database", err)
|
||||||
|
@ -67,7 +67,7 @@ func validateUsingAccount(userId int64, accountId int64) bool {
|
|||||||
func SetUsingAccount(c *middleware.Context) {
|
func SetUsingAccount(c *middleware.Context) {
|
||||||
usingAccountId := c.ParamsInt64(":id")
|
usingAccountId := c.ParamsInt64(":id")
|
||||||
|
|
||||||
if !validateUsingAccount(c.AccountId, usingAccountId) {
|
if !validateUsingAccount(c.UserId, usingAccountId) {
|
||||||
c.JsonApiErr(401, "Not a valid account", nil)
|
c.JsonApiErr(401, "Not a valid account", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ type GetAccountByIdQuery struct {
|
|||||||
|
|
||||||
type UserAccountDTO struct {
|
type UserAccountDTO struct {
|
||||||
AccountId int64 `json:"accountId"`
|
AccountId int64 `json:"accountId"`
|
||||||
Name string `json:"email"`
|
Name string `json:"name"`
|
||||||
Role RoleType `json:"role"`
|
Role RoleType `json:"role"`
|
||||||
IsUsing bool `json:"isUsing"`
|
IsUsing bool `json:"isUsing"`
|
||||||
}
|
}
|
||||||
|
@ -59,8 +59,8 @@ func TestAccountDataAccess(t *testing.T) {
|
|||||||
err := GetSignedInUser(&query)
|
err := GetSignedInUser(&query)
|
||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(query.Result.AccountId, ShouldEqual, ac2.AccountId)
|
|
||||||
So(query.Result.Email, ShouldEqual, "ac2@test.com")
|
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.Name, ShouldEqual, "ac2 name")
|
||||||
So(query.Result.Login, ShouldEqual, "ac2")
|
So(query.Result.Login, ShouldEqual, "ac2")
|
||||||
So(query.Result.AccountRole, ShouldEqual, "Admin")
|
So(query.Result.AccountRole, ShouldEqual, "Admin")
|
||||||
@ -76,6 +76,15 @@ func TestAccountDataAccess(t *testing.T) {
|
|||||||
So(len(query.Result), ShouldEqual, 2)
|
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() {
|
Convey("Can set using account", func() {
|
||||||
cmd := m.SetUsingAccountCommand{UserId: ac2.Id, AccountId: ac1.Id}
|
cmd := m.SetUsingAccountCommand{UserId: ac2.Id, AccountId: ac1.Id}
|
||||||
err := SetUsingAccount(&cmd)
|
err := SetUsingAccount(&cmd)
|
||||||
|
@ -36,7 +36,8 @@ func GetAccountUsers(query *m.GetAccountUsersQuery) error {
|
|||||||
sess := x.Table("account_user")
|
sess := x.Table("account_user")
|
||||||
sess.Join("INNER", "user", "account_user.user_id=user.id")
|
sess.Join("INNER", "user", "account_user.user_id=user.id")
|
||||||
sess.Where("account_user.account_id=?", query.AccountId)
|
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)
|
err := sess.Find(&query.Result)
|
||||||
return err
|
return err
|
||||||
|
@ -120,7 +120,16 @@ func SearchDashboards(query *m.SearchDashboardsQuery) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetDashboardTags(query *m.GetDashboardTagsQuery) 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)
|
err := sess.Find(&query.Result)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func TestDashboardDataAccess(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Should be able to get dashboard tags", func() {
|
Convey("Should be able to get dashboard tags", func() {
|
||||||
query := m.GetDashboardTagsQuery{}
|
query := m.GetDashboardTagsQuery{AccountId: 1}
|
||||||
|
|
||||||
err := GetDashboardTags(&query)
|
err := GetDashboardTags(&query)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
Loading…
Reference in New Issue
Block a user