Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add viewer role #5135

Merged
merged 8 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
♻️ Clean up and refactors of viewer role
  • Loading branch information
pabloalba committed Oct 18, 2024
commit bd08e990808be99abb3a5404d38a052284e53b75
5 changes: 3 additions & 2 deletions backend/src/app/rpc/commands/teams.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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)})
Expand Down
9 changes: 8 additions & 1 deletion common/src/app/common/types/team.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@
(ns app.common.types.team)

(def valid-roles
#{:owner :admin :editor :viewer})
#{: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}})

2 changes: 1 addition & 1 deletion frontend/src/app/main/data/changes.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
55 changes: 19 additions & 36 deletions frontend/src/app/main/data/common.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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?]}]
Expand All @@ -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]
Expand All @@ -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))))))))



6 changes: 3 additions & 3 deletions frontend/src/app/main/data/dashboard.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
20 changes: 10 additions & 10 deletions frontend/src/app/main/data/workspace/notifications.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/main/data/workspace/shortcuts.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/app/main/data/workspace/text/shortcuts.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/main/ui/dashboard.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/app/main/ui/dashboard/projects.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/main/ui/workspace.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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?)

Expand Down