loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[API] teamSearch show teams with no members if user is admin (#21204)

close #21176

authored by

6543 and committed by
GitHub
c5e88fb0 c87e6a89

+48 -24
+2 -2
build/generate-go-licenses.go
··· 64 64 } 65 65 66 66 entries = append(entries, LicenseEntry{ 67 - Name: name, 68 - Path: path, 67 + Name: name, 68 + Path: path, 69 69 LicenseText: string(licenseText), 70 70 }) 71 71 }
+3 -21
models/organization/team.go
··· 129 129 if opts.UserID > 0 { 130 130 sess = sess.Join("INNER", "team_user", "team_user.team_id = team.id") 131 131 } 132 - 133 - count, err := sess. 134 - Where(cond). 135 - Count(new(Team)) 136 - if err != nil { 137 - return nil, 0, err 138 - } 139 - 140 - if opts.UserID > 0 { 141 - sess = sess.Join("INNER", "team_user", "team_user.team_id = team.id") 142 - } 143 - 144 - if opts.PageSize == -1 { 145 - opts.PageSize = int(count) 146 - } else { 147 - sess = sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize) 148 - } 132 + sess = db.SetSessionPagination(sess, opts) 149 133 150 134 teams := make([]*Team, 0, opts.PageSize) 151 - if err = sess. 152 - Where(cond). 153 - OrderBy("lower_name"). 154 - Find(&teams); err != nil { 135 + count, err := sess.Where(cond).OrderBy("lower_name").FindAndCount(&teams) 136 + if err != nil { 155 137 return nil, 0, err 156 138 } 157 139
+1
modules/markup/markdown/meta.go
··· 11 11 "unicode/utf8" 12 12 13 13 "code.gitea.io/gitea/modules/log" 14 + 14 15 "gopkg.in/yaml.v3" 15 16 ) 16 17
+1
modules/markup/markdown/renderconfig.go
··· 8 8 "strings" 9 9 10 10 "code.gitea.io/gitea/modules/log" 11 + 11 12 "github.com/yuin/goldmark/ast" 12 13 "gopkg.in/yaml.v3" 13 14 )
+5 -1
routers/api/v1/org/team.go
··· 759 759 listOptions := utils.GetListOptions(ctx) 760 760 761 761 opts := &organization.SearchTeamOptions{ 762 - UserID: ctx.Doer.ID, 763 762 Keyword: ctx.FormTrim("q"), 764 763 OrgID: ctx.Org.Organization.ID, 765 764 IncludeDesc: ctx.FormString("include_desc") == "" || ctx.FormBool("include_desc"), 766 765 ListOptions: listOptions, 766 + } 767 + 768 + // Only admin is allowd to search for all teams 769 + if !ctx.Doer.IsAdmin { 770 + opts.UserID = ctx.Doer.ID 767 771 } 768 772 769 773 teams, maxResults, err := organization.SearchTeam(opts)
+36
tests/integration/api_org_test.go
··· 5 5 package integration 6 6 7 7 import ( 8 + "fmt" 8 9 "net/http" 9 10 "net/url" 10 11 "strings" ··· 151 152 assert.Equal(t, "org25", apiOrgList[0].FullName) 152 153 assert.Equal(t, "public", apiOrgList[0].Visibility) 153 154 } 155 + 156 + func TestAPIOrgSearchEmptyTeam(t *testing.T) { 157 + onGiteaRun(t, func(*testing.T, *url.URL) { 158 + token := getUserToken(t, "user1") 159 + orgName := "org_with_empty_team" 160 + 161 + // create org 162 + req := NewRequestWithJSON(t, "POST", "/api/v1/orgs?token="+token, &api.CreateOrgOption{ 163 + UserName: orgName, 164 + }) 165 + MakeRequest(t, req, http.StatusCreated) 166 + 167 + // create team with no member 168 + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/orgs/%s/teams?token=%s", orgName, token), &api.CreateTeamOption{ 169 + Name: "Empty", 170 + IncludesAllRepositories: true, 171 + Permission: "read", 172 + Units: []string{"repo.code", "repo.issues", "repo.ext_issues", "repo.wiki", "repo.pulls"}, 173 + }) 174 + MakeRequest(t, req, http.StatusCreated) 175 + 176 + // case-insensitive search for teams that have no members 177 + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/orgs/%s/teams/search?q=%s&token=%s", orgName, "empty", token)) 178 + resp := MakeRequest(t, req, http.StatusOK) 179 + data := struct { 180 + Ok bool 181 + Data []*api.Team 182 + }{} 183 + DecodeJSON(t, resp, &data) 184 + assert.True(t, data.Ok) 185 + if assert.Len(t, data.Data, 1) { 186 + assert.EqualValues(t, "Empty", data.Data[0].Name) 187 + } 188 + }) 189 + }