mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 19:06:18 +00:00
Merge pull request #6447 from penpot/niwinz-staging-bugfixes
✨ Ensure read-only mode on non-workspace access to file
This commit is contained in:
commit
8febfaa21e
@ -208,7 +208,7 @@
|
|||||||
[:project-id {:optional true} ::sm/uuid]])
|
[:project-id {:optional true} ::sm/uuid]])
|
||||||
|
|
||||||
(defn- migrate-file
|
(defn- migrate-file
|
||||||
[{:keys [::db/conn] :as cfg} {:keys [id] :as file}]
|
[{:keys [::db/conn] :as cfg} {:keys [id] :as file} {:keys [read-only?]}]
|
||||||
(binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg id)
|
(binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg id)
|
||||||
pmap/*tracked* (pmap/create-tracked)]
|
pmap/*tracked* (pmap/create-tracked)]
|
||||||
(let [;; For avoid unnecesary overhead of creating multiple pointers and
|
(let [;; For avoid unnecesary overhead of creating multiple pointers and
|
||||||
@ -219,43 +219,45 @@
|
|||||||
file (-> file
|
file (-> file
|
||||||
(update :data feat.fdata/process-pointers deref)
|
(update :data feat.fdata/process-pointers deref)
|
||||||
(update :data feat.fdata/process-objects (partial into {}))
|
(update :data feat.fdata/process-objects (partial into {}))
|
||||||
(fmg/migrate-file))
|
(fmg/migrate-file))]
|
||||||
|
|
||||||
;; When file is migrated, we break the rule of no perform
|
(if (or read-only? (db/read-only? conn))
|
||||||
;; mutations on get operations and update the file with all
|
file
|
||||||
;; migrations applied
|
(let [;; When file is migrated, we break the rule of no perform
|
||||||
;;
|
;; mutations on get operations and update the file with all
|
||||||
;; WARN: he following code will not work on read-only mode,
|
;; migrations applied
|
||||||
;; it is a known issue; we keep is not implemented until we
|
file (if (contains? (:features file) "fdata/objects-map")
|
||||||
;; really need this.
|
(feat.fdata/enable-objects-map file)
|
||||||
file (if (contains? (:features file) "fdata/objects-map")
|
file)
|
||||||
(feat.fdata/enable-objects-map file)
|
file (if (contains? (:features file) "fdata/pointer-map")
|
||||||
file)
|
(feat.fdata/enable-pointer-map file)
|
||||||
file (if (contains? (:features file) "fdata/pointer-map")
|
file)]
|
||||||
(feat.fdata/enable-pointer-map file)
|
|
||||||
file)]
|
|
||||||
|
|
||||||
(db/update! conn :file
|
(db/update! conn :file
|
||||||
{:data (blob/encode (:data file))
|
{:data (blob/encode (:data file))
|
||||||
:version (:version file)
|
:version (:version file)
|
||||||
:features (db/create-array conn "text" (:features file))}
|
:features (db/create-array conn "text" (:features file))}
|
||||||
{:id id})
|
{:id id}
|
||||||
|
{::db/return-keys false})
|
||||||
|
|
||||||
(when (contains? (:features file) "fdata/pointer-map")
|
(when (contains? (:features file) "fdata/pointer-map")
|
||||||
(feat.fdata/persist-pointers! cfg id))
|
(feat.fdata/persist-pointers! cfg id))
|
||||||
|
|
||||||
(feat.fmigr/upsert-migrations! conn file)
|
(feat.fmigr/upsert-migrations! conn file)
|
||||||
(feat.fmigr/resolve-applied-migrations cfg file))))
|
(feat.fmigr/resolve-applied-migrations cfg file))))))
|
||||||
|
|
||||||
(defn get-file
|
(defn get-file
|
||||||
[{:keys [::db/conn ::wrk/executor] :as cfg} id
|
[{:keys [::db/conn ::wrk/executor] :as cfg} id
|
||||||
& {:keys [project-id
|
& {:keys [project-id
|
||||||
migrate?
|
migrate?
|
||||||
include-deleted?
|
include-deleted?
|
||||||
lock-for-update?]
|
lock-for-update?
|
||||||
|
preload-pointers?]
|
||||||
:or {include-deleted? false
|
:or {include-deleted? false
|
||||||
lock-for-update? false
|
lock-for-update? false
|
||||||
migrate? true}}]
|
migrate? true
|
||||||
|
preload-pointers? false}
|
||||||
|
:as options}]
|
||||||
|
|
||||||
(assert (db/connection? conn) "expected cfg with valid connection")
|
(assert (db/connection? conn) "expected cfg with valid connection")
|
||||||
|
|
||||||
@ -273,10 +275,16 @@
|
|||||||
;; because it has heavy and synchronous operations for
|
;; because it has heavy and synchronous operations for
|
||||||
;; decoding file body that are not very friendly with virtual
|
;; decoding file body that are not very friendly with virtual
|
||||||
;; threads.
|
;; threads.
|
||||||
file (px/invoke! executor #(decode-row file))]
|
file (px/invoke! executor #(decode-row file))
|
||||||
|
|
||||||
|
file (if (and migrate? (fmg/need-migration? file))
|
||||||
|
(migrate-file cfg file options)
|
||||||
|
file)]
|
||||||
|
|
||||||
|
(if preload-pointers?
|
||||||
|
(binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg id)]
|
||||||
|
(update file :data feat.fdata/process-pointers deref))
|
||||||
|
|
||||||
(if (and migrate? (fmg/need-migration? file))
|
|
||||||
(migrate-file cfg file)
|
|
||||||
file)))
|
file)))
|
||||||
|
|
||||||
(defn get-minimal-file
|
(defn get-minimal-file
|
||||||
@ -484,7 +492,7 @@
|
|||||||
|
|
||||||
(let [perms (get-permissions conn profile-id file-id share-id)
|
(let [perms (get-permissions conn profile-id file-id share-id)
|
||||||
|
|
||||||
file (get-file cfg file-id)
|
file (get-file cfg file-id :read-only? true)
|
||||||
|
|
||||||
proj (db/get conn :project {:id (:project-id file)})
|
proj (db/get conn :project {:id (:project-id file)})
|
||||||
|
|
||||||
@ -741,7 +749,9 @@
|
|||||||
:project-id project-id
|
:project-id project-id
|
||||||
:file-id id)
|
:file-id id)
|
||||||
|
|
||||||
file (get-file cfg id :project-id project-id)]
|
file (get-file cfg id
|
||||||
|
:project-id project-id
|
||||||
|
:read-only? true)]
|
||||||
|
|
||||||
(-> (cfeat/get-team-enabled-features cf/flags team)
|
(-> (cfeat/get-team-enabled-features cf/flags team)
|
||||||
(cfeat/check-client-features! (:features params))
|
(cfeat/check-client-features! (:features params))
|
||||||
|
|||||||
@ -10,7 +10,6 @@
|
|||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.features :as cfeat]
|
[app.common.features :as cfeat]
|
||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
[app.common.files.migrations :as fmg]
|
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.thumbnails :as thc]
|
[app.common.thumbnails :as thc]
|
||||||
@ -18,7 +17,6 @@
|
|||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.db.sql :as-alias sql]
|
[app.db.sql :as-alias sql]
|
||||||
[app.features.fdata :as feat.fdata]
|
|
||||||
[app.loggers.audit :as-alias audit]
|
[app.loggers.audit :as-alias audit]
|
||||||
[app.loggers.webhooks :as-alias webhooks]
|
[app.loggers.webhooks :as-alias webhooks]
|
||||||
[app.media :as media]
|
[app.media :as media]
|
||||||
@ -200,14 +198,13 @@
|
|||||||
(db/run! cfg (fn [{:keys [::db/conn] :as cfg}]
|
(db/run! cfg (fn [{:keys [::db/conn] :as cfg}]
|
||||||
(files/check-read-permissions! conn profile-id file-id)
|
(files/check-read-permissions! conn profile-id file-id)
|
||||||
|
|
||||||
(let [team (teams/get-team conn
|
(let [team (teams/get-team conn
|
||||||
:profile-id profile-id
|
:profile-id profile-id
|
||||||
:file-id file-id)
|
:file-id file-id)
|
||||||
|
|
||||||
file (binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg file-id)]
|
file (files/get-file cfg file-id
|
||||||
(-> (files/get-file cfg file-id :migrate? false)
|
:preload-pointers? true
|
||||||
(update :data feat.fdata/process-pointers deref)
|
:read-only? true)]
|
||||||
(fmg/migrate-file)))]
|
|
||||||
|
|
||||||
(-> (cfeat/get-team-enabled-features cf/flags team)
|
(-> (cfeat/get-team-enabled-features cf/flags team)
|
||||||
(cfeat/check-file-features! (:features file)))
|
(cfeat/check-file-features! (:features file)))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user