From fc65052ba00e5a93f8894333a3d3ae7827aec3fd Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 26 Jan 2020 19:10:31 +0000 Subject: [PATCH] Add config options for task attachments (#125) Add config options for task attachments Co-authored-by: kolaente Reviewed-on: https://kolaente.dev/vikunja/api/pulls/125 --- config.yml.sample | 2 ++ docs/content/doc/setup/config.md | 2 ++ pkg/config/config.go | 22 ++++++++++++---------- pkg/routes/api/v1/info.go | 28 +++++++++++++++------------- pkg/routes/routes.go | 18 ++++++++++-------- 5 files changed, 41 insertions(+), 31 deletions(-) diff --git a/config.yml.sample b/config.yml.sample index f19dc85dbe6..1a3429bd956 100644 --- a/config.yml.sample +++ b/config.yml.sample @@ -24,6 +24,8 @@ service: enablelinksharing: true # Whether to let new users registering themselves or not enableregistration: true + # Whether to enable task attachments or not + enabletaskattachments: true database: # Database type to use. Supported types are mysql and sqlite. diff --git a/docs/content/doc/setup/config.md b/docs/content/doc/setup/config.md index 33ce79c4e16..eba75aab527 100644 --- a/docs/content/doc/setup/config.md +++ b/docs/content/doc/setup/config.md @@ -67,6 +67,8 @@ service: enablelinksharing: true # Whether to let new users registering themselves or not enableregistration: true + # Whether to enable task attachments or not + enabletaskattachments: true database: # Database type to use. Supported types are mysql and sqlite. diff --git a/pkg/config/config.go b/pkg/config/config.go index 27f68361946..07d3e77dee8 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -33,16 +33,17 @@ type Key string // These constants hold all config value keys const ( - ServiceJWTSecret Key = `service.JWTSecret` - ServiceInterface Key = `service.interface` - ServiceFrontendurl Key = `service.frontendurl` - ServiceEnableCaldav Key = `service.enablecaldav` - ServiceRootpath Key = `service.rootpath` - ServiceMaxItemsPerPage Key = `service.maxitemsperpage` - ServiceEnableMetrics Key = `service.enablemetrics` - ServiceMotd Key = `service.motd` - ServiceEnableLinkSharing Key = `service.enablelinksharing` - ServiceEnableRegistration Key = `service.enableregistration` + ServiceJWTSecret Key = `service.JWTSecret` + ServiceInterface Key = `service.interface` + ServiceFrontendurl Key = `service.frontendurl` + ServiceEnableCaldav Key = `service.enablecaldav` + ServiceRootpath Key = `service.rootpath` + ServiceMaxItemsPerPage Key = `service.maxitemsperpage` + ServiceEnableMetrics Key = `service.enablemetrics` + ServiceMotd Key = `service.motd` + ServiceEnableLinkSharing Key = `service.enablelinksharing` + ServiceEnableRegistration Key = `service.enableregistration` + ServiceEnableTaskAttachments Key = `service.enabletaskattachments` DatabaseType Key = `database.type` DatabaseHost Key = `database.host` @@ -166,6 +167,7 @@ func InitDefaultConfig() { ServiceMotd.setDefault("") ServiceEnableLinkSharing.setDefault(true) ServiceEnableRegistration.setDefault(true) + ServiceEnableTaskAttachments.setDefault(true) // Database DatabaseType.setDefault("sqlite") diff --git a/pkg/routes/api/v1/info.go b/pkg/routes/api/v1/info.go index 3f9096855d9..461104c1420 100644 --- a/pkg/routes/api/v1/info.go +++ b/pkg/routes/api/v1/info.go @@ -24,13 +24,14 @@ import ( ) type vikunjaInfos struct { - Version string `json:"version"` - FrontendURL string `json:"frontend_url"` - Motd string `json:"motd"` - LinkSharingEnabled bool `json:"link_sharing_enabled"` - MaxFileSize string `json:"max_file_size"` - RegistrationEnabled bool `json:"registration_enabled"` - AvailableMigrators []string `json:"available_migrators"` + Version string `json:"version"` + FrontendURL string `json:"frontend_url"` + Motd string `json:"motd"` + LinkSharingEnabled bool `json:"link_sharing_enabled"` + MaxFileSize string `json:"max_file_size"` + RegistrationEnabled bool `json:"registration_enabled"` + AvailableMigrators []string `json:"available_migrators"` + TaskAttachmentsEnabled bool `json:"task_attachments_enabled"` } // Info is the handler to get infos about this vikunja instance @@ -42,12 +43,13 @@ type vikunjaInfos struct { // @Router /info [get] func Info(c echo.Context) error { infos := vikunjaInfos{ - Version: version.Version, - FrontendURL: config.ServiceFrontendurl.GetString(), - Motd: config.ServiceMotd.GetString(), - LinkSharingEnabled: config.ServiceEnableLinkSharing.GetBool(), - MaxFileSize: config.FilesMaxSize.GetString(), - RegistrationEnabled: config.ServiceEnableRegistration.GetBool(), + Version: version.Version, + FrontendURL: config.ServiceFrontendurl.GetString(), + Motd: config.ServiceMotd.GetString(), + LinkSharingEnabled: config.ServiceEnableLinkSharing.GetBool(), + MaxFileSize: config.FilesMaxSize.GetString(), + RegistrationEnabled: config.ServiceEnableRegistration.GetBool(), + TaskAttachmentsEnabled: config.ServiceEnableTaskAttachments.GetBool(), } if config.MigrationWunderlistEnable.GetBool() { infos.AvailableMigrators = append(infos.AvailableMigrators, "wunderlist") diff --git a/pkg/routes/routes.go b/pkg/routes/routes.go index b3d8ef11400..aab8410569d 100644 --- a/pkg/routes/routes.go +++ b/pkg/routes/routes.go @@ -288,15 +288,17 @@ func registerAPIRoutes(a *echo.Group) { a.PUT("/tasks/:task/relations", taskRelationHandler.CreateWeb) a.DELETE("/tasks/:task/relations", taskRelationHandler.DeleteWeb) - taskAttachmentHandler := &handler.WebHandler{ - EmptyStruct: func() handler.CObject { - return &models.TaskAttachment{} - }, + if config.ServiceEnableTaskAttachments.GetBool() { + taskAttachmentHandler := &handler.WebHandler{ + EmptyStruct: func() handler.CObject { + return &models.TaskAttachment{} + }, + } + a.GET("/tasks/:task/attachments", taskAttachmentHandler.ReadAllWeb) + a.DELETE("/tasks/:task/attachments/:attachment", taskAttachmentHandler.DeleteWeb) + a.PUT("/tasks/:task/attachments", apiv1.UploadTaskAttachment) + a.GET("/tasks/:task/attachments/:attachment", apiv1.GetTaskAttachment) } - a.GET("/tasks/:task/attachments", taskAttachmentHandler.ReadAllWeb) - a.DELETE("/tasks/:task/attachments/:attachment", taskAttachmentHandler.DeleteWeb) - a.PUT("/tasks/:task/attachments", apiv1.UploadTaskAttachment) - a.GET("/tasks/:task/attachments/:attachment", apiv1.GetTaskAttachment) labelHandler := &handler.WebHandler{ EmptyStruct: func() handler.CObject {