From 8ac30c1fd8f777060f520efc5dfed28928ab13f8 Mon Sep 17 00:00:00 2001 From: Jack Case Date: Thu, 14 Sep 2023 10:13:12 -0400 Subject: [PATCH] fix: Allow writing to files with group permission without chmod on Linux (#9297) * feat: check electron config item disable-automatic-chmod * added auto chmod toggle to advanced settings page for electron * add default behavior when chmod config key doesn't exist * added auto chmod description key to en.edn --- src/electron/electron/handler.cljs | 8 +++++++- src/main/frontend/components/settings.cljs | 15 +++++++++++++++ src/resources/dicts/en.edn | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/electron/electron/handler.cljs b/src/electron/electron/handler.cljs index e17f4b73c..957242e05 100644 --- a/src/electron/electron/handler.cljs +++ b/src/electron/electron/handler.cljs @@ -97,6 +97,12 @@ (catch :default _e false))) +(defn chmod-enabled? + [] + (if (= nil (cfgs/get-item :feature/enable-automatic-chmod?)) + true + (cfgs/get-item :feature/enable-automatic-chmod?))) + (defmethod handle :copyFile [_window [_ _repo from-path to-path]] (logger/info ::copy-file from-path to-path) (fs-extra/copy from-path to-path)) @@ -107,7 +113,7 @@ (.from Buf content) content)] (try - (when (and (fs/existsSync path) (not (writable? path))) + (when (and (chmod-enabled?) (fs/existsSync path) (not (writable? path))) (fs/chmodSync path "644")) (fs/writeFileSync path content) (fs/statSync path) diff --git a/src/main/frontend/components/settings.cljs b/src/main/frontend/components/settings.cljs index 23aeabb9f..6f790324f 100644 --- a/src/main/frontend/components/settings.cljs +++ b/src/main/frontend/components/settings.cljs @@ -601,6 +601,20 @@ {:left-label (t :settings-page/network-proxy) :action (user-proxy-settings agent-opts)})) +(rum/defcs auto-chmod-row < rum/reactive + [state t] + (let [enabled? (if (= nil (state/sub [:electron/user-cfgs :feature/enable-automatic-chmod?])) + true + (state/sub [:electron/user-cfgs :feature/enable-automatic-chmod?]))] + (toggle + "automatic-chmod" + (t :settings-page/auto-chmod) + enabled? + #(do + (state/set-state! [:electron/user-cfgs :feature/enable-automatic-chmod?] (not enabled?)) + (ipc/ipc :userAppCfgs :feature/enable-automatic-chmod? (not enabled?))) + [:span.text-sm.opacity-50 (t :settings-page/auto-chmod-desc)]))) + (defn filename-format-row [] (row-with-button-action {:left-label (t :settings-page/filename-format) @@ -709,6 +723,7 @@ (usage-diagnostics-row t instrument-disabled?) (when-not (mobile-util/native-platform?) (developer-mode-row t developer-mode?)) (when (util/electron?) (https-user-agent-row https-agent-opts)) + (when (util/electron?) (auto-chmod-row t)) (when (and (util/electron?) (not (config/demo-graph? current-repo))) (filename-format-row)) (clear-cache-row t) diff --git a/src/resources/dicts/en.edn b/src/resources/dicts/en.edn index 2ccf37998..e43f3bc98 100644 --- a/src/resources/dicts/en.edn +++ b/src/resources/dicts/en.edn @@ -351,6 +351,8 @@ :settings-page/update-error-2 " Please check out the " :settings-permission/start-granting "Grant" + :settings-page/auto-chmod "Automatically change file permissions" + :settings-page/auto-chmod-desc "Disable to allow editing by multiple users with permissions granted by group membership." :yes "Yes" :submit "Submit"