From b06b9a056c0af751e576978f6ef3c914ee959b9c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 29 Mar 2022 14:29:02 +0800 Subject: Move organization related structs into sub package (#18518) * Move organization related structs into sub package * Fix test * Fix lint * Move more functions into sub packages * Fix bug * Fix test * Update models/organization/team_repo.go Co-authored-by: KN4CK3R * Apply suggestions from code review Co-authored-by: KN4CK3R * Fix fmt * Follow suggestion from @Gusted * Fix test * Fix test * Fix bug * Use ctx but db.DefaultContext on routers * Fix bug * Fix bug * fix bug * Update models/organization/team_user.go * Fix bug Co-authored-by: KN4CK3R Co-authored-by: wxiaoguang --- routers/web/org/members.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'routers/web/org/members.go') diff --git a/routers/web/org/members.go b/routers/web/org/members.go index 9e65e61404..add8e724bd 100644 --- a/routers/web/org/members.go +++ b/routers/web/org/members.go @@ -9,6 +9,7 @@ import ( "net/http" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" @@ -31,7 +32,7 @@ func Members(ctx *context.Context) { page = 1 } - opts := &models.FindOrgMembersOpts{ + opts := &organization.FindOrgMembersOpts{ OrgID: org.ID, PublicOnly: true, } @@ -45,7 +46,7 @@ func Members(ctx *context.Context) { opts.PublicOnly = !isMember && !ctx.Doer.IsAdmin } - total, err := models.CountOrgMembers(opts) + total, err := organization.CountOrgMembers(opts) if err != nil { ctx.Error(http.StatusInternalServerError, "CountOrgMembers") return @@ -54,7 +55,7 @@ func Members(ctx *context.Context) { pager := context.NewPagination(int(total), setting.UI.MembersPagingNum, page, 5) opts.ListOptions.Page = page opts.ListOptions.PageSize = setting.UI.MembersPagingNum - members, membersIsPublic, err := models.FindOrgMembers(opts) + members, membersIsPublic, err := organization.FindOrgMembers(opts) if err != nil { ctx.ServerError("GetMembers", err) return @@ -84,20 +85,20 @@ func MembersAction(ctx *context.Context) { ctx.Error(http.StatusNotFound) return } - err = models.ChangeOrgUserStatus(org.ID, uid, false) + err = organization.ChangeOrgUserStatus(org.ID, uid, false) case "public": if ctx.Doer.ID != uid && !ctx.Org.IsOwner { ctx.Error(http.StatusNotFound) return } - err = models.ChangeOrgUserStatus(org.ID, uid, true) + err = organization.ChangeOrgUserStatus(org.ID, uid, true) case "remove": if !ctx.Org.IsOwner { ctx.Error(http.StatusNotFound) return } - err = org.RemoveMember(uid) - if models.IsErrLastOrgOwner(err) { + err = models.RemoveOrgUser(org.ID, uid) + if organization.IsErrLastOrgOwner(err) { ctx.Flash.Error(ctx.Tr("form.last_org_owner")) ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": ctx.Org.OrgLink + "/members", @@ -105,8 +106,8 @@ func MembersAction(ctx *context.Context) { return } case "leave": - err = org.RemoveMember(ctx.Doer.ID) - if models.IsErrLastOrgOwner(err) { + err = models.RemoveOrgUser(org.ID, ctx.Doer.ID) + if organization.IsErrLastOrgOwner(err) { ctx.Flash.Error(ctx.Tr("form.last_org_owner")) ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": ctx.Org.OrgLink + "/members", -- cgit v1.2.3