Commit b4576edc by Daniel Lee

WIP: fix after upstream sqlstore refactoring

parent 764d25f0
...@@ -3,7 +3,6 @@ package sqlstore ...@@ -3,7 +3,6 @@ package sqlstore
import ( import (
"time" "time"
"github.com/go-xorm/xorm"
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models" m "github.com/grafana/grafana/pkg/models"
) )
...@@ -15,7 +14,7 @@ func init() { ...@@ -15,7 +14,7 @@ func init() {
} }
func AddOrUpdateDashboardPermission(cmd *m.AddOrUpdateDashboardPermissionCommand) error { func AddOrUpdateDashboardPermission(cmd *m.AddOrUpdateDashboardPermissionCommand) error {
return inTransaction(func(sess *xorm.Session) error { return inTransaction(func(sess *DBSession) error {
if res, err := sess.Query("SELECT 1 from "+dialect.Quote("dashboard_acl")+" WHERE dashboard_id =? and (user_group_id=? or user_id=?)", cmd.DashboardId, cmd.UserGroupId, cmd.UserId); err != nil { if res, err := sess.Query("SELECT 1 from "+dialect.Quote("dashboard_acl")+" WHERE dashboard_id =? and (user_group_id=? or user_id=?)", cmd.DashboardId, cmd.UserGroupId, cmd.UserId); err != nil {
return err return err
} else if len(res) == 1 { } else if len(res) == 1 {
...@@ -67,7 +66,7 @@ func AddOrUpdateDashboardPermission(cmd *m.AddOrUpdateDashboardPermissionCommand ...@@ -67,7 +66,7 @@ func AddOrUpdateDashboardPermission(cmd *m.AddOrUpdateDashboardPermissionCommand
} }
func RemoveDashboardPermission(cmd *m.RemoveDashboardPermissionCommand) error { func RemoveDashboardPermission(cmd *m.RemoveDashboardPermissionCommand) error {
return inTransaction(func(sess *xorm.Session) error { return inTransaction(func(sess *DBSession) error {
var rawSQL = "DELETE FROM " + dialect.Quote("dashboard_acl") + " WHERE dashboard_id =? and (user_group_id=? or user_id=?)" var rawSQL = "DELETE FROM " + dialect.Quote("dashboard_acl") + " WHERE dashboard_id =? and (user_group_id=? or user_id=?)"
_, err := sess.Exec(rawSQL, cmd.DashboardId, cmd.UserGroupId, cmd.UserId) _, err := sess.Exec(rawSQL, cmd.DashboardId, cmd.UserGroupId, cmd.UserId)
if err != nil { if err != nil {
......
...@@ -4,8 +4,6 @@ import ( ...@@ -4,8 +4,6 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/go-xorm/xorm"
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models" m "github.com/grafana/grafana/pkg/models"
) )
...@@ -24,7 +22,7 @@ func init() { ...@@ -24,7 +22,7 @@ func init() {
} }
func CreateUserGroup(cmd *m.CreateUserGroupCommand) error { func CreateUserGroup(cmd *m.CreateUserGroupCommand) error {
return inTransaction2(func(sess *session) error { return inTransaction(func(sess *DBSession) error {
if isNameTaken, err := isUserGroupNameTaken(cmd.Name, 0, sess); err != nil { if isNameTaken, err := isUserGroupNameTaken(cmd.Name, 0, sess); err != nil {
return err return err
...@@ -48,7 +46,7 @@ func CreateUserGroup(cmd *m.CreateUserGroupCommand) error { ...@@ -48,7 +46,7 @@ func CreateUserGroup(cmd *m.CreateUserGroupCommand) error {
} }
func UpdateUserGroup(cmd *m.UpdateUserGroupCommand) error { func UpdateUserGroup(cmd *m.UpdateUserGroupCommand) error {
return inTransaction2(func(sess *session) error { return inTransaction(func(sess *DBSession) error {
if isNameTaken, err := isUserGroupNameTaken(cmd.Name, cmd.Id, sess); err != nil { if isNameTaken, err := isUserGroupNameTaken(cmd.Name, cmd.Id, sess); err != nil {
return err return err
...@@ -76,7 +74,7 @@ func UpdateUserGroup(cmd *m.UpdateUserGroupCommand) error { ...@@ -76,7 +74,7 @@ func UpdateUserGroup(cmd *m.UpdateUserGroupCommand) error {
} }
func DeleteUserGroup(cmd *m.DeleteUserGroupCommand) error { func DeleteUserGroup(cmd *m.DeleteUserGroupCommand) error {
return inTransaction2(func(sess *session) error { return inTransaction(func(sess *DBSession) error {
if res, err := sess.Query("SELECT 1 from user_group WHERE id=?", cmd.Id); err != nil { if res, err := sess.Query("SELECT 1 from user_group WHERE id=?", cmd.Id); err != nil {
return err return err
} else if len(res) != 1 { } else if len(res) != 1 {
...@@ -98,7 +96,7 @@ func DeleteUserGroup(cmd *m.DeleteUserGroupCommand) error { ...@@ -98,7 +96,7 @@ func DeleteUserGroup(cmd *m.DeleteUserGroupCommand) error {
}) })
} }
func isUserGroupNameTaken(name string, existingId int64, sess *session) (bool, error) { func isUserGroupNameTaken(name string, existingId int64, sess *DBSession) (bool, error) {
var userGroup m.UserGroup var userGroup m.UserGroup
exists, err := sess.Where("name=?", name).Get(&userGroup) exists, err := sess.Where("name=?", name).Get(&userGroup)
...@@ -179,7 +177,7 @@ func GetUserGroupsByUser(query *m.GetUserGroupsByUserQuery) error { ...@@ -179,7 +177,7 @@ func GetUserGroupsByUser(query *m.GetUserGroupsByUserQuery) error {
} }
func AddUserGroupMember(cmd *m.AddUserGroupMemberCommand) error { func AddUserGroupMember(cmd *m.AddUserGroupMemberCommand) error {
return inTransaction(func(sess *xorm.Session) error { return inTransaction(func(sess *DBSession) error {
if res, err := sess.Query("SELECT 1 from user_group_member WHERE user_group_id=? and user_id=?", cmd.UserGroupId, cmd.UserId); err != nil { if res, err := sess.Query("SELECT 1 from user_group_member WHERE user_group_id=? and user_id=?", cmd.UserGroupId, cmd.UserId); err != nil {
return err return err
} else if len(res) == 1 { } else if len(res) == 1 {
...@@ -206,7 +204,7 @@ func AddUserGroupMember(cmd *m.AddUserGroupMemberCommand) error { ...@@ -206,7 +204,7 @@ func AddUserGroupMember(cmd *m.AddUserGroupMemberCommand) error {
} }
func RemoveUserGroupMember(cmd *m.RemoveUserGroupMemberCommand) error { func RemoveUserGroupMember(cmd *m.RemoveUserGroupMemberCommand) error {
return inTransaction(func(sess *xorm.Session) error { return inTransaction(func(sess *DBSession) error {
var rawSql = "DELETE FROM user_group_member WHERE user_group_id=? and user_id=?" var rawSql = "DELETE FROM user_group_member WHERE user_group_id=? and user_id=?"
_, err := sess.Exec(rawSql, cmd.UserGroupId, cmd.UserId) _, err := sess.Exec(rawSql, cmd.UserGroupId, cmd.UserId)
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment