Skip to content

Commit

Permalink
add correct membership info to event log
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan0xC committed Jan 27, 2025
1 parent 3d6f9cf commit a7ef547
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/api/core/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ async fn _log_user_event(
ip: &IpAddr,
conn: &mut DbConn,
) {
let orgs = Membership::get_orgs_by_user(user_id, conn).await;
let mut events: Vec<Event> = Vec::with_capacity(orgs.len() + 1); // We need an event per org and one without an org
let memberships = Membership::find_by_user(user_id, conn).await;
let mut events: Vec<Event> = Vec::with_capacity(memberships.len() + 1); // We need an event per org and one without an org

// Upstream saves the event also without any org_id.
let mut event = Event::new(event_type, event_date);
Expand All @@ -257,10 +257,11 @@ async fn _log_user_event(
events.push(event);

// For each org a user is a member of store these events per org
for org_id in orgs {
for membership in memberships {
let mut event = Event::new(event_type, event_date);
event.user_uuid = Some(user_id.clone());
event.org_uuid = Some(org_id);
event.org_uuid = Some(membership.org_uuid);
event.org_user_uuid = Some(membership.uuid);
event.act_user_uuid = Some(user_id.clone());
event.device_type = Some(device_type);
event.ip_address = Some(ip.to_string());
Expand Down

0 comments on commit a7ef547

Please sign in to comment.