mirror of
https://github.com/penpot/penpot.git
synced 2025-08-06 07:38:31 +02:00
♻️ Refactor (minor) of http session code
The rationale behind the refactor: - Make available profile data to other middlewares without the need to access to the database (mainly for error reporting). - Align with codestyle with the rest of internal modules. - Simplify code.
This commit is contained in:
parent
dbe516f725
commit
43ab19f690
10 changed files with 214 additions and 189 deletions
|
@ -13,6 +13,7 @@
|
|||
[app.config :as cf]
|
||||
[app.db :as db]
|
||||
[app.emails :as eml]
|
||||
[app.http.session :as session]
|
||||
[app.loggers.audit :as audit]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.rpc.doc :as-alias doc]
|
||||
|
@ -135,7 +136,7 @@
|
|||
profile)]
|
||||
|
||||
(with-meta response
|
||||
{::rpc/transform-response ((:create session) (:id profile))
|
||||
{::rpc/transform-response (session/create-fn session (:id profile))
|
||||
::audit/props (audit/profile->props profile)
|
||||
::audit/profile-id (:id profile)})))))
|
||||
|
||||
|
@ -162,7 +163,7 @@
|
|||
::doc/added "1.15"}
|
||||
[{:keys [session] :as cfg} _]
|
||||
(with-meta {}
|
||||
{::rpc/transform-response (:delete session)}))
|
||||
{::rpc/transform-response (session/delete-fn session)}))
|
||||
|
||||
;; ---- COMMAND: Recover Profile
|
||||
|
||||
|
@ -403,7 +404,7 @@
|
|||
token (tokens/generate sprops claims)
|
||||
resp {:invitation-token token}]
|
||||
(with-meta resp
|
||||
{::rpc/transform-response ((:create session) (:id profile))
|
||||
{::rpc/transform-response (session/create-fn session (:id profile))
|
||||
::audit/replace-props (audit/profile->props profile)
|
||||
::audit/profile-id (:id profile)}))
|
||||
|
||||
|
@ -412,7 +413,7 @@
|
|||
;; we need to mark this session as logged.
|
||||
(not= "penpot" (:auth-backend profile))
|
||||
(with-meta (profile/strip-private-attrs profile)
|
||||
{::rpc/transform-response ((:create session) (:id profile))
|
||||
{::rpc/transform-response (session/create-fn session (:id profile))
|
||||
::audit/replace-props (audit/profile->props profile)
|
||||
::audit/profile-id (:id profile)})
|
||||
|
||||
|
@ -420,7 +421,7 @@
|
|||
;; to sign in the user directly, without email verification.
|
||||
(true? is-active)
|
||||
(with-meta (profile/strip-private-attrs profile)
|
||||
{::rpc/transform-response ((:create session) (:id profile))
|
||||
{::rpc/transform-response (session/create-fn session (:id profile))
|
||||
::audit/replace-props (audit/profile->props profile)
|
||||
::audit/profile-id (:id profile)})
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
[app.common.exceptions :as ex]
|
||||
[app.common.spec :as us]
|
||||
[app.db :as db]
|
||||
[app.http.session :as session]
|
||||
[app.loggers.audit :as-alias audit]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.rpc.commands.auth :as cmd.auth]
|
||||
|
@ -63,12 +64,12 @@
|
|||
:member-email (:email profile))
|
||||
token (tokens :generate claims)]
|
||||
(with-meta {:invitation-token token}
|
||||
{::rpc/transform-response ((:create session) (:id profile))
|
||||
{::rpc/transform-response (session/create-fn session (:id profile))
|
||||
::audit/props (:props profile)
|
||||
::audit/profile-id (:id profile)}))
|
||||
|
||||
(with-meta profile
|
||||
{::rpc/transform-response ((:create session) (:id profile))
|
||||
{::rpc/transform-response (session/create-fn session (:id profile))
|
||||
::audit/props (:props profile)
|
||||
::audit/profile-id (:id profile)})))))
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
[app.common.exceptions :as ex]
|
||||
[app.common.spec :as us]
|
||||
[app.db :as db]
|
||||
[app.http.session :as session]
|
||||
[app.loggers.audit :as audit]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.rpc.doc :as-alias doc]
|
||||
|
@ -68,7 +69,7 @@
|
|||
{:id (:id profile)}))
|
||||
|
||||
(with-meta claims
|
||||
{::rpc/transform-response ((:create session) profile-id)
|
||||
{::rpc/transform-response (session/create-fn session profile-id)
|
||||
::audit/name "verify-profile-email"
|
||||
::audit/props (audit/profile->props profile)
|
||||
::audit/profile-id (:id profile)})))
|
||||
|
@ -172,7 +173,7 @@
|
|||
(let [profile (accept-invitation cfg claims invitation member)]
|
||||
(with-meta
|
||||
(assoc claims :state :created)
|
||||
{::rpc/transform-response ((:create session) (:id profile))
|
||||
{::rpc/transform-response (session/create-fn session (:id profile))
|
||||
::audit/name "accept-team-invitation"
|
||||
::audit/props (merge
|
||||
(audit/profile->props profile)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue