From 823792339f2ddda9b119e464b4151d6eca9905e1 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Mon, 14 Oct 2024 15:19:40 +0200 Subject: [PATCH] :sparkles: Kick out of a team - Visibility of System Status --- backend/src/app/rpc/commands/teams.clj | 12 ++++++++-- frontend/src/app/main/data/common.cljs | 22 ++++++++++++++++++- frontend/src/app/main/data/dashboard.cljs | 1 + frontend/src/app/main/data/workspace.cljs | 17 -------------- .../src/app/main/data/workspace/common.cljs | 21 ++++++++++++++++++ .../main/data/workspace/notifications.cljs | 22 ++++++++++--------- .../main/ui/workspace/sidebar/options.cljs | 5 +++-- .../main/ui/workspace/viewport/top_bar.cljs | 3 ++- frontend/src/debug.cljs | 3 ++- frontend/translations/en.po | 12 ++++++---- frontend/translations/es.po | 12 ++++++---- 11 files changed, 88 insertions(+), 42 deletions(-) diff --git a/backend/src/app/rpc/commands/teams.clj b/backend/src/app/rpc/commands/teams.clj index b41279c7e..54f523404 100644 --- a/backend/src/app/rpc/commands/teams.clj +++ b/backend/src/app/rpc/commands/teams.clj @@ -693,9 +693,10 @@ (sv/defmethod ::delete-team-member {::doc/added "1.17" ::sm/params schema:delete-team-member} - [{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id team-id member-id] :as params}] + [{:keys [::db/pool ::mbus/msgbus] :as cfg} {:keys [::rpc/profile-id team-id member-id] :as params}] (db/with-atomic [conn pool] - (let [perms (get-permissions conn profile-id team-id)] + (let [team (get-team pool :profile-id profile-id :team-id team-id) + perms (get-permissions conn profile-id team-id)] (when-not (or (:is-owner perms) (:is-admin perms)) (ex/raise :type :validation @@ -708,6 +709,13 @@ (db/delete! conn :team-profile-rel {:profile-id member-id :team-id team-id}) + (mbus/pub! msgbus + :topic member-id + :message {:type :removed-from-team + :subs-id member-id + :team-id team-id + :team-name (:name team)}) + nil))) ;; --- Mutation: Update Team Photo diff --git a/frontend/src/app/main/data/common.cljs b/frontend/src/app/main/data/common.cljs index 7cdc00f20..f59707028 100644 --- a/frontend/src/app/main/data/common.cljs +++ b/frontend/src/app/main/data/common.cljs @@ -17,6 +17,7 @@ [app.main.repo :as rp] [app.main.store :as st] [app.util.i18n :refer [tr]] + [app.util.router :as rt] [beicon.v2.core :as rx] [potok.v2.core :as ptk])) @@ -216,4 +217,23 @@ (assoc permissions :can-edit true :is-admin true :is-owner true) :else - permissions))))))) \ No newline at end of file + permissions))))))) + + + +(defn removed-from-team + [{:keys [team-id team-name]}] + (dm/assert! (uuid? team-id)) + (ptk/reify ::removed-from-team + ptk/WatchEvent + (watch [_ state _] + (let [msg (tr "dashboard.removed-from-team" team-name)] + + (rx/concat + (rx/of (rt/nav :dashboard-projects {:team-id (get-in state [:profile :default-team-id])})) + (->> (rx/of (ntf/info msg)) + ;; Delay so the navigation can finish + (rx/delay 250))))))) + + + diff --git a/frontend/src/app/main/data/dashboard.cljs b/frontend/src/app/main/data/dashboard.cljs index 88614547b..ead095adb 100644 --- a/frontend/src/app/main/data/dashboard.cljs +++ b/frontend/src/app/main/data/dashboard.cljs @@ -1215,4 +1215,5 @@ (case type :notification (dc/handle-notification msg) :team-permissions-change (dc/change-team-permissions (assoc msg :workspace? false)) + :removed-from-team (dc/removed-from-team msg) nil)) \ No newline at end of file diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 5afe5eeeb..78c0f8615 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -2106,24 +2106,7 @@ (pcb/mod-page {:background (:color color)}))] (rx/of (dch/commit-changes changes))))))) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Read only -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defn set-workspace-read-only - [read-only?] - (ptk/reify ::set-workspace-read-only - ptk/UpdateEvent - (update [_ state] - (assoc-in state [:workspace-global :read-only?] read-only?)) - - ptk/WatchEvent - (watch [_ _ _] - (if read-only? - (rx/of :interrupt - (remove-layout-flag :colorpalette) - (remove-layout-flag :textpalette)) - (rx/empty))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Measurements diff --git a/frontend/src/app/main/data/workspace/common.cljs b/frontend/src/app/main/data/workspace/common.cljs index 587995105..3902252c5 100644 --- a/frontend/src/app/main/data/workspace/common.cljs +++ b/frontend/src/app/main/data/workspace/common.cljs @@ -7,6 +7,8 @@ (ns app.main.data.workspace.common (:require [app.common.logging :as log] + [app.main.data.workspace.layout :as dwl] + [beicon.v2.core :as rx] [potok.v2.core :as ptk])) ;; Change this to :info :debug or :trace to debug this module @@ -56,3 +58,22 @@ ptk/UpdateEvent (update [_ state] (update-in state [:workspace-local :hide-toolbar] not)))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Read only +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defn set-workspace-read-only + [read-only?] + (ptk/reify ::set-workspace-read-only + ptk/UpdateEvent + (update [_ state] + (assoc-in state [:workspace-global :read-only?] read-only?)) + + ptk/WatchEvent + (watch [_ _ _] + (if read-only? + (rx/of :interrupt + (dwl/remove-layout-flag :colorpalette) + (dwl/remove-layout-flag :textpalette)) + (rx/empty))))) diff --git a/frontend/src/app/main/data/workspace/notifications.cljs b/frontend/src/app/main/data/workspace/notifications.cljs index 1b5a01203..85093bc74 100644 --- a/frontend/src/app/main/data/workspace/notifications.cljs +++ b/frontend/src/app/main/data/workspace/notifications.cljs @@ -12,10 +12,12 @@ [app.common.schema :as sm] [app.common.uuid :as uuid] [app.main.data.changes :as dch] - [app.main.data.common :refer [handle-notification change-team-permissions]] + [app.main.data.common :as dc] [app.main.data.websocket :as dws] + [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.util.globals :refer [global]] [app.util.mouse :as mse] @@ -103,16 +105,15 @@ (let [viewer? (= :viewer role)] (rx/concat - (->> (rx/of :interrupt - (dwe/clear-edition-mode)) + (rx/of :interrupt + (dwe/clear-edition-mode) + (dwc/set-workspace-read-only false)) + (->> (rx/of (dc/change-team-permissions msg)) ;; Delay so anything that launched :interrupt can finish - (rx/delay 500)) - + (rx/delay 100)) (if viewer? - (rx/of (dwly/set-options-mode :design)) - (rx/empty)) - - (rx/of (change-team-permissions msg))))))) + (rx/of (dwly/set-options-mode :inspect)) + (rx/of (dwly/set-options-mode :design)))))))) (defn- process-message @@ -125,8 +126,9 @@ :pointer-update (handle-pointer-update msg) :file-change (handle-file-change msg) :library-change (handle-library-change msg) - :notification (handle-notification msg) + :notification (dc/handle-notification msg) :team-permissions-change (handle-change-team-permissions (assoc msg :workspace? true)) + :removed-from-team (dc/removed-from-team msg) nil)) (defn- handle-pointer-send diff --git a/frontend/src/app/main/ui/workspace/sidebar/options.cljs b/frontend/src/app/main/ui/workspace/sidebar/options.cljs index e10fa59a5..a7505dde3 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options.cljs @@ -13,6 +13,7 @@ [app.common.geom.shapes :as gsh] [app.common.types.shape.layout :as ctl] [app.main.data.workspace :as udw] + [app.main.data.workspace.common :as dwc] [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.context :as ctx] @@ -147,8 +148,8 @@ (let [options-mode (keyword options-mode)] (st/emit! (udw/set-options-mode options-mode)) (if (= options-mode :inspect) - (st/emit! :interrupt (udw/set-workspace-read-only true)) - (st/emit! :interrupt (udw/set-workspace-read-only false))))) + (st/emit! :interrupt (dwc/set-workspace-read-only true)) + (st/emit! :interrupt (dwc/set-workspace-read-only false))))) design-content (mf/html [:& design-menu {:selected selected diff --git a/frontend/src/app/main/ui/workspace/viewport/top_bar.cljs b/frontend/src/app/main/ui/workspace/viewport/top_bar.cljs index 7c2963ae1..6767735db 100644 --- a/frontend/src/app/main/ui/workspace/viewport/top_bar.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/top_bar.cljs @@ -10,6 +10,7 @@ [app.common.files.helpers :as cfh] [app.common.types.shape.layout :as ctl] [app.main.data.workspace :as dw] + [app.main.data.workspace.common :as dwc] [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.context :as ctx] @@ -26,7 +27,7 @@ (fn [] (st/emit! :interrupt (dw/set-options-mode :design) - (dw/set-workspace-read-only false))))] + (dwc/set-workspace-read-only false))))] [:div {:class (stl/css :viewport-actions)} [:div {:class (stl/css :viewport-actions-container)} [:div {:class (stl/css :viewport-actions-title)} diff --git a/frontend/src/debug.cljs b/frontend/src/debug.cljs index d127c4bf1..d758c09d4 100644 --- a/frontend/src/debug.cljs +++ b/frontend/src/debug.cljs @@ -23,6 +23,7 @@ [app.main.data.preview :as dp] [app.main.data.viewer.shortcuts] [app.main.data.workspace :as dw] + [app.main.data.workspace.common :as dwcm] [app.main.data.workspace.path.shortcuts] [app.main.data.workspace.selection :as dws] [app.main.data.workspace.shortcuts] @@ -370,7 +371,7 @@ (defn ^:export set-workspace-read-only [read-only?] - (st/emit! (dw/set-workspace-read-only read-only?))) + (st/emit! (dwcm/set-workspace-read-only read-only?))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; REPAIR & VALIDATION diff --git a/frontend/translations/en.po b/frontend/translations/en.po index ff10bf4fa..53979c6b1 100644 --- a/frontend/translations/en.po +++ b/frontend/translations/en.po @@ -752,22 +752,26 @@ msgstr "+ New project" msgid "dashboard.new-project-prefix" msgstr "New Project" -#: src/app/main/data/dashboard.cljs:72 +#: src/app/main/data/common.cljs:72 msgid "dashboard.permissions-change.viewer" msgstr "You are now a viewer on this team." -#: src/app/main/data/dashboard.cljs:75 +#: src/app/main/data/common.cljs:75 msgid "dashboard.permissions-change.editor" msgstr "You are now an editor on this team." -#: src/app/main/data/dashboard.cljs:78 +#: src/app/main/data/common.cljs:78 msgid "dashboard.permissions-change.admin" msgstr "You are now an admin on this team." -#: src/app/main/data/dashboard.cljs:81 +#: src/app/main/data/common.cljs:195 msgid "dashboard.permissions-change.owner" msgstr "You are now owner on this team." +#: src/app/main/data/common.cljs:229 +msgid "dashboard.removed-from-team" +msgstr "You are not part of the team “%s“ anymore." + #: src/app/main/ui/dashboard/search.cljs:60 msgid "dashboard.no-matches-for" msgstr "No matches found for “%s“" diff --git a/frontend/translations/es.po b/frontend/translations/es.po index ec6795ed7..53ca42684 100644 --- a/frontend/translations/es.po +++ b/frontend/translations/es.po @@ -762,22 +762,26 @@ msgstr "+ Nuevo proyecto" msgid "dashboard.new-project-prefix" msgstr "Nuevo Proyecto" -#: src/app/main/data/dashboard.cljs:72 +#: src/app/main/data/common.cljs:72 msgid "dashboard.permissions-change.viewer" msgstr "Ahora eres lector del equipo." -#: src/app/main/data/dashboard.cljs:75 +#: src/app/main/data/common.cljs:75 msgid "dashboard.permissions-change.editor" msgstr "Ahora eres editor del equipo." -#: src/app/main/data/dashboard.cljs:78 +#: src/app/main/data/common.cljs:78 msgid "dashboard.permissions-change.admin" msgstr "Ahora eres administrador del equipo." -#: src/app/main/data/dashboard.cljs:81 +#: src/app/main/data/common.cljs:81 msgid "dashboard.permissions-change.owner" msgstr "Ahora eres el dueño del equipo." +#: src/app/main/data/common.cljs:229 +msgid "dashboard.removed-from-team" +msgstr "Ya no eres parte del equipo “%s“." + #: src/app/main/ui/dashboard/search.cljs:60 msgid "dashboard.no-matches-for" msgstr "No se encuentra “%s“"