diff options
author | Gusted <williamzijl7@hotmail.com> | 2022-08-21 18:24:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-21 17:24:05 +0100 |
commit | 0b4c166e8a90beeb1e71ee2fc16b3a240517c82d (patch) | |
tree | 607869cf2ed3caf90cb9981ab04a8fbba8e58043 /integrations | |
parent | 6d3181406d87503dbd15e4a7c764c8963f13977f (diff) | |
download | gitea-0b4c166e8a90beeb1e71ee2fc16b3a240517c82d.tar.gz gitea-0b4c166e8a90beeb1e71ee2fc16b3a240517c82d.zip |
Fix SQL Query for `SearchTeam` (#20844)
- Currently the function takes in the `UserID` option, but isn't being
used within the SQL query. This patch fixes that by checking that only
teams are being returned that the user belongs to.
Fix #20829
Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'integrations')
-rw-r--r-- | integrations/api_team_test.go | 2 | ||||
-rw-r--r-- | integrations/api_user_orgs_test.go | 22 | ||||
-rw-r--r-- | integrations/org_test.go | 9 |
3 files changed, 28 insertions, 5 deletions
diff --git a/integrations/api_team_test.go b/integrations/api_team_test.go index 82824d610b..9ea7a6f787 100644 --- a/integrations/api_team_test.go +++ b/integrations/api_team_test.go @@ -223,7 +223,7 @@ func TestAPITeamSearch(t *testing.T) { defer prepareTestEnv(t)() user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) - org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}) + org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 17}) var results TeamSearchResults diff --git a/integrations/api_user_orgs_test.go b/integrations/api_user_orgs_test.go index 9f3487cb7f..1555b53390 100644 --- a/integrations/api_user_orgs_test.go +++ b/integrations/api_user_orgs_test.go @@ -26,9 +26,20 @@ func TestUserOrgs(t *testing.T) { orgs := getUserOrgs(t, adminUsername, normalUsername) user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user3"}) + user17 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user17"}) assert.Equal(t, []*api.Organization{ { + ID: 17, + UserName: user17.Name, + FullName: user17.FullName, + AvatarURL: user17.AvatarLink(), + Description: "", + Website: "", + Location: "", + Visibility: "public", + }, + { ID: 3, UserName: user3.Name, FullName: user3.FullName, @@ -82,9 +93,20 @@ func TestMyOrgs(t *testing.T) { var orgs []*api.Organization DecodeJSON(t, resp, &orgs) user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user3"}) + user17 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user17"}) assert.Equal(t, []*api.Organization{ { + ID: 17, + UserName: user17.Name, + FullName: user17.FullName, + AvatarURL: user17.AvatarLink(), + Description: "", + Website: "", + Location: "", + Visibility: "public", + }, + { ID: 3, UserName: user3.Name, FullName: user3.FullName, diff --git a/integrations/org_test.go b/integrations/org_test.go index e4677f58de..9fb1175d7a 100644 --- a/integrations/org_test.go +++ b/integrations/org_test.go @@ -197,8 +197,8 @@ func TestOrgRestrictedUser(t *testing.T) { func TestTeamSearch(t *testing.T) { defer prepareTestEnv(t)() - user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) - org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 15}) + org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 17}) var results TeamSearchResults @@ -209,8 +209,9 @@ func TestTeamSearch(t *testing.T) { resp := session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &results) assert.NotEmpty(t, results.Data) - assert.Len(t, results.Data, 1) - assert.Equal(t, "test_team", results.Data[0].Name) + assert.Len(t, results.Data, 2) + assert.Equal(t, "review_team", results.Data[0].Name) + assert.Equal(t, "test_team", results.Data[1].Name) // no access if not organization member user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}) |