From 4622dd0e0db07de020642be4cf886db41f339bf5 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Mon, 21 Oct 2024 16:06:38 +0200 Subject: [PATCH 1/3] :bug: Fix bad team permissions showing on team page for viewer --- frontend/src/app/main/ui/dashboard/team.cljs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/main/ui/dashboard/team.cljs b/frontend/src/app/main/ui/dashboard/team.cljs index 1f744d632..a029696ef 100644 --- a/frontend/src/app/main/ui/dashboard/team.cljs +++ b/frontend/src/app/main/ui/dashboard/team.cljs @@ -258,6 +258,7 @@ (let [member-is-owner (:is-owner member) member-is-admin (and (:is-admin member) (not member-is-owner)) member-is-editor (and (:can-edit member) (and (not member-is-admin) (not member-is-owner))) + member-is-viewer (and (not member-is-editor) (not member-is-admin) (not member-is-owner)) show? (mf/use-state false) permissions (:permissions team) @@ -267,7 +268,7 @@ is-you (= (:id profile) (:id member)) can-change-rol (or is-owner is-admin) - not-superior (or is-admin (and can-change-rol (or member-is-admin member-is-editor))) + not-superior (or is-admin (and can-change-rol (or member-is-admin member-is-editor member-is-viewer))) role (cond member-is-owner "labels.owner" From 68f560e29bcdc33f4247de400d849aece2fdd144 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Mon, 21 Oct 2024 16:10:53 +0200 Subject: [PATCH 2/3] :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 From 352b09a8917df16ce56bd6528cc2300f9fc6daca Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Mon, 21 Oct 2024 16:20:49 +0200 Subject: [PATCH 3/3] :bug: Fix bad order in roles dropdown --- frontend/src/app/main/ui/dashboard/team.cljs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/main/ui/dashboard/team.cljs b/frontend/src/app/main/ui/dashboard/team.cljs index a029696ef..5524253e4 100644 --- a/frontend/src/app/main/ui/dashboard/team.cljs +++ b/frontend/src/app/main/ui/dashboard/team.cljs @@ -289,15 +289,15 @@ [:& dropdown {:show @show? :on-close on-hide} [:ul {:class (stl/css :roles-dropdown)} - [:li {:on-click on-set-admin - :class (stl/css :rol-dropdown-item)} - (tr "labels.admin")] - [:li {:on-click on-set-editor - :class (stl/css :rol-dropdown-item)} - (tr "labels.editor")] [:li {:on-click on-set-viewer :class (stl/css :rol-dropdown-item)} (tr "labels.viewer")] + [:li {:on-click on-set-editor + :class (stl/css :rol-dropdown-item)} + (tr "labels.editor")] + [:li {:on-click on-set-admin + :class (stl/css :rol-dropdown-item)} + (tr "labels.admin")] (when is-owner [:li {:on-click (partial on-set-owner member) :class (stl/css :rol-dropdown-item)}