mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-02 19:49:07 +02:00
Remove duplicate UserJoined events from the response
This commit is contained in:
@@ -853,6 +853,17 @@ func (am *DefaultAccountManager) redeemInvite(account *Account, userID string) e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debugf("user %s of account %s redeemed invite", user.ID, account.Id)
|
log.Debugf("user %s of account %s redeemed invite", user.ID, account.Id)
|
||||||
|
_, err = am.eventStore.Save(&activity.Event{
|
||||||
|
Timestamp: time.Now(),
|
||||||
|
Activity: activity.UserJoined,
|
||||||
|
AccountID: account.Id,
|
||||||
|
TargetID: userID,
|
||||||
|
InitiatorID: userID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("failed saving activity event %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,33 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import "github.com/netbirdio/netbird/management/server/activity"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/netbirdio/netbird/management/server/activity"
|
||||||
|
)
|
||||||
|
|
||||||
// GetEvents returns a list of activity events of an account
|
// GetEvents returns a list of activity events of an account
|
||||||
func (am *DefaultAccountManager) GetEvents(accountID, userID string) ([]*activity.Event, error) {
|
func (am *DefaultAccountManager) GetEvents(accountID, userID string) ([]*activity.Event, error) {
|
||||||
return am.eventStore.Get(accountID, 0, 1000, true)
|
events, err := am.eventStore.Get(accountID, 0, 10000, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is a workaround for duplicate activity.UserJoined events that might occur when a user redeems invite.
|
||||||
|
// we will need to find a better way to handle this.
|
||||||
|
filtered := make([]*activity.Event, 0)
|
||||||
|
dups := make(map[string]struct{})
|
||||||
|
for _, event := range events {
|
||||||
|
if event.Activity == activity.UserJoined {
|
||||||
|
key := event.TargetID + event.InitiatorID + event.AccountID + fmt.Sprint(event.Activity)
|
||||||
|
_, duplicate := dups[key]
|
||||||
|
if duplicate {
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
dups[key] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filtered = append(filtered, event)
|
||||||
|
}
|
||||||
|
|
||||||
|
return filtered, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user