Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
fixed report receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
dreske committed Oct 13, 2021
1 parent 5131014 commit dfdd402
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
5 changes: 5 additions & 0 deletions resources/db/migration/V1.2.0.3__remove_invalid_reports.sql
Original file line number Diff line number Diff line change
@@ -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';
14 changes: 8 additions & 6 deletions src/repositories/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/services/bugreports.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit dfdd402

Please sign in to comment.