From 4af76f9a9ac1a032d8f534c496ee8fbef1dd8afc Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 7 Nov 2023 16:31:56 +0100 Subject: [PATCH] :sparkles: Add backward compatibility layer for features handling --- backend/scripts/repl | 2 -- backend/scripts/start-dev | 2 -- backend/src/app/rpc/commands/files.clj | 35 +++++++------------ backend/src/app/rpc/commands/files_update.clj | 27 +++++++------- backend/src/app/rpc/commands/teams.clj | 9 +++-- 5 files changed, 31 insertions(+), 44 deletions(-) diff --git a/backend/scripts/repl b/backend/scripts/repl index 4eb6680a0..0503d03d6 100755 --- a/backend/scripts/repl +++ b/backend/scripts/repl @@ -11,8 +11,6 @@ export PENPOT_FLAGS="\ enable-login-with-github \ enable-login-with-gitlab \ enable-backend-asserts \ - enable-fdata-storage-pointer-map \ - enable-fdata-storage-objets-map \ enable-audit-log \ enable-transit-readable-response \ enable-demo-users \ diff --git a/backend/scripts/start-dev b/backend/scripts/start-dev index d9ba4b1ce..3e525dfc7 100755 --- a/backend/scripts/start-dev +++ b/backend/scripts/start-dev @@ -11,8 +11,6 @@ export PENPOT_FLAGS="\ enable-audit-log \ enable-transit-readable-response \ enable-demo-users \ - enable-fdata-storage-pointer-map \ - enable-fdata-storage-objets-map \ disable-secure-session-cookies \ enable-smtp \ enable-access-tokens"; diff --git a/backend/src/app/rpc/commands/files.clj b/backend/src/app/rpc/commands/files.clj index 54fb909ad..d3514cdd4 100644 --- a/backend/src/app/rpc/commands/files.clj +++ b/backend/src/app/rpc/commands/files.clj @@ -46,6 +46,11 @@ (def supported-features #{"storage/objects-map" "storage/pointer-map" + "internal/geom-record" + "internal/shape-record" + "fdata/pointer-map" + "fdata/objects-map" + "fdata/shape-data-type" "components/v2"}) (defn get-default-features @@ -250,17 +255,6 @@ (into #{} (comp (filter pmap/pointer-map?) (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! [{:keys [features] :as file} client-features] @@ -277,22 +271,18 @@ :hint "file has 'components/v2' feature enabled but frontend didn't specifies it" :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 ;; does not support pointer-map resolution mechanism; this just resolves the ;; pointers on backend and return a complete file. (and (contains? 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))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; QUERY COMMANDS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -350,9 +340,8 @@ file (-> (db/get conn :file params) (decode-row) - (pmg/migrate-file)) - - file (handle-file-features! file client-features)] + (pmg/migrate-file) + (handle-file-features! client-features))] ;; NOTE: when file is migrated, we break the rule of no perform ;; mutations on get operations and update the file with all diff --git a/backend/src/app/rpc/commands/files_update.clj b/backend/src/app/rpc/commands/files_update.clj index 0accca0a3..5cc49366d 100644 --- a/backend/src/app/rpc/commands/files_update.clj +++ b/backend/src/app/rpc/commands/files_update.clj @@ -15,7 +15,6 @@ [app.common.schema :as sm] [app.common.schema.generators :as smg] [app.common.spec :as us] - [app.common.types.file :as ctf] [app.common.uuid :as uuid] [app.config :as cf] [app.db :as db] @@ -201,7 +200,13 @@ (contains? features "storage/pointer-map") (wrap-with-pointer-map-context) + (contains? features "fdata/pointer-map") + (wrap-with-pointer-map-context) + (contains? features "storage/objects-map") + (wrap-with-objects-map-context) + + (contains? features "fdata/objects-map") (wrap-with-objects-map-context)) file (assoc file :features features) @@ -243,20 +248,12 @@ (-> file (update :revn inc) (update :data (fn [data] - (cond-> data - :always - (-> (blob/decode) - (assoc :id (:id file)) - (pmg/migrate-data)) - - (and (contains? ffeat/*current* "components/v2") - (not (contains? ffeat/*previous* "components/v2"))) - (ctf/migrate-to-components-v2) - - :always - (-> (cp/process-changes changes) - (blob/encode))))))) - + (-> data + (blob/decode) + (assoc :id (:id file)) + (pmg/migrate-data) + (cp/process-changes changes) + (blob/encode)))))) (defn- update-file* [{:keys [::db/conn] :as cfg} {:keys [profile-id file changes session-id ::created-at] :as params}] diff --git a/backend/src/app/rpc/commands/teams.clj b/backend/src/app/rpc/commands/teams.clj index e846f0b34..e2e88e620 100644 --- a/backend/src/app/rpc/commands/teams.clj +++ b/backend/src/app/rpc/commands/teams.clj @@ -79,6 +79,11 @@ (def check-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 (declare retrieve-teams) @@ -123,6 +128,7 @@ [conn profile-id] (let [profile (profile/get-profile conn profile-id)] (->> (db/exec! conn [sql:teams (:default-team-id profile) profile-id]) + (map decode-row) (mapv process-permissions)))) ;; --- Query: Team (by ID) @@ -148,8 +154,7 @@ (when-not result (ex/raise :type :not-found :code :team-does-not-exist)) - - (process-permissions result))) + (-> result decode-row process-permissions))) ;; --- Query: Team Members