🐛 Fix corner case of change rol to viewer when editing a text

This commit is contained in:
Pablo Alba 2024-10-21 16:10:53 +02:00
parent 4622dd0e0d
commit 68f560e29b
3 changed files with 42 additions and 36 deletions

View file

@ -118,22 +118,25 @@
:created-at (:created-at commit) :created-at (:created-at commit)
:commit-id commit-id :commit-id commit-id
:changes (vec changes) :changes (vec changes)
:features features}] :features features}
permissions (:permissions state)]
(->> (rp/cmd! :update-file params) ;; Prevent commit changes by a team member without edition permission
(rx/mapcat (fn [{:keys [revn lagged] :as response}] (when (:can-edit permissions)
(log/debug :hint "changes persisted" :commit-id (dm/str commit-id) :lagged (count lagged)) (->> (rp/cmd! :update-file params)
(rx/of (ptk/data-event ::commit-persisted commit) (rx/mapcat (fn [{:keys [revn lagged] :as response}]
(update-file-revn file-id revn)))) (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/catch (fn [cause]
(rx/concat (rx/concat
(if (= :authentication (:type cause)) (if (= :authentication (:type cause))
(rx/empty) (rx/empty)
(rx/of (ptk/data-event ::error cause) (rx/of (ptk/data-event ::error cause)
(update-status :error))) (update-status :error)))
(rx/of (discard-persistence-state)) (rx/of (discard-persistence-state))
(rx/throw cause)))))))))) (rx/throw cause)))))))))))
(defn- run-persistence-task (defn- run-persistence-task

View file

@ -18,8 +18,8 @@
[app.main.data.workspace.common :as dwc] [app.main.data.workspace.common :as dwc]
[app.main.data.workspace.edition :as dwe] [app.main.data.workspace.edition :as dwe]
[app.main.data.workspace.layout :as dwly] [app.main.data.workspace.layout :as dwly]
[app.main.data.workspace.libraries :as dwl] [app.main.data.workspace.libraries :as dwl]
[app.main.data.workspace.texts :as dwt]
[app.util.globals :refer [global]] [app.util.globals :refer [global]]
[app.util.mouse :as mse] [app.util.mouse :as mse]
[app.util.object :as obj] [app.util.object :as obj]
@ -106,7 +106,8 @@
(rx/of :interrupt (rx/of :interrupt
(dwe/clear-edition-mode) (dwe/clear-edition-mode)
(dwc/set-workspace-read-only false)) (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 ;; Delay so anything that launched :interrupt can finish
(rx/delay 100)) (rx/delay 100))
(if (= :viewer role) (if (= :viewer role)

View file

@ -34,30 +34,32 @@
{::mf/wrap [mf/memo] {::mf/wrap [mf/memo]
::mf/wrap-props false} ::mf/wrap-props false}
[] []
(let [status (mf/deref ref:persistence-status)] (let [status (mf/deref ref:persistence-status)
[:div {:class (stl/css :persistence-status-widget)} workspace-read-only? (mf/use-ctx ctx/workspace-read-only?)]
(case status (when-not workspace-read-only?
:pending [:div {:class (stl/css :persistence-status-widget)}
[:div {:class (stl/css :status-icon :pending-status) (case status
:title (tr "workspace.header.unsaved")} :pending
i/status-alert] [:div {:class (stl/css :status-icon :pending-status)
:title (tr "workspace.header.unsaved")}
i/status-alert]
:saving :saving
[:div {:class (stl/css :status-icon :pending-status) [:div {:class (stl/css :status-icon :pending-status)
:title (tr "workspace.header.unsaved")} :title (tr "workspace.header.unsaved")}
i/status-alert] i/status-alert]
:saved :saved
[:div {:class (stl/css :status-icon :saved-status) [:div {:class (stl/css :status-icon :saved-status)
:title (tr "workspace.header.saved")} :title (tr "workspace.header.saved")}
i/status-tick] i/status-tick]
:error :error
[:div {:class (stl/css :status-icon :error-status) [:div {:class (stl/css :status-icon :error-status)
:title "There was an error saving the data. Please refresh if this persists."} :title "There was an error saving the data. Please refresh if this persists."}
i/status-wrong] i/status-wrong]
nil)])) nil)])))
;; --- Zoom Widget ;; --- Zoom Widget