mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 00:45:19 +00:00
Allow users to be readded if they were ever removed (#1945)
* Allow users to be readded if they were ever removed * Address review comment * lint
This commit is contained in:
parent
a64023a5af
commit
a6acb1cd1a
1
changes/issue-1941-allow-readd-users
Normal file
1
changes/issue-1941-allow-readd-users
Normal file
@ -0,0 +1 @@
|
||||
* Allow host users to be readded.
|
@ -1,4 +1,5 @@
|
||||
//+build !windows
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package constant
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
//+build !windows
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package platform
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package update
|
||||
|
@ -1,3 +1,4 @@
|
||||
//go:build !full
|
||||
// +build !full
|
||||
|
||||
package bindata
|
||||
|
@ -863,7 +863,7 @@ func (d *Datastore) SaveHostUsers(host *fleet.Host) error {
|
||||
|
||||
insertValues := strings.TrimSuffix(strings.Repeat("(?, ?, ?, ?, ?),", len(host.Users)), ",")
|
||||
insertSql := fmt.Sprintf(
|
||||
`INSERT IGNORE INTO host_users (host_id, uid, username, user_type, groupname) VALUES %s`,
|
||||
`INSERT INTO host_users (host_id, uid, username, user_type, groupname) VALUES %s ON DUPLICATE KEY UPDATE removed_at=NULL`,
|
||||
insertValues,
|
||||
)
|
||||
if _, err := d.writer.Exec(insertSql, insertArgs...); err != nil {
|
||||
|
@ -1340,6 +1340,18 @@ func TestSaveUsers(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
require.Len(t, host.Users, 1)
|
||||
assert.Equal(t, host.Users[0].Uid, u2.Uid)
|
||||
|
||||
// readd u1
|
||||
host.Users = []fleet.HostUser{u1, u2}
|
||||
host.Modified = true
|
||||
|
||||
err = ds.SaveHost(host)
|
||||
require.Nil(t, err)
|
||||
|
||||
host, err = ds.Host(host.ID)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, host.Users, 2)
|
||||
test.ElementsMatchSkipID(t, host.Users, []fleet.HostUser{u1, u2})
|
||||
}
|
||||
|
||||
func TestSaveUsersWithoutUid(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user