mirror of
https://github.com/penpot/penpot.git
synced 2025-07-21 02:28:09 +02:00
🐛 Properly handle share-tokens on viewer.
This commit is contained in:
parent
51f9dfbc4f
commit
388d255243
5 changed files with 38 additions and 32 deletions
|
@ -120,7 +120,8 @@
|
|||
(reset! storage {})
|
||||
(i18n/set-default-locale!))))
|
||||
|
||||
(def logout
|
||||
(defn logout
|
||||
[]
|
||||
(ptk/reify ::logout
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
|
|
|
@ -71,13 +71,10 @@
|
|||
(watch [_ state stream]
|
||||
(let [params (cond-> {:page-id page-id
|
||||
:file-id file-id}
|
||||
(string? token) (assoc :share-token token))]
|
||||
(->> (rx/zip (rp/query :viewer-bundle params)
|
||||
(rp/query :file-libraries {:file-id file-id}))
|
||||
(string? token) (assoc :token token))]
|
||||
(->> (rp/query :viewer-bundle params)
|
||||
(rx/first)
|
||||
(rx/map #(apply bundle-fetched %))
|
||||
#_(rx/catch (fn [error-data]
|
||||
(rx/of (rt/nav :not-found)))))))))
|
||||
(rx/map bundle-fetched))))))
|
||||
|
||||
(defn- extract-frames
|
||||
[objects]
|
||||
|
@ -89,7 +86,7 @@
|
|||
(vec))))
|
||||
|
||||
(defn bundle-fetched
|
||||
[{:keys [project file page share-token] :as bundle} libraries]
|
||||
[{:keys [project file page share-token token libraries] :as bundle}]
|
||||
(us/verify ::bundle bundle)
|
||||
(ptk/reify ::file-fetched
|
||||
ptk/UpdateEvent
|
||||
|
@ -103,6 +100,7 @@
|
|||
:file file
|
||||
:page page
|
||||
:frames frames
|
||||
:token token
|
||||
:share-token share-token}))))))
|
||||
|
||||
(def create-share-link
|
||||
|
@ -244,12 +242,12 @@
|
|||
(let [page-id (get-in state [:viewer-local :page-id])
|
||||
file-id (get-in state [:viewer-local :file-id])
|
||||
frames (get-in state [:viewer-data :frames])
|
||||
share-token (get-in state [:viewer-data :share-token])
|
||||
token (get-in state [:viewer-data :token])
|
||||
index (d/index-of-pred frames #(= (:id %) frame-id))]
|
||||
(rx/of (rt/nav :viewer
|
||||
{:page-id page-id
|
||||
:file-id file-id}
|
||||
{:token share-token
|
||||
{:token token
|
||||
:index index}))))))
|
||||
|
||||
(defn set-current-frame [frame-id]
|
||||
|
|
|
@ -178,7 +178,7 @@
|
|||
(defmethod ptk/handle-error :validation
|
||||
[error]
|
||||
(ts/schedule
|
||||
(st/emitf (dm/show {:content "Unexpected validation error."
|
||||
(st/emitf (dm/show {:content "Unexpected validation error (server side)."
|
||||
:type :error
|
||||
:timeout 5000})))
|
||||
(when-let [explain (:explain error)]
|
||||
|
@ -190,11 +190,13 @@
|
|||
|
||||
(defmethod ptk/handle-error :authentication
|
||||
[error]
|
||||
(ts/schedule 0 #(st/emit! logout)))
|
||||
(ts/schedule 0 #(st/emit! (logout))))
|
||||
|
||||
(defmethod ptk/handle-error :authorization
|
||||
[error]
|
||||
(ts/schedule 0 #(st/emit! logout)))
|
||||
(ts/schedule
|
||||
(st/emitf (dm/show {:content "Not authorized to see this content."
|
||||
:type :error}))))
|
||||
|
||||
(defmethod ptk/handle-error :assertion
|
||||
[{:keys [data stack message context] :as error}]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue