From 68f560e29bcdc33f4247de400d849aece2fdd144 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Mon, 21 Oct 2024 16:10:53 +0200 Subject: [PATCH] :bug: Fix corner case of change rol to viewer when editing a text --- frontend/src/app/main/data/persistence.cljs | 31 +++++++------- .../main/data/workspace/notifications.cljs | 5 ++- .../app/main/ui/workspace/right_header.cljs | 42 ++++++++++--------- 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/frontend/src/app/main/data/persistence.cljs b/frontend/src/app/main/data/persistence.cljs index 9a17eda3f..7741b6103 100644 --- a/frontend/src/app/main/data/persistence.cljs +++ b/frontend/src/app/main/data/persistence.cljs @@ -118,22 +118,25 @@ :created-at (:created-at commit) :commit-id commit-id :changes (vec changes) - :features features}] + :features features} + permissions (:permissions state)] - (->> (rp/cmd! :update-file params) - (rx/mapcat (fn [{:keys [revn lagged] :as response}] - (log/debug :hint "changes persisted" :commit-id (dm/str commit-id) :lagged (count lagged)) - (rx/of (ptk/data-event ::commit-persisted commit) - (update-file-revn file-id revn)))) + ;; Prevent commit changes by a team member without edition permission + (when (:can-edit permissions) + (->> (rp/cmd! :update-file params) + (rx/mapcat (fn [{:keys [revn lagged] :as response}] + (log/debug :hint "changes persisted" :commit-id (dm/str commit-id) :lagged (count lagged)) + (rx/of (ptk/data-event ::commit-persisted commit) + (update-file-revn file-id revn)))) - (rx/catch (fn [cause] - (rx/concat - (if (= :authentication (:type cause)) - (rx/empty) - (rx/of (ptk/data-event ::error cause) - (update-status :error))) - (rx/of (discard-persistence-state)) - (rx/throw cause)))))))))) + (rx/catch (fn [cause] + (rx/concat + (if (= :authentication (:type cause)) + (rx/empty) + (rx/of (ptk/data-event ::error cause) + (update-status :error))) + (rx/of (discard-persistence-state)) + (rx/throw cause))))))))))) (defn- run-persistence-task diff --git a/frontend/src/app/main/data/workspace/notifications.cljs b/frontend/src/app/main/data/workspace/notifications.cljs index 5a82818a1..d8a4fdb4e 100644 --- a/frontend/src/app/main/data/workspace/notifications.cljs +++ b/frontend/src/app/main/data/workspace/notifications.cljs @@ -18,8 +18,8 @@ [app.main.data.workspace.common :as dwc] [app.main.data.workspace.edition :as dwe] [app.main.data.workspace.layout :as dwly] - [app.main.data.workspace.libraries :as dwl] + [app.main.data.workspace.texts :as dwt] [app.util.globals :refer [global]] [app.util.mouse :as mse] [app.util.object :as obj] @@ -106,7 +106,8 @@ (rx/of :interrupt (dwe/clear-edition-mode) (dwc/set-workspace-read-only false)) - (->> (rx/of (dc/change-team-role msg)) + (->> (rx/of (dc/change-team-role msg) + ::dwt/update-editor-state) ;; Delay so anything that launched :interrupt can finish (rx/delay 100)) (if (= :viewer role) diff --git a/frontend/src/app/main/ui/workspace/right_header.cljs b/frontend/src/app/main/ui/workspace/right_header.cljs index f9e2e3252..2c4466bd8 100644 --- a/frontend/src/app/main/ui/workspace/right_header.cljs +++ b/frontend/src/app/main/ui/workspace/right_header.cljs @@ -34,30 +34,32 @@ {::mf/wrap [mf/memo] ::mf/wrap-props false} [] - (let [status (mf/deref ref:persistence-status)] - [:div {:class (stl/css :persistence-status-widget)} - (case status - :pending - [:div {:class (stl/css :status-icon :pending-status) - :title (tr "workspace.header.unsaved")} - i/status-alert] + (let [status (mf/deref ref:persistence-status) + workspace-read-only? (mf/use-ctx ctx/workspace-read-only?)] + (when-not workspace-read-only? + [:div {:class (stl/css :persistence-status-widget)} + (case status + :pending + [:div {:class (stl/css :status-icon :pending-status) + :title (tr "workspace.header.unsaved")} + i/status-alert] - :saving - [:div {:class (stl/css :status-icon :pending-status) - :title (tr "workspace.header.unsaved")} - i/status-alert] + :saving + [:div {:class (stl/css :status-icon :pending-status) + :title (tr "workspace.header.unsaved")} + i/status-alert] - :saved - [:div {:class (stl/css :status-icon :saved-status) - :title (tr "workspace.header.saved")} - i/status-tick] + :saved + [:div {:class (stl/css :status-icon :saved-status) + :title (tr "workspace.header.saved")} + i/status-tick] - :error - [:div {:class (stl/css :status-icon :error-status) - :title "There was an error saving the data. Please refresh if this persists."} - i/status-wrong] + :error + [:div {:class (stl/css :status-icon :error-status) + :title "There was an error saving the data. Please refresh if this persists."} + i/status-wrong] - nil)])) + nil)]))) ;; --- Zoom Widget