mirror of
https://github.com/penpot/penpot.git
synced 2025-02-08 08:09:14 -05:00
✨ Reuse permission from rpc/cond middleware for get-file rpc method
This commit is contained in:
parent
22d7cfc7fa
commit
40d7bb04b4
3 changed files with 17 additions and 5 deletions
|
@ -295,8 +295,16 @@
|
||||||
::sm/result schema:file-with-permissions}
|
::sm/result schema:file-with-permissions}
|
||||||
[cfg {:keys [::rpc/profile-id id project-id] :as params}]
|
[cfg {:keys [::rpc/profile-id id project-id] :as params}]
|
||||||
(db/tx-run! cfg (fn [{:keys [::db/conn] :as cfg}]
|
(db/tx-run! cfg (fn [{:keys [::db/conn] :as cfg}]
|
||||||
(let [perms (get-permissions conn profile-id id)]
|
;; The COND middleware makes initial request for a file and
|
||||||
|
;; permissions when the incoming request comes with an
|
||||||
|
;; ETAG. When ETAG does not matches, the request is resolved
|
||||||
|
;; and this code is executed, in this case the permissions
|
||||||
|
;; will be already prefetched and we just reuse them instead
|
||||||
|
;; of making an additional database queries.
|
||||||
|
(let [perms (or (:permissions (::cond/object params))
|
||||||
|
(get-permissions conn profile-id id))]
|
||||||
(check-read-permissions! perms)
|
(check-read-permissions! perms)
|
||||||
|
|
||||||
(let [team (teams/get-team conn
|
(let [team (teams/get-team conn
|
||||||
:profile-id profile-id
|
:profile-id profile-id
|
||||||
:project-id project-id
|
:project-id project-id
|
||||||
|
|
|
@ -54,11 +54,16 @@
|
||||||
(l/trc :hint "instrumenting method" :service (::sv/name mdata))
|
(l/trc :hint "instrumenting method" :service (::sv/name mdata))
|
||||||
(fn [cfg {:keys [::key] :as params}]
|
(fn [cfg {:keys [::key] :as params}]
|
||||||
(if *enabled*
|
(if *enabled*
|
||||||
(let [key' (when (or reuse-key? key)
|
(let [object (when (some? key)
|
||||||
(some->> (get-object cfg params) (key-fn params) (fmt-key)))]
|
(get-object cfg params))
|
||||||
|
key' (when (some? object)
|
||||||
|
(->> object (key-fn params) (fmt-key)))]
|
||||||
(if (and (some? key) (= key key'))
|
(if (and (some? key) (= key key'))
|
||||||
(fn [_] {::rres/status 304})
|
(fn [_] {::rres/status 304})
|
||||||
(let [result (f cfg params)
|
(let [params (if (some? object)
|
||||||
|
(assoc params ::object object)
|
||||||
|
params)
|
||||||
|
result (f cfg params)
|
||||||
etag (or (and reuse-key? key')
|
etag (or (and reuse-key? key')
|
||||||
(some->> result meta ::key fmt-key)
|
(some->> result meta ::key fmt-key)
|
||||||
(some->> result (key-fn params) fmt-key))]
|
(some->> result (key-fn params) fmt-key))]
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
(t/is (nil? error))
|
(t/is (nil? error))
|
||||||
(t/is (map? result))
|
(t/is (map? result))
|
||||||
(t/is (contains? (meta result) :app.http/headers))
|
(t/is (contains? (meta result) :app.http/headers))
|
||||||
(t/is (contains? (meta result) :app.rpc.cond/key))
|
|
||||||
|
|
||||||
(let [etag (-> result meta :app.http/headers (get "etag"))
|
(let [etag (-> result meta :app.http/headers (get "etag"))
|
||||||
{:keys [error result]} (th/command! (assoc params ::cond/key etag))]
|
{:keys [error result]} (th/command! (assoc params ::cond/key etag))]
|
||||||
|
|
Loading…
Add table
Reference in a new issue