Skip to content

Commit df374c3

Browse files
committed
Expose Attachemnt Settings by API
1 parent e1535c7 commit df374c3

File tree

6 files changed

+94
-0
lines changed

6 files changed

+94
-0
lines changed

integrations/api_settings_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,16 @@ func TestAPIExposedSettings(t *testing.T) {
4646
MirrorsDisabled: setting.Repository.DisableMirrors,
4747
HTTPGitDisabled: setting.Repository.DisableHTTPGit,
4848
}, repo)
49+
50+
attachment := new(api.GeneralAttachmentSettings)
51+
req = NewRequest(t, "GET", "/api/v1/settings/attachment")
52+
resp = MakeRequest(t, req, http.StatusOK)
53+
54+
DecodeJSON(t, resp, &attachment)
55+
assert.EqualValues(t, &api.GeneralAttachmentSettings{
56+
Enabled: setting.Attachment.Enabled,
57+
AllowedTypes: setting.Attachment.AllowedTypes,
58+
MaxFiles: setting.Attachment.MaxFiles,
59+
MaxSize: setting.Attachment.MaxSize,
60+
}, attachment)
4961
}

modules/structs/settings.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ type GeneralAPISettings struct {
2222
DefaultGitTreesPerPage int `json:"default_git_trees_per_page"`
2323
DefaultMaxBlobSize int64 `json:"default_max_blob_size"`
2424
}
25+
26+
// GeneralAttachmentSettings contains global Attachment settings exposed by API
27+
type GeneralAttachmentSettings struct {
28+
Enabled bool `json:"enabled"`
29+
AllowedTypes string `json:"allowed_types"`
30+
MaxSize int64 `json:"max_size"`
31+
MaxFiles int `json:"max_files"`
32+
}

routers/api/v1/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ func RegisterRoutes(m *macaron.Macaron) {
522522
m.Group("/settings", func() {
523523
m.Get("/ui", settings.GetGeneralUISettings)
524524
m.Get("/api", settings.GetGeneralAPISettings)
525+
m.Get("/attachment", settings.GetGeneralAttachmentSettings)
525526
m.Get("/repository", settings.GetGeneralRepoSettings)
526527
})
527528

routers/api/v1/settings/settings.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,21 @@ func GetGeneralRepoSettings(ctx *context.APIContext) {
6060
HTTPGitDisabled: setting.Repository.DisableHTTPGit,
6161
})
6262
}
63+
64+
// GetGeneralAttachmentSettings returns instance's global settings for Attachment
65+
func GetGeneralAttachmentSettings(ctx *context.APIContext) {
66+
// swagger:operation GET /settings/Attachment settings getGeneralAttachmentSettings
67+
// ---
68+
// summary: Get instance's global settings for Attachment
69+
// produces:
70+
// - application/json
71+
// responses:
72+
// "200":
73+
// "$ref": "#/responses/GeneralAttachmentSettings"
74+
ctx.JSON(http.StatusOK, api.GeneralAttachmentSettings{
75+
Enabled: setting.Attachment.Enabled,
76+
AllowedTypes: setting.Attachment.AllowedTypes,
77+
MaxFiles: setting.Attachment.MaxFiles,
78+
MaxSize: setting.Attachment.MaxSize,
79+
})
80+
}

routers/api/v1/swagger/settings.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ type swaggerResponseGeneralAPISettings struct {
2626
// in:body
2727
Body api.GeneralAPISettings `json:"body"`
2828
}
29+
30+
// GeneralAttachmentSettings
31+
// swagger:response GeneralAttachmentSettings
32+
type swaggerResponseGeneralAttachmentSettings struct {
33+
// in:body
34+
Body api.GeneralAttachmentSettings `json:"body"`
35+
}

templates/swagger/v1_json.tmpl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8672,6 +8672,23 @@
86728672
}
86738673
}
86748674
},
8675+
"/settings/Attachment": {
8676+
"get": {
8677+
"produces": [
8678+
"application/json"
8679+
],
8680+
"tags": [
8681+
"settings"
8682+
],
8683+
"summary": "Get instance's global settings for Attachment",
8684+
"operationId": "getGeneralAttachmentSettings",
8685+
"responses": {
8686+
"200": {
8687+
"$ref": "#/responses/GeneralAttachmentSettings"
8688+
}
8689+
}
8690+
}
8691+
},
86758692
"/settings/api": {
86768693
"get": {
86778694
"produces": [
@@ -13021,6 +13038,31 @@
1302113038
},
1302213039
"x-go-package": "code.gitea.io/gitea/modules/structs"
1302313040
},
13041+
"GeneralAttachmentSettings": {
13042+
"description": "GeneralAttachmentSettings contains global Attachment settings exposed by API",
13043+
"type": "object",
13044+
"properties": {
13045+
"allowed_types": {
13046+
"type": "string",
13047+
"x-go-name": "AllowedTypes"
13048+
},
13049+
"enabled": {
13050+
"type": "boolean",
13051+
"x-go-name": "Enabled"
13052+
},
13053+
"max_files": {
13054+
"type": "integer",
13055+
"format": "int64",
13056+
"x-go-name": "MaxFiles"
13057+
},
13058+
"max_size": {
13059+
"type": "integer",
13060+
"format": "int64",
13061+
"x-go-name": "MaxSize"
13062+
}
13063+
},
13064+
"x-go-package": "code.gitea.io/gitea/modules/structs"
13065+
},
1302413066
"GeneralRepoSettings": {
1302513067
"description": "GeneralRepoSettings contains global repository settings exposed by API",
1302613068
"type": "object",
@@ -15247,6 +15289,12 @@
1524715289
"$ref": "#/definitions/GeneralAPISettings"
1524815290
}
1524915291
},
15292+
"GeneralAttachmentSettings": {
15293+
"description": "GeneralAttachmentSettings",
15294+
"schema": {
15295+
"$ref": "#/definitions/GeneralAttachmentSettings"
15296+
}
15297+
},
1525015298
"GeneralRepoSettings": {
1525115299
"description": "GeneralRepoSettings",
1525215300
"schema": {

0 commit comments

Comments
 (0)