mirror of
https://github.com/penpot/penpot.git
synced 2025-02-08 16:18:11 -05:00
♻️ Clean up and refactors of viewer role
This commit is contained in:
parent
66530ca868
commit
bd08e99080
11 changed files with 53 additions and 60 deletions
|
@ -652,7 +652,7 @@
|
||||||
|
|
||||||
(mbus/pub! msgbus
|
(mbus/pub! msgbus
|
||||||
:topic member-id
|
:topic member-id
|
||||||
:message {:type :team-permissions-change
|
:message {:type :team-role-change
|
||||||
:subs-id member-id
|
:subs-id member-id
|
||||||
:team-id team-id
|
:team-id team-id
|
||||||
:role role})
|
:role role})
|
||||||
|
@ -711,7 +711,8 @@
|
||||||
|
|
||||||
(mbus/pub! msgbus
|
(mbus/pub! msgbus
|
||||||
:topic member-id
|
:topic member-id
|
||||||
:message {:type :removed-from-team
|
:message {:type :team-membership-change
|
||||||
|
:change :removed
|
||||||
:subs-id member-id
|
:subs-id member-id
|
||||||
:team-id team-id
|
:team-id team-id
|
||||||
:team-name (:name team)})
|
:team-name (:name team)})
|
||||||
|
|
|
@ -7,4 +7,11 @@
|
||||||
(ns app.common.types.team)
|
(ns app.common.types.team)
|
||||||
|
|
||||||
(def valid-roles
|
(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}})
|
||||||
|
|
||||||
|
|
|
@ -182,7 +182,7 @@
|
||||||
uchg (vec undo-changes)
|
uchg (vec undo-changes)
|
||||||
rchg (vec redo-changes)
|
rchg (vec redo-changes)
|
||||||
features (features/get-team-enabled-features state)
|
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)
|
;; Prevent commit changes by a viewer team member (it really should never happen)
|
||||||
(if user-viewer?
|
(if user-viewer?
|
||||||
|
|
|
@ -174,6 +174,14 @@
|
||||||
(rx/tap on-success)
|
(rx/tap on-success)
|
||||||
(rx/catch on-error))))))
|
(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
|
(defn change-team-permissions
|
||||||
[{:keys [team-id role workspace?]}]
|
[{:keys [team-id role workspace?]}]
|
||||||
|
@ -182,19 +190,7 @@
|
||||||
(ptk/reify ::change-team-permissions
|
(ptk/reify ::change-team-permissions
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
(let [msg (case role
|
(rx/of (ntf/info (change-role-msg 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))))
|
|
||||||
|
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -203,37 +199,24 @@
|
||||||
[:teams team-id :permissions])]
|
[:teams team-id :permissions])]
|
||||||
(update-in state route
|
(update-in state route
|
||||||
(fn [permissions]
|
(fn [permissions]
|
||||||
(cond
|
(merge permissions (get tt/permissions-for-role role))))))))
|
||||||
(= 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)))))))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn removed-from-team
|
(defn team-membership-change
|
||||||
[{:keys [team-id team-name]}]
|
[{:keys [team-id team-name change]}]
|
||||||
(dm/assert! (uuid? team-id))
|
(dm/assert! (uuid? team-id))
|
||||||
(ptk/reify ::removed-from-team
|
(ptk/reify ::team-membership-change
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(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/concat
|
||||||
(rx/of (rt/nav :dashboard-projects {:team-id (get-in state [:profile :default-team-id])}))
|
(rx/of (rt/nav :dashboard-projects {:team-id (get-in state [:profile :default-team-id])}))
|
||||||
(->> (rx/of (ntf/info msg))
|
(->> (rx/of (ntf/info msg))
|
||||||
;; Delay so the navigation can finish
|
;; Delay so the navigation can finish
|
||||||
(rx/delay 250)))))))
|
(rx/delay 250))))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1223,7 +1223,7 @@
|
||||||
(defn- process-message
|
(defn- process-message
|
||||||
[{:keys [type] :as msg}]
|
[{:keys [type] :as msg}]
|
||||||
(case type
|
(case type
|
||||||
:notification (dc/handle-notification msg)
|
:notification (dc/handle-notification msg)
|
||||||
:team-permissions-change (handle-change-team-permissions-dashboard msg)
|
:team-role-change (handle-change-team-permissions-dashboard msg)
|
||||||
:removed-from-team (dc/removed-from-team msg)
|
:team-membership-change (dc/team-membership-change msg)
|
||||||
nil))
|
nil))
|
|
@ -121,16 +121,16 @@
|
||||||
(defn- process-message
|
(defn- process-message
|
||||||
[{:keys [type] :as msg}]
|
[{:keys [type] :as msg}]
|
||||||
(case type
|
(case type
|
||||||
:join-file (handle-presence msg)
|
:join-file (handle-presence msg)
|
||||||
:leave-file (handle-presence msg)
|
:leave-file (handle-presence msg)
|
||||||
:presence (handle-presence msg)
|
:presence (handle-presence msg)
|
||||||
:disconnect (handle-presence msg)
|
:disconnect (handle-presence msg)
|
||||||
:pointer-update (handle-pointer-update msg)
|
:pointer-update (handle-pointer-update msg)
|
||||||
:file-change (handle-file-change msg)
|
:file-change (handle-file-change msg)
|
||||||
:library-change (handle-library-change msg)
|
:library-change (handle-library-change msg)
|
||||||
:notification (dc/handle-notification msg)
|
:notification (dc/handle-notification msg)
|
||||||
:team-permissions-change (handle-change-team-permissions (assoc msg :workspace? true))
|
:team-role-change (handle-change-team-permissions (assoc msg :workspace? true))
|
||||||
:removed-from-team (dc/removed-from-team msg)
|
:team-membership-change (dc/team-membership-change msg)
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
(defn- handle-pointer-send
|
(defn- handle-pointer-send
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
(defn emit-when-no-readonly
|
(defn emit-when-no-readonly
|
||||||
[& events]
|
[& events]
|
||||||
(let [file (deref refs/workspace-file)
|
(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?)
|
read-only? (or (deref refs/workspace-read-only?)
|
||||||
user-viewer?)]
|
user-viewer?)]
|
||||||
(when-not read-only?
|
(when-not read-only?
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
(ns app.main.data.workspace.text.shortcuts
|
(ns app.main.data.workspace.text.shortcuts
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
[app.common.text :as txt]
|
[app.common.text :as txt]
|
||||||
[app.main.data.shortcuts :as ds]
|
[app.main.data.shortcuts :as ds]
|
||||||
[app.main.data.workspace.texts :as dwt]
|
[app.main.data.workspace.texts :as dwt]
|
||||||
|
@ -190,7 +191,7 @@
|
||||||
(defn- update-attrs-when-no-readonly [props]
|
(defn- update-attrs-when-no-readonly [props]
|
||||||
(let [undo-id (js/Symbol)
|
(let [undo-id (js/Symbol)
|
||||||
file (deref refs/workspace-file)
|
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?)
|
read-only? (or (deref refs/workspace-read-only?)
|
||||||
user-viewer?)
|
user-viewer?)
|
||||||
shapes-with-children (deref refs/selected-shapes-with-children)
|
shapes-with-children (deref refs/selected-shapes-with-children)
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
content-width (mf/use-state 0)
|
content-width (mf/use-state 0)
|
||||||
project-id (:id project)
|
project-id (:id project)
|
||||||
team-id (:id team)
|
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)
|
dashboard-local (mf/deref refs/dashboard-local)
|
||||||
file-menu-open? (:menu-open dashboard-local)
|
file-menu-open? (:menu-open dashboard-local)
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
(ns app.main.ui.dashboard.projects
|
(ns app.main.ui.dashboard.projects
|
||||||
(:require-macros [app.main.style :as stl])
|
(:require-macros [app.main.style :as stl])
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.main.data.dashboard :as dd]
|
[app.main.data.dashboard :as dd]
|
||||||
[app.main.data.events :as ev]
|
[app.main.data.events :as ev]
|
||||||
|
@ -312,9 +313,9 @@
|
||||||
(sort-by :modified-at)
|
(sort-by :modified-at)
|
||||||
(reverse))
|
(reverse))
|
||||||
recent-map (mf/deref recent-files-ref)
|
recent-map (mf/deref recent-files-ref)
|
||||||
you-owner? (get-in team [:permissions :is-owner])
|
you-owner? (dm/get-in team [:permissions :is-owner])
|
||||||
you-admin? (get-in team [:permissions :is-admin])
|
you-admin? (dm/get-in team [:permissions :is-admin])
|
||||||
you-viewer? (not (get-in team [:permissions :can-edit]))
|
you-viewer? (not (dm/get-in team [:permissions :can-edit]))
|
||||||
can-invite? (or you-owner? you-admin?)
|
can-invite? (or you-owner? you-admin?)
|
||||||
|
|
||||||
show-team-hero* (mf/use-state #(get storage/global ::show-team-hero true))
|
show-team-hero* (mf/use-state #(get storage/global ::show-team-hero true))
|
||||||
|
|
|
@ -172,7 +172,7 @@
|
||||||
team-id (:team-id project)
|
team-id (:team-id project)
|
||||||
file-name (:name file)
|
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?)
|
read-only? (or (mf/deref refs/workspace-read-only?)
|
||||||
user-viewer?)
|
user-viewer?)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue