From a2848c95decfb58b9e1772b1014bb4c0117d3584 Mon Sep 17 00:00:00 2001 From: zemzema <33085810+zemzema@users.noreply.github.com> Date: Tue, 23 Jul 2024 10:56:08 +0200 Subject: [PATCH] feature (onlyoffice): view only in only office (#715) * Update index.go Enable/Disable edit only Office documents * Function typo Function type * feature (onlyoffice): view only in only office Added onlyoffice_can_edit in plugin_enable so that target attribute can be toggled and only appear when only office is enabled. * feature (onlyoffice): view only in only office Code formating. --- server/plugin/plg_editor_onlyoffice/index.go | 32 ++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/server/plugin/plg_editor_onlyoffice/index.go b/server/plugin/plg_editor_onlyoffice/index.go index 34a7bca5..2cb1d162 100644 --- a/server/plugin/plg_editor_onlyoffice/index.go +++ b/server/plugin/plg_editor_onlyoffice/index.go @@ -27,6 +27,7 @@ var ( plugin_enable func() bool server_url func() string can_download func() bool + can_edit func() bool ) type onlyOfficeCacheData struct { @@ -45,8 +46,8 @@ func init() { } f.Name = "enable" f.Type = "enable" - f.Target = []string{"onlyoffice_server", "onlyoffice_can_download"} - f.Description = "Enable/Disable the office suite to manage word, excel and powerpoint documents." + f.Target = []string{"onlyoffice_server", "onlyoffice_can_download", "onlyoffice_can_edit"} + f.Description = "Enable/Disable the office suite and options to manage word, excel and powerpoint documents." f.Default = false if u := os.Getenv("ONLYOFFICE_URL"); u != "" { f.Default = true @@ -54,6 +55,7 @@ func init() { return f }).Bool() } + server_url = func() string { return Config.Get("features.office.onlyoffice_server").Schema(func(f *FormElement) *FormElement { if f == nil { @@ -72,6 +74,21 @@ func init() { return f }).String() } + + can_edit = func() bool { + return Config.Get("features.office.can_edit").Schema(func(f *FormElement) *FormElement { + if f == nil { + f = &FormElement{} + } + f.Id = "onlyoffice_can_edit" + f.Name = "can_edit" + f.Type = "boolean" + f.Description = "Enable/Disable editing in onlyoffice" + f.Default = true + return f + }).Bool() +} + can_download = func() bool { return Config.Get("features.office.can_download").Schema(func(f *FormElement) *FormElement { if f == nil { @@ -90,6 +107,7 @@ func init() { plugin_enable() server_url() can_download() + can_edit() }) Hooks.Register.HttpEndpoint(func(r *mux.Router, app *App) error { @@ -346,7 +364,9 @@ func IframeContentHandler(ctx *App, res http.ResponseWriter, req *http.Request) "fileType": "%s", "key": "%s", "permissions": { - "download": %s + "download": %s, + "edit": %t + } }, "editorConfig": { @@ -385,6 +405,12 @@ func IframeContentHandler(ctx *App, res http.ResponseWriter, req *http.Request) } return "false" }(), + func() string { + if can_edit() { + return "true" + } + return "false" + }(), filestashServerLocation, oodsMode, userId,