0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-11 07:11:32 -05:00

Move paste feature checking function to common/features

This commit is contained in:
Andrey Antukh 2023-11-29 15:43:27 +01:00 committed by Andrés Moya
parent ea156198c6
commit 12907771b0
3 changed files with 47 additions and 44 deletions

View file

@ -260,3 +260,46 @@
:feature (first not-supported)
:hint (str/ffmt "the source team does not have support '%' features"
(str/join "," not-supported))))))
(defn check-paste-features!
"Function used for check feature compability between currently enabled
features set on the application with the provided featured set by
the paste data (frontend clipboard)."
[enabled-features paste-features]
(let [not-supported (-> enabled-features
(set/difference paste-features)
;; NOTE: we don't want to raise a feature-mismatch
;; exception for features which don't require an
;; explicit file migration process or has no real
;; effect on file data structure
(set/difference no-migration-features))]
(when (seq not-supported)
(ex/raise :type :restriction
:code :missing-features-in-paste-content
:feature (first not-supported)
:hint (str/ffmt "expected features '%' not present in pasted content"
(str/join "," not-supported)))))
(let [not-supported (set/difference enabled-features supported-features)]
(when (seq not-supported)
(ex/raise :type :restriction
:code :paste-feature-not-supported
:feature (first not-supported)
:hint (str/ffmt "features '%' not supported in the application"
(str/join "," not-supported)))))
(let [not-supported (-> paste-features
(set/difference enabled-features)
(set/difference backend-only-features)
(set/difference frontend-only-features))]
(when (seq not-supported)
(ex/raise :type :restriction
:code :paste-feature-not-enabled
:feature (first not-supported)
:hint (str/ffmt "paste features '%' not enabled on the application"
(str/join "," not-supported))))))

View file

@ -80,7 +80,6 @@
[app.util.webapi :as wapi]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[clojure.set :as set]
[cuerdas.core :as str]
[potok.core :as ptk]))
@ -1736,47 +1735,8 @@
(= (:width (:selrect (first (vals paste-obj))))
(:width (:selrect frame-obj)))))
(defn- check-paste-features!
"Function used for check feature compability between currently
enabled features set on the application with the provided featured
set by the paste data."
[enabled-features paste-features]
(let [not-supported (-> enabled-features
(set/difference paste-features)
;; NOTE: we don't want to raise a feature-mismatch
;; exception for features which don't require an
;; explicit file migration process or has no real
;; effect on file data structure
(set/difference cfeat/no-migration-features))]
(when (seq not-supported)
(ex/raise :type :restriction
:code :missing-features-in-paste-content
:feature (first not-supported)
:hint (str/ffmt "expected features '%' not present in pasted content"
(str/join "," not-supported)))))
(let [not-supported (set/difference enabled-features cfeat/supported-features)]
(when (seq not-supported)
(ex/raise :type :restriction
:code :paste-feature-not-supported
:feature (first not-supported)
:hint (str/ffmt "features '%' not supported in the application"
(str/join "," not-supported)))))
(let [not-supported (-> paste-features
(set/difference enabled-features)
(set/difference cfeat/backend-only-features)
(set/difference cfeat/frontend-only-features))]
(when (seq not-supported)
(ex/raise :type :restriction
:code :paste-feature-not-enabled
:feature (first not-supported)
:hint (str/ffmt "paste features '%' not enabled on the application"
(str/join "," not-supported))))))
(def ^:private schema:paste-data
(def ^:private
schema:paste-data
(sm/define
[:map {:title "paste-data"}
[:type [:= :copied-shapes]]
@ -1816,7 +1776,7 @@
{:hint "invalid paste data"
:code :invalid-paste-data})
(check-paste-features! features (:features pdata))
(cfeat/check-paste-features! features (:features pdata))
(if (= file-id (:file-id pdata))
(let [pdata (assoc pdata :images [])]
(rx/of (paste-shapes pdata)))

View file

@ -881,7 +881,7 @@ msgstr "The email «%s» has been reported as spam or permanently bounce."
msgid "errors.feature-mismatch"
msgstr ""
"Looks like you are opening a file that has the feature '%s' enabled but "
"your penpot frontend does not supports it or has it disabled."
"the current penpot version does not supports it or has it disabled."
#: src/app/main/errors.cljs
msgid "errors.file-feature-mismatch"