mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 16:30:37 -05:00
🐛 Disables buttons in view mode for users without permissions
This commit is contained in:
parent
5b25a42f32
commit
47e0c2c75b
4 changed files with 37 additions and 6 deletions
|
@ -18,6 +18,7 @@
|
||||||
- Fix broken profile and profile options form.
|
- Fix broken profile and profile options form.
|
||||||
- Fix problem with mask and flip [#715](https://github.com/penpot/penpot/issues/715)
|
- Fix problem with mask and flip [#715](https://github.com/penpot/penpot/issues/715)
|
||||||
- Fix problem with rotated blur [Taiga #1370](https://tree.taiga.io/project/penpot/issue/1370)
|
- Fix problem with rotated blur [Taiga #1370](https://tree.taiga.io/project/penpot/issue/1370)
|
||||||
|
- Disables buttons in view mode for users without permissions [Taiga #1328](https://tree.taiga.io/project/penpot/issue/1328)
|
||||||
|
|
||||||
### :heart: Community contributions by (Thank you!)
|
### :heart: Community contributions by (Thank you!)
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,8 @@
|
||||||
(st/emit! (rt/initialize-router ui/routes)
|
(st/emit! (rt/initialize-router ui/routes)
|
||||||
(rt/initialize-history on-navigate))
|
(rt/initialize-history on-navigate))
|
||||||
|
|
||||||
(st/emit! (udu/fetch-profile))
|
(st/emit! (udu/fetch-profile)
|
||||||
|
(udu/fetch-user-teams))
|
||||||
(mf/mount (mf/element ui/app) (dom/get-element "app"))
|
(mf/mount (mf/element ui/app) (dom/get-element "app"))
|
||||||
(mf/mount (mf/element modal) (dom/get-element "modal")))
|
(mf/mount (mf/element modal) (dom/get-element "modal")))
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,10 @@
|
||||||
(ptk/reify ::profile-fetched
|
(ptk/reify ::profile-fetched
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(assoc state :profile data))
|
(-> state
|
||||||
|
(assoc :profile data)
|
||||||
|
;; Safeguard if the profile is loaded after teams
|
||||||
|
(assoc-in [:profile :teams] (get-in state [:profile :teams]))))
|
||||||
|
|
||||||
ptk/EffectEvent
|
ptk/EffectEvent
|
||||||
(effect [_ state stream]
|
(effect [_ state stream]
|
||||||
|
@ -203,4 +206,23 @@
|
||||||
(->> (rp/query :team-users {:team-id team-id})
|
(->> (rp/query :team-users {:team-id team-id})
|
||||||
(rx/map #(partial fetched %)))))))
|
(rx/map #(partial fetched %)))))))
|
||||||
|
|
||||||
|
(defn user-teams-fetched [data]
|
||||||
|
(ptk/reify ::user-teams-fetched
|
||||||
|
ptk/UpdateEvent
|
||||||
|
(update [_ state]
|
||||||
|
(let [teams (->> data
|
||||||
|
(group-by :id)
|
||||||
|
(d/mapm #(first %2)))]
|
||||||
|
(assoc-in state [:profile :teams] teams)))))
|
||||||
|
|
||||||
|
(defn fetch-user-teams []
|
||||||
|
(ptk/reify ::fetch-user-teams
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state s]
|
||||||
|
(->> (rp/query! :teams)
|
||||||
|
(rx/map user-teams-fetched)
|
||||||
|
(rx/catch (fn [error]
|
||||||
|
(if (= (:type error) :not-found)
|
||||||
|
(rx/of (rt/nav :auth-login))
|
||||||
|
(rx/empty))))))))
|
||||||
|
|
||||||
|
|
|
@ -191,6 +191,11 @@
|
||||||
profile (mf/deref refs/profile)
|
profile (mf/deref refs/profile)
|
||||||
anonymous? (= uuid/zero (:id profile))
|
anonymous? (= uuid/zero (:id profile))
|
||||||
|
|
||||||
|
team-id (get-in data [:project :team-id])
|
||||||
|
|
||||||
|
has-permission? (and (not anonymous?)
|
||||||
|
(contains? (:teams profile) team-id))
|
||||||
|
|
||||||
project-id (get-in data [:project :id])
|
project-id (get-in data [:project :id])
|
||||||
file-id (get-in data [:file :id])
|
file-id (get-in data [:file :id])
|
||||||
page-id (get-in data [:page :id])
|
page-id (get-in data [:page :id])
|
||||||
|
@ -219,7 +224,9 @@
|
||||||
|
|
||||||
[:header.viewer-header
|
[:header.viewer-header
|
||||||
[:div.main-icon
|
[:div.main-icon
|
||||||
[:a {:on-click on-goback} i/logo-icon]]
|
[:a {:on-click on-goback
|
||||||
|
;; If the user doesn't have permission we disable the link
|
||||||
|
:style {:pointer-events (when-not has-permission? "none")}} i/logo-icon]]
|
||||||
|
|
||||||
[:div.sitemap-zone {:alt (t locale "viewer.header.sitemap")
|
[:div.sitemap-zone {:alt (t locale "viewer.header.sitemap")
|
||||||
:on-click on-click}
|
:on-click on-click}
|
||||||
|
@ -238,7 +245,7 @@
|
||||||
:alt "View mode"}
|
:alt "View mode"}
|
||||||
i/play]
|
i/play]
|
||||||
|
|
||||||
(when-not anonymous?
|
(when has-permission?
|
||||||
[:button.mode-zone-button.tooltip.tooltip-bottom
|
[:button.mode-zone-button.tooltip.tooltip-bottom
|
||||||
{:on-click #(navigate :comments)
|
{:on-click #(navigate :comments)
|
||||||
:class (dom/classnames :active (= section :comments))
|
:class (dom/classnames :active (= section :comments))
|
||||||
|
@ -257,11 +264,11 @@
|
||||||
:comments [:& comments-menu {:locale locale}]
|
:comments [:& comments-menu {:locale locale}]
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
(when-not anonymous?
|
(when has-permission?
|
||||||
[:& share-link {:token (:token data)
|
[:& share-link {:token (:token data)
|
||||||
:page (:page data)}])
|
:page (:page data)}])
|
||||||
|
|
||||||
(when-not anonymous?
|
(when has-permission?
|
||||||
[:a.btn-text-basic.btn-small {:on-click on-edit}
|
[:a.btn-text-basic.btn-small {:on-click on-edit}
|
||||||
(t locale "viewer.header.edit-page")])
|
(t locale "viewer.header.edit-page")])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue