]> source.dussan.org Git - gitea.git/commitdiff
Remove User.GetOrganizations() (#14032)
author6543 <6543@obermui.de>
Fri, 18 Jun 2021 17:00:53 +0000 (19:00 +0200)
committerGitHub <noreply@github.com>
Fri, 18 Jun 2021 17:00:53 +0000 (19:00 +0200)
as title

integrations/org_count_test.go
models/user.go
templates/user/dashboard/repolist.tmpl

index 755ee3cee59f04c61505fc2fa705b620b2f054c5..20917dc17e0c5092bdacceb982c609d55de76ff5 100644 (file)
@@ -114,11 +114,12 @@ func doCheckOrgCounts(username string, orgCounts map[string]int, strict bool, ca
                        Name: username,
                }).(*models.User)
 
-               user.GetOrganizations(&models.SearchOrganizationsOptions{All: true})
+               orgs, err := models.GetOrgsByUserID(user.ID, true)
+               assert.NoError(t, err)
 
                calcOrgCounts := map[string]int{}
 
-               for _, org := range user.Orgs {
+               for _, org := range orgs {
                        calcOrgCounts[org.LowerName] = org.NumRepos
                        count, ok := canonicalCounts[org.LowerName]
                        if ok {
index 002c050651f17a14ae07baf848a03c84566a2c82..59983414221978b5a1abae21f4e00867ee6e1180 100644 (file)
@@ -112,7 +112,6 @@ type User struct {
        LoginName   string
        Type        UserType
        OwnedOrgs   []*User       `xorm:"-"`
-       Orgs        []*User       `xorm:"-"`
        Repos       []*Repository `xorm:"-"`
        Location    string
        Website     string
@@ -603,58 +602,6 @@ func (u *User) GetOwnedOrganizations() (err error) {
        return err
 }
 
-// GetOrganizations returns paginated organizations that user belongs to.
-// TODO: does not respect All and show orgs you privately participate
-func (u *User) GetOrganizations(opts *SearchOrganizationsOptions) error {
-       sess := x.NewSession()
-       defer sess.Close()
-
-       schema, err := x.TableInfo(new(User))
-       if err != nil {
-               return err
-       }
-       groupByCols := &strings.Builder{}
-       for _, col := range schema.Columns() {
-               fmt.Fprintf(groupByCols, "`%s`.%s,", schema.Name, col.Name)
-       }
-       groupByStr := groupByCols.String()
-       groupByStr = groupByStr[0 : len(groupByStr)-1]
-
-       sess.Select("`user`.*, count(repo_id) as org_count").
-               Table("user").
-               Join("INNER", "org_user", "`org_user`.org_id=`user`.id").
-               Join("LEFT", builder.
-                       Select("id as repo_id, owner_id as repo_owner_id").
-                       From("repository").
-                       Where(accessibleRepositoryCondition(u)), "`repository`.repo_owner_id = `org_user`.org_id").
-               And("`org_user`.uid=?", u.ID).
-               GroupBy(groupByStr)
-       if opts.PageSize != 0 {
-               sess = opts.setSessionPagination(sess)
-       }
-       type OrgCount struct {
-               User     `xorm:"extends"`
-               OrgCount int
-       }
-       orgCounts := make([]*OrgCount, 0, 10)
-
-       if err := sess.
-               Asc("`user`.name").
-               Find(&orgCounts); err != nil {
-               return err
-       }
-
-       orgs := make([]*User, len(orgCounts))
-       for i, orgCount := range orgCounts {
-               orgCount.User.NumRepos = orgCount.OrgCount
-               orgs[i] = &orgCount.User
-       }
-
-       u.Orgs = orgs
-
-       return nil
-}
-
 // DisplayName returns full name if it's not empty,
 // returns username otherwise.
 func (u *User) DisplayName() string {
index 8ac07e1df63eaa49cde05d5502383ac32a1c9a8f..f39d3711d473fa38919576f46b0c79e084a8d1f0 100644 (file)
@@ -9,7 +9,7 @@
        :more-repos-link="'{{.ContextUser.HomeLink}}'"
        {{if not .ContextUser.IsOrganization}}
        :organizations="[
-       {{range .ContextUser.Orgs}}
+       {{range .Orgs}}
        {name: '{{.Name}}', num_repos: '{{.NumRepos}}'},
        {{end}}
        ]"