diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index e6c2973ad11..af314251fac 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -1781,7 +1781,7 @@ func Routes() *web.Router { m.Get("/{org}/permissions", reqToken(), org.GetUserOrgsPermissions) }, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryUser, auth_model.AccessTokenScopeCategoryOrganization), context.UserAssignmentAPI(), checkTokenPublicOnly(), individualPermsChecker) m.Post("/orgs", tokenRequiresScopes(auth_model.AccessTokenScopeCategoryOrganization), reqToken(), bind(api.CreateOrgOption{}), org.Create) - m.Get("/orgs", org.GetAll, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryOrganization)) + m.Get("/orgs", tokenRequiresScopes(auth_model.AccessTokenScopeCategoryOrganization), org.GetAll) m.Group("/orgs/{org}", func() { m.Combo("").Get(org.Get). Patch(reqToken(), reqOrgOwnership(), bind(api.EditOrgOption{}), org.Edit). diff --git a/tests/integration/api_org_test.go b/tests/integration/api_org_test.go index 7d048d8788c..5e62f6e0410 100644 --- a/tests/integration/api_org_test.go +++ b/tests/integration/api_org_test.go @@ -121,6 +121,9 @@ func testAPIOrgGeneral(t *testing.T) { user1Token := getTokenForLoggedInUser(t, user1Session, auth_model.AccessTokenScopeWriteOrganization) t.Run("OrgGetAll", func(t *testing.T) { + miscToken := getTokenForLoggedInUser(t, user1Session, auth_model.AccessTokenScopeReadMisc) + MakeRequest(t, NewRequest(t, "GET", "/api/v1/orgs").AddTokenAuth(miscToken), http.StatusForbidden) + // accessing with a token will return all orgs req := NewRequest(t, "GET", "/api/v1/orgs").AddTokenAuth(user1Token) resp := MakeRequest(t, req, http.StatusOK) @@ -130,6 +133,14 @@ func testAPIOrgGeneral(t *testing.T) { assert.Equal(t, "Limited Org 36", apiOrgList[1].FullName) assert.Equal(t, api.VisibilityStringLimited, apiOrgList[1].Visibility) + publicOnlyToken := getTokenForLoggedInUser(t, user1Session, auth_model.AccessTokenScopeReadOrganization, auth_model.AccessTokenScopePublicOnly) + resp = MakeRequest(t, NewRequest(t, "GET", "/api/v1/orgs").AddTokenAuth(publicOnlyToken), http.StatusOK) + apiOrgList = DecodeJSON(t, resp, []*api.Organization{}) + assert.Len(t, apiOrgList, 9) + for _, org := range apiOrgList { + assert.Equal(t, api.VisibilityStringPublic, org.Visibility) + } + // accessing without a token will return only public orgs req = NewRequest(t, "GET", "/api/v1/orgs") resp = MakeRequest(t, req, http.StatusOK)