From b06e34f144c367a64b7e1eabb3d4a77ef68f8ad5 Mon Sep 17 00:00:00 2001 From: Ward Vandewege Date: Sun, 17 Oct 2021 11:29:03 -0400 Subject: [PATCH] Bugfix: the check to see if a node was already shared into a namespace was incorrect. --- sharing.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sharing.go b/sharing.go index 83ce526..2905c8e 100644 --- a/sharing.go +++ b/sharing.go @@ -21,12 +21,15 @@ func (h *Headscale) AddSharedMachineToNamespace(m *Machine, ns *Namespace) error return errorSameNamespace } - sharedMachine := SharedMachine{} - if err := h.db.Where("machine_id = ? AND namespace_id", m.ID, ns.ID).First(&sharedMachine).Error; err == nil { + sharedMachines := []SharedMachine{} + if err := h.db.Where("machine_id = ? AND namespace_id = ?", m.ID, ns.ID).Find(&sharedMachines).Error; err != nil { + return err + } + if len(sharedMachines) > 0 { return errorMachineAlreadyShared } - sharedMachine = SharedMachine{ + sharedMachine := SharedMachine{ MachineID: m.ID, Machine: *m, NamespaceID: ns.ID,