Skip to content

Commit 2a52aee

Browse files
6543zeripathtechknowlogick
authored
API: Expose its limitation settings (#12714)
* API: Expose its limitation settings * TESTs Co-authored-by: zeripath <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 45c0ec3 commit 2a52aee

File tree

7 files changed

+133
-14
lines changed

7 files changed

+133
-14
lines changed

integrations/api_issue_reaction_test.go

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

1313
"code.gitea.io/gitea/models"
14-
"code.gitea.io/gitea/modules/setting"
1514
api "code.gitea.io/gitea/modules/structs"
1615

1716
"github.com/stretchr/testify/assert"
1817
)
1918

20-
func TestAPIAllowedReactions(t *testing.T) {
21-
defer prepareTestEnv(t)()
22-
23-
a := new(api.GeneralUISettings)
24-
25-
req := NewRequest(t, "GET", "/api/v1/settings/ui")
26-
resp := MakeRequest(t, req, http.StatusOK)
27-
28-
DecodeJSON(t, resp, &a)
29-
assert.Len(t, a.AllowedReactions, len(setting.UI.Reactions))
30-
assert.ElementsMatch(t, setting.UI.Reactions, a.AllowedReactions)
31-
}
32-
3319
func TestAPIIssuesReactions(t *testing.T) {
3420
defer prepareTestEnv(t)()
3521

integrations/api_settings_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 integrations
6+
7+
import (
8+
"net/http"
9+
"testing"
10+
11+
"code.gitea.io/gitea/modules/setting"
12+
api "code.gitea.io/gitea/modules/structs"
13+
14+
"github.com/stretchr/testify/assert"
15+
)
16+
17+
func TestAPIExposedSettings(t *testing.T) {
18+
defer prepareTestEnv(t)()
19+
20+
ui := new(api.GeneralUISettings)
21+
req := NewRequest(t, "GET", "/api/v1/settings/ui")
22+
resp := MakeRequest(t, req, http.StatusOK)
23+
24+
DecodeJSON(t, resp, &ui)
25+
assert.Len(t, ui.AllowedReactions, len(setting.UI.Reactions))
26+
assert.ElementsMatch(t, setting.UI.Reactions, ui.AllowedReactions)
27+
28+
apiSettings := new(api.GeneralAPISettings)
29+
req = NewRequest(t, "GET", "/api/v1/settings/api")
30+
resp = MakeRequest(t, req, http.StatusOK)
31+
32+
DecodeJSON(t, resp, &apiSettings)
33+
assert.EqualValues(t, &api.GeneralAPISettings{
34+
MaxResponseItems: setting.API.MaxResponseItems,
35+
DefaultPagingNum: setting.API.DefaultPagingNum,
36+
DefaultGitTreesPerPage: setting.API.DefaultGitTreesPerPage,
37+
DefaultMaxBlobSize: setting.API.DefaultMaxBlobSize,
38+
}, apiSettings)
39+
40+
repo := new(api.GeneralRepoSettings)
41+
req = NewRequest(t, "GET", "/api/v1/settings/repository")
42+
resp = MakeRequest(t, req, http.StatusOK)
43+
44+
DecodeJSON(t, resp, &repo)
45+
assert.EqualValues(t, &api.GeneralRepoSettings{
46+
MirrorsDisabled: setting.Repository.DisableMirrors,
47+
HTTPGitDisabled: setting.Repository.DisableHTTPGit,
48+
}, repo)
49+
}

modules/structs/settings.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ type GeneralRepoSettings struct {
1414
type GeneralUISettings struct {
1515
AllowedReactions []string `json:"allowed_reactions"`
1616
}
17+
18+
// GeneralAPISettings contains global api settings exposed by it
19+
type GeneralAPISettings struct {
20+
MaxResponseItems int `json:"max_response_items"`
21+
DefaultPagingNum int `json:"default_paging_num"`
22+
DefaultGitTreesPerPage int `json:"default_git_trees_per_page"`
23+
DefaultMaxBlobSize int64 `json:"default_max_blob_size"`
24+
}

routers/api/v1/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ func RegisterRoutes(m *macaron.Macaron) {
521521
m.Post("/markdown/raw", misc.MarkdownRaw)
522522
m.Group("/settings", func() {
523523
m.Get("/ui", settings.GetGeneralUISettings)
524+
m.Get("/api", settings.GetGeneralAPISettings)
524525
m.Get("/repository", settings.GetGeneralRepoSettings)
525526
})
526527

routers/api/v1/settings/settings.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ func GetGeneralUISettings(ctx *context.APIContext) {
2727
})
2828
}
2929

30+
// GetGeneralAPISettings returns instance's global settings for api
31+
func GetGeneralAPISettings(ctx *context.APIContext) {
32+
// swagger:operation GET /settings/api settings getGeneralAPISettings
33+
// ---
34+
// summary: Get instance's global settings for api
35+
// produces:
36+
// - application/json
37+
// responses:
38+
// "200":
39+
// "$ref": "#/responses/GeneralAPISettings"
40+
ctx.JSON(http.StatusOK, api.GeneralAPISettings{
41+
MaxResponseItems: setting.API.MaxResponseItems,
42+
DefaultPagingNum: setting.API.DefaultPagingNum,
43+
DefaultGitTreesPerPage: setting.API.DefaultGitTreesPerPage,
44+
DefaultMaxBlobSize: setting.API.DefaultMaxBlobSize,
45+
})
46+
}
47+
3048
// GetGeneralRepoSettings returns instance's global settings for repositories
3149
func GetGeneralRepoSettings(ctx *context.APIContext) {
3250
// swagger:operation GET /settings/repository settings getGeneralRepositorySettings

routers/api/v1/swagger/settings.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ type swaggerResponseGeneralUISettings struct {
1919
// in:body
2020
Body api.GeneralUISettings `json:"body"`
2121
}
22+
23+
// GeneralAPISettings
24+
// swagger:response GeneralAPISettings
25+
type swaggerResponseGeneralAPISettings struct {
26+
// in:body
27+
Body api.GeneralAPISettings `json:"body"`
28+
}

templates/swagger/v1_json.tmpl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8672,6 +8672,23 @@
86728672
}
86738673
}
86748674
},
8675+
"/settings/api": {
8676+
"get": {
8677+
"produces": [
8678+
"application/json"
8679+
],
8680+
"tags": [
8681+
"settings"
8682+
],
8683+
"summary": "Get instance's global settings for api",
8684+
"operationId": "getGeneralAPISettings",
8685+
"responses": {
8686+
"200": {
8687+
"$ref": "#/responses/GeneralAPISettings"
8688+
}
8689+
}
8690+
}
8691+
},
86758692
"/settings/repository": {
86768693
"get": {
86778694
"produces": [
@@ -12977,6 +12994,33 @@
1297712994
},
1297812995
"x-go-package": "code.gitea.io/gitea/modules/structs"
1297912996
},
12997+
"GeneralAPISettings": {
12998+
"description": "GeneralAPISettings contains global api settings exposed by it",
12999+
"type": "object",
13000+
"properties": {
13001+
"default_git_trees_per_page": {
13002+
"type": "integer",
13003+
"format": "int64",
13004+
"x-go-name": "DefaultGitTreesPerPage"
13005+
},
13006+
"default_max_blob_size": {
13007+
"type": "integer",
13008+
"format": "int64",
13009+
"x-go-name": "DefaultMaxBlobSize"
13010+
},
13011+
"default_paging_num": {
13012+
"type": "integer",
13013+
"format": "int64",
13014+
"x-go-name": "DefaultPagingNum"
13015+
},
13016+
"max_response_items": {
13017+
"type": "integer",
13018+
"format": "int64",
13019+
"x-go-name": "MaxResponseItems"
13020+
}
13021+
},
13022+
"x-go-package": "code.gitea.io/gitea/modules/structs"
13023+
},
1298013024
"GeneralRepoSettings": {
1298113025
"description": "GeneralRepoSettings contains global repository settings exposed by API",
1298213026
"type": "object",
@@ -15197,6 +15241,12 @@
1519715241
}
1519815242
}
1519915243
},
15244+
"GeneralAPISettings": {
15245+
"description": "GeneralAPISettings",
15246+
"schema": {
15247+
"$ref": "#/definitions/GeneralAPISettings"
15248+
}
15249+
},
1520015250
"GeneralRepoSettings": {
1520115251
"description": "GeneralRepoSettings",
1520215252
"schema": {

0 commit comments

Comments
 (0)