Skip to content

Commit

Permalink
fix: wrong key in role association
Browse files Browse the repository at this point in the history
fix "unsupported relations: Roles" error when using `unassign-group` on a user

closes moul#329
  • Loading branch information
korween authored and libvoid committed Jul 17, 2023
1 parent c436462 commit b85e3e8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/bastion/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -1874,12 +1874,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
}
Expand All @@ -1894,12 +1897,15 @@ GLOBAL OPTIONS:
tx.Rollback()
return err
}
if err := model.Association("Roles").Append(&appendRoles); err != nil {

roles := tx.Model(user).Association("Roles")

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
}
Expand Down

0 comments on commit b85e3e8

Please sign in to comment.