Calendar config API endpoints bug fixes. (#17640)

Bug fixes for frontend
- google_calendar can be nil for global config to indicate that it
should not change
- `fleet/teams/:id` endpoint now working
This commit is contained in:
Victor Lyuboslavsky 2024-03-14 15:01:52 -05:00 committed by Victor Lyuboslavsky
parent c9b917a491
commit d3e1716572
No known key found for this signature in database
3 changed files with 28 additions and 0 deletions

View File

@ -209,6 +209,15 @@ func (svc *Service) ModifyTeam(ctx context.Context, teamID uint, payload fleet.T
team.Config.Integrations.Jira = payload.Integrations.Jira team.Config.Integrations.Jira = payload.Integrations.Jira
team.Config.Integrations.Zendesk = payload.Integrations.Zendesk team.Config.Integrations.Zendesk = payload.Integrations.Zendesk
// Only update the google calendar integration if it's not nil
if payload.Integrations.GoogleCalendar != nil {
invalid := &fleet.InvalidArgumentError{}
_ = svc.validateTeamCalendarIntegrations(ctx, team, payload.Integrations.GoogleCalendar, appCfg, invalid)
if invalid.HasErrors() {
return nil, ctxerr.Wrap(ctx, invalid)
}
team.Config.Integrations.GoogleCalendar = payload.Integrations.GoogleCalendar
}
} }
if payload.WebhookSettings != nil || payload.Integrations != nil { if payload.WebhookSettings != nil || payload.Integrations != nil {

View File

@ -478,6 +478,10 @@ func (svc *Service) ModifyAppConfig(ctx context.Context, p []byte, applyOpts fle
} }
} }
} }
// If google_calendar is null, we keep the existing setting. If it's not null, we update.
if newAppConfig.Integrations.GoogleCalendar == nil {
appConfig.Integrations.GoogleCalendar = oldAppConfig.Integrations.GoogleCalendar
}
if !license.IsPremium() { if !license.IsPremium() {
// reset transparency url to empty for downgraded licenses // reset transparency url to empty for downgraded licenses

View File

@ -1029,6 +1029,21 @@ func (s *integrationEnterpriseTestSuite) TestTeamEndpoints() {
modifyExpiry.HostExpirySettings.HostExpiryWindow = 0 modifyExpiry.HostExpirySettings.HostExpiryWindow = 0
s.DoJSON("PATCH", fmt.Sprintf("/api/latest/fleet/teams/%d", tm1ID), modifyExpiry, http.StatusUnprocessableEntity, &tmResp) s.DoJSON("PATCH", fmt.Sprintf("/api/latest/fleet/teams/%d", tm1ID), modifyExpiry, http.StatusUnprocessableEntity, &tmResp)
// Modify team's calendar config
modifyCalendar := fleet.TeamPayload{
Integrations: &fleet.TeamIntegrations{
GoogleCalendar: &fleet.TeamGoogleCalendarIntegration{
Email: "calendar@example.com",
},
},
}
s.DoJSON("PATCH", fmt.Sprintf("/api/latest/fleet/teams/%d", tm1ID), modifyCalendar, http.StatusOK, &tmResp)
assert.Equal(t, modifyCalendar.Integrations.GoogleCalendar, tmResp.Team.Config.Integrations.GoogleCalendar)
// Illegal team calendar config
modifyCalendar.Integrations.GoogleCalendar.Enable = true
s.DoJSON("PATCH", fmt.Sprintf("/api/latest/fleet/teams/%d", tm1ID), modifyCalendar, http.StatusUnprocessableEntity, &tmResp)
// list team users // list team users
var usersResp listUsersResponse var usersResp listUsersResponse
s.DoJSON("GET", fmt.Sprintf("/api/latest/fleet/teams/%d/users", tm1ID), nil, http.StatusOK, &usersResp) s.DoJSON("GET", fmt.Sprintf("/api/latest/fleet/teams/%d/users", tm1ID), nil, http.StatusOK, &usersResp)