Minor improvement on internal RPC metadata api

This commit is contained in:
Andrey Antukh 2022-10-11 15:21:39 +02:00 committed by Andrés Moya
parent 8e6b93e2a7
commit e50137d186
8 changed files with 31 additions and 24 deletions

View file

@ -32,13 +32,13 @@
(defn- handle-response-transformation (defn- handle-response-transformation
[response request mdata] [response request mdata]
(let [response (if (sv/wrapped? response) @response response)] (let [response (if (sv/wrapped? response) @response response)]
(if-let [transform-fn (:transform-response mdata)] (if-let [transform-fn (::transform-response mdata)]
(p/do (transform-fn request response)) (p/do (transform-fn request response))
(p/resolved response)))) (p/resolved response))))
(defn- handle-before-comple-hook (defn- handle-before-comple-hook
[response mdata] [response mdata]
(when-let [hook-fn (:before-complete mdata)] (when-let [hook-fn (::before-complete mdata)]
(ex/ignoring (hook-fn))) (ex/ignoring (hook-fn)))
response) response)

View file

@ -14,6 +14,7 @@
[app.db :as db] [app.db :as db]
[app.emails :as eml] [app.emails :as eml]
[app.loggers.audit :as audit] [app.loggers.audit :as audit]
[app.rpc :as-alias rpc]
[app.rpc.doc :as-alias doc] [app.rpc.doc :as-alias doc]
[app.rpc.mutations.teams :as teams] [app.rpc.mutations.teams :as teams]
[app.rpc.queries.profile :as profile] [app.rpc.queries.profile :as profile]
@ -134,7 +135,7 @@
profile)] profile)]
(with-meta response (with-meta response
{:transform-response ((:create session) (:id profile)) {::rpc/transform-response ((:create session) (:id profile))
::audit/props (audit/profile->props profile) ::audit/props (audit/profile->props profile)
::audit/profile-id (:id profile)}))))) ::audit/profile-id (:id profile)})))))
@ -161,7 +162,7 @@
::doc/added "1.15"} ::doc/added "1.15"}
[{:keys [session] :as cfg} _] [{:keys [session] :as cfg} _]
(with-meta {} (with-meta {}
{:transform-response (:delete session)})) {::rpc/transform-response (:delete session)}))
;; ---- COMMAND: Recover Profile ;; ---- COMMAND: Recover Profile
@ -401,7 +402,7 @@
token (tokens/generate sprops claims) token (tokens/generate sprops claims)
resp {:invitation-token token}] resp {:invitation-token token}]
(with-meta resp (with-meta resp
{:transform-response ((:create session) (:id profile)) {::rpc/transform-response ((:create session) (:id profile))
::audit/replace-props (audit/profile->props profile) ::audit/replace-props (audit/profile->props profile)
::audit/profile-id (:id profile)})) ::audit/profile-id (:id profile)}))
@ -410,7 +411,7 @@
;; we need to mark this session as logged. ;; we need to mark this session as logged.
(not= "penpot" (:auth-backend profile)) (not= "penpot" (:auth-backend profile))
(with-meta (profile/strip-private-attrs profile) (with-meta (profile/strip-private-attrs profile)
{:transform-response ((:create session) (:id profile)) {::rpc/transform-response ((:create session) (:id profile))
::audit/replace-props (audit/profile->props profile) ::audit/replace-props (audit/profile->props profile)
::audit/profile-id (:id profile)}) ::audit/profile-id (:id profile)})
@ -418,7 +419,7 @@
;; to sign in the user directly, without email verification. ;; to sign in the user directly, without email verification.
(true? is-active) (true? is-active)
(with-meta (profile/strip-private-attrs profile) (with-meta (profile/strip-private-attrs profile)
{:transform-response ((:create session) (:id profile)) {::rpc/transform-response ((:create session) (:id profile))
::audit/replace-props (audit/profile->props profile) ::audit/replace-props (audit/profile->props profile)
::audit/profile-id (:id profile)}) ::audit/profile-id (:id profile)})

View file

@ -16,6 +16,7 @@
[app.config :as cf] [app.config :as cf]
[app.db :as db] [app.db :as db]
[app.media :as media] [app.media :as media]
[app.rpc :as-alias rpc]
[app.rpc.doc :as-alias doc] [app.rpc.doc :as-alias doc]
[app.rpc.queries.files :as files] [app.rpc.queries.files :as files]
[app.rpc.queries.projects :as projects] [app.rpc.queries.projects :as projects]
@ -879,10 +880,11 @@
(export! output-stream))))] (export! output-stream))))]
(with-meta (sv/wrap nil) (with-meta (sv/wrap nil)
{:transform-response (fn [_ response] {::rpc/transform-response
(-> response (fn [_ response]
(assoc :body resp) (-> response
(assoc :headers {"content-type" "application/octet-stream"})))}))) (assoc :body resp)
(assoc :headers {"content-type" "application/octet-stream"})))})))
(s/def ::file ::media/upload) (s/def ::file ::media/upload)
(s/def ::import-binfile (s/def ::import-binfile

View file

@ -11,6 +11,7 @@
[app.common.spec :as us] [app.common.spec :as us]
[app.db :as db] [app.db :as db]
[app.loggers.audit :as-alias audit] [app.loggers.audit :as-alias audit]
[app.rpc :as-alias rpc]
[app.rpc.commands.auth :as cmd.auth] [app.rpc.commands.auth :as cmd.auth]
[app.rpc.doc :as-alias doc] [app.rpc.doc :as-alias doc]
[app.rpc.queries.profile :as profile] [app.rpc.queries.profile :as profile]
@ -62,12 +63,12 @@
:member-email (:email profile)) :member-email (:email profile))
token (tokens :generate claims)] token (tokens :generate claims)]
(with-meta {:invitation-token token} (with-meta {:invitation-token token}
{:transform-response ((:create session) (:id profile)) {::rpc/transform-response ((:create session) (:id profile))
::audit/props (:props profile) ::audit/props (:props profile)
::audit/profile-id (:id profile)})) ::audit/profile-id (:id profile)}))
(with-meta profile (with-meta profile
{:transform-response ((:create session) (:id profile)) {::rpc/transform-response ((:create session) (:id profile))
::audit/props (:props profile) ::audit/props (:props profile)
::audit/profile-id (:id profile)}))))) ::audit/profile-id (:id profile)})))))

