aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-09-05 09:43:06 +0200
committerGitHub <noreply@github.com>2020-09-05 08:43:06 +0100
commitdba5d82f86dc9dc757404f03bf80ebbe28a5a0b1 (patch)
treeb59de4d8745ff000d3e4fc9c581ede5abaae6bdf
parentbab1204db4c6f0b3346a84b3c37fd6386fcee48d (diff)
downloadgitea-dba5d82f86dc9dc757404f03bf80ebbe28a5a0b1.tar.gz
gitea-dba5d82f86dc9dc757404f03bf80ebbe28a5a0b1.zip
Expose Attachemnt Settings by API (#12514)
close #12368
-rw-r--r--integrations/api_settings_test.go12
-rw-r--r--modules/structs/settings.go8
-rw-r--r--routers/api/v1/api.go1
-rw-r--r--routers/api/v1/settings/settings.go18
-rw-r--r--routers/api/v1/swagger/settings.go7
-rw-r--r--templates/swagger/v1_json.tmpl48
6 files changed, 94 insertions, 0 deletions
diff --git a/integrations/api_settings_test.go b/integrations/api_settings_test.go
index 3eb8e93044..60dbf7a9dc 100644
--- a/integrations/api_settings_test.go
+++ b/integrations/api_settings_test.go
@@ -46,4 +46,16 @@ func TestAPIExposedSettings(t *testing.T) {
MirrorsDisabled: setting.Repository.DisableMirrors,
HTTPGitDisabled: setting.Repository.DisableHTTPGit,
}, repo)
+
+ attachment := new(api.GeneralAttachmentSettings)
+ req = NewRequest(t, "GET", "/api/v1/settings/attachment")
+ resp = MakeRequest(t, req, http.StatusOK)
+
+ DecodeJSON(t, resp, &attachment)
+ assert.EqualValues(t, &api.GeneralAttachmentSettings{
+ Enabled: setting.Attachment.Enabled,
+ AllowedTypes: setting.Attachment.AllowedTypes,
+ MaxFiles: setting.Attachment.MaxFiles,
+ MaxSize: setting.Attachment.MaxSize,
+ }, attachment)
}
diff --git a/modules/structs/settings.go b/modules/structs/settings.go
index f1ff1344ea..6874d6705b 100644
--- a/modules/structs/settings.go
+++ b/modules/structs/settings.go
@@ -22,3 +22,11 @@ type GeneralAPISettings struct {
DefaultGitTreesPerPage int `json:"default_git_trees_per_page"`
DefaultMaxBlobSize int64 `json:"default_max_blob_size"`
}
+
+// GeneralAttachmentSettings contains global Attachment settings exposed by API
+type GeneralAttachmentSettings struct {
+ Enabled bool `json:"enabled"`
+ AllowedTypes string `json:"allowed_types"`
+ MaxSize int64 `json:"max_size"`
+ MaxFiles int `json:"max_files"`
+}
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 027c6abc97..5f472f3518 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -522,6 +522,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/settings", func() {
m.Get("/ui", settings.GetGeneralUISettings)
m.Get("/api", settings.GetGeneralAPISettings)
+ m.Get("/attachment", settings.GetGeneralAttachmentSettings)
m.Get("/repository", settings.GetGeneralRepoSettings)
})
diff --git a/routers/api/v1/settings/settings.go b/routers/api/v1/settings/settings.go
index 7ec0d74c83..29210751d6 100644
--- a/routers/api/v1/settings/settings.go
+++ b/routers/api/v1/settings/settings.go
@@ -60,3 +60,21 @@ func GetGeneralRepoSettings(ctx *context.APIContext) {
HTTPGitDisabled: setting.Repository.DisableHTTPGit,
})
}
+
+// GetGeneralAttachmentSettings returns instance's global settings for Attachment
+func GetGeneralAttachmentSettings(ctx *context.APIContext) {
+ // swagger:operation GET /settings/Attachment settings getGeneralAttachmentSettings
+ // ---
+ // summary: Get instance's global settings for Attachment
+ // produces:
+ // - application/json
+ // responses:
+ // "200":
+ // "$ref": "#/responses/GeneralAttachmentSettings"
+ ctx.JSON(http.StatusOK, api.GeneralAttachmentSettings{
+ Enabled: setting.Attachment.Enabled,
+ AllowedTypes: setting.Attachment.AllowedTypes,
+ MaxFiles: setting.Attachment.MaxFiles,
+ MaxSize: setting.Attachment.MaxSize,
+ })
+}
diff --git a/routers/api/v1/swagger/settings.go b/routers/api/v1/swagger/settings.go
index ad0d891dde..4bf153cb9c 100644
--- a/routers/api/v1/swagger/settings.go
+++ b/routers/api/v1/swagger/settings.go
@@ -26,3 +26,10 @@ type swaggerResponseGeneralAPISettings struct {
// in:body
Body api.GeneralAPISettings `json:"body"`
}
+
+// GeneralAttachmentSettings
+// swagger:response GeneralAttachmentSettings
+type swaggerResponseGeneralAttachmentSettings struct {
+ // in:body
+ Body api.GeneralAttachmentSettings `json:"body"`
+}
diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl
index 86dd817ede..3c563aa673 100644
--- a/templates/swagger/v1_json.tmpl
+++ b/templates/swagger/v1_json.tmpl
@@ -8672,6 +8672,23 @@
}
}
},
+ "/settings/Attachment": {
+ "get": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "settings"
+ ],
+ "summary": "Get instance's global settings for Attachment",
+ "operationId": "getGeneralAttachmentSettings",
+ "responses": {
+ "200": {
+ "$ref": "#/responses/GeneralAttachmentSettings"
+ }
+ }
+ }
+ },
"/settings/api": {
"get": {
"produces": [
@@ -13021,6 +13038,31 @@
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
+ "GeneralAttachmentSettings": {
+ "description": "GeneralAttachmentSettings contains global Attachment settings exposed by API",
+ "type": "object",
+ "properties": {
+ "allowed_types": {
+ "type": "string",
+ "x-go-name": "AllowedTypes"
+ },
+ "enabled": {
+ "type": "boolean",
+ "x-go-name": "Enabled"
+ },
+ "max_files": {
+ "type": "integer",
+ "format": "int64",
+ "x-go-name": "MaxFiles"
+ },
+ "max_size": {
+ "type": "integer",
+ "format": "int64",
+ "x-go-name": "MaxSize"
+ }
+ },
+ "x-go-package": "code.gitea.io/gitea/modules/structs"
+ },
"GeneralRepoSettings": {
"description": "GeneralRepoSettings contains global repository settings exposed by API",
"type": "object",
@@ -15247,6 +15289,12 @@
"$ref": "#/definitions/GeneralAPISettings"
}
},
+ "GeneralAttachmentSettings": {
+ "description": "GeneralAttachmentSettings",
+ "schema": {
+ "$ref": "#/definitions/GeneralAttachmentSettings"
+ }
+ },
"GeneralRepoSettings": {
"description": "GeneralRepoSettings",
"schema": {