mirror of
https://github.com/penpot/penpot.git
synced 2025-05-11 09:46:38 +02:00
✨ Add some improvements to the auditlog module.
This commit is contained in:
parent
09d1c958ce
commit
1b69eda43e
6 changed files with 48 additions and 22 deletions
|
@ -270,8 +270,9 @@
|
||||||
::tenant]))
|
::tenant]))
|
||||||
|
|
||||||
(defn- parse-flags
|
(defn- parse-flags
|
||||||
[{:keys [flags]}]
|
[config]
|
||||||
(flags/parse flags flags/default))
|
(-> (:flags config)
|
||||||
|
(flags/parse flags/default)))
|
||||||
|
|
||||||
(defn read-env
|
(defn read-env
|
||||||
[prefix]
|
[prefix]
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
[profile]
|
[profile]
|
||||||
(-> profile
|
(-> profile
|
||||||
(select-keys [:is-active :is-muted :auth-backend :email :default-team-id :default-project-id :fullname :lang])
|
(select-keys [:is-active :is-muted :auth-backend :email :default-team-id :default-project-id :fullname :lang])
|
||||||
|
(merge (:props profile))
|
||||||
(d/without-nils)))
|
(d/without-nils)))
|
||||||
|
|
||||||
(defn clean-props
|
(defn clean-props
|
||||||
|
|
|
@ -119,7 +119,8 @@
|
||||||
(::audit/profile-id resultm))
|
(::audit/profile-id resultm))
|
||||||
props (d/merge params' (::audit/props resultm))]
|
props (d/merge params' (::audit/props resultm))]
|
||||||
(audit :cmd :submit
|
(audit :cmd :submit
|
||||||
:type (::type cfg)
|
:type (or (::audit/type resultm)
|
||||||
|
(::type cfg))
|
||||||
:name (or (::audit/name resultm)
|
:name (or (::audit/name resultm)
|
||||||
(::sv/name mdata))
|
(::sv/name mdata))
|
||||||
:profile-id profile-id
|
:profile-id profile-id
|
||||||
|
|
|
@ -197,7 +197,6 @@
|
||||||
ptoken (tokens :generate-predefined
|
ptoken (tokens :generate-predefined
|
||||||
{:iss :profile-identity
|
{:iss :profile-identity
|
||||||
:profile-id (:id profile)})]
|
:profile-id (:id profile)})]
|
||||||
|
|
||||||
(eml/send! {::eml/conn conn
|
(eml/send! {::eml/conn conn
|
||||||
::eml/factory eml/register
|
::eml/factory eml/register
|
||||||
:public-uri (:public-uri cfg)
|
:public-uri (:public-uri cfg)
|
||||||
|
@ -351,11 +350,14 @@
|
||||||
|
|
||||||
(defn- update-profile
|
(defn- update-profile
|
||||||
[conn {:keys [id fullname lang theme] :as params}]
|
[conn {:keys [id fullname lang theme] :as params}]
|
||||||
(db/update! conn :profile
|
(let [profile (db/update! conn :profile
|
||||||
{:fullname fullname
|
{:fullname fullname
|
||||||
:lang lang
|
:lang lang
|
||||||
:theme theme}
|
:theme theme}
|
||||||
{:id id}))
|
{:id id})]
|
||||||
|
(-> profile
|
||||||
|
(profile/decode-profile-row)
|
||||||
|
(profile/strip-private-attrs))))
|
||||||
|
|
||||||
(s/def ::update-profile
|
(s/def ::update-profile
|
||||||
(s/keys :req-un [::id ::fullname]
|
(s/keys :req-un [::id ::fullname]
|
||||||
|
@ -364,8 +366,9 @@
|
||||||
(sv/defmethod ::update-profile
|
(sv/defmethod ::update-profile
|
||||||
[{:keys [pool] :as cfg} params]
|
[{:keys [pool] :as cfg} params]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(update-profile conn params)
|
(let [profile (update-profile conn params)]
|
||||||
nil))
|
(with-meta profile
|
||||||
|
{::audit/props (audit/profile->props profile)}))))
|
||||||
|
|
||||||
;; --- MUTATION: Update Password
|
;; --- MUTATION: Update Password
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
|
[app.loggers.audit :as audit]
|
||||||
[app.metrics :as mtx]
|
[app.metrics :as mtx]
|
||||||
[app.rpc.mutations.teams :as teams]
|
[app.rpc.mutations.teams :as teams]
|
||||||
[app.rpc.queries.profile :as profile]
|
[app.rpc.queries.profile :as profile]
|
||||||
|
@ -63,7 +64,10 @@
|
||||||
|
|
||||||
(with-meta claims
|
(with-meta claims
|
||||||
{:transform-response ((:create session) profile-id)
|
{:transform-response ((:create session) profile-id)
|
||||||
:before-complete (annotate-profile-activation metrics)})))
|
:before-complete (annotate-profile-activation metrics)
|
||||||
|
::audit/name "verify-profile-email"
|
||||||
|
::audit/props (audit/profile->props profile)
|
||||||
|
::audit/profile-id (:id profile)})))
|
||||||
|
|
||||||
(defmethod process-token :auth
|
(defmethod process-token :auth
|
||||||
[{:keys [conn] :as cfg} _params {:keys [profile-id] :as claims}]
|
[{:keys [conn] :as cfg} _params {:keys [profile-id] :as claims}]
|
||||||
|
@ -116,8 +120,7 @@
|
||||||
;; user is already logged in with some account.
|
;; user is already logged in with some account.
|
||||||
(and (uuid? profile-id)
|
(and (uuid? profile-id)
|
||||||
(uuid? member-id))
|
(uuid? member-id))
|
||||||
(do
|
(let [profile (accept-invitation cfg claims)]
|
||||||
(accept-invitation cfg claims)
|
|
||||||
(if (= member-id profile-id)
|
(if (= member-id profile-id)
|
||||||
;; If the current session is already matches the invited
|
;; If the current session is already matches the invited
|
||||||
;; member, then just return the token and leave the frontend
|
;; member, then just return the token and leave the frontend
|
||||||
|
@ -131,27 +134,44 @@
|
||||||
;; account.
|
;; account.
|
||||||
(with-meta
|
(with-meta
|
||||||
(assoc claims :state :created)
|
(assoc claims :state :created)
|
||||||
{:transform-response ((:create session) member-id)})))
|
{:transform-response ((:create session) member-id)
|
||||||
|
::audit/name "accept-team-invitation"
|
||||||
|
::audit/props (merge
|
||||||
|
(audit/profile->props profile)
|
||||||
|
{:team-id (:team-id claims)
|
||||||
|
:role (:role claims)})
|
||||||
|
::audit/profile-id profile-id})))
|
||||||
|
|
||||||
;; This happens when member-id is not filled in the invitation but
|
;; This happens when member-id is not filled in the invitation but
|
||||||
;; the user already has an account (probably with other mail) and
|
;; the user already has an account (probably with other mail) and
|
||||||
;; is already logged-in.
|
;; is already logged-in.
|
||||||
(and (uuid? profile-id)
|
(and (uuid? profile-id)
|
||||||
(nil? member-id))
|
(nil? member-id))
|
||||||
(do
|
(let [profile (accept-invitation cfg (assoc claims :member-id profile-id))]
|
||||||
(accept-invitation cfg (assoc claims :member-id profile-id))
|
(with-meta
|
||||||
(assoc claims :state :created))
|
(assoc claims :state :created)
|
||||||
|
{::audit/name "accept-team-invitation"
|
||||||
|
::audit/props (merge
|
||||||
|
(audit/profile->props profile)
|
||||||
|
{:team-id (:team-id claims)
|
||||||
|
:role (:role claims)})
|
||||||
|
::audit/profile-id profile-id}))
|
||||||
|
|
||||||
;; This happens when member-id is filled but the accessing user is
|
;; This happens when member-id is filled but the accessing user is
|
||||||
;; not logged-in. In this case we proceed to accept invitation and
|
;; not logged-in. In this case we proceed to accept invitation and
|
||||||
;; leave the user logged-in.
|
;; leave the user logged-in.
|
||||||
(and (nil? profile-id)
|
(and (nil? profile-id)
|
||||||
(uuid? member-id))
|
(uuid? member-id))
|
||||||
(do
|
(let [profile (accept-invitation cfg claims)]
|
||||||
(accept-invitation cfg claims)
|
|
||||||
(with-meta
|
(with-meta
|
||||||
(assoc claims :state :created)
|
(assoc claims :state :created)
|
||||||
{:transform-response ((:create session) member-id)}))
|
{:transform-response ((:create session) member-id)
|
||||||
|
::audit/name "accept-team-invitation"
|
||||||
|
::audit/props (merge
|
||||||
|
(audit/profile->props profile)
|
||||||
|
{:team-id (:team-id claims)
|
||||||
|
:role (:role claims)})
|
||||||
|
::audit/profile-id member-id}))
|
||||||
|
|
||||||
;; In this case, we wait until frontend app redirect user to
|
;; In this case, we wait until frontend app redirect user to
|
||||||
;; registeration page, the user is correctly registered and the
|
;; registeration page, the user is correctly registered and the
|
||||||
|
|
|
@ -89,7 +89,7 @@
|
||||||
|
|
||||||
;; (th/print-result! out)
|
;; (th/print-result! out)
|
||||||
(t/is (nil? (:error out)))
|
(t/is (nil? (:error out)))
|
||||||
(t/is (nil? (:result out)))))
|
(t/is (map? (:result out)))))
|
||||||
|
|
||||||
(t/testing "query profile after update"
|
(t/testing "query profile after update"
|
||||||
(let [data {::th/type :profile
|
(let [data {::th/type :profile
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue