mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Allow to refetch hosts if you are an observer/maintainer for the team for that host (#1649)
This commit is contained in:
parent
d88fac6b76
commit
e8def4af00
3 changed files with 36 additions and 4 deletions
1
changes/issue-1644-refetch-host-in-team
Normal file
1
changes/issue-1644-refetch-host-in-team
Normal file
|
|
@ -0,0 +1 @@
|
|||
* Allow observers and maintainers to refetch a host in a team they belong to.
|
||||
|
|
@ -183,10 +183,6 @@ func (svc Service) AddHostsToTeamByFilter(ctx context.Context, teamID *uint, opt
|
|||
}
|
||||
|
||||
func (svc *Service) RefetchHost(ctx context.Context, id uint) error {
|
||||
if err := svc.authz.Authorize(ctx, &fleet.Host{}, fleet.ActionRead); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
host, err := svc.ds.Host(id)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "find host for refetch")
|
||||
|
|
|
|||
|
|
@ -110,6 +110,41 @@ func TestRefetchHost(t *testing.T) {
|
|||
}
|
||||
|
||||
require.NoError(t, svc.RefetchHost(test.UserContext(test.UserAdmin), host.ID))
|
||||
require.NoError(t, svc.RefetchHost(test.UserContext(test.UserObserver), host.ID))
|
||||
require.NoError(t, svc.RefetchHost(test.UserContext(test.UserMaintainer), host.ID))
|
||||
}
|
||||
|
||||
func TestRefetchHostUserInTeams(t *testing.T) {
|
||||
ds := new(mock.Store)
|
||||
svc := newTestService(ds, nil, nil)
|
||||
|
||||
host := &fleet.Host{ID: 3, TeamID: ptr.Uint(4)}
|
||||
|
||||
ds.HostFunc = func(hid uint) (*fleet.Host, error) {
|
||||
return host, nil
|
||||
}
|
||||
ds.SaveHostFunc = func(host *fleet.Host) error {
|
||||
assert.True(t, host.RefetchRequested)
|
||||
return nil
|
||||
}
|
||||
|
||||
maintainer := &fleet.User{
|
||||
Teams: []fleet.UserTeam{
|
||||
{
|
||||
Team: fleet.Team{ID: 4},
|
||||
Role: fleet.RoleMaintainer,
|
||||
},
|
||||
}}
|
||||
require.NoError(t, svc.RefetchHost(test.UserContext(maintainer), host.ID))
|
||||
|
||||
observer := &fleet.User{
|
||||
Teams: []fleet.UserTeam{
|
||||
{
|
||||
Team: fleet.Team{ID: 4},
|
||||
Role: fleet.RoleObserver,
|
||||
},
|
||||
}}
|
||||
require.NoError(t, svc.RefetchHost(test.UserContext(observer), host.ID))
|
||||
}
|
||||
|
||||
func TestAddHostsToTeamByFilter(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue