diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-19 19:41:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-19 19:41:40 +0800 |
commit | 7a0347315995b25bcb2dca4786504fb699b5f004 (patch) | |
tree | 803dfd39286216fd0521ad16539ffd9fc5f87fc0 /models/org_team.go | |
parent | a09b40de8d1dae7107437cfba42cee201fcd6d42 (diff) | |
download | gitea-7a0347315995b25bcb2dca4786504fb699b5f004.tar.gz gitea-7a0347315995b25bcb2dca4786504fb699b5f004.zip |
Use a standalone struct name for Organization (#17632)
* Use a standalone struct name for Organization
* recover unnecessary change
* make the code readable
* Fix template failure
* Fix template failure
* Move HasMemberWithUserID to org
* Fix test
* Remove unnecessary user type check
* Fix test
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'models/org_team.go')
-rw-r--r-- | models/org_team.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/models/org_team.go b/models/org_team.go index 10178ec88a..e3ad23c111 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -6,6 +6,7 @@ package models import ( + "context" "errors" "fmt" "sort" @@ -17,7 +18,6 @@ import ( "code.gitea.io/gitea/modules/setting" "xorm.io/builder" - "xorm.io/xorm" ) const ownerTeamName = "Owners" @@ -872,7 +872,8 @@ func AddTeamMember(team *Team, userID int64) error { return sess.Commit() } -func removeTeamMember(e *xorm.Session, team *Team, userID int64) error { +func removeTeamMember(ctx context.Context, team *Team, userID int64) error { + e := db.GetEngine(ctx) isMember, err := isTeamMember(e, team.OrgID, team.ID, userID) if err != nil || !isMember { return err @@ -926,7 +927,7 @@ func removeTeamMember(e *xorm.Session, team *Team, userID int64) error { }); err != nil { return err } else if count == 0 { - return removeOrgUser(e, team.OrgID, userID) + return removeOrgUser(ctx, team.OrgID, userID) } return nil @@ -934,15 +935,15 @@ func removeTeamMember(e *xorm.Session, team *Team, userID int64) error { // RemoveTeamMember removes member from given team of given organization. func RemoveTeamMember(team *Team, userID int64) error { - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - if err := sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return err } - if err := removeTeamMember(sess, team, userID); err != nil { + defer committer.Close() + if err := removeTeamMember(ctx, team, userID); err != nil { return err } - return sess.Commit() + return committer.Commit() } // IsUserInTeams returns if a user in some teams |