diff --git a/resources/db/migration/V1.2.0.3__remove_invalid_reports.sql b/resources/db/migration/V1.2.0.3__remove_invalid_reports.sql new file mode 100644 index 0000000..170c6dd --- /dev/null +++ b/resources/db/migration/V1.2.0.3__remove_invalid_reports.sql @@ -0,0 +1,5 @@ +-- delete reports without email +delete from bug_reports where email is null or email = ''; + +-- Update schnelltestportal bug receivers +update operators set bug_reports_receiver = 'center' where operator_number = 'cwa-schnelltestportal'; \ No newline at end of file diff --git a/src/repositories/operators.go b/src/repositories/operators.go index 55d9455..13652cb 100644 --- a/src/repositories/operators.go +++ b/src/repositories/operators.go @@ -76,24 +76,26 @@ func (r *operatorsRepository) GetOrCreateByToken(ctx context.Context, token jwt. name = entry.(string) } - operatorNumber := "" + var operatorNumber *string if entry, ok := token.Get("preferred_username"); ok { - operatorNumber = entry.(string) + tmp := entry.(string) + operatorNumber = &tmp } - email := "" + var email *string if entry, ok := token.Get("email"); ok { - email = entry.(string) + tmp := entry.(string) + email = &tmp } receiver := domain.ReportReceiverOperator return r.Save(ctx, domain.Operator{ UUID: id.String(), - OperatorNumber: &operatorNumber, + OperatorNumber: operatorNumber, Name: name, Subject: &subject, BugReportsReceiver: &receiver, - Email: &email, + Email: email, }) } return operator, nil diff --git a/src/services/bugreports.go b/src/services/bugreports.go index 3865e10..88be645 100644 --- a/src/services/bugreports.go +++ b/src/services/bugreports.go @@ -1,6 +1,7 @@ package services import ( + "com.t-systems-mms.cwa/core/util" "com.t-systems-mms.cwa/domain" "com.t-systems-mms.cwa/repositories" "context" @@ -71,12 +72,16 @@ func (s *bugReportsService) CreateBugReport(ctx context.Context, centerUUID, sub return domain.BugReport{}, err } - email := center.Operator.Email + var email *string if center.Operator.BugReportsReceiver != nil && *center.Operator.BugReportsReceiver == "center" { email = center.Email } - if email == nil { + if util.IsNilOrEmpty(email) { + email = center.Operator.Email + } + + if util.IsNilOrEmpty(email) { if value, err := s.settingsRepository.FindValue(ctx, ConfigDefaultReportsEmail); err != nil { logrus.WithError(err).WithField("key", ConfigDefaultReportsEmail).Error("Error getting config value") return domain.BugReport{}, errors.New("invalid config")