diff --git a/api4/system_test.go b/api4/system_test.go index 9076e2609c..6c4620c254 100644 --- a/api4/system_test.go +++ b/api4/system_test.go @@ -571,6 +571,25 @@ func TestClearServerBusy(t *testing.T) { }) } +func TestGetServerBusy(t *testing.T) { + th := Setup(t).InitBasic() + defer th.TearDown() + + th.App.Srv().Busy.Set(time.Second * 30) + + t.Run("as system user", func(t *testing.T) { + _, resp := th.Client.GetServerBusy() + CheckForbiddenStatus(t, resp) + }) + + t.Run("as system admin", func(t *testing.T) { + sbs, resp := th.SystemAdminClient.GetServerBusy() + expires := time.Unix(sbs.Expires, 0) + CheckNoError(t, resp) + require.Greater(t, expires.Unix(), time.Now().Unix()) + }) +} + func TestGetServerBusyExpires(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() diff --git a/model/client4.go b/model/client4.go index 47a78b0d08..0bdbb9343f 100644 --- a/model/client4.go +++ b/model/client4.go @@ -4752,8 +4752,23 @@ func (c *Client4) ClearServerBusy() (bool, *Response) { return CheckStatusOK(r), BuildResponse(r) } +// GetServerBusy returns the current ServerBusyState including the time when a server marked busy +// will automatically have the flag cleared. +func (c *Client4) GetServerBusy() (*ServerBusyState, *Response) { + r, err := c.DoApiGet(c.GetServerBusyRoute(), "") + if err != nil { + return nil, BuildErrorResponse(r, err) + } + defer closeBody(r) + + sbs := ServerBusyStateFromJson(r.Body) + return sbs, BuildResponse(r) +} + // GetServerBusyExpires returns the time when a server marked busy // will automatically have the flag cleared. +// +// Deprecated: Use GetServerBusy instead. func (c *Client4) GetServerBusyExpires() (*time.Time, *Response) { r, err := c.DoApiGet(c.GetServerBusyRoute(), "") if err != nil {