View file

@ -10,6 +10,7 @@
[app.common.spec :as us] [app.common.spec :as us]
[app.db :as db] [app.db :as db]
[app.loggers.audit :as audit] [app.loggers.audit :as audit]
[app.rpc :as-alias rpc]
[app.rpc.doc :as-alias doc] [app.rpc.doc :as-alias doc]
[app.rpc.mutations.teams :as teams] [app.rpc.mutations.teams :as teams]
[app.rpc.queries.profile :as profile] [app.rpc.queries.profile :as profile]
@ -67,7 +68,7 @@
{:id (:id profile)})) {:id (:id profile)}))
(with-meta claims (with-meta claims
{:transform-response ((:create session) profile-id) {::rpc/transform-response ((:create session) profile-id)
::audit/name "verify-profile-email" ::audit/name "verify-profile-email"
::audit/props (audit/profile->props profile) ::audit/props (audit/profile->props profile)
::audit/profile-id (:id profile)}))) ::audit/profile-id (:id profile)})))
@ -171,7 +172,7 @@
(let [profile (accept-invitation cfg claims invitation member)] (let [profile (accept-invitation cfg claims invitation member)]
(with-meta (with-meta
(assoc claims :state :created) (assoc claims :state :created)
{:transform-response ((:create session) (:id profile)) {::rpc/transform-response ((:create session) (:id profile))
::audit/name "accept-team-invitation" ::audit/name "accept-team-invitation"
::audit/props (merge ::audit/props (merge
(audit/profile->props profile) (audit/profile->props profile)

View file

@ -14,6 +14,7 @@
[app.emails :as eml] [app.emails :as eml]
[app.loggers.audit :as audit] [app.loggers.audit :as audit]
[app.media :as media] [app.media :as media]
[app.rpc :as-alias rpc]
[app.rpc.commands.auth :as cmd.auth] [app.rpc.commands.auth :as cmd.auth]
[app.rpc.doc :as-alias doc] [app.rpc.doc :as-alias doc]
[app.rpc.mutations.teams :as teams] [app.rpc.mutations.teams :as teams]
@ -277,7 +278,7 @@
{:id profile-id}) {:id profile-id})
(with-meta {} (with-meta {}
{:transform-response (:delete session)})))) {::rpc/transform-response (:delete session)}))))
(def sql:owned-teams (def sql:owned-teams
"with owner_teams as ( "with owner_teams as (
@ -323,7 +324,7 @@
::doc/deprecated "1.15"} ::doc/deprecated "1.15"}
[{:keys [session] :as cfg} _] [{:keys [session] :as cfg} _]
(with-meta {} (with-meta {}
{:transform-response (:delete session)})) {::rpc/transform-response (:delete session)}))
;; --- MUTATION: Recover Profile ;; --- MUTATION: Recover Profile

View file

@ -16,6 +16,7 @@
[app.emails :as eml] [app.emails :as eml]
[app.loggers.audit :as audit] [app.loggers.audit :as audit]
[app.media :as media] [app.media :as media]
[app.rpc :as-alias rpc]
[app.rpc.mutations.projects :as projects] [app.rpc.mutations.projects :as projects]
[app.rpc.permissions :as perms] [app.rpc.permissions :as perms]
[app.rpc.queries.profile :as profile] [app.rpc.queries.profile :as profile]
@ -490,7 +491,7 @@
(with-meta team (with-meta team
{::audit/props {:invitations (count emails)} {::audit/props {:invitations (count emails)}
:before-complete ::rpc/before-complete
#(audit-fn :cmd :submit #(audit-fn :cmd :submit
:type "mutation" :type "mutation"
:name "invite-team-member" :name "invite-team-member"

View file

@ -17,6 +17,7 @@
[app.common.types.shape-tree :as ctt] [app.common.types.shape-tree :as ctt]
[app.db :as db] [app.db :as db]
[app.db.sql :as sql] [app.db.sql :as sql]
[app.rpc :as-alias rpc]
[app.rpc.helpers :as rpch] [app.rpc.helpers :as rpch]
[app.rpc.permissions :as perms] [app.rpc.permissions :as perms]
[app.rpc.queries.projects :as projects] [app.rpc.queries.projects :as projects]
@ -569,12 +570,11 @@
(ex/raise :type :not-found (ex/raise :type :not-found
:code :file-thumbnail-not-found)) :code :file-thumbnail-not-found))
(with-meta (with-meta {:data (:data row)
{:data (:data row) :props (some-> (:props row) db/decode-transit-pgobject)
:props (some-> (:props row) db/decode-transit-pgobject) :revn (:revn row)
:revn (:revn row) :file-id (:file-id row)}
:file-id (:file-id row)} {::rpc/transform-response (rpch/http-cache {:max-age (* 1000 60 60)})})))
{:transform-response (rpch/http-cache {:max-age (* 1000 60 60)})})))
;; --- Helpers ;; --- Helpers