From 14b360d0e5cd26ecf784005da405443d85507901 Mon Sep 17 00:00:00 2001 From: Gullipalli Chetan Kumar Date: Tue, 12 Dec 2023 13:41:24 +0530 Subject: [PATCH] TP-47107| added restriction to not update incident to same status (#318) --- common/util/slack_helpers.go | 8 ++++++++ internal/processor/action/incident_resolve_action.go | 5 ++++- .../processor/action/incident_update_status_action.go | 11 ++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/common/util/slack_helpers.go b/common/util/slack_helpers.go index 47fc068..96477be 100644 --- a/common/util/slack_helpers.go +++ b/common/util/slack_helpers.go @@ -93,3 +93,11 @@ func PostArchivingTimeToIncidentChannel(channelId string, incidentStatus string, _, _, errMessage := client.PostMessage(channelId, msgOption) return errMessage } + +func PostIncidentStatusErrorMessage(status, channelId, userId string, client *socketmode.Client) { + message := fmt.Sprintf("current incident status is already `%s`", status) + _, errMessage := client.PostEphemeral(channelId, userId, slack.MsgOptionText(message, false)) + if errMessage != nil { + logger.Error(fmt.Sprintf("post response failed for channel id %s", channelId), zap.String("message", message), zap.Error(errMessage)) + } +} diff --git a/internal/processor/action/incident_resolve_action.go b/internal/processor/action/incident_resolve_action.go index 18a746b..b8431cc 100644 --- a/internal/processor/action/incident_resolve_action.go +++ b/internal/processor/action/incident_resolve_action.go @@ -45,7 +45,10 @@ func (irp *ResolveIncidentAction) IncidentResolveProcess(callback slack.Interact zap.String("channel", channelId), zap.String("user_id", callback.User.ID), zap.Error(err)) } - + if incidentEntity.Status == incident.ResolvedId { + util.PostIncidentStatusErrorMessage(incident.Resolved, channelId, callback.User.ID, irp.client) + return + } incidentStatusEntity, _ := irp.incidentService.FindIncidentStatusByName(incident.Resolved) //check if active tags are set or else throw error var flag = true diff --git a/internal/processor/action/incident_update_status_action.go b/internal/processor/action/incident_update_status_action.go index 75affd0..2b57220 100644 --- a/internal/processor/action/incident_update_status_action.go +++ b/internal/processor/action/incident_update_status_action.go @@ -82,6 +82,14 @@ func (isp *UpdateIncidentAction) IncidentUpdateStatus(callback slack.Interaction zap.String("user_id", user.ID), zap.Error(err)) return } + var payload interface{} + isp.client.Ack(*request, payload) + + channelId := callback.View.PrivateMetadata + if incidentEntity.Status == result.ID { + util.PostIncidentStatusErrorMessage(result.Name, channelId, callback.User.ID, isp.client) + return + } tags, err := isp.tagService.FindTagsByTeamId(incidentEntity.TeamId) if err != nil || tags == nil { @@ -115,7 +123,6 @@ func (isp *UpdateIncidentAction) IncidentUpdateStatus(callback slack.Interaction } } - incidentEntity.Status = result.ID incidentEntity.UpdatedBy = user.ID @@ -154,8 +161,6 @@ func (isp *UpdateIncidentAction) IncidentUpdateStatus(callback slack.Interaction msgUpdate.ProcessAction(incidentEntity.SlackChannel) }() - var payload interface{} - isp.client.Ack(*request, payload) } func buildUpdateIncidentStatusRequest(blockActions map[string]map[string]slack.BlockAction) uint {