* move Setting function into its own package * swagger add&use new section "settings" * move api AllowedReactions into general UI-Settings endpoint * prepare TEST * linttags/v1.13.0-rc1
func TestAPIAllowedReactions(t *testing.T) { | func TestAPIAllowedReactions(t *testing.T) { | ||||
defer prepareTestEnv(t)() | defer prepareTestEnv(t)() | ||||
type allowed []string | |||||
a := new(api.GeneralUISettings) | |||||
a := new(allowed) | |||||
req := NewRequest(t, "GET", "/api/v1/settings/allowed_reactions") | |||||
req := NewRequest(t, "GET", "/api/v1/settings/ui") | |||||
resp := MakeRequest(t, req, http.StatusOK) | resp := MakeRequest(t, req, http.StatusOK) | ||||
DecodeJSON(t, resp, &a) | DecodeJSON(t, resp, &a) | ||||
assert.Len(t, *a, len(setting.UI.Reactions)) | |||||
assert.ElementsMatch(t, setting.UI.Reactions, *a) | |||||
assert.Len(t, a.AllowedReactions, len(setting.UI.Reactions)) | |||||
assert.ElementsMatch(t, setting.UI.Reactions, a.AllowedReactions) | |||||
} | } | ||||
func TestAPIIssuesReactions(t *testing.T) { | func TestAPIIssuesReactions(t *testing.T) { |
MirrorsDisabled bool `json:"mirrors_disabled"` | MirrorsDisabled bool `json:"mirrors_disabled"` | ||||
HTTPGitDisabled bool `json:"http_git_disabled"` | HTTPGitDisabled bool `json:"http_git_disabled"` | ||||
} | } | ||||
// GeneralUISettings contains global ui settings exposed by API | |||||
type GeneralUISettings struct { | |||||
AllowedReactions []string `json:"allowed_reactions"` | |||||
} |
"code.gitea.io/gitea/routers/api/v1/notify" | "code.gitea.io/gitea/routers/api/v1/notify" | ||||
"code.gitea.io/gitea/routers/api/v1/org" | "code.gitea.io/gitea/routers/api/v1/org" | ||||
"code.gitea.io/gitea/routers/api/v1/repo" | "code.gitea.io/gitea/routers/api/v1/repo" | ||||
"code.gitea.io/gitea/routers/api/v1/settings" | |||||
_ "code.gitea.io/gitea/routers/api/v1/swagger" // for swagger generation | _ "code.gitea.io/gitea/routers/api/v1/swagger" // for swagger generation | ||||
"code.gitea.io/gitea/routers/api/v1/user" | "code.gitea.io/gitea/routers/api/v1/user" | ||||
m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown) | m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown) | ||||
m.Post("/markdown/raw", misc.MarkdownRaw) | m.Post("/markdown/raw", misc.MarkdownRaw) | ||||
m.Group("/settings", func() { | m.Group("/settings", func() { | ||||
m.Get("/allowed_reactions", misc.SettingGetsAllowedReactions) | |||||
m.Get("/repository", misc.GetGeneralRepoSettings) | |||||
m.Get("/ui", settings.GetGeneralUISettings) | |||||
m.Get("/repository", settings.GetGeneralRepoSettings) | |||||
}) | }) | ||||
// Notifications | // Notifications |
// Use of this source code is governed by a MIT-style | // Use of this source code is governed by a MIT-style | ||||
// license that can be found in the LICENSE file. | // license that can be found in the LICENSE file. | ||||
package misc | |||||
package settings | |||||
import ( | import ( | ||||
"net/http" | "net/http" | ||||
api "code.gitea.io/gitea/modules/structs" | api "code.gitea.io/gitea/modules/structs" | ||||
) | ) | ||||
// SettingGetsAllowedReactions return allowed reactions | |||||
func SettingGetsAllowedReactions(ctx *context.APIContext) { | |||||
// swagger:operation GET /settings/allowed_reactions miscellaneous getAllowedReactions | |||||
// GetGeneralUISettings returns instance's global settings for ui | |||||
func GetGeneralUISettings(ctx *context.APIContext) { | |||||
// swagger:operation GET /settings/ui settings getGeneralUISettings | |||||
// --- | // --- | ||||
// summary: Returns string array of allowed reactions | |||||
// summary: Get instance's global settings for ui | |||||
// produces: | // produces: | ||||
// - application/json | // - application/json | ||||
// responses: | // responses: | ||||
// "200": | // "200": | ||||
// "$ref": "#/responses/StringSlice" | |||||
ctx.JSON(http.StatusOK, setting.UI.Reactions) | |||||
// "$ref": "#/responses/GeneralUISettings" | |||||
ctx.JSON(http.StatusOK, api.GeneralUISettings{ | |||||
AllowedReactions: setting.UI.Reactions, | |||||
}) | |||||
} | } | ||||
// GetGeneralRepoSettings returns instance's global settings for repositories | // GetGeneralRepoSettings returns instance's global settings for repositories | ||||
func GetGeneralRepoSettings(ctx *context.APIContext) { | func GetGeneralRepoSettings(ctx *context.APIContext) { | ||||
// swagger:operation GET /settings/repository miscellaneous getGeneralRepositorySettings | |||||
// swagger:operation GET /settings/repository settings getGeneralRepositorySettings | |||||
// --- | // --- | ||||
// summary: Get instance's global settings for repositories | // summary: Get instance's global settings for repositories | ||||
// produces: | // produces: |
// in:body | // in:body | ||||
Body []string `json:"body"` | Body []string `json:"body"` | ||||
} | } | ||||
// GeneralRepoSettings | |||||
// swagger:response GeneralRepoSettings | |||||
type swaggerResponseGeneralRepoSettings struct { | |||||
// in:body | |||||
Body api.GeneralRepoSettings `json:"body"` | |||||
} |
// Copyright 2020 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. | |||||
package swagger | |||||
import api "code.gitea.io/gitea/modules/structs" | |||||
// GeneralRepoSettings | |||||
// swagger:response GeneralRepoSettings | |||||
type swaggerResponseGeneralRepoSettings struct { | |||||
// in:body | |||||
Body api.GeneralRepoSettings `json:"body"` | |||||
} | |||||
// GeneralUISettings | |||||
// swagger:response GeneralUISettings | |||||
type swaggerResponseGeneralUISettings struct { | |||||
// in:body | |||||
Body api.GeneralUISettings `json:"body"` | |||||
} |
} | } | ||||
} | } | ||||
}, | }, | ||||
"/settings/allowed_reactions": { | |||||
"/settings/repository": { | |||||
"get": { | "get": { | ||||
"produces": [ | "produces": [ | ||||
"application/json" | "application/json" | ||||
], | ], | ||||
"tags": [ | "tags": [ | ||||
"miscellaneous" | |||||
"settings" | |||||
], | ], | ||||
"summary": "Returns string array of allowed reactions", | |||||
"operationId": "getAllowedReactions", | |||||
"summary": "Get instance's global settings for repositories", | |||||
"operationId": "getGeneralRepositorySettings", | |||||
"responses": { | "responses": { | ||||
"200": { | "200": { | ||||
"$ref": "#/responses/StringSlice" | |||||
"$ref": "#/responses/GeneralRepoSettings" | |||||
} | } | ||||
} | } | ||||
} | } | ||||
}, | }, | ||||
"/settings/repository": { | |||||
"/settings/ui": { | |||||
"get": { | "get": { | ||||
"produces": [ | "produces": [ | ||||
"application/json" | "application/json" | ||||
], | ], | ||||
"tags": [ | "tags": [ | ||||
"miscellaneous" | |||||
"settings" | |||||
], | ], | ||||
"summary": "Get instance's global settings for repositories", | |||||
"operationId": "getGeneralRepositorySettings", | |||||
"summary": "Get instance's global settings for ui", | |||||
"operationId": "getGeneralUISettings", | |||||
"responses": { | "responses": { | ||||
"200": { | "200": { | ||||
"$ref": "#/responses/GeneralRepoSettings" | |||||
"$ref": "#/responses/GeneralUISettings" | |||||
} | } | ||||
} | } | ||||
} | } | ||||
}, | }, | ||||
"x-go-package": "code.gitea.io/gitea/modules/structs" | "x-go-package": "code.gitea.io/gitea/modules/structs" | ||||
}, | }, | ||||
"GeneralUISettings": { | |||||
"description": "GeneralUISettings contains global ui settings exposed by API", | |||||
"type": "object", | |||||
"properties": { | |||||
"allowed_reactions": { | |||||
"type": "array", | |||||
"items": { | |||||
"type": "string" | |||||
}, | |||||
"x-go-name": "AllowedReactions" | |||||
} | |||||
}, | |||||
"x-go-package": "code.gitea.io/gitea/modules/structs" | |||||
}, | |||||
"GitBlobResponse": { | "GitBlobResponse": { | ||||
"description": "GitBlobResponse represents a git blob", | "description": "GitBlobResponse represents a git blob", | ||||
"type": "object", | "type": "object", | ||||
"$ref": "#/definitions/GeneralRepoSettings" | "$ref": "#/definitions/GeneralRepoSettings" | ||||
} | } | ||||
}, | }, | ||||
"GeneralUISettings": { | |||||
"description": "GeneralUISettings", | |||||
"schema": { | |||||
"$ref": "#/definitions/GeneralUISettings" | |||||
} | |||||
}, | |||||
"GitBlobResponse": { | "GitBlobResponse": { | ||||
"description": "GitBlobResponse", | "description": "GitBlobResponse", | ||||
"schema": { | "schema": { |