From 06bce92cdca1225b0e0b28e2d66960dbe9267092 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 22 Sep 2022 16:52:48 +0200 Subject: [PATCH] :paperclip: Fix linter issues on backend --- backend/src/app/rpc/commands/auth.clj | 120 +++++++++--------- backend/src/app/rpc/commands/verify_token.clj | 5 +- .../src/app/rpc/mutations/verify_token.clj | 4 +- 3 files changed, 64 insertions(+), 65 deletions(-) diff --git a/backend/src/app/rpc/commands/auth.clj b/backend/src/app/rpc/commands/auth.clj index 486755e39..5c0a3e801 100644 --- a/backend/src/app/rpc/commands/auth.clj +++ b/backend/src/app/rpc/commands/auth.clj @@ -355,76 +355,76 @@ (defn register-profile [{:keys [conn sprops session] :as cfg} {:keys [token] :as params}] - (let [claims (tokens/verify sprops {:token token :iss :prepared-register}) - params (merge params claims)] + (let [claims (tokens/verify sprops {:token token :iss :prepared-register}) + params (merge params claims) - (let [is-active (or (:is-active params) - (not (contains? cf/flags :email-verification)) + is-active (or (:is-active params) + (not (contains? cf/flags :email-verification)) - ;; DEPRECATED: v1.15 - (contains? cf/flags :insecure-register)) + ;; DEPRECATED: v1.15 + (contains? cf/flags :insecure-register)) - profile (if-let [profile-id (:profile-id claims)] - (profile/retrieve-profile conn profile-id) - (->> (assoc params :is-active is-active) - (create-profile conn) - (create-profile-relations conn) - (profile/decode-profile-row))) - audit-fn (:audit cfg) + profile (if-let [profile-id (:profile-id claims)] + (profile/retrieve-profile conn profile-id) + (->> (assoc params :is-active is-active) + (create-profile conn) + (create-profile-relations conn) + (profile/decode-profile-row))) + audit-fn (:audit cfg) - invitation (when-let [token (:invitation-token params)] - (tokens/verify sprops {:token token :iss :team-invitation}))] + invitation (when-let [token (:invitation-token params)] + (tokens/verify sprops {:token token :iss :team-invitation}))] - ;; If profile is filled in claims, means it tries to register - ;; again, so we proceed to update the modified-at attr - ;; accordingly. - (when-let [id (:profile-id claims)] - (db/update! conn :profile {:modified-at (dt/now)} {:id id}) - (audit-fn :cmd :submit - :type "fact" - :name "register-profile-retry" - :profile-id id)) + ;; If profile is filled in claims, means it tries to register + ;; again, so we proceed to update the modified-at attr + ;; accordingly. + (when-let [id (:profile-id claims)] + (db/update! conn :profile {:modified-at (dt/now)} {:id id}) + (audit-fn :cmd :submit + :type "fact" + :name "register-profile-retry" + :profile-id id)) - (cond - ;; If invitation token comes in params, this is because the - ;; user comes from team-invitation process; in this case, - ;; regenerate token and send back to the user a new invitation - ;; token (and mark current session as logged). This happens - ;; only if the invitation email matches with the register - ;; email. - (and (some? invitation) (= (:email profile) (:member-email invitation))) - (let [claims (assoc invitation :member-id (:id profile)) - token (tokens/generate sprops claims) - resp {:invitation-token token}] - (with-meta resp - {:transform-response ((:create session) (:id profile)) - ::audit/replace-props (audit/profile->props profile) - ::audit/profile-id (:id profile)})) - - ;; If auth backend is different from "penpot" means user is - ;; registering using third party auth mechanism; in this case - ;; we need to mark this session as logged. - (not= "penpot" (:auth-backend profile)) - (with-meta (profile/strip-private-attrs profile) + (cond + ;; If invitation token comes in params, this is because the + ;; user comes from team-invitation process; in this case, + ;; regenerate token and send back to the user a new invitation + ;; token (and mark current session as logged). This happens + ;; only if the invitation email matches with the register + ;; email. + (and (some? invitation) (= (:email profile) (:member-email invitation))) + (let [claims (assoc invitation :member-id (:id profile)) + token (tokens/generate sprops claims) + resp {:invitation-token token}] + (with-meta resp {:transform-response ((:create session) (:id profile)) ::audit/replace-props (audit/profile->props profile) - ::audit/profile-id (:id profile)}) + ::audit/profile-id (:id profile)})) - ;; If the `:enable-insecure-register` flag is set, we proceed - ;; 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)) - ::audit/replace-props (audit/profile->props profile) - ::audit/profile-id (:id profile)}) + ;; If auth backend is different from "penpot" means user is + ;; registering using third party auth mechanism; in this case + ;; 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)) + ::audit/replace-props (audit/profile->props profile) + ::audit/profile-id (:id profile)}) - ;; In all other cases, send a verification email. - :else - (do - (send-email-verification! conn sprops profile) - (with-meta profile - {::audit/replace-props (audit/profile->props profile) - ::audit/profile-id (:id profile)})))))) + ;; If the `:enable-insecure-register` flag is set, we proceed + ;; 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)) + ::audit/replace-props (audit/profile->props profile) + ::audit/profile-id (:id profile)}) + + ;; In all other cases, send a verification email. + :else + (do + (send-email-verification! conn sprops profile) + (with-meta profile + {::audit/replace-props (audit/profile->props profile) + ::audit/profile-id (:id profile)}))))) (s/def ::register-profile (s/keys :req-un [::token ::fullname])) diff --git a/backend/src/app/rpc/commands/verify_token.clj b/backend/src/app/rpc/commands/verify_token.clj index 4a93b9bce..27f453464 100644 --- a/backend/src/app/rpc/commands/verify_token.clj +++ b/backend/src/app/rpc/commands/verify_token.clj @@ -10,14 +10,13 @@ [app.common.spec :as us] [app.db :as db] [app.loggers.audit :as audit] + [app.rpc.doc :as-alias doc] [app.rpc.mutations.teams :as teams] [app.rpc.queries.profile :as profile] [app.tokens :as tokens] - [app.rpc.doc :as-alias doc] [app.tokens.spec.team-invitation :as-alias spec.team-invitation] [app.util.services :as sv] - [clojure.spec.alpha :as s] - [cuerdas.core :as str])) + [clojure.spec.alpha :as s])) (s/def ::iss keyword?) (s/def ::exp ::us/inst) diff --git a/backend/src/app/rpc/mutations/verify_token.clj b/backend/src/app/rpc/mutations/verify_token.clj index 9befd4e0f..a8551847b 100644 --- a/backend/src/app/rpc/mutations/verify_token.clj +++ b/backend/src/app/rpc/mutations/verify_token.clj @@ -7,9 +7,9 @@ (ns app.rpc.mutations.verify-token (:require [app.db :as db] - [app.tokens :as tokens] - [app.rpc.doc :as-alias doc] [app.rpc.commands.verify-token :refer [process-token]] + [app.rpc.doc :as-alias doc] + [app.tokens :as tokens] [app.util.services :as sv] [clojure.spec.alpha :as s]))