mirror of
https://github.com/penpot/penpot.git
synced 2025-05-15 00:46:38 +02:00
🐛 Fix incorrect interaction of library-absorb mechanism and storage-pointes
This commit is contained in:
parent
a3f3e31c73
commit
ef4bd8c598
2 changed files with 46 additions and 43 deletions
|
@ -798,11 +798,11 @@
|
||||||
|
|
||||||
;; --- MUTATION COMMAND: set-file-shared
|
;; --- MUTATION COMMAND: set-file-shared
|
||||||
|
|
||||||
(defn unlink-files
|
(defn- unlink-files!
|
||||||
[conn {:keys [id] :as params}]
|
[conn {:keys [id]}]
|
||||||
(db/delete! conn :file-library-rel {:library-file-id id}))
|
(db/delete! conn :file-library-rel {:library-file-id id}))
|
||||||
|
|
||||||
(defn set-file-shared
|
(defn- set-file-shared!
|
||||||
[conn {:keys [id is-shared] :as params}]
|
[conn {:keys [id is-shared] :as params}]
|
||||||
(db/update! conn :file
|
(db/update! conn :file
|
||||||
{:is-shared is-shared}
|
{:is-shared is-shared}
|
||||||
|
@ -813,49 +813,50 @@
|
||||||
FROM file_library_rel AS flr
|
FROM file_library_rel AS flr
|
||||||
INNER JOIN file AS f ON (f.id = flr.file_id)
|
INNER JOIN file AS f ON (f.id = flr.file_id)
|
||||||
WHERE flr.library_file_id = ?
|
WHERE flr.library_file_id = ?
|
||||||
|
AND (f.deleted_at IS NULL OR f.deleted_at > now())
|
||||||
ORDER BY f.created_at ASC;")
|
ORDER BY f.created_at ASC;")
|
||||||
|
|
||||||
(defn absorb-library
|
(defn- absorb-library!
|
||||||
"Find all files using a shared library, and absorb all library assets
|
"Find all files using a shared library, and absorb all library assets
|
||||||
into the file local libraries"
|
into the file local libraries"
|
||||||
[conn {:keys [id] :as params}]
|
[conn {:keys [id] :as library}]
|
||||||
(let [library (db/get-by-id conn :file id)]
|
(let [ldata (binding [pmap/*load-fn* (partial load-pointer conn id)]
|
||||||
(when (:is-shared library)
|
(-> library decode-row (process-pointers deref) pmg/migrate-file :data))
|
||||||
(let [ldata (binding [pmap/*load-fn* (partial load-pointer conn id)]
|
rows (db/exec! conn [sql:get-referenced-files id])]
|
||||||
(-> library decode-row load-all-pointers! pmg/migrate-file :data))
|
(doseq [file-id (map :id rows)]
|
||||||
rows (db/exec! conn [sql:get-referenced-files id])]
|
(binding [pmap/*load-fn* (partial load-pointer conn file-id)
|
||||||
(doseq [file-id (map :id rows)]
|
pmap/*tracked* (atom {})]
|
||||||
(binding [pmap/*load-fn* (partial load-pointer conn file-id)
|
(let [file (-> (db/get-by-id conn :file file-id
|
||||||
pmap/*tracked* (atom {})]
|
::db/check-deleted? false
|
||||||
(let [file (-> (db/get-by-id conn :file file-id
|
::db/remove-deleted? false)
|
||||||
::db/check-deleted? false
|
(decode-row)
|
||||||
::db/remove-deleted? false)
|
(load-all-pointers!)
|
||||||
(decode-row)
|
(pmg/migrate-file))
|
||||||
(load-all-pointers!)
|
data (ctf/absorb-assets (:data file) ldata)]
|
||||||
(pmg/migrate-file))
|
(db/update! conn :file
|
||||||
data (ctf/absorb-assets (:data file) ldata)]
|
{:revn (inc (:revn file))
|
||||||
(db/update! conn :file
|
:data (blob/encode data)
|
||||||
{:revn (inc (:revn file))
|
:modified-at (dt/now)}
|
||||||
:data (blob/encode data)
|
{:id file-id})
|
||||||
:modified-at (dt/now)}
|
(persist-pointers! conn file-id))))))
|
||||||
{:id file-id})
|
|
||||||
(persist-pointers! conn file-id))))))))
|
|
||||||
|
|
||||||
(s/def ::set-file-shared
|
(def ^:private schema:set-file-shared
|
||||||
(s/keys :req [::rpc/profile-id]
|
[:map {:title "set-file-shared"}
|
||||||
:req-un [::id ::is-shared]))
|
[:id ::sm/uuid]
|
||||||
|
[:is-shared :boolean]])
|
||||||
|
|
||||||
(sv/defmethod ::set-file-shared
|
(sv/defmethod ::set-file-shared
|
||||||
{::doc/added "1.17"
|
{::doc/added "1.17"
|
||||||
::webhooks/event? true}
|
::webhooks/event? true
|
||||||
|
::sm/params schema:set-file-shared}
|
||||||
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id id is-shared] :as params}]
|
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id id is-shared] :as params}]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(check-edition-permissions! conn profile-id id)
|
(check-edition-permissions! conn profile-id id)
|
||||||
(when-not is-shared
|
(let [file (set-file-shared! conn params)]
|
||||||
(absorb-library conn params)
|
(when-not is-shared
|
||||||
(unlink-files conn params))
|
(absorb-library! conn file)
|
||||||
|
(unlink-files! conn file))
|
||||||
|
|
||||||
(let [file (set-file-shared conn params)]
|
|
||||||
(rph/with-meta
|
(rph/with-meta
|
||||||
(select-keys file [:id :name :is-shared])
|
(select-keys file [:id :name :is-shared])
|
||||||
{::audit/props {:name (:name file)
|
{::audit/props {:name (:name file)
|
||||||
|
@ -864,24 +865,26 @@
|
||||||
|
|
||||||
;; --- MUTATION COMMAND: delete-file
|
;; --- MUTATION COMMAND: delete-file
|
||||||
|
|
||||||
(defn mark-file-deleted
|
(defn- mark-file-deleted!
|
||||||
[conn {:keys [id] :as params}]
|
[conn {:keys [id]}]
|
||||||
(db/update! conn :file
|
(db/update! conn :file
|
||||||
{:deleted-at (dt/now)}
|
{:deleted-at (dt/now)}
|
||||||
{:id id}))
|
{:id id}))
|
||||||
|
|
||||||
(s/def ::delete-file
|
(def ^:private schema:delete-file
|
||||||
(s/keys :req [::rpc/profile-id]
|
[:map {:title "delete-file"}
|
||||||
:req-un [::id]))
|
[:id ::sm/uuid]])
|
||||||
|
|
||||||
(sv/defmethod ::delete-file
|
(sv/defmethod ::delete-file
|
||||||
{::doc/added "1.17"
|
{::doc/added "1.17"
|
||||||
::webhooks/event? true}
|
::webhooks/event? true
|
||||||
|
::sm/params schema:delete-file}
|
||||||
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id id] :as params}]
|
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id id] :as params}]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(check-edition-permissions! conn profile-id id)
|
(check-edition-permissions! conn profile-id id)
|
||||||
(absorb-library conn params)
|
(let [file (mark-file-deleted! conn params)]
|
||||||
(let [file (mark-file-deleted conn params)]
|
(when (:is-shared file)
|
||||||
|
(absorb-library! conn file))
|
||||||
|
|
||||||
(rph/with-meta (rph/wrap)
|
(rph/with-meta (rph/wrap)
|
||||||
{::audit/props {:project-id (:project-id file)
|
{::audit/props {:project-id (:project-id file)
|
||||||
|
|
|
@ -246,7 +246,7 @@
|
||||||
(defn mark-file-deleted*
|
(defn mark-file-deleted*
|
||||||
([params] (mark-file-deleted* *pool* params))
|
([params] (mark-file-deleted* *pool* params))
|
||||||
([conn {:keys [id] :as params}]
|
([conn {:keys [id] :as params}]
|
||||||
(#'files/mark-file-deleted conn {:id id})))
|
(#'files/mark-file-deleted! conn {:id id})))
|
||||||
|
|
||||||
(defn create-team*
|
(defn create-team*
|
||||||
([i params] (create-team* *pool* i params))
|
([i params] (create-team* *pool* i params))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue