mirror of
https://github.com/penpot/penpot.git
synced 2025-03-11 23:31:21 -05:00
✨ Move paste feature checking function to common/features
This commit is contained in:
parent
ea156198c6
commit
12907771b0
3 changed files with 47 additions and 44 deletions
|
@ -260,3 +260,46 @@
|
||||||
:feature (first not-supported)
|
:feature (first not-supported)
|
||||||
:hint (str/ffmt "the source team does not have support '%' features"
|
:hint (str/ffmt "the source team does not have support '%' features"
|
||||||
(str/join "," not-supported))))))
|
(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))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,6 @@
|
||||||
[app.util.webapi :as wapi]
|
[app.util.webapi :as wapi]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
[clojure.set :as set]
|
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[potok.core :as ptk]))
|
[potok.core :as ptk]))
|
||||||
|
|
||||||
|
@ -1736,47 +1735,8 @@
|
||||||
(= (:width (:selrect (first (vals paste-obj))))
|
(= (:width (:selrect (first (vals paste-obj))))
|
||||||
(:width (:selrect frame-obj)))))
|
(:width (:selrect frame-obj)))))
|
||||||
|
|
||||||
(defn- check-paste-features!
|
(def ^:private
|
||||||
"Function used for check feature compability between currently
|
schema:paste-data
|
||||||
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
|
|
||||||
(sm/define
|
(sm/define
|
||||||
[:map {:title "paste-data"}
|
[:map {:title "paste-data"}
|
||||||
[:type [:= :copied-shapes]]
|
[:type [:= :copied-shapes]]
|
||||||
|
@ -1816,7 +1776,7 @@
|
||||||
{:hint "invalid paste data"
|
{:hint "invalid paste data"
|
||||||
:code :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))
|
(if (= file-id (:file-id pdata))
|
||||||
(let [pdata (assoc pdata :images [])]
|
(let [pdata (assoc pdata :images [])]
|
||||||
(rx/of (paste-shapes pdata)))
|
(rx/of (paste-shapes pdata)))
|
||||||
|
|
|
@ -881,7 +881,7 @@ msgstr "The email «%s» has been reported as spam or permanently bounce."
|
||||||
msgid "errors.feature-mismatch"
|
msgid "errors.feature-mismatch"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Looks like you are opening a file that has the feature '%s' enabled but "
|
"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
|
#: src/app/main/errors.cljs
|
||||||
msgid "errors.file-feature-mismatch"
|
msgid "errors.file-feature-mismatch"
|
||||||
|
|
Loading…
Add table
Reference in a new issue