mirror of
https://github.com/grafana/grafana.git
synced 2025-01-21 14:03:29 -06:00
teams: refactor.
This commit is contained in:
parent
9f8e43916d
commit
9f33f00343
@ -255,19 +255,28 @@ func AddTeamMember(cmd *m.AddTeamMemberCommand) error {
|
||||
})
|
||||
}
|
||||
|
||||
func getTeamMember(sess *DBSession, orgId int64, teamId int64, userId int64) (m.TeamMember, error) {
|
||||
rawSql := `SELECT * FROM team_member WHERE org_id=? and team_id=? and user_id=?`
|
||||
var member m.TeamMember
|
||||
exists, err := sess.SQL(rawSql, orgId, teamId, userId).Get(&member)
|
||||
|
||||
if err != nil {
|
||||
return member, err
|
||||
}
|
||||
if !exists {
|
||||
return member, m.ErrTeamMemberNotFound
|
||||
}
|
||||
|
||||
return member, nil
|
||||
}
|
||||
|
||||
// UpdateTeamMember updates a team member
|
||||
func UpdateTeamMember(cmd *m.UpdateTeamMemberCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
rawSql := `SELECT * FROM team_member WHERE org_id=? and team_id=? and user_id=?`
|
||||
var member m.TeamMember
|
||||
exists, err := sess.SQL(rawSql, cmd.OrgId, cmd.TeamId, cmd.UserId).Get(&member)
|
||||
|
||||
member, err := getTeamMember(sess, cmd.OrgId, cmd.TeamId, cmd.UserId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exists {
|
||||
return m.ErrTeamMemberNotFound
|
||||
}
|
||||
|
||||
if cmd.ProtectLastAdmin {
|
||||
_, err := isLastAdmin(sess, cmd.OrgId, cmd.TeamId, cmd.UserId)
|
||||
|
Loading…
Reference in New Issue
Block a user