mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-20 01:06:45 +00:00
fix tests
This commit is contained in:
@@ -87,7 +87,7 @@ type Account struct {
|
||||
Peers map[string]*nbpeer.Peer `gorm:"-"`
|
||||
PeersG []nbpeer.Peer `json:"-" gorm:"foreignKey:AccountID;references:id"`
|
||||
Users map[string]*User `gorm:"-"`
|
||||
UsersG []User `json:"-" gorm:"foreignKey:AccountID;references:id"`
|
||||
UsersG []*User `json:"-" gorm:"foreignKey:AccountID;references:id"`
|
||||
Groups map[string]*Group `gorm:"-"`
|
||||
GroupsG []*Group `json:"-" gorm:"foreignKey:AccountID;references:id"`
|
||||
Policies []*Policy `gorm:"foreignKey:AccountID;references:id"`
|
||||
|
||||
@@ -28,7 +28,6 @@ type Group struct {
|
||||
// Peers list of the group
|
||||
Peers []string `gorm:"-"` // Peers and GroupPeers list will be ignored when writing to the DB. Use AddPeerToGroup and RemovePeerFromGroup methods to modify group membership
|
||||
GroupPeers []GroupPeer `gorm:"foreignKey:GroupID;references:id;constraint:OnDelete:CASCADE;"`
|
||||
Users []string `gorm:"-"`
|
||||
GroupUsers []GroupUser `gorm:"foreignKey:GroupID;references:id;constraint:OnDelete:CASCADE;"`
|
||||
|
||||
// Resources contains a list of resources in that group
|
||||
@@ -69,26 +68,6 @@ func (g *Group) StoreGroupPeers() {
|
||||
g.Peers = []string{}
|
||||
}
|
||||
|
||||
func (g *Group) LoadGroupUsers() {
|
||||
g.Users = make([]string, len(g.GroupUsers))
|
||||
for i, user := range g.GroupUsers {
|
||||
g.Users[i] = user.UserID
|
||||
}
|
||||
g.GroupUsers = []GroupUser{}
|
||||
}
|
||||
|
||||
func (g *Group) StoreGroupUsers() {
|
||||
g.GroupUsers = make([]GroupUser, len(g.Users))
|
||||
for i, user := range g.Users {
|
||||
g.GroupUsers[i] = GroupUser{
|
||||
AccountID: g.AccountID,
|
||||
GroupID: g.ID,
|
||||
UserID: user,
|
||||
}
|
||||
}
|
||||
g.Users = []string{}
|
||||
}
|
||||
|
||||
// EventMeta returns activity event meta related to the group
|
||||
func (g *Group) EventMeta() map[string]any {
|
||||
return map[string]any{"name": g.Name}
|
||||
@@ -99,21 +78,41 @@ func (g *Group) EventMetaResource(resource *types.NetworkResource) map[string]an
|
||||
}
|
||||
|
||||
func (g *Group) Copy() *Group {
|
||||
var peers []string
|
||||
if g.Peers != nil {
|
||||
peers = make([]string, len(g.Peers))
|
||||
copy(peers, g.Peers)
|
||||
}
|
||||
|
||||
var groupPeers []GroupPeer
|
||||
if g.GroupPeers != nil {
|
||||
groupPeers = make([]GroupPeer, len(g.GroupPeers))
|
||||
copy(groupPeers, g.GroupPeers)
|
||||
}
|
||||
|
||||
var groupUsers []GroupUser
|
||||
if g.GroupUsers != nil {
|
||||
groupUsers = make([]GroupUser, len(g.GroupUsers))
|
||||
copy(groupUsers, g.GroupUsers)
|
||||
}
|
||||
|
||||
var resources []Resource
|
||||
if g.Resources != nil {
|
||||
resources = make([]Resource, len(g.Resources))
|
||||
copy(resources, g.Resources)
|
||||
}
|
||||
|
||||
group := &Group{
|
||||
ID: g.ID,
|
||||
AccountID: g.AccountID,
|
||||
Name: g.Name,
|
||||
Issued: g.Issued,
|
||||
Peers: make([]string, len(g.Peers)),
|
||||
GroupPeers: make([]GroupPeer, len(g.GroupPeers)),
|
||||
GroupUsers: make([]GroupUser, len(g.GroupUsers)),
|
||||
Resources: make([]Resource, len(g.Resources)),
|
||||
Peers: peers,
|
||||
GroupPeers: groupPeers,
|
||||
GroupUsers: groupUsers,
|
||||
Resources: resources,
|
||||
IntegrationReference: g.IntegrationReference,
|
||||
}
|
||||
copy(group.Peers, g.Peers)
|
||||
copy(group.GroupPeers, g.GroupPeers)
|
||||
copy(group.GroupUsers, g.GroupUsers)
|
||||
copy(group.Resources, g.Resources)
|
||||
return group
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,7 @@ func (u *User) LoadAutoGroups() {
|
||||
for _, group := range u.Groups {
|
||||
u.AutoGroups = append(u.AutoGroups, group.GroupID)
|
||||
}
|
||||
u.Groups = []*GroupUser{}
|
||||
}
|
||||
|
||||
func (u *User) StoreAutoGroups() {
|
||||
@@ -124,6 +125,7 @@ func (u *User) StoreAutoGroups() {
|
||||
UserID: u.Id,
|
||||
})
|
||||
}
|
||||
u.AutoGroups = []string{}
|
||||
}
|
||||
|
||||
// IsBlocked returns true if the user is blocked, false otherwise
|
||||
@@ -218,10 +220,16 @@ func (u *User) ToUserInfo(userData *idp.UserData) (*UserInfo, error) {
|
||||
|
||||
// Copy the user
|
||||
func (u *User) Copy() *User {
|
||||
groupUsers := make([]*GroupUser, len(u.Groups))
|
||||
copy(groupUsers, u.Groups)
|
||||
autoGroups := make([]string, len(u.AutoGroups))
|
||||
copy(autoGroups, u.AutoGroups)
|
||||
var groupUsers []*GroupUser
|
||||
if u.Groups != nil {
|
||||
groupUsers = make([]*GroupUser, len(u.Groups))
|
||||
copy(groupUsers, u.Groups)
|
||||
}
|
||||
var autoGroups []string
|
||||
if u.AutoGroups != nil {
|
||||
autoGroups = make([]string, len(u.AutoGroups))
|
||||
copy(autoGroups, u.AutoGroups)
|
||||
}
|
||||
|
||||
pats := make(map[string]*PersonalAccessToken, len(u.PATs))
|
||||
for k, v := range u.PATs {
|
||||
|
||||
Reference in New Issue
Block a user