aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-01-12 16:43:44 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2020-01-12 23:43:44 +0800
commit10055bd2b1d18d3ccbec78cbc213e459ddb75804 (patch)
tree0c3aacafab3f852a0509c4dcd2055aa93e36c0c3 /routers/api/v1
parent497e15fdc28518ab03e2f1114fb112b8c0630e18 (diff)
downloadgitea-10055bd2b1d18d3ccbec78cbc213e459ddb75804.tar.gz
gitea-10055bd2b1d18d3ccbec78cbc213e459ddb75804.zip
[API] add GET /orgs endpoint (#9560)
* introduce `GET /orgs` * add TEST * show also other VisibleType's * update description * refactor a lot * SearchUserOptions by default return only public
Diffstat (limited to 'routers/api/v1')
-rw-r--r--routers/api/v1/admin/org.go2
-rw-r--r--routers/api/v1/api.go1
-rw-r--r--routers/api/v1/org/org.go47
3 files changed, 49 insertions, 1 deletions
diff --git a/routers/api/v1/admin/org.go b/routers/api/v1/admin/org.go
index 1db4e592ff..ca2ef574f3 100644
--- a/routers/api/v1/admin/org.go
+++ b/routers/api/v1/admin/org.go
@@ -104,7 +104,7 @@ func GetAllOrgs(ctx *context.APIContext) {
OrderBy: models.SearchOrderByAlphabetically,
Page: ctx.QueryInt("page"),
PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
- Private: true,
+ Visible: []api.VisibleType{api.VisibleTypePublic, api.VisibleTypeLimited, api.VisibleTypePrivate},
})
if err != nil {
ctx.Error(http.StatusInternalServerError, "SearchOrganizations", err)
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index fd7f7c05cf..86c7450173 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -821,6 +821,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/user/orgs", reqToken(), org.ListMyOrgs)
m.Get("/users/:username/orgs", org.ListUserOrgs)
m.Post("/orgs", reqToken(), bind(api.CreateOrgOption{}), org.Create)
+ m.Get("/orgs", org.GetAll)
m.Group("/orgs/:orgname", func() {
m.Combo("").Get(org.Get).
Patch(reqToken(), reqOrgOwnership(), bind(api.EditOrgOption{}), org.Edit).
diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go
index 67770e70aa..4bcd60a679 100644
--- a/routers/api/v1/org/org.go
+++ b/routers/api/v1/org/org.go
@@ -66,6 +66,53 @@ func ListUserOrgs(ctx *context.APIContext) {
listUserOrgs(ctx, u, ctx.User.IsAdmin)
}
+// GetAll return list of all public organizations
+func GetAll(ctx *context.APIContext) {
+ // swagger:operation Get /orgs organization orgGetAll
+ // ---
+ // summary: Get list of organizations
+ // produces:
+ // - application/json
+ // parameters:
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
+ // responses:
+ // "200":
+ // "$ref": "#/responses/OrganizationList"
+
+ vMode := []api.VisibleType{api.VisibleTypePublic}
+ if ctx.IsSigned {
+ vMode = append(vMode, api.VisibleTypeLimited)
+ if ctx.User.IsAdmin {
+ vMode = append(vMode, api.VisibleTypePrivate)
+ }
+ }
+
+ publicOrgs, _, err := models.SearchUsers(&models.SearchUserOptions{
+ Type: models.UserTypeOrganization,
+ OrderBy: models.SearchOrderByAlphabetically,
+ Page: ctx.QueryInt("page"),
+ PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
+ Visible: vMode,
+ })
+ if err != nil {
+ ctx.Error(http.StatusInternalServerError, "SearchOrganizations", err)
+ return
+ }
+ orgs := make([]*api.Organization, len(publicOrgs))
+ for i := range publicOrgs {
+ orgs[i] = convert.ToOrganization(publicOrgs[i])
+ }
+
+ ctx.JSON(http.StatusOK, &orgs)
+}
+
// Create api for create organization
func Create(ctx *context.APIContext, form api.CreateOrgOption) {
// swagger:operation POST /orgs organization orgCreate