mirror of
https://github.com/netbirdio/netbird.git
synced 2025-05-02 07:14:48 +02:00
Display peers of a user that it has access to (#571)
If a user has a non-admin role, display all peers that user's peers have access to when calling /peers endpoint of the HTTP API.
This commit is contained in:
parent
e965d6c022
commit
8b0a1bbae0
@ -106,13 +106,29 @@ func (am *DefaultAccountManager) GetPeers(accountID, userID string) ([]*Peer, er
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
peers := make([]*Peer, 0, len(account.Peers))
|
peers := make([]*Peer, 0)
|
||||||
|
peersMap := make(map[string]*Peer)
|
||||||
for _, peer := range account.Peers {
|
for _, peer := range account.Peers {
|
||||||
if !user.IsAdmin() && user.Id != peer.UserID {
|
if !user.IsAdmin() && user.Id != peer.UserID {
|
||||||
// only display peers that belong to the current user if the current user is not an admin
|
// only display peers that belong to the current user if the current user is not an admin
|
||||||
continue
|
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
|
return peers, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user