Skip to content

Commit b06e34f

Browse files
committed
Bugfix: the check to see if a node was already shared into a namespace
was incorrect.
1 parent 9a74722 commit b06e34f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Diff for: sharing.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ func (h *Headscale) AddSharedMachineToNamespace(m *Machine, ns *Namespace) error
2121
return errorSameNamespace
2222
}
2323

24-
sharedMachine := SharedMachine{}
25-
if err := h.db.Where("machine_id = ? AND namespace_id", m.ID, ns.ID).First(&sharedMachine).Error; err == nil {
24+
sharedMachines := []SharedMachine{}
25+
if err := h.db.Where("machine_id = ? AND namespace_id = ?", m.ID, ns.ID).Find(&sharedMachines).Error; err != nil {
26+
return err
27+
}
28+
if len(sharedMachines) > 0 {
2629
return errorMachineAlreadyShared
2730
}
2831

29-
sharedMachine = SharedMachine{
32+
sharedMachine := SharedMachine{
3033
MachineID: m.ID,
3134
Machine: *m,
3235
NamespaceID: ns.ID,

0 commit comments

Comments
 (0)