refactor: sqlstore inTransaction consolidated to one version, fixes #8376

This commit is contained in:
Torkel Ödegaard
2017-05-23 10:56:23 +02:00
parent 5e33b5fcfa
commit 359421b5e8
18 changed files with 70 additions and 105 deletions
+4 -6
View File
@@ -4,8 +4,6 @@ import (
"fmt"
"time"
"github.com/go-xorm/xorm"
"github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models"
)
@@ -18,7 +16,7 @@ func init() {
}
func AddOrgUser(cmd *m.AddOrgUserCommand) error {
return inTransaction(func(sess *xorm.Session) error {
return inTransaction(func(sess *DBSession) error {
// check if user exists
if res, err := sess.Query("SELECT 1 from org_user WHERE org_id=? and user_id=?", cmd.OrgId, cmd.UserId); err != nil {
return err
@@ -46,7 +44,7 @@ func AddOrgUser(cmd *m.AddOrgUserCommand) error {
}
func UpdateOrgUser(cmd *m.UpdateOrgUserCommand) error {
return inTransaction(func(sess *xorm.Session) error {
return inTransaction(func(sess *DBSession) error {
var orgUser m.OrgUser
exists, err := sess.Where("org_id=? AND user_id=?", cmd.OrgId, cmd.UserId).Get(&orgUser)
if err != nil {
@@ -81,7 +79,7 @@ func GetOrgUsers(query *m.GetOrgUsersQuery) error {
}
func RemoveOrgUser(cmd *m.RemoveOrgUserCommand) error {
return inTransaction(func(sess *xorm.Session) error {
return inTransaction(func(sess *DBSession) error {
var rawSql = "DELETE FROM org_user WHERE org_id=? and user_id=?"
_, err := sess.Exec(rawSql, cmd.OrgId, cmd.UserId)
if err != nil {
@@ -92,7 +90,7 @@ func RemoveOrgUser(cmd *m.RemoveOrgUserCommand) error {
})
}
func validateOneAdminLeftInOrg(orgId int64, sess *xorm.Session) error {
func validateOneAdminLeftInOrg(orgId int64, sess *DBSession) error {
// validate that there is an admin user left
res, err := sess.Query("SELECT 1 from org_user WHERE org_id=? and role='Admin'", orgId)
if err != nil {