📎 Fix linter issues on backend

This commit is contained in:
Andrey Antukh 2022-09-22 16:52:48 +02:00
parent 757cee67fb
commit 06bce92cdc
3 changed files with 64 additions and 65 deletions

View file

@ -355,76 +355,76 @@
(defn register-profile (defn register-profile
[{:keys [conn sprops session] :as cfg} {:keys [token] :as params}] [{:keys [conn sprops session] :as cfg} {:keys [token] :as params}]
(let [claims (tokens/verify sprops {:token token :iss :prepared-register}) (let [claims (tokens/verify sprops {:token token :iss :prepared-register})
params (merge params claims)] params (merge params claims)
(let [is-active (or (:is-active params) is-active (or (:is-active params)
(not (contains? cf/flags :email-verification)) (not (contains? cf/flags :email-verification))
;; DEPRECATED: v1.15 ;; DEPRECATED: v1.15
(contains? cf/flags :insecure-register)) (contains? cf/flags :insecure-register))
profile (if-let [profile-id (:profile-id claims)] profile (if-let [profile-id (:profile-id claims)]
(profile/retrieve-profile conn profile-id) (profile/retrieve-profile conn profile-id)
(->> (assoc params :is-active is-active) (->> (assoc params :is-active is-active)
(create-profile conn) (create-profile conn)
(create-profile-relations conn) (create-profile-relations conn)
(profile/decode-profile-row))) (profile/decode-profile-row)))
audit-fn (:audit cfg) audit-fn (:audit cfg)
invitation (when-let [token (:invitation-token params)] invitation (when-let [token (:invitation-token params)]
(tokens/verify sprops {:token token :iss :team-invitation}))] (tokens/verify sprops {:token token :iss :team-invitation}))]
;; If profile is filled in claims, means it tries to register ;; If profile is filled in claims, means it tries to register
;; again, so we proceed to update the modified-at attr ;; again, so we proceed to update the modified-at attr
;; accordingly. ;; accordingly.
(when-let [id (:profile-id claims)] (when-let [id (:profile-id claims)]
(db/update! conn :profile {:modified-at (dt/now)} {:id id}) (db/update! conn :profile {:modified-at (dt/now)} {:id id})
(audit-fn :cmd :submit (audit-fn :cmd :submit
:type "fact" :type "fact"
:name "register-profile-retry" :name "register-profile-retry"
:profile-id id)) :profile-id id))
(cond (cond
;; If invitation token comes in params, this is because the ;; If invitation token comes in params, this is because the
;; user comes from team-invitation process; in this case, ;; user comes from team-invitation process; in this case,
;; regenerate token and send back to the user a new invitation ;; regenerate token and send back to the user a new invitation
;; token (and mark current session as logged). This happens ;; token (and mark current session as logged). This happens
;; only if the invitation email matches with the register ;; only if the invitation email matches with the register
;; email. ;; email.
(and (some? invitation) (= (:email profile) (:member-email invitation))) (and (some? invitation) (= (:email profile) (:member-email invitation)))
(let [claims (assoc invitation :member-id (:id profile)) (let [claims (assoc invitation :member-id (:id profile))
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))
::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)) {: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)}))
;; If the `:enable-insecure-register` flag is set, we proceed ;; If auth backend is different from "penpot" means user is
;; to sign in the user directly, without email verification. ;; registering using third party auth mechanism; in this case
(true? is-active) ;; we need to mark this session as logged.
(with-meta (profile/strip-private-attrs profile) (not= "penpot" (:auth-backend profile))
{:transform-response ((:create session) (:id profile)) (with-meta (profile/strip-private-attrs profile)
::audit/replace-props (audit/profile->props profile) {:transform-response ((:create session) (:id profile))
::audit/profile-id (:id profile)}) ::audit/replace-props (audit/profile->props profile)
::audit/profile-id (:id profile)})
;; In all other cases, send a verification email. ;; If the `:enable-insecure-register` flag is set, we proceed
:else ;; to sign in the user directly, without email verification.
(do (true? is-active)
(send-email-verification! conn sprops profile) (with-meta (profile/strip-private-attrs profile)
(with-meta profile {: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)})
;; 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/def ::register-profile
(s/keys :req-un [::token ::fullname])) (s/keys :req-un [::token ::fullname]))

View file

@ -10,14 +10,13 @@
[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.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]
[app.tokens :as tokens] [app.tokens :as tokens]
[app.rpc.doc :as-alias doc]
[app.tokens.spec.team-invitation :as-alias spec.team-invitation] [app.tokens.spec.team-invitation :as-alias spec.team-invitation]
[app.util.services :as sv] [app.util.services :as sv]
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]))
[cuerdas.core :as str]))
(s/def ::iss keyword?) (s/def ::iss keyword?)
(s/def ::exp ::us/inst) (s/def ::exp ::us/inst)

View file

@ -7,9 +7,9 @@
(ns app.rpc.mutations.verify-token (ns app.rpc.mutations.verify-token
(:require (:require
[app.db :as db] [app.db :as db]
[app.tokens :as tokens]
[app.rpc.doc :as-alias doc]
[app.rpc.commands.verify-token :refer [process-token]] [app.rpc.commands.verify-token :refer [process-token]]
[app.rpc.doc :as-alias doc]
[app.tokens :as tokens]
[app.util.services :as sv] [app.util.services :as sv]
[clojure.spec.alpha :as s])) [clojure.spec.alpha :as s]))