mirror of
https://github.com/penpot/penpot.git
synced 2025-05-13 19:56:38 +02:00
✨ Add backward compatibility layer for features handling
This commit is contained in:
parent
300b6d1758
commit
4af76f9a9a
5 changed files with 31 additions and 44 deletions
|
@ -11,8 +11,6 @@ export PENPOT_FLAGS="\
|
||||||
enable-login-with-github \
|
enable-login-with-github \
|
||||||
enable-login-with-gitlab \
|
enable-login-with-gitlab \
|
||||||
enable-backend-asserts \
|
enable-backend-asserts \
|
||||||
enable-fdata-storage-pointer-map \
|
|
||||||
enable-fdata-storage-objets-map \
|
|
||||||
enable-audit-log \
|
enable-audit-log \
|
||||||
enable-transit-readable-response \
|
enable-transit-readable-response \
|
||||||
enable-demo-users \
|
enable-demo-users \
|
||||||
|
|
|
@ -11,8 +11,6 @@ export PENPOT_FLAGS="\
|
||||||
enable-audit-log \
|
enable-audit-log \
|
||||||
enable-transit-readable-response \
|
enable-transit-readable-response \
|
||||||
enable-demo-users \
|
enable-demo-users \
|
||||||
enable-fdata-storage-pointer-map \
|
|
||||||
enable-fdata-storage-objets-map \
|
|
||||||
disable-secure-session-cookies \
|
disable-secure-session-cookies \
|
||||||
enable-smtp \
|
enable-smtp \
|
||||||
enable-access-tokens";
|
enable-access-tokens";
|
||||||
|
|
|
@ -46,6 +46,11 @@
|
||||||
(def supported-features
|
(def supported-features
|
||||||
#{"storage/objects-map"
|
#{"storage/objects-map"
|
||||||
"storage/pointer-map"
|
"storage/pointer-map"
|
||||||
|
"internal/geom-record"
|
||||||
|
"internal/shape-record"
|
||||||
|
"fdata/pointer-map"
|
||||||
|
"fdata/objects-map"
|
||||||
|
"fdata/shape-data-type"
|
||||||
"components/v2"})
|
"components/v2"})
|
||||||
|
|
||||||
(defn get-default-features
|
(defn get-default-features
|
||||||
|
@ -250,17 +255,6 @@
|
||||||
(into #{} (comp (filter pmap/pointer-map?)
|
(into #{} (comp (filter pmap/pointer-map?)
|
||||||
(map pmap/get-id)))))
|
(map pmap/get-id)))))
|
||||||
|
|
||||||
;; FIXME: file locking
|
|
||||||
(defn- process-components-v2-feature
|
|
||||||
"A special case handling of the components/v2 feature."
|
|
||||||
[{:keys [features data] :as file}]
|
|
||||||
(let [data (ctf/migrate-to-components-v2 data)
|
|
||||||
features (conj features "components/v2")]
|
|
||||||
(-> file
|
|
||||||
(assoc ::pmg/migrated true)
|
|
||||||
(assoc :features features)
|
|
||||||
(assoc :data data))))
|
|
||||||
|
|
||||||
(defn handle-file-features!
|
(defn handle-file-features!
|
||||||
[{:keys [features] :as file} client-features]
|
[{:keys [features] :as file} client-features]
|
||||||
|
|
||||||
|
@ -277,22 +271,18 @@
|
||||||
:hint "file has 'components/v2' feature enabled but frontend didn't specifies it"
|
:hint "file has 'components/v2' feature enabled but frontend didn't specifies it"
|
||||||
:file-id (:id file)))
|
:file-id (:id file)))
|
||||||
|
|
||||||
;; This operation is needed because the components migration generates a new
|
|
||||||
;; page with random id which is returned to the client; without persisting
|
|
||||||
;; the migration this can cause that two simultaneous clients can have a
|
|
||||||
;; different view of the file data and end persisting two pages with main
|
|
||||||
;; components and breaking the whole file."
|
|
||||||
(and (contains? client-features "components/v2")
|
|
||||||
(not (contains? features "components/v2")))
|
|
||||||
(as-> file (process-components-v2-feature file))
|
|
||||||
|
|
||||||
;; This operation is needed for backward comapatibility with frontends that
|
;; This operation is needed for backward comapatibility with frontends that
|
||||||
;; does not support pointer-map resolution mechanism; this just resolves the
|
;; does not support pointer-map resolution mechanism; this just resolves the
|
||||||
;; pointers on backend and return a complete file.
|
;; pointers on backend and return a complete file.
|
||||||
(and (contains? features "storage/pointer-map")
|
(and (contains? features "storage/pointer-map")
|
||||||
(not (contains? client-features "storage/pointer-map")))
|
(not (contains? client-features "storage/pointer-map")))
|
||||||
|
(process-pointers deref)
|
||||||
|
|
||||||
|
(and (contains? features "fdata/pointer-map")
|
||||||
|
(not (contains? client-features "fdata/pointer-map")))
|
||||||
(process-pointers deref)))
|
(process-pointers deref)))
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; QUERY COMMANDS
|
;; QUERY COMMANDS
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -350,9 +340,8 @@
|
||||||
|
|
||||||
file (-> (db/get conn :file params)
|
file (-> (db/get conn :file params)
|
||||||
(decode-row)
|
(decode-row)
|
||||||
(pmg/migrate-file))
|
(pmg/migrate-file)
|
||||||
|
(handle-file-features! client-features))]
|
||||||
file (handle-file-features! file client-features)]
|
|
||||||
|
|
||||||
;; NOTE: when file is migrated, we break the rule of no perform
|
;; NOTE: when file is migrated, we break the rule of no perform
|
||||||
;; mutations on get operations and update the file with all
|
;; mutations on get operations and update the file with all
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.schema.generators :as smg]
|
[app.common.schema.generators :as smg]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.common.types.file :as ctf]
|
|
||||||
[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]
|
||||||
|
@ -201,7 +200,13 @@
|
||||||
(contains? features "storage/pointer-map")
|
(contains? features "storage/pointer-map")
|
||||||
(wrap-with-pointer-map-context)
|
(wrap-with-pointer-map-context)
|
||||||
|
|
||||||
|
(contains? features "fdata/pointer-map")
|
||||||
|
(wrap-with-pointer-map-context)
|
||||||
|
|
||||||
(contains? features "storage/objects-map")
|
(contains? features "storage/objects-map")
|
||||||
|
(wrap-with-objects-map-context)
|
||||||
|
|
||||||
|
(contains? features "fdata/objects-map")
|
||||||
(wrap-with-objects-map-context))
|
(wrap-with-objects-map-context))
|
||||||
|
|
||||||
file (assoc file :features features)
|
file (assoc file :features features)
|
||||||
|
@ -243,20 +248,12 @@
|
||||||
(-> file
|
(-> file
|
||||||
(update :revn inc)
|
(update :revn inc)
|
||||||
(update :data (fn [data]
|
(update :data (fn [data]
|
||||||
(cond-> data
|
(-> data
|
||||||
:always
|
(blob/decode)
|
||||||
(-> (blob/decode)
|
(assoc :id (:id file))
|
||||||
(assoc :id (:id file))
|
(pmg/migrate-data)
|
||||||
(pmg/migrate-data))
|
(cp/process-changes changes)
|
||||||
|
(blob/encode))))))
|
||||||
(and (contains? ffeat/*current* "components/v2")
|
|
||||||
(not (contains? ffeat/*previous* "components/v2")))
|
|
||||||
(ctf/migrate-to-components-v2)
|
|
||||||
|
|
||||||
:always
|
|
||||||
(-> (cp/process-changes changes)
|
|
||||||
(blob/encode)))))))
|
|
||||||
|
|
||||||
|
|
||||||
(defn- update-file*
|
(defn- update-file*
|
||||||
[{:keys [::db/conn] :as cfg} {:keys [profile-id file changes session-id ::created-at] :as params}]
|
[{:keys [::db/conn] :as cfg} {:keys [profile-id file changes session-id ::created-at] :as params}]
|
||||||
|
|
|
@ -79,6 +79,11 @@
|
||||||
(def check-read-permissions!
|
(def check-read-permissions!
|
||||||
(perms/make-check-fn has-read-permissions?))
|
(perms/make-check-fn has-read-permissions?))
|
||||||
|
|
||||||
|
(defn decode-row
|
||||||
|
[{:keys [features] :as row}]
|
||||||
|
(cond-> row
|
||||||
|
features (assoc :features (db/decode-pgarray features #{}))))
|
||||||
|
|
||||||
;; --- Query: Teams
|
;; --- Query: Teams
|
||||||
|
|
||||||
(declare retrieve-teams)
|
(declare retrieve-teams)
|
||||||
|
@ -123,6 +128,7 @@
|
||||||
[conn profile-id]
|
[conn profile-id]
|
||||||
(let [profile (profile/get-profile conn profile-id)]
|
(let [profile (profile/get-profile conn profile-id)]
|
||||||
(->> (db/exec! conn [sql:teams (:default-team-id profile) profile-id])
|
(->> (db/exec! conn [sql:teams (:default-team-id profile) profile-id])
|
||||||
|
(map decode-row)
|
||||||
(mapv process-permissions))))
|
(mapv process-permissions))))
|
||||||
|
|
||||||
;; --- Query: Team (by ID)
|
;; --- Query: Team (by ID)
|
||||||
|
@ -148,8 +154,7 @@
|
||||||
(when-not result
|
(when-not result
|
||||||
(ex/raise :type :not-found
|
(ex/raise :type :not-found
|
||||||
:code :team-does-not-exist))
|
:code :team-does-not-exist))
|
||||||
|
(-> result decode-row process-permissions)))
|
||||||
(process-permissions result)))
|
|
||||||
|
|
||||||
;; --- Query: Team Members
|
;; --- Query: Team Members
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue