Skip to content

Commit b534a51

Browse files
6543lafriks
andauthored
[API] Expose allowed Reactions (#11735)
* [API] Expose allowed Reactions * dont be in soutch a rush * add TEST * use ElementsMatch Co-authored-by: Lauris BH <[email protected]>
1 parent 2842f6c commit b534a51

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

integrations/api_issue_reaction_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,27 @@ import (
1111
"time"
1212

1313
"code.gitea.io/gitea/models"
14+
"code.gitea.io/gitea/modules/setting"
1415
api "code.gitea.io/gitea/modules/structs"
1516

1617
"github.com/stretchr/testify/assert"
1718
)
1819

20+
func TestAPIAllowedReactions(t *testing.T) {
21+
defer prepareTestEnv(t)()
22+
23+
type allowed []string
24+
25+
a := new(allowed)
26+
27+
req := NewRequest(t, "GET", "/api/v1/settings/allowed_reactions")
28+
resp := MakeRequest(t, req, http.StatusOK)
29+
30+
DecodeJSON(t, resp, &a)
31+
assert.Len(t, *a, len(setting.UI.Reactions))
32+
assert.ElementsMatch(t, setting.UI.Reactions, *a)
33+
}
34+
1935
func TestAPIIssuesReactions(t *testing.T) {
2036
defer prepareTestEnv(t)()
2137

routers/api/v1/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,9 @@ func RegisterRoutes(m *macaron.Macaron) {
512512
m.Get("/signing-key.gpg", misc.SigningKey)
513513
m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown)
514514
m.Post("/markdown/raw", misc.MarkdownRaw)
515+
m.Group("/settings", func() {
516+
m.Get("/allowed_reactions", misc.SettingGetsAllowedReactions)
517+
})
515518

516519
// Notifications
517520
m.Group("/notifications", func() {

routers/api/v1/misc/settings.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2020 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package misc
6+
7+
import (
8+
"code.gitea.io/gitea/modules/context"
9+
"code.gitea.io/gitea/modules/setting"
10+
)
11+
12+
// SettingGetsAllowedReactions return allowed reactions
13+
func SettingGetsAllowedReactions(ctx *context.APIContext) {
14+
// swagger:operation GET /settings/allowed_reactions miscellaneous getAllowedReactions
15+
// ---
16+
// summary: Returns string array of allowed reactions
17+
// produces:
18+
// - application/json
19+
// responses:
20+
// "200":
21+
// "$ref": "#/responses/StringSlice"
22+
ctx.JSON(200, setting.UI.Reactions)
23+
}

routers/api/v1/swagger/misc.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ type swaggerResponseServerVersion struct {
1414
// in:body
1515
Body api.ServerVersion `json:"body"`
1616
}
17+
18+
// StringSlice
19+
// swagger:response StringSlice
20+
type swaggerResponseStringSlice struct {
21+
// in:body
22+
Body []string `json:"body"`
23+
}

templates/swagger/v1_json.tmpl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8343,6 +8343,23 @@
83438343
}
83448344
}
83458345
},
8346+
"/settings/allowed_reactions": {
8347+
"get": {
8348+
"produces": [
8349+
"application/json"
8350+
],
8351+
"tags": [
8352+
"miscellaneous"
8353+
],
8354+
"summary": "Returns string array of allowed reactions",
8355+
"operationId": "getAllowedReactions",
8356+
"responses": {
8357+
"200": {
8358+
"$ref": "#/responses/StringSlice"
8359+
}
8360+
}
8361+
}
8362+
},
83468363
"/signing-key.gpg": {
83478364
"get": {
83488365
"produces": [
@@ -15042,6 +15059,15 @@
1504215059
}
1504315060
}
1504415061
},
15062+
"StringSlice": {
15063+
"description": "StringSlice",
15064+
"schema": {
15065+
"type": "array",
15066+
"items": {
15067+
"type": "string"
15068+
}
15069+
}
15070+
},
1504515071
"Tag": {
1504615072
"description": "Tag",
1504715073
"schema": {

0 commit comments

Comments
 (0)