From 97b7ac171267c97cfeed33a740648b227a8ff047 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 6 Jun 2021 11:23:41 +0800 Subject: [PATCH 01/14] Add pagination for user setting orgs --- models/org.go | 37 +++++++++++++++++++++++ routers/web/user/setting/profile.go | 20 +++++++++++- templates/user/settings/organization.tmpl | 1 + 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/models/org.go b/models/org.go index 8e60422ef150b..cbaa6172bc74d 100644 --- a/models/org.go +++ b/models/org.go @@ -519,6 +519,43 @@ func GetUserOrgsList(user *User) ([]*MinimalOrg, error) { return orgs, nil } +// FindOrgOptions finds orgs options +type FindOrgOptions struct { + db.ListOptions + UserID int64 + IncludePrivate bool +} + +func (opts FindOrgOptions) toConds() builder.Cond { + var cond = builder.NewCond() + if opts.UserID > 0 { + cond = cond.And(builder.Eq{"`org_user`.uid": opts.UserID}) + } + if !opts.IncludePrivate { + cond = cond.And(builder.Eq{"`org_user`.visibility=?": structs.VisibleTypePublic}) + } + return cond +} + +// FindOrgs returns a list of organizations according given conditions +func FindOrgs(opts FindOrgOptions) ([]*User, error) { + orgs := make([]*User, 0, 10) + sess := db.GetEngine(db.DefaultContext).Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id"). + Where(opts.toConds()). + Asc("`user`.name") + if opts.Page > 0 && opts.PageSize > 0 { + sess.Limit(opts.PageSize, opts.PageSize*(opts.Page-1)) + } + return orgs, sess.Find(&orgs) +} + +// CountOrgs returns total count organizations according options +func CountOrgs(opts FindOrgOptions) (int64, error) { + return db.GetEngine(db.DefaultContext).Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id"). + Where(opts.toConds()). + Count(new(User)) +} + func getOwnedOrgsByUserID(sess db.Engine, userID int64) ([]*User, error) { orgs := make([]*User, 0, 10) return orgs, sess. diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index d7aa3264c58a8..721be579aaa34 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -214,12 +214,30 @@ func DeleteAvatar(ctx *context.Context) { func Organization(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["PageIsSettingsOrganization"] = true - orgs, err := models.GetOrgsByUserID(ctx.User.ID, ctx.IsSigned) + + opts := models.FindOrgOptions{ + ListOptions: models.ListOptions{ + PageSize: setting.UI.Admin.UserPagingNum, + Page: ctx.QueryInt("page"), + }, + UserID: ctx.User.ID, + IncludePrivate: ctx.IsSigned, + } + + if opts.Page <= 0 { + opts.Page = 1 + } + + orgs, err := models.FindOrgs(opts) if err != nil { ctx.ServerError("GetOrgsByUserID", err) return } + total, err := models.CountOrgs(opts) ctx.Data["Orgs"] = orgs + pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5) + pager.SetDefaultParams(ctx) + ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, tplSettingsOrganization) } diff --git a/templates/user/settings/organization.tmpl b/templates/user/settings/organization.tmpl index 3bab1c8957f17..1689c1b9e2290 100644 --- a/templates/user/settings/organization.tmpl +++ b/templates/user/settings/organization.tmpl @@ -29,6 +29,7 @@ {{end}} + {{template "base/paginate" .}} {{else}} {{.i18n.Tr "settings.orgs_none"}} {{end}} From e3fb47ca07f21a700978decc319d3c35a8f10a58 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 6 Jun 2021 11:51:42 +0800 Subject: [PATCH 02/14] Use FindOrgs instead of GetOrgsByUserID --- models/org_test.go | 19 ++++++++++++++++--- routers/api/v1/org/org.go | 15 ++++++++++++--- routers/web/user/profile.go | 7 +++++-- routers/web/user/setting/profile.go | 6 +++++- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/models/org_test.go b/models/org_test.go index 10ae877458215..805c63300b374 100644 --- a/models/org_test.go +++ b/models/org_test.go @@ -307,18 +307,31 @@ func TestIsPublicMembership(t *testing.T) { test(unittest.NonexistentID, unittest.NonexistentID, false) } -func TestGetOrgsByUserID(t *testing.T) { +func TestFindOrgs(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - orgs, err := GetOrgsByUserID(4, true) + orgs, err := FindOrgs(FindOrgOptions{ + UserID: 4, + IncludePrivate: true, + }) assert.NoError(t, err) if assert.Len(t, orgs, 1) { assert.EqualValues(t, 3, orgs[0].ID) } - orgs, err = GetOrgsByUserID(4, false) + orgs, err = FindOrgs(FindOrgOptions{ + UserID: 4, + IncludePrivate: false, + }) assert.NoError(t, err) assert.Len(t, orgs, 0) + + total, err := CountOrgs(FindOrgOptions{ + UserID: 4, + IncludePrivate: true, + }) + assert.NoError(t, err) + assert.EqualValues(t, 1, total) } func TestGetOwnedOrgsByUserID(t *testing.T) { diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index bbf127f891446..cb3fa5264c9c4 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -20,13 +20,22 @@ import ( ) func listUserOrgs(ctx *context.APIContext, u *models.User) { - listOptions := utils.GetListOptions(ctx) showPrivate := ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == u.ID) - orgs, err := models.GetOrgsByUserID(u.ID, showPrivate) + var opts = models.FindOrgOptions{ + ListOptions: listOptions, + UserID: u.ID, + IncludePrivate: showPrivate, + } + orgs, err := models.FindOrgs(opts) + if err != nil { + ctx.Error(http.StatusInternalServerError, "FindOrgs", err) + return + } + maxResults, err := models.CountOrgs(opts) if err != nil { - ctx.Error(http.StatusInternalServerError, "GetOrgsByUserID", err) + ctx.Error(http.StatusInternalServerError, "CountOrgs", err) return } diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 72d36761da8ce..9d0b4e3c15aa4 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -167,9 +167,12 @@ func Profile(ctx *context.Context) { showPrivate := ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == ctxUser.ID) - orgs, err := models.GetOrgsByUserID(ctxUser.ID, showPrivate) + orgs, err := models.FindOrgs(models.FindOrgOptions{ + UserID: ctxUser.ID, + IncludePrivate: showPrivate, + }) if err != nil { - ctx.ServerError("GetOrgsByUserIDDesc", err) + ctx.ServerError("FindOrgs", err) return } diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 721be579aaa34..d0c3e8986b48a 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -230,10 +230,14 @@ func Organization(ctx *context.Context) { orgs, err := models.FindOrgs(opts) if err != nil { - ctx.ServerError("GetOrgsByUserID", err) + ctx.ServerError("FindOrgs", err) return } total, err := models.CountOrgs(opts) + if err != nil { + ctx.ServerError("CountOrgs", err) + return + } ctx.Data["Orgs"] = orgs pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5) pager.SetDefaultParams(ctx) From 6eaea6f61b94071ebc85873475ff4e0055003450 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 6 Jun 2021 12:42:23 +0800 Subject: [PATCH 03/14] Fix bug --- models/org.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/org.go b/models/org.go index cbaa6172bc74d..6d9ef721d0099 100644 --- a/models/org.go +++ b/models/org.go @@ -532,7 +532,7 @@ func (opts FindOrgOptions) toConds() builder.Cond { cond = cond.And(builder.Eq{"`org_user`.uid": opts.UserID}) } if !opts.IncludePrivate { - cond = cond.And(builder.Eq{"`org_user`.visibility=?": structs.VisibleTypePublic}) + cond = cond.And(builder.Eq{"`user`.visibility=?": structs.VisibleTypePublic}) } return cond } From 9f9c7cf6cd8897e7794ce49c2ff1214061329cce Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 6 Jun 2021 13:21:52 +0800 Subject: [PATCH 04/14] Fix test --- models/org_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/org_test.go b/models/org_test.go index 805c63300b374..7dee3388546f8 100644 --- a/models/org_test.go +++ b/models/org_test.go @@ -324,7 +324,7 @@ func TestFindOrgs(t *testing.T) { IncludePrivate: false, }) assert.NoError(t, err) - assert.Len(t, orgs, 0) + assert.EqualValues(t, 0, len(orgs)) total, err := CountOrgs(FindOrgOptions{ UserID: 4, From 43d75c03903cef5c42c55a735cea42fcb951d8ab Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 8 Jun 2021 10:57:25 +0800 Subject: [PATCH 05/14] Fix bug --- models/org.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/org.go b/models/org.go index 6d9ef721d0099..61bc3fe255b0a 100644 --- a/models/org.go +++ b/models/org.go @@ -532,7 +532,7 @@ func (opts FindOrgOptions) toConds() builder.Cond { cond = cond.And(builder.Eq{"`org_user`.uid": opts.UserID}) } if !opts.IncludePrivate { - cond = cond.And(builder.Eq{"`user`.visibility=?": structs.VisibleTypePublic}) + cond = cond.And(builder.Eq{"`user`.visibility": structs.VisibleTypePublic}) } return cond } From 4359288fd08ec8530682916697f87f3f9f392910 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 15 Jun 2021 18:47:34 +0800 Subject: [PATCH 06/14] Fix bug --- models/org.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/models/org.go b/models/org.go index 61bc3fe255b0a..cfb3f729ab170 100644 --- a/models/org.go +++ b/models/org.go @@ -529,10 +529,14 @@ type FindOrgOptions struct { func (opts FindOrgOptions) toConds() builder.Cond { var cond = builder.NewCond() if opts.UserID > 0 { - cond = cond.And(builder.Eq{"`org_user`.uid": opts.UserID}) + cond = cond.And(builder.In("`user`.`id`", queryUserOrgIDs(opts.UserID))) } if !opts.IncludePrivate { cond = cond.And(builder.Eq{"`user`.visibility": structs.VisibleTypePublic}) + } else { + cond = cond.And(builder.Eq{"`user`.visibility": structs.VisibleTypePrivate}.Or( + builder.Eq{"`user`.visibility": structs.VisibleTypeLimited}, + )) } return cond } @@ -540,7 +544,7 @@ func (opts FindOrgOptions) toConds() builder.Cond { // FindOrgs returns a list of organizations according given conditions func FindOrgs(opts FindOrgOptions) ([]*User, error) { orgs := make([]*User, 0, 10) - sess := db.GetEngine(db.DefaultContext).Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id"). + sess := db.GetEngine(db.DefaultContext). Where(opts.toConds()). Asc("`user`.name") if opts.Page > 0 && opts.PageSize > 0 { From 712693b972f844d785a27b4175bb6d452cf2b0b1 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 8 Aug 2021 17:56:31 +0800 Subject: [PATCH 07/14] Fix bug --- routers/web/user/setting/profile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index d0c3e8986b48a..686606f5ecafa 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -218,7 +218,7 @@ func Organization(ctx *context.Context) { opts := models.FindOrgOptions{ ListOptions: models.ListOptions{ PageSize: setting.UI.Admin.UserPagingNum, - Page: ctx.QueryInt("page"), + Page: ctx.FormInt("page"), }, UserID: ctx.User.ID, IncludePrivate: ctx.IsSigned, From f9c9dd0ad11e468b3a917b17740658ead40cddf3 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 15 Oct 2021 15:44:50 +0800 Subject: [PATCH 08/14] Fix test --- models/org.go | 5 +++++ routers/api/v1/org/org.go | 2 +- routers/web/user/setting/profile.go | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/models/org.go b/models/org.go index cfb3f729ab170..ae0753032decb 100644 --- a/models/org.go +++ b/models/org.go @@ -526,6 +526,11 @@ type FindOrgOptions struct { IncludePrivate bool } +func queryUserOrgIDs(userID int64) *builder.Builder { + return builder.Select("org_id").From("org_user"). + Where(builder.Eq{"uid": userID}) +} + func (opts FindOrgOptions) toConds() builder.Cond { var cond = builder.NewCond() if opts.UserID > 0 { diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index cb3fa5264c9c4..42c61ab859707 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -47,7 +47,7 @@ func listUserOrgs(ctx *context.APIContext, u *models.User) { apiOrgs[i] = convert.ToOrganization(orgs[i]) } - ctx.SetLinkHeader(maxResults, listOptions.PageSize) + ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) ctx.SetTotalCountHeader(int64(maxResults)) ctx.JSON(http.StatusOK, &apiOrgs) } diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 686606f5ecafa..36fe45df04ff7 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -216,7 +216,7 @@ func Organization(ctx *context.Context) { ctx.Data["PageIsSettingsOrganization"] = true opts := models.FindOrgOptions{ - ListOptions: models.ListOptions{ + ListOptions: db.ListOptions{ PageSize: setting.UI.Admin.UserPagingNum, Page: ctx.FormInt("page"), }, From 7678260aa6c9cb2a0502ffc77ced6fcf78c3e23d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 16 Oct 2021 10:32:19 +0800 Subject: [PATCH 09/14] Fix test --- models/org.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/models/org.go b/models/org.go index ae0753032decb..9c2c551bc7238 100644 --- a/models/org.go +++ b/models/org.go @@ -528,7 +528,10 @@ type FindOrgOptions struct { func queryUserOrgIDs(userID int64) *builder.Builder { return builder.Select("org_id").From("org_user"). - Where(builder.Eq{"uid": userID}) + Where(builder.Eq{ + "uid": userID, + "is_public": true, + }) } func (opts FindOrgOptions) toConds() builder.Cond { @@ -538,10 +541,6 @@ func (opts FindOrgOptions) toConds() builder.Cond { } if !opts.IncludePrivate { cond = cond.And(builder.Eq{"`user`.visibility": structs.VisibleTypePublic}) - } else { - cond = cond.And(builder.Eq{"`user`.visibility": structs.VisibleTypePrivate}.Or( - builder.Eq{"`user`.visibility": structs.VisibleTypeLimited}, - )) } return cond } From 90274a48324fbc23f4bbe420b65b569d10c570b9 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 19 Nov 2021 23:08:38 +0800 Subject: [PATCH 10/14] Fix build --- models/org.go | 4 ++-- routers/api/v1/org/org.go | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/models/org.go b/models/org.go index 9c2c551bc7238..bd0803a49ca30 100644 --- a/models/org.go +++ b/models/org.go @@ -546,8 +546,8 @@ func (opts FindOrgOptions) toConds() builder.Cond { } // FindOrgs returns a list of organizations according given conditions -func FindOrgs(opts FindOrgOptions) ([]*User, error) { - orgs := make([]*User, 0, 10) +func FindOrgs(opts FindOrgOptions) ([]*Organization, error) { + orgs := make([]*Organization, 0, 10) sess := db.GetEngine(db.DefaultContext). Where(opts.toConds()). Asc("`user`.name") diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index 42c61ab859707..209876aa95eeb 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -39,7 +39,6 @@ func listUserOrgs(ctx *context.APIContext, u *models.User) { return } - maxResults := len(orgs) orgs, _ = util.PaginateSlice(orgs, listOptions.Page, listOptions.PageSize).([]*models.Organization) apiOrgs := make([]*api.Organization, len(orgs)) From 34a6f4c3845fded02afb8fac2d14cc4e7bf42069 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 20 Nov 2021 00:37:31 +0800 Subject: [PATCH 11/14] Fix test --- models/org.go | 5 ++--- models/org_test.go | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/models/org.go b/models/org.go index bd0803a49ca30..3419ed5a0105c 100644 --- a/models/org.go +++ b/models/org.go @@ -529,8 +529,7 @@ type FindOrgOptions struct { func queryUserOrgIDs(userID int64) *builder.Builder { return builder.Select("org_id").From("org_user"). Where(builder.Eq{ - "uid": userID, - "is_public": true, + "uid": userID, }) } @@ -559,7 +558,7 @@ func FindOrgs(opts FindOrgOptions) ([]*Organization, error) { // CountOrgs returns total count organizations according options func CountOrgs(opts FindOrgOptions) (int64, error) { - return db.GetEngine(db.DefaultContext).Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id"). + return db.GetEngine(db.DefaultContext). Where(opts.toConds()). Count(new(User)) } diff --git a/models/org_test.go b/models/org_test.go index 7dee3388546f8..9e7cd9e8c1a42 100644 --- a/models/org_test.go +++ b/models/org_test.go @@ -324,7 +324,7 @@ func TestFindOrgs(t *testing.T) { IncludePrivate: false, }) assert.NoError(t, err) - assert.EqualValues(t, 0, len(orgs)) + assert.EqualValues(t, 1, len(orgs)) total, err := CountOrgs(FindOrgOptions{ UserID: 4, From ad98e7027c405e6182ba187e952390eaae1dcc67 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 20 Nov 2021 16:26:04 +0800 Subject: [PATCH 12/14] Remove unnecessary functions and fix test --- integrations/org_count_test.go | 5 ++++- models/org.go | 31 +++++++------------------------ models/org_test.go | 2 +- 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/integrations/org_count_test.go b/integrations/org_count_test.go index a394dba01c2e9..a45d1e81b59e2 100644 --- a/integrations/org_count_test.go +++ b/integrations/org_count_test.go @@ -116,7 +116,10 @@ func doCheckOrgCounts(username string, orgCounts map[string]int, strict bool, ca Name: username, }).(*models.User) - orgs, err := models.GetOrgsByUserID(user.ID, true) + orgs, err := models.FindOrgs(models.FindOrgOptions{ + UserID: user.ID, + IncludePrivate: true, + }) assert.NoError(t, err) calcOrgCounts := map[string]int{} diff --git a/models/org.go b/models/org.go index 3419ed5a0105c..b3e67fb521345 100644 --- a/models/org.go +++ b/models/org.go @@ -440,24 +440,6 @@ func getUsersWhoCanCreateOrgRepo(e db.Engine, orgID int64) ([]*User, error) { And("team_user.org_id = ?", orgID).Asc("`user`.name").Find(&users) } -func getOrgsByUserID(e db.Engine, userID int64, showAll bool) ([]*Organization, error) { - orgs := make([]*Organization, 0, 10) - sess := e.Where("`org_user`.uid=?", userID) - if !showAll { - sess = sess.And("`org_user`.is_public=?", true) - } - return orgs, sess. - Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id"). - Asc("`user`.name"). - Find(&orgs) -} - -// GetOrgsByUserID returns a list of organizations that the given user ID -// has joined. -func GetOrgsByUserID(userID int64, showAll bool) ([]*Organization, error) { - return getOrgsByUserID(db.GetEngine(db.DefaultContext), userID, showAll) -} - // MinimalOrg represents a simple orgnization with only needed columns type MinimalOrg = Organization @@ -526,17 +508,18 @@ type FindOrgOptions struct { IncludePrivate bool } -func queryUserOrgIDs(userID int64) *builder.Builder { - return builder.Select("org_id").From("org_user"). - Where(builder.Eq{ - "uid": userID, - }) +func queryUserOrgIDs(userID int64, includePrivate bool) *builder.Builder { + var cond = builder.Eq{"uid": userID} + if !includePrivate { + cond["is_public"] = true + } + return builder.Select("org_id").From("org_user").Where(cond) } func (opts FindOrgOptions) toConds() builder.Cond { var cond = builder.NewCond() if opts.UserID > 0 { - cond = cond.And(builder.In("`user`.`id`", queryUserOrgIDs(opts.UserID))) + cond = cond.And(builder.In("`user`.`id`", queryUserOrgIDs(opts.UserID, opts.IncludePrivate))) } if !opts.IncludePrivate { cond = cond.And(builder.Eq{"`user`.visibility": structs.VisibleTypePublic}) diff --git a/models/org_test.go b/models/org_test.go index 9e7cd9e8c1a42..7dee3388546f8 100644 --- a/models/org_test.go +++ b/models/org_test.go @@ -324,7 +324,7 @@ func TestFindOrgs(t *testing.T) { IncludePrivate: false, }) assert.NoError(t, err) - assert.EqualValues(t, 1, len(orgs)) + assert.EqualValues(t, 0, len(orgs)) total, err := CountOrgs(FindOrgOptions{ UserID: 4, From 0313af8cc1f8b64623f1394006417c4eaeba4dae Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 20 Nov 2021 17:55:03 +0800 Subject: [PATCH 13/14] revert unnecessary change --- models/org_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/org_test.go b/models/org_test.go index 7dee3388546f8..805c63300b374 100644 --- a/models/org_test.go +++ b/models/org_test.go @@ -324,7 +324,7 @@ func TestFindOrgs(t *testing.T) { IncludePrivate: false, }) assert.NoError(t, err) - assert.EqualValues(t, 0, len(orgs)) + assert.Len(t, orgs, 0) total, err := CountOrgs(FindOrgOptions{ UserID: 4, From 33b8dba14463cd657b133114beced2a7e9833194 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 20 Nov 2021 18:00:23 +0800 Subject: [PATCH 14/14] remove unnecessary code --- routers/api/v1/org/org.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index 209876aa95eeb..f539662d6269e 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -12,7 +12,6 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/routers/api/v1/user" "code.gitea.io/gitea/routers/api/v1/utils" @@ -39,8 +38,6 @@ func listUserOrgs(ctx *context.APIContext, u *models.User) { return } - orgs, _ = util.PaginateSlice(orgs, listOptions.Page, listOptions.PageSize).([]*models.Organization) - apiOrgs := make([]*api.Organization, len(orgs)) for i := range orgs { apiOrgs[i] = convert.ToOrganization(orgs[i])