Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display peers that user has access too in the API #571

Merged
merged 2 commits into from
Nov 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions management/server/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,29 @@ func (am *DefaultAccountManager) GetPeers(accountID, userID string) ([]*Peer, er
return nil, err
}

peers := make([]*Peer, 0, len(account.Peers))
peers := make([]*Peer, 0)
peersMap := make(map[string]*Peer)
for _, peer := range account.Peers {
if !user.IsAdmin() && user.Id != peer.UserID {
// only display peers that belong to the current user if the current user is not an admin
continue
}
peers = append(peers, peer.Copy())
p := peer.Copy()
peers = append(peers, p)
peersMap[peer.Key] = p
}

// fetch all the peers that have access to the user's peers
for _, peer := range peers {
aclPeers := am.getPeersByACL(account, peer.Key)
for _, p := range aclPeers {
peersMap[p.Key] = p
}
}

peers = make([]*Peer, 0, len(peersMap))
for _, peer := range peersMap {
peers = append(peers, peer)
}

return peers, nil
Expand Down