From ce2846425171127b1bb888701d85b48e2d1018bb Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 7 Apr 2020 16:40:22 +0200 Subject: [PATCH] :sparkles: Enable anonymous users and viewer with token. --- frontend/src/uxbox/main/data/viewer.cljs | 15 ++++++----- frontend/src/uxbox/main/refs.cljs | 2 +- frontend/src/uxbox/main/ui.cljs | 14 +++++----- frontend/src/uxbox/main/ui/viewer.cljs | 7 +++-- frontend/src/uxbox/main/ui/viewer/header.cljs | 26 +++++++++++++------ 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/frontend/src/uxbox/main/data/viewer.cljs b/frontend/src/uxbox/main/data/viewer.cljs index 26fe30479..d3ad06487 100644 --- a/frontend/src/uxbox/main/data/viewer.cljs +++ b/frontend/src/uxbox/main/data/viewer.cljs @@ -41,7 +41,7 @@ (declare bundle-fetched) (defn initialize - [page-id] + [page-id share-token] (ptk/reify ::initialize ptk/UpdateEvent (update [_ state] @@ -49,18 +49,21 @@ ptk/WatchEvent (watch [_ state stream] - (rx/of (fetch-bundle page-id))))) + (rx/of (fetch-bundle page-id share-token))))) ;; --- Data Fetching (defn fetch-bundle - [page-id] + [page-id share-token] (ptk/reify ::fetch-file ptk/WatchEvent (watch [_ state stream] - (->> (rp/query :viewer-bundle {:page-id page-id}) - (rx/map bundle-fetched))))) - + (let [params (cond-> {:page-id page-id} + (string? share-token) (assoc :share-token share-token))] + (->> (rp/query :viewer-bundle params) + (rx/map bundle-fetched) + (rx/catch (fn [error-data] + (rx/of (rt/nav :not-found))))))))) (defn- extract-frames [page] diff --git a/frontend/src/uxbox/main/refs.cljs b/frontend/src/uxbox/main/refs.cljs index 19da8d924..2a8fab50c 100644 --- a/frontend/src/uxbox/main/refs.cljs +++ b/frontend/src/uxbox/main/refs.cljs @@ -5,7 +5,7 @@ ;; This Source Code Form is "Incompatible With Secondary Licenses", as ;; defined by the Mozilla Public License, v. 2.0. ;; -;; Copyright (c) 2017-2019 Andrey Antukh +;; Copyright (c) 2020 UXBOX Labs SL (ns uxbox.main.refs "A collection of derived refs." diff --git a/frontend/src/uxbox/main/ui.cljs b/frontend/src/uxbox/main/ui.cljs index 8eb0cb911..7a0cf1602 100644 --- a/frontend/src/uxbox/main/ui.cljs +++ b/frontend/src/uxbox/main/ui.cljs @@ -101,12 +101,6 @@ :profile-recovery [:& profile-recovery-page] - :viewer - (let [index (d/parse-integer (get-in route [:params :query :index])) - page-id (uuid (get-in route [:params :path :page-id]))] - [:& viewer-page {:page-id page-id - :index index}]) - (:settings-profile :settings-password) [:& settings/settings {:route route}] @@ -126,6 +120,14 @@ :dashboard-library-palettes-index) [:& dashboard {:route route}] + :viewer + (let [index (d/parse-integer (get-in route [:params :query :index])) + token (get-in route [:params :query :token]) + page-id (uuid (get-in route [:params :path :page-id]))] + [:& viewer-page {:page-id page-id + :index index + :token token}]) + :workspace (let [project-id (uuid (get-in route [:params :path :project-id])) file-id (uuid (get-in route [:params :path :file-id])) diff --git a/frontend/src/uxbox/main/ui/viewer.cljs b/frontend/src/uxbox/main/ui/viewer.cljs index 87ac9f540..f9a71c21b 100644 --- a/frontend/src/uxbox/main/ui/viewer.cljs +++ b/frontend/src/uxbox/main/ui/viewer.cljs @@ -96,8 +96,11 @@ (l/derive st/state))) (mf/defc viewer-page - [{:keys [page-id index] :as props}] - (mf/use-effect (mf/deps page-id) #(st/emit! (dv/initialize page-id))) + [{:keys [page-id index token] :as props}] + (mf/use-effect + (mf/deps page-id token) + #(st/emit! (dv/initialize page-id token))) + (let [data (mf/deref viewer-data-ref) local (mf/deref viewer-local-ref)] (when data diff --git a/frontend/src/uxbox/main/ui/viewer/header.cljs b/frontend/src/uxbox/main/ui/viewer/header.cljs index 4964ed707..25e4e26b6 100644 --- a/frontend/src/uxbox/main/ui/viewer/header.cljs +++ b/frontend/src/uxbox/main/ui/viewer/header.cljs @@ -18,8 +18,10 @@ [uxbox.main.store :as st] [uxbox.main.ui.components.dropdown :refer [dropdown]] [uxbox.main.data.viewer :as dv] + [uxbox.main.refs :as refs] [uxbox.util.data :refer [classnames]] [uxbox.util.dom :as dom] + [uxbox.util.uuid :as uuid] [uxbox.util.i18n :as i18n :refer [t tr]] [uxbox.util.math :as mth] [uxbox.util.router :as rt]) @@ -64,7 +66,6 @@ create #(st/emit! dv/create-share-link) delete #(st/emit! dv/delete-share-link) href (.-href js/location)] - [:* [:span.btn-share.tooltip.tooltip-bottom {:alt "Share link" @@ -78,7 +79,7 @@ [:span.share-link-title "Share link"] [:div.share-link-input (if (string? token) - [:span.link (str href "&" token)] + [:span.link (str href "&token=" token)] [:span "Share link will apear here"]) i/chain] [:span.share-link-subtitle "Anyone with the link will have access"] @@ -87,16 +88,23 @@ [:button.btn-delete {:on-click delete} "Remove link"] [:button.btn-primary {:on-click create} "Create link"])]]]])) - (mf/defc header [{:keys [data index local fullscreen? toggle-fullscreen] :as props}] (let [{:keys [project file page frames]} data total (count frames) on-click #(st/emit! dv/toggle-thumbnails-panel) + + profile (mf/deref refs/profile) + anonymous? (= uuid/zero (:id profile)) + + project-id (get-in data [:project :id]) + file-id (get-in data [:file :id]) + page-id (get-in data [:page :id]) + on-edit #(st/emit! (rt/nav :workspace - {:project-id (get-in data [:project :id]) - :file-id (get-in data [:file :id])} - {:page-id (get-in data [:page :id])}))] + {:project-id project-id + :file-id file-id} + {:page-id page-id}))] [:header.viewer-header [:div.main-icon [:a i/logo-icon]] @@ -112,8 +120,10 @@ [:span.counters (str (inc index) " / " total)]] [:div.options-zone - [:& share-link {:page (:page data)}] - [:span.btn-primary {:on-click on-edit} "Edit page"] + (when-not anonymous? + [:& share-link {:page (:page data)}]) + (when-not anonymous? + [:span.btn-primary {:on-click on-edit} "Edit page"]) [:& zoom-widget {:zoom (:zoom local)}] [:span.btn-fullscreen.tooltip.tooltip-bottom {:alt "Full screen"