INFRA-3437|Amit|Add resolve restriction (#435)
* INFRA-3437|Amit|Add resolve restriction * INFRA-3437|Amit|Add resolve restriction * INFRA-3437|Amit|Add resolve restriction * INFRA-3437|Amit|Add resolve restriction * INFRA-3437|Amit|Add resolve restriction
This commit is contained in:
@@ -18,6 +18,7 @@ type TeamDTO struct {
|
||||
}
|
||||
|
||||
type TeamSeverityUpdateRule struct {
|
||||
Strategy []string `json:"strategy"`
|
||||
AllowedUserIds []string `json:"allowed_user_ids"`
|
||||
Strategy []string `json:"strategy"`
|
||||
AllowedUserIdsForSeverityChange []string `json:"allowed_user_ids_severity"`
|
||||
AllowedUserIdsForResolve []string `json:"allowed_user_ids_resolve"`
|
||||
}
|
||||
|
||||
@@ -1440,7 +1440,7 @@ func (i *IncidentServiceV2) UpdateSeverityId(
|
||||
|
||||
func isValidRequestForUpdateSeverity(teamSeverityUpdateRule team.TeamSeverityUpdateRule, reportingTeam team.TeamEntity, userDTO *user.UserDTO) bool {
|
||||
strategy := teamSeverityUpdateRule.Strategy
|
||||
allowedUserIds := teamSeverityUpdateRule.AllowedUserIds
|
||||
allowedUserIds := teamSeverityUpdateRule.AllowedUserIdsForSeverityChange
|
||||
if (strategy != nil && len(strategy) > 0) || (allowedUserIds != nil && len(allowedUserIds) > 0) {
|
||||
if strategy != nil && len(strategy) > 0 && slices.Contains(strategy, "REPORTER") && stringUtil.StringInList(reportingTeam.SlackUserIds, userDTO.SlackUserId) {
|
||||
return true
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
package impl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/lib/pq"
|
||||
"github.com/slack-go/slack"
|
||||
"github.com/spf13/viper"
|
||||
"go.uber.org/zap"
|
||||
"golang.org/x/exp/slices"
|
||||
"houston/common"
|
||||
"houston/common/metrics"
|
||||
tagUtil "houston/common/tag"
|
||||
"houston/common/util"
|
||||
houstonSlackUtil "houston/common/util/slack"
|
||||
stringUtil "houston/common/util/string"
|
||||
"houston/logger"
|
||||
"houston/model/customErrors"
|
||||
"houston/model/incident"
|
||||
tagModel "houston/model/tag"
|
||||
"houston/model/team"
|
||||
"houston/model/user"
|
||||
rcaService "houston/service/rca/impl"
|
||||
service "houston/service/request"
|
||||
utils "houston/service/utils"
|
||||
@@ -207,6 +212,10 @@ func (i *IncidentServiceV2) ExecuteIncidentResolveFlow(
|
||||
requestType string,
|
||||
) error {
|
||||
logger.Info(fmt.Sprintf("%s Recevied request to execute incident resolve flow: %v", resolveLogTag, request))
|
||||
err := i.evaluateIncidentResolveRestriction(incidentEntity, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rcaTags, err := i.getTagsAsMap(request)
|
||||
if err != nil {
|
||||
@@ -292,6 +301,48 @@ func (i *IncidentServiceV2) ExecuteIncidentResolveFlow(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *IncidentServiceV2) evaluateIncidentResolveRestriction(incidentEntity *incident.IncidentEntity, userID string) error {
|
||||
reportingTeam := incidentEntity.ReportingTeam
|
||||
var teamSeverityUpdateRule team.TeamSeverityUpdateRule
|
||||
var err = json.Unmarshal(reportingTeam.TeamSeverityUpdateRule, &teamSeverityUpdateRule)
|
||||
if err == nil {
|
||||
userEntity, err := i.userRepository.FindHoustonUserBySlackUserId(userID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("%s resolve inclident update failure", resolveLogTag), zap.Error(err))
|
||||
return fmt.Errorf("%s user not found", userID)
|
||||
}
|
||||
if !isValidRequestForResolve(teamSeverityUpdateRule, reportingTeam, userEntity.ToDTO()) {
|
||||
_, err := i.slackService.PostMessageByChannelID("`Please ask team who created the incident to resolve or ask department head`", false, incidentEntity.SlackChannel)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("%s resolve inclident not allowed", resolveLogTag), zap.Error(err))
|
||||
}
|
||||
return fmt.Errorf("Please ask team who created the incident to resolve or ask department head")
|
||||
}
|
||||
} else {
|
||||
logger.Error(fmt.Sprintf("%s resolve inclident update failure", resolveLogTag), zap.Error(err))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func isValidRequestForResolve(teamSeverityUpdateRule team.TeamSeverityUpdateRule, reportingTeam team.TeamEntity, userDTO *user.UserDTO) bool {
|
||||
strategy := teamSeverityUpdateRule.Strategy
|
||||
allowedUserIds := teamSeverityUpdateRule.AllowedUserIdsForResolve
|
||||
hasValidStrategy := strategy != nil && len(strategy) > 0
|
||||
if hasValidStrategy || (allowedUserIds != nil && len(allowedUserIds) > 0) {
|
||||
if hasValidStrategy && slices.Contains(strategy, "RESOLVE_REPORTING_TEAM") && stringUtil.StringInList(reportingTeam.SlackUserIds, userDTO.SlackUserId) {
|
||||
return true
|
||||
}
|
||||
|
||||
if allowedUserIds != nil && len(allowedUserIds) > 0 && stringUtil.StringInList(allowedUserIds, strconv.FormatUint(uint64(userDTO.ID), 10)) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
}
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
func (i *IncidentServiceV2) processTagDetailsFlow(incidentId uint, rcaTags map[string]tagUtil.TagMapValue) error {
|
||||
incidentTagsEntity, err := i.incidentRepository.GetIncidentTagsByIncidentId(incidentId)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user