From e50137d186513f6b4d1b1dd28f946c916b63ae05 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 11 Oct 2022 15:21:39 +0200 Subject: [PATCH] :sparkles: Minor improvement on internal RPC metadata api --- backend/src/app/rpc.clj | 4 ++-- backend/src/app/rpc/commands/auth.clj | 11 ++++++----- backend/src/app/rpc/commands/binfile.clj | 10 ++++++---- backend/src/app/rpc/commands/ldap.clj | 5 +++-- backend/src/app/rpc/commands/verify_token.clj | 5 +++-- backend/src/app/rpc/mutations/profile.clj | 5 +++-- backend/src/app/rpc/mutations/teams.clj | 3 ++- backend/src/app/rpc/queries/files.clj | 12 ++++++------ 8 files changed, 31 insertions(+), 24 deletions(-) diff --git a/backend/src/app/rpc.clj b/backend/src/app/rpc.clj index 12e16db88..2b4b204aa 100644 --- a/backend/src/app/rpc.clj +++ b/backend/src/app/rpc.clj @@ -32,13 +32,13 @@ (defn- handle-response-transformation [response request mdata] (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/resolved response)))) (defn- handle-before-comple-hook [response mdata] - (when-let [hook-fn (:before-complete mdata)] + (when-let [hook-fn (::before-complete mdata)] (ex/ignoring (hook-fn))) response) diff --git a/backend/src/app/rpc/commands/auth.clj b/backend/src/app/rpc/commands/auth.clj index 26576194c..6f7484e2b 100644 --- a/backend/src/app/rpc/commands/auth.clj +++ b/backend/src/app/rpc/commands/auth.clj @@ -14,6 +14,7 @@ [app.db :as db] [app.emails :as eml] [app.loggers.audit :as audit] + [app.rpc :as-alias rpc] [app.rpc.doc :as-alias doc] [app.rpc.mutations.teams :as teams] [app.rpc.queries.profile :as profile] @@ -134,7 +135,7 @@ profile)] (with-meta response - {:transform-response ((:create session) (:id profile)) + {::rpc/transform-response ((:create session) (:id profile)) ::audit/props (audit/profile->props profile) ::audit/profile-id (:id profile)}))))) @@ -161,7 +162,7 @@ ::doc/added "1.15"} [{:keys [session] :as cfg} _] (with-meta {} - {:transform-response (:delete session)})) + {::rpc/transform-response (:delete session)})) ;; ---- COMMAND: Recover Profile @@ -401,7 +402,7 @@ token (tokens/generate sprops claims) resp {:invitation-token token}] (with-meta resp - {:transform-response ((:create session) (:id profile)) + {::rpc/transform-response ((:create session) (:id profile)) ::audit/replace-props (audit/profile->props profile) ::audit/profile-id (:id profile)})) @@ -410,7 +411,7 @@ ;; we need to mark this session as logged. (not= "penpot" (:auth-backend 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/profile-id (:id profile)}) @@ -418,7 +419,7 @@ ;; to sign in the user directly, without email verification. (true? is-active) (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/profile-id (:id profile)}) diff --git a/backend/src/app/rpc/commands/binfile.clj b/backend/src/app/rpc/commands/binfile.clj index 8144b7464..9c01debe0 100644 --- a/backend/src/app/rpc/commands/binfile.clj +++ b/backend/src/app/rpc/commands/binfile.clj @@ -16,6 +16,7 @@ [app.config :as cf] [app.db :as db] [app.media :as media] + [app.rpc :as-alias rpc] [app.rpc.doc :as-alias doc] [app.rpc.queries.files :as files] [app.rpc.queries.projects :as projects] @@ -879,10 +880,11 @@ (export! output-stream))))] (with-meta (sv/wrap nil) - {:transform-response (fn [_ response] - (-> response - (assoc :body resp) - (assoc :headers {"content-type" "application/octet-stream"})))}))) + {::rpc/transform-response + (fn [_ response] + (-> response + (assoc :body resp) + (assoc :headers {"content-type" "application/octet-stream"})))}))) (s/def ::file ::media/upload) (s/def ::import-binfile diff --git a/backend/src/app/rpc/commands/ldap.clj b/backend/src/app/rpc/commands/ldap.clj index a0eab43e9..d7633336f 100644 --- a/backend/src/app/rpc/commands/ldap.clj +++ b/backend/src/app/rpc/commands/ldap.clj @@ -11,6 +11,7 @@ [app.common.spec :as us] [app.db :as db] [app.loggers.audit :as-alias audit] + [app.rpc :as-alias rpc] [app.rpc.commands.auth :as cmd.auth] [app.rpc.doc :as-alias doc] [app.rpc.queries.profile :as profile] @@ -62,12 +63,12 @@ :member-email (:email profile)) token (tokens :generate claims)] (with-meta {:invitation-token token} - {:transform-response ((:create session) (:id profile)) + {::rpc/transform-response ((:create session) (:id profile)) ::audit/props (:props profile) ::audit/profile-id (:id profile)})) (with-meta profile - {:transform-response ((:create session) (:id profile)) + {::rpc/transform-response ((:create session) (:id profile)) ::audit/props (:props profile) ::audit/profile-id (:id profile)}))))) diff --git a/backend/src/app/rpc/commands/verify_token.clj b/backend/src/app/rpc/commands/verify_token.clj index 03e5e1d00..f02db8839 100644 --- a/backend/src/app/rpc/commands/verify_token.clj +++ b/backend/src/app/rpc/commands/verify_token.clj @@ -10,6 +10,7 @@ [app.common.spec :as us] [app.db :as db] [app.loggers.audit :as audit] + [app.rpc :as-alias rpc] [app.rpc.doc :as-alias doc] [app.rpc.mutations.teams :as teams] [app.rpc.queries.profile :as profile] @@ -67,7 +68,7 @@ {:id (:id profile)})) (with-meta claims - {:transform-response ((:create session) profile-id) + {::rpc/transform-response ((:create session) profile-id) ::audit/name "verify-profile-email" ::audit/props (audit/profile->props profile) ::audit/profile-id (:id profile)}))) @@ -171,7 +172,7 @@ (let [profile (accept-invitation cfg claims invitation member)] (with-meta (assoc claims :state :created) - {:transform-response ((:create session) (:id profile)) + {::rpc/transform-response ((:create session) (:id profile)) ::audit/name "accept-team-invitation" ::audit/props (merge (audit/profile->props profile) diff --git a/backend/src/app/rpc/mutations/profile.clj b/backend/src/app/rpc/mutations/profile.clj index 39e4c92e9..73555557a 100644 --- a/backend/src/app/rpc/mutations/profile.clj +++ b/backend/src/app/rpc/mutations/profile.clj @@ -14,6 +14,7 @@ [app.emails :as eml] [app.loggers.audit :as audit] [app.media :as media] + [app.rpc :as-alias rpc] [app.rpc.commands.auth :as cmd.auth] [app.rpc.doc :as-alias doc] [app.rpc.mutations.teams :as teams] @@ -277,7 +278,7 @@ {:id profile-id}) (with-meta {} - {:transform-response (:delete session)})))) + {::rpc/transform-response (:delete session)})))) (def sql:owned-teams "with owner_teams as ( @@ -323,7 +324,7 @@ ::doc/deprecated "1.15"} [{:keys [session] :as cfg} _] (with-meta {} - {:transform-response (:delete session)})) + {::rpc/transform-response (:delete session)})) ;; --- MUTATION: Recover Profile diff --git a/backend/src/app/rpc/mutations/teams.clj b/backend/src/app/rpc/mutations/teams.clj index e7f6e88df..da04e4c65 100644 --- a/backend/src/app/rpc/mutations/teams.clj +++ b/backend/src/app/rpc/mutations/teams.clj @@ -16,6 +16,7 @@ [app.emails :as eml] [app.loggers.audit :as audit] [app.media :as media] + [app.rpc :as-alias rpc] [app.rpc.mutations.projects :as projects] [app.rpc.permissions :as perms] [app.rpc.queries.profile :as profile] @@ -490,7 +491,7 @@ (with-meta team {::audit/props {:invitations (count emails)} - :before-complete + ::rpc/before-complete #(audit-fn :cmd :submit :type "mutation" :name "invite-team-member" diff --git a/backend/src/app/rpc/queries/files.clj b/backend/src/app/rpc/queries/files.clj index 57748559d..349c54bc2 100644 --- a/backend/src/app/rpc/queries/files.clj +++ b/backend/src/app/rpc/queries/files.clj @@ -17,6 +17,7 @@ [app.common.types.shape-tree :as ctt] [app.db :as db] [app.db.sql :as sql] + [app.rpc :as-alias rpc] [app.rpc.helpers :as rpch] [app.rpc.permissions :as perms] [app.rpc.queries.projects :as projects] @@ -569,12 +570,11 @@ (ex/raise :type :not-found :code :file-thumbnail-not-found)) - (with-meta - {:data (:data row) - :props (some-> (:props row) db/decode-transit-pgobject) - :revn (:revn row) - :file-id (:file-id row)} - {:transform-response (rpch/http-cache {:max-age (* 1000 60 60)})}))) + (with-meta {:data (:data row) + :props (some-> (:props row) db/decode-transit-pgobject) + :revn (:revn row) + :file-id (:file-id row)} + {::rpc/transform-response (rpch/http-cache {:max-age (* 1000 60 60)})}))) ;; --- Helpers