Merge pull request #2793 from penpot/niwinz-access-tokens

🎉 ♻️ Refactor & Access Tokens (part 1)
This commit is contained in:
Alejandro 2023-01-20 09:36:47 +01:00 committed by GitHub
commit 42e97f8be1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
95 changed files with 2804 additions and 2496 deletions

View file

@ -27,7 +27,7 @@
(ptk/reify ::create-share-link
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/mutation! :create-share-link params)
(->> (rp/cmd! :create-share-link params)
(rx/map share-link-created)))))
(defn delete-share-link
@ -41,6 +41,6 @@
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/mutation! :delete-share-link {:id id})
(->> (rp/cmd! :delete-share-link {:id id})
(rx/ignore)))))

View file

@ -185,7 +185,7 @@
ptk/WatchEvent
(watch [_ state _]
(let [team-id (:current-team-id state)]
(->> (rp/query! :projects {:team-id team-id})
(->> (rp/cmd! :get-projects {:team-id team-id})
(rx/map projects-fetched))))))
;; --- EVENT: search
@ -671,7 +671,7 @@
{:keys [on-success on-error]
:or {on-success identity
on-error rx/throw}} (meta params)]
(->> (rp/mutation! :create-project params)
(->> (rp/cmd! :create-project params)
(rx/tap on-success)
(rx/map project-created)
(rx/catch on-error))))))
@ -733,7 +733,7 @@
(watch [_ state _]
(let [project (get-in state [:dashboard-projects id])
params (select-keys project [:id :is-pinned :team-id])]
(->> (rp/mutation :update-project-pin params)
(->> (rp/cmd! :update-project-pin params)
(rx/ignore))))))
;; --- EVENT: rename-project
@ -751,7 +751,7 @@
ptk/WatchEvent
(watch [_ _ _]
(let [params {:id id :name name}]
(->> (rp/mutation :rename-project params)
(->> (rp/cmd! :rename-project params)
(rx/ignore))))))
;; --- EVENT: delete-project
@ -766,7 +766,7 @@
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/mutation :delete-project {:id id})
(->> (rp/cmd! :delete-project {:id id})
(rx/ignore)))))
;; --- EVENT: delete-file
@ -1077,7 +1077,7 @@
action-name (if in-project? :create-file :create-project)
action (if in-project? file-created project-created)]
(->> (rp/mutation! action-name params)
(->> (rp/cmd! action-name params)
(rx/map action))))))
(defn open-selected-file

View file

@ -76,7 +76,7 @@
(ptk/reify ::load-team-fonts
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/query :font-variants {:team-id team-id})
(->> (rp/cmd! :get-font-variants {:team-id team-id})
(rx/map fonts-fetched)))))
(defn process-upload
@ -236,7 +236,7 @@
ptk/WatchEvent
(watch [_ state _]
(let [team-id (:current-team-id state)]
(->> (rp/mutation! :update-font {:id id :name name :team-id team-id})
(->> (rp/cmd! :update-font {:id id :name name :team-id team-id})
(rx/ignore))))))
(defn delete-font
@ -253,7 +253,7 @@
ptk/WatchEvent
(watch [_ state _]
(let [team-id (:current-team-id state)]
(->> (rp/mutation! :delete-font {:id font-id :team-id team-id})
(->> (rp/cmd! :delete-font {:id font-id :team-id team-id})
(rx/ignore))))))
(defn delete-font-variant
@ -270,7 +270,7 @@
ptk/WatchEvent
(watch [_ state _]
(let [team-id (:current-team-id state)]
(->> (rp/mutation! :delete-font-variant {:id id :team-id team-id})
(->> (rp/cmd! :delete-font-variant {:id id :team-id team-id})
(rx/ignore))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View file

@ -124,7 +124,7 @@
(ptk/reify ::fetch-profile
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/query! :profile)
(->> (rp/cmd! :get-profile)
(rx/map profile-fetched)))))
;; --- EVENT: INITIALIZE PROFILE
@ -207,7 +207,7 @@
;; the returned profile is an NOT authenticated profile, we
;; proceed to logout and show an error message.
(->> (rp/command! :login-with-password (d/without-nils params))
(->> (rp/cmd! :login-with-password (d/without-nils params))
(rx/merge-map (fn [data]
(rx/merge
(rx/of (fetch-profile))
@ -293,7 +293,7 @@
(ptk/reify ::logout
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/command! :logout)
(->> (rp/cmd! :logout)
(rx/delay-at-least 300)
(rx/catch (constantly (rx/of 1)))
(rx/map #(logged-out params)))))))
@ -309,7 +309,7 @@
(let [mdata (meta data)
on-success (:on-success mdata identity)
on-error (:on-error mdata rx/throw)]
(->> (rp/mutation :update-profile (dissoc data :props))
(->> (rp/cmd! :update-profile (dissoc data :props))
(rx/catch on-error)
(rx/mapcat
(fn [_]
@ -333,7 +333,7 @@
(let [{:keys [on-error on-success]
:or {on-error identity
on-success identity}} (meta data)]
(->> (rp/mutation :request-email-change data)
(->> (rp/cmd! :request-email-change data)
(rx/tap on-success)
(rx/catch on-error))))))
@ -343,7 +343,7 @@
(ptk/reify ::cancel-email-change
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/mutation :cancel-email-change {})
(->> (rp/cmd! :cancel-email-change {})
(rx/map (constantly (fetch-profile)))))))
;; --- Update Password (Form)
@ -364,7 +364,7 @@
on-success identity}} (meta data)
params {:old-password (:password-old data)
:password (:password-1 data)}]
(->> (rp/mutation :update-profile-password params)
(->> (rp/cmd! :update-profile-password params)
(rx/tap on-success)
(rx/catch (fn [err]
(on-error err)
@ -382,7 +382,7 @@
;; the response value of update-profile-props RPC call
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/mutation :update-profile-props {:props props})
(->> (rp/cmd! :update-profile-props {:props props})
(rx/map (constantly (fetch-profile)))))))
(defn mark-onboarding-as-viewed
@ -394,7 +394,7 @@
(let [version (or version (:main @cf/version))
props {:onboarding-viewed true
:release-notes-viewed version}]
(->> (rp/mutation :update-profile-props {:props props})
(->> (rp/cmd! :update-profile-props {:props props})
(rx/map (constantly (fetch-profile)))))))))
(defn mark-questions-as-answered
@ -407,7 +407,7 @@
ptk/WatchEvent
(watch [_ _ _]
(let [props {:onboarding-questions-answered true}]
(->> (rp/mutation :update-profile-props {:props props})
(->> (rp/cmd! :update-profile-props {:props props})
(rx/map (constantly (fetch-profile))))))))
@ -431,7 +431,7 @@
(->> (rx/of file)
(rx/map di/validate-file)
(rx/map prepare)
(rx/mapcat #(rp/mutation :update-profile-photo %))
(rx/mapcat #(rp/cmd! :update-profile-photo %))
(rx/do on-success)
(rx/map (constantly (fetch-profile)))
(rx/catch on-error))))))
@ -460,7 +460,7 @@
ptk/WatchEvent
(watch [_ state _]
(let [share-id (-> state :viewer-local :share-id)]
(->> (rp/command! :get-profiles-for-file-comments {:team-id team-id :share-id share-id})
(->> (rp/cmd! :get-profiles-for-file-comments {:team-id team-id :share-id share-id})
(rx/map #(partial fetched %))))))))
;; --- EVENT: request-account-deletion
@ -473,7 +473,7 @@
(let [{:keys [on-error on-success]
:or {on-error rx/throw
on-success identity}} (meta params)]
(->> (rp/mutation :delete-profile {})
(->> (rp/cmd! :delete-profile {})
(rx/tap on-success)
(rx/delay-at-least 300)
(rx/catch (constantly (rx/of 1)))
@ -495,7 +495,7 @@
:or {on-error rx/throw
on-success identity}} (meta data)]
(->> (rp/command! :request-profile-recovery data)
(->> (rp/cmd! :request-profile-recovery data)
(rx/tap on-success)
(rx/catch on-error))))))
@ -514,7 +514,7 @@
(let [{:keys [on-error on-success]
:or {on-error rx/throw
on-success identity}} (meta data)]
(->> (rp/command! :recover-profile data)
(->> (rp/cmd! :recover-profile data)
(rx/tap on-success)
(rx/catch on-error))))))
@ -525,7 +525,7 @@
(ptk/reify ::create-demo-profile
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/command! :create-demo-profile {})
(->> (rp/cmd! :create-demo-profile {})
(rx/map login)))))

