mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 15:39:50 -05:00
🐛 Fix incorrect features setup on persist-temp-file rpc method
This commit is contained in:
parent
194d3251a4
commit
77564531eb
1 changed files with 58 additions and 43 deletions
|
@ -8,11 +8,13 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
[app.common.features :as cfeat]
|
[app.common.features :as cfeat]
|
||||||
[app.common.files.changes :as fch]
|
[app.common.files.changes :as cpc]
|
||||||
[app.common.spec :as us]
|
[app.common.schema :as sm]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
|
[app.db.sql :as sql]
|
||||||
|
[app.features.fdata :as fdata]
|
||||||
[app.rpc :as-alias rpc]
|
[app.rpc :as-alias rpc]
|
||||||
[app.rpc.commands.files :as files]
|
[app.rpc.commands.files :as files]
|
||||||
[app.rpc.commands.files-create :as files.create]
|
[app.rpc.commands.files-create :as files.create]
|
||||||
|
@ -21,28 +23,26 @@
|
||||||
[app.rpc.commands.teams :as teams]
|
[app.rpc.commands.teams :as teams]
|
||||||
[app.rpc.doc :as-alias doc]
|
[app.rpc.doc :as-alias doc]
|
||||||
[app.util.blob :as blob]
|
[app.util.blob :as blob]
|
||||||
|
[app.util.pointer-map :as pmap]
|
||||||
[app.util.services :as sv]
|
[app.util.services :as sv]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[clojure.set :as set]
|
[clojure.set :as set]))
|
||||||
[clojure.spec.alpha :as s]))
|
|
||||||
|
|
||||||
|
|
||||||
;; --- MUTATION COMMAND: create-temp-file
|
;; --- MUTATION COMMAND: create-temp-file
|
||||||
|
|
||||||
(s/def ::create-page ::us/boolean)
|
(def ^:private schema:create-temp-file
|
||||||
|
[:map {:title "create-temp-file"}
|
||||||
(s/def ::create-temp-file
|
[:name :string]
|
||||||
(s/keys :req [::rpc/profile-id]
|
[:project-id ::sm/uuid]
|
||||||
:req-un [::files/name
|
[:id {:optional true} ::sm/uuid]
|
||||||
::files/project-id]
|
[:is-shared :boolean]
|
||||||
:opt-un [::files/id
|
[:features ::cfeat/features]
|
||||||
::files/is-shared
|
[:create-page :boolean]])
|
||||||
::files/features
|
|
||||||
::create-page]))
|
|
||||||
|
|
||||||
(sv/defmethod ::create-temp-file
|
(sv/defmethod ::create-temp-file
|
||||||
{::doc/added "1.17"
|
{::doc/added "1.17"
|
||||||
::doc/module :files}
|
::doc/module :files
|
||||||
|
::sm/params schema:create-temp-file}
|
||||||
[cfg {:keys [::rpc/profile-id project-id] :as params}]
|
[cfg {:keys [::rpc/profile-id project-id] :as params}]
|
||||||
(db/tx-run! cfg (fn [{:keys [::db/conn] :as cfg}]
|
(db/tx-run! cfg (fn [{:keys [::db/conn] :as cfg}]
|
||||||
(projects/check-edition-permissions! conn profile-id project-id)
|
(projects/check-edition-permissions! conn profile-id project-id)
|
||||||
|
@ -72,16 +72,18 @@
|
||||||
|
|
||||||
;; --- MUTATION COMMAND: update-temp-file
|
;; --- MUTATION COMMAND: update-temp-file
|
||||||
|
|
||||||
(s/def ::update-temp-file
|
|
||||||
(s/keys :req [::rpc/profile-id]
|
(def ^:private schema:update-temp-file
|
||||||
:req-un [::files.update/changes
|
[:map {:title "update-temp-file"}
|
||||||
::files.update/revn
|
[:changes [:vector ::cpc/change]]
|
||||||
::files.update/session-id
|
[:revn {:min 0} :int]
|
||||||
::files/id]))
|
[:session-id ::sm/uuid]
|
||||||
|
[:id ::sm/uuid]])
|
||||||
|
|
||||||
(sv/defmethod ::update-temp-file
|
(sv/defmethod ::update-temp-file
|
||||||
{::doc/added "1.17"
|
{::doc/added "1.17"
|
||||||
::doc/module :files}
|
::doc/module :files
|
||||||
|
::sm/params schema:update-temp-file}
|
||||||
[cfg {:keys [::rpc/profile-id session-id id revn changes] :as params}]
|
[cfg {:keys [::rpc/profile-id session-id id revn changes] :as params}]
|
||||||
(db/tx-run! cfg (fn [{:keys [::db/conn]}]
|
(db/tx-run! cfg (fn [{:keys [::db/conn]}]
|
||||||
(db/insert! conn :file-change
|
(db/insert! conn :file-change
|
||||||
|
@ -98,37 +100,50 @@
|
||||||
;; --- MUTATION COMMAND: persist-temp-file
|
;; --- MUTATION COMMAND: persist-temp-file
|
||||||
|
|
||||||
(defn persist-temp-file
|
(defn persist-temp-file
|
||||||
[conn {:keys [id] :as params}]
|
[{:keys [::db/conn] :as cfg} {:keys [id] :as params}]
|
||||||
(let [file (db/get-by-id conn :file id)
|
(let [file (files/get-file cfg id
|
||||||
revs (db/query conn :file-change
|
:migrate? false
|
||||||
{:file-id id}
|
:lock-for-update? true)]
|
||||||
{:order-by [[:revn :asc]]})
|
|
||||||
revn (count revs)]
|
|
||||||
|
|
||||||
(when (nil? (:deleted-at file))
|
(when (nil? (:deleted-at file))
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
:code :cant-persist-already-persisted-file))
|
:code :cant-persist-already-persisted-file))
|
||||||
|
|
||||||
|
(let [changes (->> (db/cursor conn
|
||||||
|
(sql/select :file-change {:file-id id}
|
||||||
|
{:order-by [[:revn :asc]]})
|
||||||
|
{:chunk-size 10})
|
||||||
|
(sequence (mapcat (comp blob/decode :changes))))
|
||||||
|
|
||||||
|
file (update file :data cpc/process-changes changes)
|
||||||
|
|
||||||
|
file (if (contains? (:features file) "fdata/objects-map")
|
||||||
|
(fdata/enable-objects-map file)
|
||||||
|
file)
|
||||||
|
|
||||||
|
file (if (contains? (:features file) "fdata/pointer-map")
|
||||||
|
(binding [pmap/*tracked* (pmap/create-tracked)]
|
||||||
|
(let [file (fdata/enable-pointer-map file)]
|
||||||
|
(fdata/persist-pointers! cfg id)
|
||||||
|
file))
|
||||||
|
file)]
|
||||||
|
|
||||||
(let [data
|
|
||||||
(->> revs
|
|
||||||
(mapcat #(->> % :changes blob/decode))
|
|
||||||
(fch/process-changes (blob/decode (:data file))))]
|
|
||||||
(db/update! conn :file
|
(db/update! conn :file
|
||||||
{:deleted-at nil
|
{:deleted-at nil
|
||||||
:revn revn
|
:revn 1
|
||||||
:data (blob/encode data)}
|
:data (blob/encode (:data file))}
|
||||||
{:id id}))
|
{:id id})
|
||||||
nil))
|
nil)))
|
||||||
|
|
||||||
(s/def ::persist-temp-file
|
(def ^:private schema:persist-temp-file
|
||||||
(s/keys :req [::rpc/profile-id]
|
[:map {:title "persist-temp-file"}
|
||||||
:req-un [::files/id]))
|
[:id ::sm/uuid]])
|
||||||
|
|
||||||
(sv/defmethod ::persist-temp-file
|
(sv/defmethod ::persist-temp-file
|
||||||
{::doc/added "1.17"
|
{::doc/added "1.17"
|
||||||
::doc/module :files}
|
::doc/module :files
|
||||||
|
::sm/params schema:persist-temp-file}
|
||||||
[cfg {:keys [::rpc/profile-id id] :as params}]
|
[cfg {:keys [::rpc/profile-id id] :as params}]
|
||||||
(db/tx-run! cfg (fn [{:keys [::db/conn]}]
|
(db/tx-run! cfg (fn [{:keys [::db/conn] :as cfg}]
|
||||||
(files/check-edition-permissions! conn profile-id id)
|
(files/check-edition-permissions! conn profile-id id)
|
||||||
(persist-temp-file conn params))))
|
(persist-temp-file cfg params))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue