diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-11 15:03:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-11 15:03:30 +0800 |
commit | 90eb9fb889e5d3a5845576dbc63e3792f3da33f2 (patch) | |
tree | 4107df9dd446fe9a93e49cba1e59d0f721e70351 /models/org.go | |
parent | 492e1c2fbd1b646f4428207942a9f89b56f7b6a9 (diff) | |
download | gitea-90eb9fb889e5d3a5845576dbc63e3792f3da33f2.tar.gz gitea-90eb9fb889e5d3a5845576dbc63e3792f3da33f2.zip |
Move EmailAddress & UserRedirect into models/user/ (#17607)
* Move EmailAddress into models/user/
* Fix test
* rename user_mail to user_email
* Fix test
* Move UserRedirect into models/user/
* Fix lint & test
* Fix lint
* Fix lint
* remove nolint comment
* Fix lint
Diffstat (limited to 'models/org.go')
-rw-r--r-- | models/org.go | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/models/org.go b/models/org.go index c6d2562f15..1840cae9fa 100644 --- a/models/org.go +++ b/models/org.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/storage" @@ -163,25 +164,25 @@ func CreateOrganization(org, owner *User) (err error) { org.NumMembers = 1 org.Type = UserTypeOrganization - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - if err = sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return err } + defer committer.Close() - if err = deleteUserRedirect(sess, org.Name); err != nil { + if err = user_model.DeleteUserRedirect(ctx, org.Name); err != nil { return err } - if _, err = sess.Insert(org); err != nil { + if err = db.Insert(ctx, org); err != nil { return fmt.Errorf("insert organization: %v", err) } - if err = org.generateRandomAvatar(sess); err != nil { + if err = org.generateRandomAvatar(db.GetEngine(ctx)); err != nil { return fmt.Errorf("generate random avatar: %v", err) } // Add initial creator to organization and owner team. - if _, err = sess.Insert(&OrgUser{ + if err = db.Insert(ctx, &OrgUser{ UID: owner.ID, OrgID: org.ID, }); err != nil { @@ -198,7 +199,7 @@ func CreateOrganization(org, owner *User) (err error) { IncludesAllRepositories: true, CanCreateOrgRepo: true, } - if _, err = sess.Insert(t); err != nil { + if err = db.Insert(ctx, t); err != nil { return fmt.Errorf("insert owner team: %v", err) } @@ -212,14 +213,11 @@ func CreateOrganization(org, owner *User) (err error) { }) } - if _, err = sess.Insert(&units); err != nil { - if err := sess.Rollback(); err != nil { - log.Error("CreateOrganization: sess.Rollback: %v", err) - } + if err = db.Insert(ctx, &units); err != nil { return err } - if _, err = sess.Insert(&TeamUser{ + if err = db.Insert(ctx, &TeamUser{ UID: owner.ID, OrgID: org.ID, TeamID: t.ID, @@ -227,7 +225,7 @@ func CreateOrganization(org, owner *User) (err error) { return fmt.Errorf("insert team-user relation: %v", err) } - return sess.Commit() + return committer.Commit() } // GetOrgByName returns organization by given name. |