[API] Expose allowed Reactions (#11735)

* [API] Expose allowed Reactions

* dont be in soutch a rush

* add TEST

* use ElementsMatch

Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
6543 2020-06-04 11:16:53 +02:00 committed by GitHub
parent 2842f6cf42
commit b534a5164f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 75 additions and 0 deletions

View File

@ -11,11 +11,27 @@ import (
"time" "time"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestAPIAllowedReactions(t *testing.T) {
defer prepareTestEnv(t)()
type allowed []string
a := new(allowed)
req := NewRequest(t, "GET", "/api/v1/settings/allowed_reactions")
resp := MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &a)
assert.Len(t, *a, len(setting.UI.Reactions))
assert.ElementsMatch(t, setting.UI.Reactions, *a)
}
func TestAPIIssuesReactions(t *testing.T) { func TestAPIIssuesReactions(t *testing.T) {
defer prepareTestEnv(t)() defer prepareTestEnv(t)()

View File

@ -512,6 +512,9 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/signing-key.gpg", misc.SigningKey) m.Get("/signing-key.gpg", misc.SigningKey)
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.Get("/allowed_reactions", misc.SettingGetsAllowedReactions)
})
// Notifications // Notifications
m.Group("/notifications", func() { m.Group("/notifications", func() {

View File

@ -0,0 +1,23 @@
// 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 misc
import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
)
// SettingGetsAllowedReactions return allowed reactions
func SettingGetsAllowedReactions(ctx *context.APIContext) {
// swagger:operation GET /settings/allowed_reactions miscellaneous getAllowedReactions
// ---
// summary: Returns string array of allowed reactions
// produces:
// - application/json
// responses:
// "200":
// "$ref": "#/responses/StringSlice"
ctx.JSON(200, setting.UI.Reactions)
}

View File

@ -14,3 +14,10 @@ type swaggerResponseServerVersion struct {
// in:body // in:body
Body api.ServerVersion `json:"body"` Body api.ServerVersion `json:"body"`
} }
// StringSlice
// swagger:response StringSlice
type swaggerResponseStringSlice struct {
// in:body
Body []string `json:"body"`
}

View File

@ -8343,6 +8343,23 @@
} }
} }
}, },
"/settings/allowed_reactions": {
"get": {
"produces": [
"application/json"
],
"tags": [
"miscellaneous"
],
"summary": "Returns string array of allowed reactions",
"operationId": "getAllowedReactions",
"responses": {
"200": {
"$ref": "#/responses/StringSlice"
}
}
}
},
"/signing-key.gpg": { "/signing-key.gpg": {
"get": { "get": {
"produces": [ "produces": [
@ -15042,6 +15059,15 @@
} }
} }
}, },
"StringSlice": {
"description": "StringSlice",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
},
"Tag": { "Tag": {
"description": "Tag", "description": "Tag",
"schema": { "schema": {