View file

@ -129,22 +129,22 @@
(rx/map :content)
(rx/map #(vector key %)))))]
(->> (rp/query! :view-only-bundle params')
(rx/mapcat
(fn [bundle]
(->> (rx/from (-> bundle :file :data :pages-index seq))
(rx/merge-map
(fn [[_ page :as kp]]
(if (t/pointer? page)
(resolve kp)
(rx/of kp))))
(rx/reduce conj {})
(rx/map (fn [pages-index]
(update-in bundle [:file :data] assoc :pages-index pages-index))))))
(rx/mapcat
(fn [{:keys [fonts] :as bundle}]
(rx/of (df/fonts-fetched fonts)
(bundle-fetched (merge bundle params))))))))))
(->> (rp/cmd! :get-view-only-bundle params')
(rx/mapcat
(fn [bundle]
(->> (rx/from (-> bundle :file :data :pages-index seq))
(rx/merge-map
(fn [[_ page :as kp]]
(if (t/pointer? page)
(resolve kp)
(rx/of kp))))
(rx/reduce conj {})
(rx/map (fn [pages-index]
(update-in bundle [:file :data] assoc :pages-index pages-index))))))
(rx/mapcat
(fn [{:keys [fonts] :as bundle}]
(rx/of (df/fonts-fetched fonts)
(bundle-fetched (merge bundle params))))))))))
(declare go-to-frame-auto)

View file

@ -267,7 +267,7 @@
(->> (rx/zip (rp/cmd! :get-file {:id file-id :features features})
(rp/cmd! :get-file-object-thumbnails {:file-id file-id})
(rp/query! :project {:id project-id})
(rp/cmd! :get-project {:id project-id})
(rp/cmd! :get-team-users {:file-id file-id})
(rp/cmd! :get-profiles-for-file-comments {:file-id file-id :share-id share-id}))
(rx/take 1)
@ -1427,7 +1427,7 @@
:file-id file-id
:content blob
:is-local true}))
(rx/mapcat #(rp/mutation! :upload-file-media-object %))
(rx/mapcat #(rp/cmd! :upload-file-media-object %))
(rx/map (fn [media]
(assoc media :prev-id (:id imgpart))))))
@ -1564,7 +1564,7 @@
(into (d/ordered-set)))
undo-id (js/Symbol)]
(rx/of (dwu/start-undo-transaction undo-id)
(rx/of (dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(dws/select-shapes selected)
(ptk/data-event :layout/update [frame-id])

View file

@ -125,7 +125,7 @@
(rx/map dmm/validate-file)
(rx/filter (comp not svg-blob?))
(rx/map prepare-blob)
(rx/mapcat #(rp/mutation! :upload-file-media-object %))
(rx/mapcat #(rp/cmd! :upload-file-media-object %))
(rx/do on-image))
(->> (rx/from blobs)
@ -361,7 +361,7 @@
:type :info
:timeout nil
:tag :media-loading}))
(->> (rp/mutation! :clone-file-media-object params)
(->> (rp/cmd! :clone-file-media-object params)
(rx/do on-success)
(rx/catch on-error)
(rx/finalize #(st/emit! (dm/hide-tag :media-loading)))))))))

View file

@ -214,7 +214,7 @@
:features features}]
(when (:id params)
(->> (rp/mutation :update-file params)
(->> (rp/cmd! :update-file params)
(rx/ignore)))))))
(defn update-persistence-status

View file

@ -12,17 +12,23 @@
[app.util.http :as http]
[beicon.core :as rx]))
(derive :get-all-projects ::query)
(derive :get-comment-threads ::query)
(derive :get-file ::query)
(derive :get-file-object-thumbnails ::query)
(derive :get-file-libraries ::query)
(derive :get-file-fragment ::query)
(derive :search-files ::query)
(derive :get-teams ::query)
(derive :get-team-users ::query)
(derive :get-team-members ::query)
(derive :get-team-stats ::query)
(derive :get-file-libraries ::query)
(derive :get-file-object-thumbnails ::query)
(derive :get-font-variants ::query)
(derive :get-profile ::query)
(derive :get-project ::query)
(derive :get-team-invitations ::query)
(derive :get-team-members ::query)
(derive :get-team-shared-files ::query)
(derive :get-team-stats ::query)
(derive :get-team-users ::query)
(derive :get-teams ::query)
(derive :get-view-only-bundle ::query)
(derive :search-files ::query)
(defn handle-response
[{:keys [status body] :as response}]
@ -164,15 +170,6 @@
(rx/map http/conditional-decode-transit)
(rx/mapcat handle-response))))
(defmethod command :send-feedback
[_ params]
(->> (http/send! {:method :post
:uri (u/join @cf/public-uri "api/feedback")
:credentials "include"
:body (http/transit-data params)})
(rx/map http/conditional-decode-transit)
(rx/mapcat handle-response)))
(defn- send-export
[{:keys [blob?] :as params}]
(->> (http/send! {:method :post
@ -200,3 +197,12 @@
:body (http/form-data params)})
(rx/map http/conditional-decode-transit)
(rx/mapcat handle-response)))
(defmethod command ::multipart-upload
[id params]
(->> (http/send! {:method :post
:uri (u/join @cf/public-uri "api/rpc/command/" (name id))
:credentials "include"
:body (http/form-data params)})
(rx/map http/conditional-decode-transit)
(rx/mapcat handle-response)))

View file

@ -207,7 +207,7 @@
(mf/deps show?)
(fn []
(when show?
(->> (rp/query! :all-projects)
(->> (rp/cmd! :get-all-projects)
(rx/map group-by-team)
(rx/subs #(when (mf/ref-val mounted-ref)
(reset! teams %)))))))

View file

@ -94,7 +94,7 @@
(mf/deps team)
(fn [item]
(swap! uploading conj (:id item))
(->> (rp/mutation! :create-font-variant item)
(->> (rp/cmd! :create-font-variant item)
(rx/delay-at-least 2000)
(rx/subs (fn [font]
(swap! fonts dissoc (:id item))

View file

@ -99,7 +99,7 @@
;; We just recheck with an additional profile request; this avoids
;; some race conditions that causes unexpected redirects on
;; invitations workflows (and probably other cases).
(->> (rp/query! :profile)
(->> (rp/command! :get-profile)
(rx/subs (fn [{:keys [id] :as profile}]
(if (= id uuid/zero)
(st/emit! (rt/nav :auth-login))

View file

@ -55,7 +55,7 @@
(fn [form _]
(reset! loading true)
(let [data (:clean-data @form)]
(->> (rp/command! :send-feedback data)
(->> (rp/command! :send-user-feedback data)
(rx/subs on-succes on-error)))))]
[:& fm/form {:class "feedback-form"

View file

@ -196,7 +196,7 @@
:content blob
:is-local true}))
(rx/tap #(progress! context :upload-media name))
(rx/flat-map #(rp/mutation! :upload-file-media-object %))))
(rx/flat-map #(rp/cmd! :upload-file-media-object %))))
(defn resolve-text-content [node context]
(let [resolve (:resolve context)]
@ -511,7 +511,7 @@
:content content
:is-local false})))
(rx/tap #(progress! context :upload-media (:name %)))
(rx/merge-map #(rp/mutation! :upload-file-media-object %))
(rx/merge-map #(rp/cmd! :upload-file-media-object %))
(rx/map (constantly media))
(rx/catch #(do (.error js/console (str "Error uploading media: " (:name media)) )
(rx/empty)))))))