From b7573c0b7275587e59f5ce24f988edb2d7db7ecc Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 15 Nov 2024 15:43:45 +0100 Subject: [PATCH 1/2] :sparkles: Change frontend-only features automatic team assignation rules The frontend-only features are now ignored from files and from teams and they do not autoassigns automatically to team and file on file creation or update operations. --- backend/src/app/binfile/common.clj | 7 +++++-- backend/src/app/binfile/v1.clj | 1 + backend/src/app/rpc/commands/files_create.clj | 4 +++- backend/src/app/rpc/commands/files_update.clj | 3 ++- backend/src/app/rpc/commands/teams.clj | 4 +++- frontend/src/app/main.cljs | 7 ++++--- frontend/src/app/main/features.cljs | 19 +++++++++++-------- 7 files changed, 29 insertions(+), 16 deletions(-) diff --git a/backend/src/app/binfile/common.clj b/backend/src/app/binfile/common.clj index e97083b13..8808aa4f6 100644 --- a/backend/src/app/binfile/common.clj +++ b/backend/src/app/binfile/common.clj @@ -445,8 +445,11 @@ (fn [features] (let [features (cfeat/check-supported-features! features)] (-> (::features cfg #{}) - (set/difference cfeat/frontend-only-features) - (set/union features)))))) + (set/union features) + ;; We never want to store + ;; frontend-only features on file + (set/difference cfeat/frontend-only-features)))))) + _ (when (contains? cf/flags :file-schema-validation) (fval/validate-file-schema! file)) diff --git a/backend/src/app/binfile/v1.clj b/backend/src/app/binfile/v1.clj index aaa2f47db..086d296a2 100644 --- a/backend/src/app/binfile/v1.clj +++ b/backend/src/app/binfile/v1.clj @@ -514,6 +514,7 @@ (if (set? features) (-> features (cfeat/migrate-legacy-features) + (set/difference cfeat/frontend-only-features) (set/difference cfeat/backend-only-features)) #{})))) diff --git a/backend/src/app/rpc/commands/files_create.clj b/backend/src/app/rpc/commands/files_create.clj index 72c3ab884..e4540b27e 100644 --- a/backend/src/app/rpc/commands/files_create.clj +++ b/backend/src/app/rpc/commands/files_create.clj @@ -111,13 +111,15 @@ ;; features, because some features can be enabled ;; globally, but the team is still not migrated properly. features (-> (cfeat/get-team-enabled-features cf/flags team) - (cfeat/check-client-features! (:features params))) + (cfeat/check-client-features! (:features params)) + (set/difference cfeat/frontend-only-features)) ;; We also include all no migration features declared by ;; client; that enables the ability to enable a runtime ;; feature on frontend and make it permanent on file features (-> (:features params #{}) (set/intersection cfeat/no-migration-features) + (set/difference cfeat/frontend-only-features) (set/union features)) params (-> params diff --git a/backend/src/app/rpc/commands/files_update.clj b/backend/src/app/rpc/commands/files_update.clj index fb17be891..1a01a281d 100644 --- a/backend/src/app/rpc/commands/files_update.clj +++ b/backend/src/app/rpc/commands/files_update.clj @@ -139,7 +139,8 @@ features (-> (cfeat/get-team-enabled-features cf/flags team) (cfeat/check-client-features! (:features params)) - (cfeat/check-file-features! (:features file) (:features params))) + (cfeat/check-file-features! (:features file) (:features params)) + (set/difference cfeat/frontend-only-features)) changes (if changes-with-metadata (->> changes-with-metadata (mapcat :changes) vec) diff --git a/backend/src/app/rpc/commands/teams.clj b/backend/src/app/rpc/commands/teams.clj index a9850a6e5..f111b1184 100644 --- a/backend/src/app/rpc/commands/teams.clj +++ b/backend/src/app/rpc/commands/teams.clj @@ -30,7 +30,8 @@ [app.storage :as sto] [app.util.services :as sv] [app.util.time :as dt] - [app.worker :as wrk])) + [app.worker :as wrk] + [clojure.set :as set])) ;; --- Helpers & Specs @@ -416,6 +417,7 @@ ::quotes/profile-id profile-id}) (let [features (-> (cfeat/get-enabled-features cf/flags) + (set/difference cfeat/frontend-only-features) (cfeat/check-client-features! (:features params))) params (-> params (assoc :profile-id profile-id) diff --git a/frontend/src/app/main.cljs b/frontend/src/app/main.cljs index 517376ba2..e9824671f 100644 --- a/frontend/src/app/main.cljs +++ b/frontend/src/app/main.cljs @@ -30,6 +30,7 @@ [app.util.i18n :as i18n] [app.util.theme :as theme] [beicon.v2.core :as rx] + [cuerdas.core :as str] [debug] [features] [potok.v2.core :as ptk] @@ -38,11 +39,11 @@ (log/setup! {:app :info}) (when (= :browser cf/target) - (log/info :message "Welcome to penpot" - :version (:full cf/version) + (log/info :version (:full cf/version) :asserts *assert* :build-date cf/build-date - :public-uri (dm/str cf/public-uri))) + :public-uri (dm/str cf/public-uri)) + (log/info :flags (str/join "," (map name cf/flags)))) (declare reinit) diff --git a/frontend/src/app/main/features.cljs b/frontend/src/app/main/features.cljs index 02a2c3ba2..16c98ba62 100644 --- a/frontend/src/app/main/features.cljs +++ b/frontend/src/app/main/features.cljs @@ -33,10 +33,13 @@ (defn get-team-enabled-features [state] - (-> global-enabled-features - (set/union (:features-runtime state #{})) - (set/intersection cfeat/no-migration-features) - (set/union (:features-team state #{})))) + (let [runtime-features (:features-runtime state #{}) + team-features (->> (:features-team state #{}) + (into #{} cfeat/xf-remove-ephimeral))] + (-> global-enabled-features + (set/union runtime-features) + (set/intersection cfeat/no-migration-features) + (set/union team-features)))) (def features-ref (l/derived get-team-enabled-features st/state =)) @@ -124,9 +127,9 @@ (let [features (get-team-enabled-features state)] (if (contains? features "render-wasm/v1") (render.wasm/initialize true) - (render.wasm/initialize false))) + (render.wasm/initialize false)) - (log/trc :hint "initialized features" - :team (str/join "," (:features-team state)) - :runtime (str/join "," (:features-runtime state))))))) + (log/inf :hint "initialized" + :enabled (str/join "," features) + :runtime (str/join "," (:features-runtime state)))))))) From 47d28758d771ec42a2610d83def4d5b22cd348d9 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 15 Nov 2024 15:54:57 +0100 Subject: [PATCH 2/2] :sparkles: Clean frontend and backend features on exportation --- backend/src/app/binfile/common.clj | 10 ++++++++++ backend/src/app/binfile/v1.clj | 12 +----------- backend/src/app/binfile/v3.clj | 12 +++++++++--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/backend/src/app/binfile/common.clj b/backend/src/app/binfile/common.clj index 8808aa4f6..739b272e1 100644 --- a/backend/src/app/binfile/common.clj +++ b/backend/src/app/binfile/common.clj @@ -134,6 +134,16 @@ (update :data feat.fdata/process-pointers deref) (update :data feat.fdata/process-objects (partial into {})))))))) +(defn clean-file-features + [file] + (update file :features (fn [features] + (if (set? features) + (-> features + (cfeat/migrate-legacy-features) + (set/difference cfeat/frontend-only-features) + (set/difference cfeat/backend-only-features)) + #{})))) + (defn get-project [cfg project-id] (db/get cfg :project {:id project-id})) diff --git a/backend/src/app/binfile/v1.clj b/backend/src/app/binfile/v1.clj index 086d296a2..244720d2b 100644 --- a/backend/src/app/binfile/v1.clj +++ b/backend/src/app/binfile/v1.clj @@ -508,16 +508,6 @@ (update :object-id #(str/replace-first % #"^(.*?)/" (str file-id "/"))))) thumbnails)) -(defn- clean-features - [file] - (update file :features (fn [features] - (if (set? features) - (-> features - (cfeat/migrate-legacy-features) - (set/difference cfeat/frontend-only-features) - (set/difference cfeat/backend-only-features)) - #{})))) - (defmethod read-section :v1/files [{:keys [::db/conn ::input ::project-id ::bfc/overwrite ::name] :as system}] @@ -528,7 +518,7 @@ file-id (:id file) file-id' (bfc/lookup-index file-id) - file (clean-features file) + file (bfc/clean-file-features file) thumbnails (:thumbnails file)] (when (not= file-id expected-file-id) diff --git a/backend/src/app/binfile/v3.clj b/backend/src/app/binfile/v3.clj index 4c1f8e205..7980c21df 100644 --- a/backend/src/app/binfile/v3.clj +++ b/backend/src/app/binfile/v3.clj @@ -12,6 +12,7 @@ [app.common.data :as d] [app.common.data.macros :as dm] [app.common.exceptions :as ex] + [app.common.features :as cfeat] [app.common.json :as json] [app.common.logging :as l] [app.common.schema :as sm] @@ -55,7 +56,8 @@ [:map [:id ::sm/uuid] [:name :string] - [:project-id ::sm/uuid]]]] + [:project-id ::sm/uuid] + [:features ::cfeat/features]]]] [:relations {:optional true} [:vector @@ -203,7 +205,10 @@ (dissoc :libraries)) embed-assets - (update :data #(bfc/embed-assets cfg % file-id))))) + (update :data #(bfc/embed-assets cfg % file-id)) + + :always + (bfc/clean-file-features)))) (defn- resolve-extension [mtype] @@ -259,7 +264,8 @@ (vswap! bfc/*state* update :files assoc file-id {:id file-id :project-id (:project-id file) - :name (:name file)}) + :name (:name file) + :features (:features file)}) (let [file (cond-> (dissoc file :data) (:options data)