diff --git a/backend/src/app/rpc/commands/teams.clj b/backend/src/app/rpc/commands/teams.clj index 54f52340490..ffe7f428218 100644 --- a/backend/src/app/rpc/commands/teams.clj +++ b/backend/src/app/rpc/commands/teams.clj @@ -652,7 +652,7 @@ (mbus/pub! msgbus :topic member-id - :message {:type :team-permissions-change + :message {:type :team-role-change :subs-id member-id :team-id team-id :role role}) @@ -711,7 +711,8 @@ (mbus/pub! msgbus :topic member-id - :message {:type :removed-from-team + :message {:type :team-membership-change + :change :removed :subs-id member-id :team-id team-id :team-name (:name team)}) diff --git a/common/src/app/common/types/team.cljc b/common/src/app/common/types/team.cljc index 5eaa3787d95..aed6f203971 100644 --- a/common/src/app/common/types/team.cljc +++ b/common/src/app/common/types/team.cljc @@ -7,4 +7,11 @@ (ns app.common.types.team) (def valid-roles - #{:owner :admin :editor :viewer}) \ No newline at end of file + #{:owner :admin :editor :viewer}) + +(def permissions-for-role + {:viewer {:can-edit false :is-admin false :is-owner false} + :editor {:can-edit true :is-admin false :is-owner false} + :admin {:can-edit true :is-admin true :is-owner false} + :owner {:can-edit true :is-admin true :is-owner true}}) + diff --git a/frontend/src/app/main/data/changes.cljs b/frontend/src/app/main/data/changes.cljs index cfc6a41fa14..0f64541416e 100644 --- a/frontend/src/app/main/data/changes.cljs +++ b/frontend/src/app/main/data/changes.cljs @@ -182,7 +182,7 @@ uchg (vec undo-changes) rchg (vec redo-changes) features (features/get-team-enabled-features state) - user-viewer? (not (get-in state [:workspace-file :permissions :can-edit]))] + user-viewer? (not (dm/get-in state [:workspace-file :permissions :can-edit]))] ;; Prevent commit changes by a viewer team member (it really should never happen) (if user-viewer? diff --git a/frontend/src/app/main/data/common.cljs b/frontend/src/app/main/data/common.cljs index f597070283a..136fafd6bb6 100644 --- a/frontend/src/app/main/data/common.cljs +++ b/frontend/src/app/main/data/common.cljs @@ -174,6 +174,14 @@ (rx/tap on-success) (rx/catch on-error)))))) +(defn- change-role-msg + [role] + (case role + :viewer (tr "dashboard.permissions-change.viewer") + :editor (tr "dashboard.permissions-change.editor") + :admin (tr "dashboard.permissions-change.admin") + :owner (tr "dashboard.permissions-change.owner"))) + (defn change-team-permissions [{:keys [team-id role workspace?]}] @@ -182,19 +190,7 @@ (ptk/reify ::change-team-permissions ptk/WatchEvent (watch [_ _ _] - (let [msg (case role - :viewer - (tr "dashboard.permissions-change.viewer") - - :editor - (tr "dashboard.permissions-change.editor") - - :admin - (tr "dashboard.permissions-change.admin") - - :owner - (tr "dashboard.permissions-change.owner"))] - (rx/of (ntf/info msg)))) + (rx/of (ntf/info (change-role-msg role)))) ptk/UpdateEvent (update [_ state] @@ -203,37 +199,24 @@ [:teams team-id :permissions])] (update-in state route (fn [permissions] - (cond - (= role :viewer) - (assoc permissions :can-edit false :is-admin false :is-owner false) - - (= role :editor) - (assoc permissions :can-edit true :is-admin false :is-owner false) - - (= role :admin) - (assoc permissions :can-edit true :is-admin true :is-owner false) - - (= role :owner) - (assoc permissions :can-edit true :is-admin true :is-owner true) - - :else - permissions))))))) + (merge permissions (get tt/permissions-for-role role)))))))) -(defn removed-from-team - [{:keys [team-id team-name]}] +(defn team-membership-change + [{:keys [team-id team-name change]}] (dm/assert! (uuid? team-id)) - (ptk/reify ::removed-from-team + (ptk/reify ::team-membership-change ptk/WatchEvent (watch [_ state _] - (let [msg (tr "dashboard.removed-from-team" team-name)] + (when (= :removed change) + (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)) + (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))))))) + (rx/delay 250)))))))) diff --git a/frontend/src/app/main/data/dashboard.cljs b/frontend/src/app/main/data/dashboard.cljs index a6b5c4903db..03ccc2ec76b 100644 --- a/frontend/src/app/main/data/dashboard.cljs +++ b/frontend/src/app/main/data/dashboard.cljs @@ -1223,7 +1223,7 @@ (defn- process-message [{:keys [type] :as msg}] (case type - :notification (dc/handle-notification msg) - :team-permissions-change (handle-change-team-permissions-dashboard msg) - :removed-from-team (dc/removed-from-team msg) + :notification (dc/handle-notification msg) + :team-role-change (handle-change-team-permissions-dashboard msg) + :team-membership-change (dc/team-membership-change msg) nil)) \ No newline at end of file diff --git a/frontend/src/app/main/data/workspace/notifications.cljs b/frontend/src/app/main/data/workspace/notifications.cljs index f670993efec..449c26e6b07 100644 --- a/frontend/src/app/main/data/workspace/notifications.cljs +++ b/frontend/src/app/main/data/workspace/notifications.cljs @@ -121,16 +121,16 @@ (defn- process-message [{:keys [type] :as msg}] (case type - :join-file (handle-presence msg) - :leave-file (handle-presence msg) - :presence (handle-presence msg) - :disconnect (handle-presence msg) - :pointer-update (handle-pointer-update msg) - :file-change (handle-file-change msg) - :library-change (handle-library-change 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) + :join-file (handle-presence msg) + :leave-file (handle-presence msg) + :presence (handle-presence msg) + :disconnect (handle-presence msg) + :pointer-update (handle-pointer-update msg) + :file-change (handle-file-change msg) + :library-change (handle-library-change msg) + :notification (dc/handle-notification msg) + :team-role-change (handle-change-team-permissions (assoc msg :workspace? true)) + :team-membership-change (dc/team-membership-change msg) nil)) (defn- handle-pointer-send diff --git a/frontend/src/app/main/data/workspace/shortcuts.cljs b/frontend/src/app/main/data/workspace/shortcuts.cljs index 99ecf28fe60..03f27594c53 100644 --- a/frontend/src/app/main/data/workspace/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/shortcuts.cljs @@ -45,7 +45,7 @@ (defn emit-when-no-readonly [& events] (let [file (deref refs/workspace-file) - user-viewer? (not (get-in file [:permissions :can-edit])) + user-viewer? (not (dm/get-in file [:permissions :can-edit])) read-only? (or (deref refs/workspace-read-only?) user-viewer?)] (when-not read-only? diff --git a/frontend/src/app/main/data/workspace/text/shortcuts.cljs b/frontend/src/app/main/data/workspace/text/shortcuts.cljs index d67b327d3cc..446aa015b9a 100644 --- a/frontend/src/app/main/data/workspace/text/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/text/shortcuts.cljs @@ -7,6 +7,7 @@ (ns app.main.data.workspace.text.shortcuts (:require [app.common.data :as d] + [app.common.data.macros :as dm] [app.common.text :as txt] [app.main.data.shortcuts :as ds] [app.main.data.workspace.texts :as dwt] @@ -190,7 +191,7 @@ (defn- update-attrs-when-no-readonly [props] (let [undo-id (js/Symbol) file (deref refs/workspace-file) - user-viewer? (not (get-in file [:permissions :can-edit])) + user-viewer? (not (dm/get-in file [:permissions :can-edit])) read-only? (or (deref refs/workspace-read-only?) user-viewer?) shapes-with-children (deref refs/selected-shapes-with-children) diff --git a/frontend/src/app/main/ui/dashboard.cljs b/frontend/src/app/main/ui/dashboard.cljs index eff810496be..37e023cc045 100644 --- a/frontend/src/app/main/ui/dashboard.cljs +++ b/frontend/src/app/main/ui/dashboard.cljs @@ -65,7 +65,7 @@ content-width (mf/use-state 0) project-id (:id project) team-id (:id team) - you-viewer? (not (get-in team [:permissions :can-edit])) + you-viewer? (not (dm/get-in team [:permissions :can-edit])) dashboard-local (mf/deref refs/dashboard-local) file-menu-open? (:menu-open dashboard-local) diff --git a/frontend/src/app/main/ui/dashboard/projects.cljs b/frontend/src/app/main/ui/dashboard/projects.cljs index f2f5c20eeff..34903f35fd4 100644 --- a/frontend/src/app/main/ui/dashboard/projects.cljs +++ b/frontend/src/app/main/ui/dashboard/projects.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.dashboard.projects (:require-macros [app.main.style :as stl]) (:require + [app.common.data.macros :as dm] [app.common.geom.point :as gpt] [app.main.data.dashboard :as dd] [app.main.data.events :as ev] @@ -312,9 +313,9 @@ (sort-by :modified-at) (reverse)) recent-map (mf/deref recent-files-ref) - you-owner? (get-in team [:permissions :is-owner]) - you-admin? (get-in team [:permissions :is-admin]) - you-viewer? (not (get-in team [:permissions :can-edit])) + you-owner? (dm/get-in team [:permissions :is-owner]) + you-admin? (dm/get-in team [:permissions :is-admin]) + you-viewer? (not (dm/get-in team [:permissions :can-edit])) can-invite? (or you-owner? you-admin?) show-team-hero* (mf/use-state #(get storage/global ::show-team-hero true)) diff --git a/frontend/src/app/main/ui/workspace.cljs b/frontend/src/app/main/ui/workspace.cljs index 75d4221377c..96ac09b3004 100644 --- a/frontend/src/app/main/ui/workspace.cljs +++ b/frontend/src/app/main/ui/workspace.cljs @@ -172,7 +172,7 @@ team-id (:team-id project) file-name (:name file) - user-viewer? (not (get-in file [:permissions :can-edit])) + user-viewer? (not (dm/get-in file [:permissions :can-edit])) read-only? (or (mf/deref refs/workspace-read-only?) user-viewer?)