From bbe0b22a8bc77ba8e178a914eaa97b7f2acbb714 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 13 Dec 2024 11:48:37 +0100 Subject: [PATCH] :bug: Fix unhandled exception on accepting invitation In an interaction with the audit log; happens when an old invitation (with created-by as nil) is accepted. --- backend/src/app/rpc/commands/verify_token.clj | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/backend/src/app/rpc/commands/verify_token.clj b/backend/src/app/rpc/commands/verify_token.clj index d725ceda2..27679536e 100644 --- a/backend/src/app/rpc/commands/verify_token.clj +++ b/backend/src/app/rpc/commands/verify_token.clj @@ -166,23 +166,26 @@ ;; invited team. (let [props {:team-id (:team-id claims) :role (:role claims) - :invitation-id (:id invitation)} + :invitation-id (:id invitation)}] - accept-invitation-event - (-> (audit/event-from-rpc-params params) - (assoc ::audit/name "accept-team-invitation") - (assoc ::audit/props props)) + (audit/submit! + cfg + (-> (audit/event-from-rpc-params params) + (assoc ::audit/name "accept-team-invitation") + (assoc ::audit/props props))) - accept-invitation-from-event - (-> (audit/event-from-rpc-params params) - (assoc ::audit/profile-id (:created-by invitation)) - (assoc ::audit/name "accept-team-invitation-from") - (assoc ::audit/props (assoc props - :profile-id (:id profile) - :email (:email profile))))] - - (audit/submit! cfg accept-invitation-event) - (audit/submit! cfg accept-invitation-from-event) + ;; NOTE: Backward compatibility; old invitations can + ;; have the `created-by` to be nil; so in this case we + ;; don't submit this event to the audit-log + (when-let [created-by (:created-by invitation)] + (audit/submit! + cfg + (-> (audit/event-from-rpc-params params) + (assoc ::audit/profile-id created-by) + (assoc ::audit/name "accept-team-invitation-from") + (assoc ::audit/props (assoc props + :profile-id (:id profile) + :email (:email profile)))))) (accept-invitation cfg claims invitation profile) (assoc claims :state :created))