summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/admin/org.go29
-rw-r--r--routers/api/v1/admin/user.go25
-rw-r--r--routers/api/v1/api.go3
3 files changed, 57 insertions, 0 deletions
diff --git a/routers/api/v1/admin/org.go b/routers/api/v1/admin/org.go
index 406cbb9a31..03263a86dd 100644
--- a/routers/api/v1/admin/org.go
+++ b/routers/api/v1/admin/org.go
@@ -1,4 +1,5 @@
// Copyright 2015 The Gogs Authors. All rights reserved.
+// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
@@ -66,3 +67,31 @@ func CreateOrg(ctx *context.APIContext, form api.CreateOrgOption) {
ctx.JSON(201, convert.ToOrganization(org))
}
+
+//GetAllOrgs API for getting information of all the organizations
+func GetAllOrgs(ctx *context.APIContext) {
+ // swagger:operation GET /admin/orgs admin adminGetAllOrgs
+ // ---
+ // summary: List all organizations
+ // produces:
+ // - application/json
+ // responses:
+ // "200":
+ // "$ref": "#/responses/OrganizationList"
+ // "403":
+ // "$ref": "#/responses/forbidden"
+ users, _, err := models.SearchUsers(&models.SearchUserOptions{
+ Type: models.UserTypeOrganization,
+ OrderBy: models.SearchOrderByAlphabetically,
+ PageSize: -1,
+ })
+ if err != nil {
+ ctx.Error(500, "SearchOrganizations", err)
+ return
+ }
+ orgs := make([]*api.Organization, len(users))
+ for i := range users {
+ orgs[i] = convert.ToOrganization(users[i])
+ }
+ ctx.JSON(200, &orgs)
+}
diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go
index cff8ae4850..e35beffc92 100644
--- a/routers/api/v1/admin/user.go
+++ b/routers/api/v1/admin/user.go
@@ -1,4 +1,5 @@
// Copyright 2015 The Gogs Authors. All rights reserved.
+// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
@@ -291,3 +292,27 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
ctx.Status(204)
}
+
+//GetAllUsers API for getting information of all the users
+func GetAllUsers(ctx *context.APIContext) {
+ // swagger:operation GET /admin/users admin adminGetAllUsers
+ // ---
+ // summary: List all users
+ // produces:
+ // - application/json
+ // responses:
+ // "200":
+ // "$ref": "#/responses/UserList"
+ // "403":
+ // "$ref": "#/responses/forbidden"
+ users, _, err := models.SearchUsers(&models.SearchUserOptions{
+ Type: models.UserTypeIndividual,
+ OrderBy: models.SearchOrderByAlphabetically,
+ PageSize: -1,
+ })
+ if err != nil {
+ ctx.Error(500, "SearchUsers", err)
+ return
+ }
+ ctx.JSON(200, &users)
+}
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 82c4b78de8..2787d01a04 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -671,7 +671,9 @@ func RegisterRoutes(m *macaron.Macaron) {
})
m.Group("/admin", func() {
+ m.Get("/orgs", admin.GetAllOrgs)
m.Group("/users", func() {
+ m.Get("", admin.GetAllUsers)
m.Post("", bind(api.CreateUserOption{}), admin.CreateUser)
m.Group("/:username", func() {
m.Combo("").Patch(bind(api.EditUserOption{}), admin.EditUser).
@@ -680,6 +682,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("", bind(api.CreateKeyOption{}), admin.CreatePublicKey)
m.Delete("/:id", admin.DeleteUserPublicKey)
})
+ m.Get("/orgs", org.ListUserOrgs)
m.Post("/orgs", bind(api.CreateOrgOption{}), admin.CreateOrg)
m.Post("/repos", bind(api.CreateRepoOption{}), admin.CreateRepo)
})