Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Move AllowedReactions endpoint into GetGenneralUI endpoint + creat new swagger section settings #11854

Merged
merged 14 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions integrations/api_issue_reaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ import (
func TestAPIAllowedReactions(t *testing.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)

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) {
Expand Down
5 changes: 5 additions & 0 deletions modules/structs/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ type GeneralRepoSettings struct {
MirrorsDisabled bool `json:"mirrors_disabled"`
HTTPGitDisabled bool `json:"http_git_disabled"`
}

// GeneralUISettings contains global ui settings exposed by API
type GeneralUISettings struct {
AllowedReactions []string `json:"allowed_reactions"`
}
5 changes: 3 additions & 2 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import (
"code.gitea.io/gitea/routers/api/v1/notify"
"code.gitea.io/gitea/routers/api/v1/org"
"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/user"

Expand Down Expand Up @@ -513,8 +514,8 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown)
m.Post("/markdown/raw", misc.MarkdownRaw)
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package misc
package settings

import (
"net/http"
Expand All @@ -12,22 +12,24 @@ import (
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:
// - application/json
// responses:
// "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
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
// produces:
Expand Down
7 changes: 0 additions & 7 deletions routers/api/v1/swagger/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,3 @@ type swaggerResponseStringSlice struct {
// in:body
Body []string `json:"body"`
}

// GeneralRepoSettings
// swagger:response GeneralRepoSettings
type swaggerResponseGeneralRepoSettings struct {
// in:body
Body api.GeneralRepoSettings `json:"body"`
}
21 changes: 21 additions & 0 deletions routers/api/v1/swagger/settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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"`
}
40 changes: 30 additions & 10 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8470,36 +8470,36 @@
}
}
},
"/settings/allowed_reactions": {
"/settings/repository": {
"get": {
"produces": [
"application/json"
],
"tags": [
"miscellaneous"
"settings"
],
"summary": "Returns string array of allowed reactions",
"operationId": "getAllowedReactions",
"summary": "Get instance's global settings for repositories",
"operationId": "getGeneralRepositorySettings",
"responses": {
"200": {
"$ref": "#/responses/StringSlice"
"$ref": "#/responses/GeneralRepoSettings"
}
}
}
},
"/settings/repository": {
"/settings/ui": {
"get": {
"produces": [
"application/json"
],
"tags": [
"miscellaneous"
"settings"
],
"summary": "Get instance's global settings for repositories",
"operationId": "getGeneralRepositorySettings",
"summary": "Get instance's global settings for ui",
"operationId": "getGeneralUISettings",
"responses": {
"200": {
"$ref": "#/responses/GeneralRepoSettings"
"$ref": "#/responses/GeneralUISettings"
}
}
}
Expand Down Expand Up @@ -12753,6 +12753,20 @@
},
"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": {
"description": "GitBlobResponse represents a git blob",
"type": "object",
Expand Down Expand Up @@ -14928,6 +14942,12 @@
"$ref": "#/definitions/GeneralRepoSettings"
}
},
"GeneralUISettings": {
"description": "GeneralUISettings",
"schema": {
"$ref": "#/definitions/GeneralUISettings"
}
},
"GitBlobResponse": {
"description": "GitBlobResponse",
"schema": {
Expand Down