Skip to content
7 changes: 7 additions & 0 deletions modules/context/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ type APIValidationError struct {
URL string `json:"url"`
}

// APIInvalidTopicsError is error format response to invalid topics
// swagger:response invalidTopicsError
type APIInvalidTopicsError struct {
Topics []string `json:"invalidTopics"`
Message string `json:"message"`
}

//APIEmpty is an empty response
// swagger:response empty
type APIEmpty struct{}
Expand Down
2 changes: 2 additions & 0 deletions routers/api/v1/admin/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func CreateOrg(ctx *context.APIContext, form api.CreateOrgOption) {
// "$ref": "#/responses/forbidden"
// "422":
// "$ref": "#/responses/validationError"

u := user.GetUserByParams(ctx)
if ctx.Written() {
return
Expand Down Expand Up @@ -95,6 +96,7 @@ func GetAllOrgs(ctx *context.APIContext) {
// "$ref": "#/responses/OrganizationList"
// "403":
// "$ref": "#/responses/forbidden"

users, _, err := models.SearchUsers(&models.SearchUserOptions{
Type: models.UserTypeOrganization,
OrderBy: models.SearchOrderByAlphabetically,
Expand Down
5 changes: 5 additions & 0 deletions routers/api/v1/admin/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ func CreateRepo(ctx *context.APIContext, form api.CreateRepoOption) {
// "$ref": "#/responses/Repository"
// "403":
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
// "409":
// "$ref": "#/responses/error"
// "422":
// "$ref": "#/responses/validationError"

owner := user.GetUserByParams(ctx)
if ctx.Written() {
return
Expand Down
8 changes: 8 additions & 0 deletions routers/api/v1/admin/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
// "$ref": "#/responses/User"
// "403":
// "$ref": "#/responses/forbidden"
// "400":
// "$ref": "#/responses/error"
// "422":
// "$ref": "#/responses/validationError"

u := &models.User{
Name: form.Username,
FullName: form.FullName,
Expand Down Expand Up @@ -127,6 +130,7 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
// "$ref": "#/responses/forbidden"
// "422":
// "$ref": "#/responses/validationError"

u := user.GetUserByParams(ctx)
if ctx.Written() {
return
Expand Down Expand Up @@ -215,6 +219,7 @@ func DeleteUser(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
// "422":
// "$ref": "#/responses/validationError"

u := user.GetUserByParams(ctx)
if ctx.Written() {
return
Expand Down Expand Up @@ -260,6 +265,7 @@ func CreatePublicKey(ctx *context.APIContext, form api.CreateKeyOption) {
// "$ref": "#/responses/forbidden"
// "422":
// "$ref": "#/responses/validationError"

u := user.GetUserByParams(ctx)
if ctx.Written() {
return
Expand Down Expand Up @@ -293,6 +299,7 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"

u := user.GetUserByParams(ctx)
if ctx.Written() {
return
Expand Down Expand Up @@ -325,6 +332,7 @@ func GetAllUsers(ctx *context.APIContext) {
// "$ref": "#/responses/UserList"
// "403":
// "$ref": "#/responses/forbidden"

users, _, err := models.SearchUsers(&models.SearchUserOptions{
Type: models.UserTypeIndividual,
OrderBy: models.SearchOrderByAlphabetically,
Expand Down
9 changes: 4 additions & 5 deletions routers/api/v1/misc/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package misc

import (
"net/http"
"strings"

"code.gitea.io/gitea/modules/context"
Expand Down Expand Up @@ -65,20 +64,20 @@ func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
if form.Wiki {
_, err := ctx.Write([]byte(markdown.RenderWiki(md, urlPrefix, meta)))
if err != nil {
ctx.Error(http.StatusInternalServerError, "", err)
ctx.Error(500, "", err)
return
}
} else {
_, err := ctx.Write(markdown.Render(md, urlPrefix, meta))
if err != nil {
ctx.Error(http.StatusInternalServerError, "", err)
ctx.Error(500, "", err)
return
}
}
default:
_, err := ctx.Write(markdown.RenderRaw([]byte(form.Text), "", false))
if err != nil {
ctx.Error(http.StatusInternalServerError, "", err)
ctx.Error(500, "", err)
return
}
}
Expand Down Expand Up @@ -112,7 +111,7 @@ func MarkdownRaw(ctx *context.APIContext) {
}
_, err = ctx.Write(markdown.RenderRaw(body, "", false))
if err != nil {
ctx.Error(http.StatusInternalServerError, "", err)
ctx.Error(500, "", err)
return
}
}
3 changes: 1 addition & 2 deletions routers/api/v1/misc/signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package misc

import (
"fmt"
"net/http"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
Expand Down Expand Up @@ -57,6 +56,6 @@ func SigningKey(ctx *context.Context) {
_, err = ctx.Write([]byte(content))
if err != nil {
log.Error("Error writing key content %v", err)
ctx.Error(http.StatusInternalServerError, fmt.Sprintf("%v", err))
ctx.Error(500, fmt.Sprintf("%v", err))
}
}
3 changes: 3 additions & 0 deletions routers/api/v1/org/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func ListHooks(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/HookList"

org := ctx.Org.Organization
orgHooks, err := models.GetWebhooksByOrgID(org.ID)
if err != nil {
Expand Down Expand Up @@ -63,6 +64,7 @@ func GetHook(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Hook"

org := ctx.Org.Organization
hookID := ctx.ParamsInt64(":id")
hook, err := utils.GetOrgHook(ctx, org.ID, hookID)
Expand Down Expand Up @@ -159,6 +161,7 @@ func DeleteHook(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"

org := ctx.Org.Organization
hookID := ctx.ParamsInt64(":id")
if err := models.DeleteWebhookByOrgID(org.ID, hookID); err != nil {
Expand Down
13 changes: 13 additions & 0 deletions routers/api/v1/org/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func ListMembers(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/UserList"

publicOnly := true
if ctx.User != nil {
isMember, err := ctx.Org.Organization.IsOrgMember(ctx.User.ID)
Expand Down Expand Up @@ -78,6 +79,7 @@ func ListPublicMembers(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/UserList"

listMembers(ctx, true)
}

Expand All @@ -100,8 +102,11 @@ func IsMember(ctx *context.APIContext) {
// responses:
// "204":
// description: user is a member
// "302":
// description: redirection to /orgs/{org}/public_members/{username}
// "404":
// description: user is not a member

userToCheck := user.GetUserByParams(ctx)
if ctx.Written() {
return
Expand Down Expand Up @@ -153,6 +158,7 @@ func IsPublicMember(ctx *context.APIContext) {
// description: user is a public member
// "404":
// description: user is not a public member

userToCheck := user.GetUserByParams(ctx)
if ctx.Written() {
return
Expand Down Expand Up @@ -185,6 +191,9 @@ func PublicizeMember(ctx *context.APIContext) {
// responses:
// "204":
// description: membership publicized
// "403":
// "$ref": "#/responses/forbidden"

userToPublicize := user.GetUserByParams(ctx)
if ctx.Written() {
return
Expand Down Expand Up @@ -222,6 +231,9 @@ func ConcealMember(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
// "403":
// "$ref": "#/responses/forbidden"

userToConceal := user.GetUserByParams(ctx)
if ctx.Written() {
return
Expand Down Expand Up @@ -259,6 +271,7 @@ func DeleteMember(ctx *context.APIContext) {
// responses:
// "204":
// description: member removed

member := user.GetUserByParams(ctx)
if ctx.Written() {
return
Expand Down
5 changes: 5 additions & 0 deletions routers/api/v1/org/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func ListMyOrgs(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/OrganizationList"

listUserOrgs(ctx, ctx.User, true)
}

Expand All @@ -55,6 +56,7 @@ func ListUserOrgs(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/OrganizationList"

u := user.GetUserByParams(ctx)
if ctx.Written() {
return
Expand Down Expand Up @@ -135,6 +137,7 @@ func Get(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Organization"

if !models.HasOrgVisible(ctx.Org.Organization, ctx.User) {
ctx.NotFound("HasOrgVisible", nil)
return
Expand Down Expand Up @@ -165,6 +168,7 @@ func Edit(ctx *context.APIContext, form api.EditOrgOption) {
// responses:
// "200":
// "$ref": "#/responses/Organization"

org := ctx.Org.Organization
org.FullName = form.FullName
org.Description = form.Description
Expand Down Expand Up @@ -197,6 +201,7 @@ func Delete(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"

if err := models.DeleteOrganization(ctx.Org.Organization); err != nil {
ctx.Error(500, "DeleteOrganization", err)
return
Expand Down
Loading