From 49a52c48984513f46187d42215a9aec7a50f01ba Mon Sep 17 00:00:00 2001 From: korween Date: Mon, 25 Apr 2022 22:11:11 +0200 Subject: [PATCH] fix: "unsupported relations: Roles" when using `unassign-group` on a user https://github.com/moul/sshportal/issues/329 --- pkg/bastion/shell.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/bastion/shell.go b/pkg/bastion/shell.go index 012c5f998..d1b874ba3 100644 --- a/pkg/bastion/shell.go +++ b/pkg/bastion/shell.go @@ -1955,12 +1955,15 @@ GLOBAL OPTIONS: tx.Rollback() return err } - if err := model.Association("Groups").Append(&appendGroups); err != nil { + + groups := tx.Model(user).Association("Groups") + + if err := groups.Append(&appendGroups); err != nil { tx.Rollback() return err } if len(deleteGroups) > 0 { - if err := model.Association("Groups").Delete(deleteGroups); err != nil { + if err := groups.Delete(deleteGroups); err != nil { tx.Rollback() return err } @@ -1975,12 +1978,15 @@ GLOBAL OPTIONS: tx.Rollback() return err } - if err := model.Association("Roles").Append(&appendRoles); err != nil { + + roles := tx.Model(user).Association("Groups") + + if err := roles.Append(&appendRoles); err != nil { tx.Rollback() return err } if len(deleteRoles) > 0 { - if err := model.Association("Roles").Delete(deleteRoles); err != nil { + if err := roles.Delete(deleteRoles); err != nil { tx.Rollback() return err }