Skip to content

Commit 361cab8

Browse files
authored
Merge branch 'develop' into build-worker-status
2 parents 0ed86d5 + ae42e7b commit 361cab8

File tree

5 files changed

+51
-59
lines changed

5 files changed

+51
-59
lines changed

pkg/appClone/AppCloneService.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -548,19 +548,24 @@ func (impl *AppCloneServiceImpl) configDataClone(cfData []*bean3.ConfigData) []*
548548
var copiedData []*bean3.ConfigData
549549
for _, refdata := range cfData {
550550
data := &bean3.ConfigData{
551-
Name: refdata.Name,
552-
Type: refdata.Type,
553-
External: refdata.External,
554-
MountPath: refdata.MountPath,
555-
Data: refdata.Data,
556-
DefaultData: refdata.DefaultData,
557-
DefaultMountPath: refdata.DefaultMountPath,
558-
Global: refdata.Global,
559-
ExternalSecretType: refdata.ExternalSecretType,
560-
FilePermission: refdata.FilePermission,
561-
SubPath: refdata.SubPath,
562-
ESOSubPath: refdata.ESOSubPath,
563-
MergeStrategy: refdata.MergeStrategy,
551+
Name: refdata.Name,
552+
Type: refdata.Type,
553+
External: refdata.External,
554+
MountPath: refdata.MountPath,
555+
Data: refdata.Data,
556+
DefaultData: refdata.DefaultData,
557+
DefaultMountPath: refdata.DefaultMountPath,
558+
Global: refdata.Global,
559+
ExternalSecretType: refdata.ExternalSecretType,
560+
FilePermission: refdata.FilePermission,
561+
SubPath: refdata.SubPath,
562+
ESOSubPath: refdata.ESOSubPath,
563+
MergeStrategy: refdata.MergeStrategy,
564+
ESOSecretData: refdata.ESOSecretData,
565+
DefaultESOSecretData: refdata.DefaultESOSecretData,
566+
ExternalSecret: refdata.ExternalSecret,
567+
DefaultExternalSecret: refdata.DefaultExternalSecret,
568+
RoleARN: refdata.RoleARN,
564569
}
565570
copiedData = append(copiedData, data)
566571
}

pkg/notifier/NotificationConfigService.go

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -294,23 +294,14 @@ func (impl *NotificationConfigServiceImpl) BuildNotificationSettingsResponse(not
294294
if config.Providers != nil && len(config.Providers) > 0 {
295295
var slackIds []*int
296296
var webhookIds []*int
297-
var sesUserIds []int32
298-
var smtpUserIds []int32
299297
var providerConfigs []*beans.ProvidersConfig
300298
for _, item := range config.Providers {
301-
// if item.ConfigId > 0 that means, user is of user repository, else user email is custom
302-
if item.ConfigId > 0 {
303-
if item.Destination == util.Slack {
304-
slackIds = append(slackIds, &item.ConfigId)
305-
} else if item.Destination == util.SES {
306-
sesUserIds = append(sesUserIds, int32(item.ConfigId))
307-
} else if item.Destination == util.SMTP {
308-
smtpUserIds = append(smtpUserIds, int32(item.ConfigId))
309-
} else if item.Destination == util.Webhook {
310-
webhookIds = append(webhookIds, &item.ConfigId)
311-
}
299+
if item.Destination == util.Slack {
300+
slackIds = append(slackIds, &item.ConfigId)
301+
} else if item.Destination == util.Webhook {
302+
webhookIds = append(webhookIds, &item.ConfigId)
312303
} else {
313-
providerConfigs = append(providerConfigs, &beans.ProvidersConfig{Dest: string(item.Destination), Recipient: item.Recipient})
304+
providerConfigs = append(providerConfigs, &beans.ProvidersConfig{Dest: string(item.Destination), Recipient: item.Recipient, Id: item.ConfigId})
314305
}
315306
}
316307
if len(slackIds) > 0 {
@@ -333,27 +324,6 @@ func (impl *NotificationConfigServiceImpl) BuildNotificationSettingsResponse(not
333324
providerConfigs = append(providerConfigs, &beans.ProvidersConfig{Id: item.Id, ConfigName: item.ConfigName, Dest: string(util.Webhook)})
334325
}
335326
}
336-
337-
if len(sesUserIds) > 0 {
338-
sesConfigs, err := impl.userRepository.GetByIds(sesUserIds)
339-
if err != nil && err != pg.ErrNoRows {
340-
impl.logger.Errorw("error in fetching user", "sesUserIds", sesUserIds, "error", err)
341-
return notificationSettingsResponses, deletedItemCount, err
342-
}
343-
for _, item := range sesConfigs {
344-
providerConfigs = append(providerConfigs, &beans.ProvidersConfig{Id: int(item.Id), ConfigName: item.EmailId, Dest: string(util.SES)})
345-
}
346-
}
347-
if len(smtpUserIds) > 0 {
348-
smtpConfigs, err := impl.userRepository.GetByIds(smtpUserIds)
349-
if err != nil && err != pg.ErrNoRows {
350-
impl.logger.Errorw("error in fetching user", "smtpUserIds", smtpUserIds, "error", err)
351-
return notificationSettingsResponses, deletedItemCount, err
352-
}
353-
for _, item := range smtpConfigs {
354-
providerConfigs = append(providerConfigs, &beans.ProvidersConfig{Id: int(item.Id), ConfigName: item.EmailId, Dest: string(util.SMTP)})
355-
}
356-
}
357327
notificationSettingsResponse.ProvidersConfig = providerConfigs
358328
}
359329

pkg/notifier/SESNotificationService.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,23 @@ func (impl *SESNotificationServiceImpl) SaveOrEditNotificationConfig(channelReq
6060
for _, config := range sesConfigs {
6161
if config.Id != 0 {
6262

63+
model, err := impl.sesRepository.FindOne(config.Id)
64+
if err != nil && !util.IsErrNoRows(err) {
65+
impl.logger.Errorw("err while fetching ses config", "err", err)
66+
return []int{}, err
67+
}
68+
6369
if config.Default {
6470
_, err := impl.sesRepository.UpdateSESConfigDefault()
6571
if err != nil && !util.IsErrNoRows(err) {
6672
impl.logger.Errorw("err while updating ses config", "err", err)
6773
return []int{}, err
6874
}
6975
} else {
76+
// check if this config is already default, we don't want to reverse it
77+
if model.Default {
78+
return []int{}, fmt.Errorf("cannot update default config to non default")
79+
}
7080
_, err := impl.sesRepository.FindDefault()
7181
if err != nil && !util.IsErrNoRows(err) {
7282
impl.logger.Errorw("err while updating ses config", "err", err)
@@ -76,11 +86,6 @@ func (impl *SESNotificationServiceImpl) SaveOrEditNotificationConfig(channelReq
7686
}
7787
}
7888

79-
model, err := impl.sesRepository.FindOne(config.Id)
80-
if err != nil && !util.IsErrNoRows(err) {
81-
impl.logger.Errorw("err while fetching ses config", "err", err)
82-
return []int{}, err
83-
}
8489
adapter.BuildConfigUpdateModelForSES(config, model, userId)
8590
model, uErr := impl.sesRepository.UpdateSESConfig(model)
8691
if uErr != nil {
@@ -175,6 +180,10 @@ func (impl *SESNotificationServiceImpl) DeleteNotificationConfig(deleteReq *bean
175180
impl.logger.Errorw("found notifications using this config, cannot delete", "config", deleteReq)
176181
return fmt.Errorf(" Please delete all notifications using this config before deleting")
177182
}
183+
// check if default then dont delete
184+
if existingConfig.Default {
185+
return fmt.Errorf("default configuration cannot be deleted")
186+
}
178187
existingConfig.UpdatedOn = time.Now()
179188
existingConfig.UpdatedBy = userId
180189
//deleting slack config

pkg/notifier/SMTPNotificationService.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,23 @@ func (impl *SMTPNotificationServiceImpl) SaveOrEditNotificationConfig(channelReq
6060
for _, config := range smtpConfigs {
6161
if config.Id != 0 {
6262

63+
model, err := impl.smtpRepository.FindOne(config.Id)
64+
if err != nil && !util.IsErrNoRows(err) {
65+
impl.logger.Errorw("err while fetching smtp config", "err", err)
66+
return []int{}, err
67+
}
68+
6369
if config.Default {
6470
_, err := impl.smtpRepository.UpdateSMTPConfigDefault()
6571
if err != nil && !util.IsErrNoRows(err) {
6672
impl.logger.Errorw("err while updating smtp config", "err", err)
6773
return []int{}, err
6874
}
6975
} else {
76+
// check if this config is already default, we don't want to reverse it
77+
if model.Default {
78+
return []int{}, fmt.Errorf("cannot update default config to non default")
79+
}
7080
_, err := impl.smtpRepository.FindDefault()
7181
if err != nil && !util.IsErrNoRows(err) {
7282
impl.logger.Errorw("err while updating smtp config", "err", err)
@@ -76,11 +86,6 @@ func (impl *SMTPNotificationServiceImpl) SaveOrEditNotificationConfig(channelReq
7686
}
7787
}
7888

79-
model, err := impl.smtpRepository.FindOne(config.Id)
80-
if err != nil && !util.IsErrNoRows(err) {
81-
impl.logger.Errorw("err while fetching smtp config", "err", err)
82-
return []int{}, err
83-
}
8489
adapter.BuildConfigUpdateModelForSMTP(config, model, userId)
8590
model, uErr := impl.smtpRepository.UpdateSMTPConfig(model)
8691
if uErr != nil {
@@ -175,6 +180,10 @@ func (impl *SMTPNotificationServiceImpl) DeleteNotificationConfig(deleteReq *bea
175180
impl.logger.Errorw("found notifications using this config, cannot delete", "config", deleteReq)
176181
return fmt.Errorf(" Please delete all notifications using this config before deleting")
177182
}
183+
// check if default then dont delete
184+
if existingConfig.Default {
185+
return fmt.Errorf("default configuration cannot be deleted")
186+
}
178187
existingConfig.UpdatedOn = time.Now()
179188
existingConfig.UpdatedBy = userId
180189
//deleting smtp config

pkg/notifier/beans/beans.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ type NSDeleteRequest struct {
224224

225225
type NotificationRequest struct {
226226
UpdateType util.UpdateType `json:"updateType,omitempty"`
227-
SesConfigId int `json:"sesConfigId,omitempty"`
228227
Providers []*bean.Provider `json:"providers"`
229228
NotificationConfigRequest []*NotificationConfigRequest `json:"notificationConfigRequest" validate:"required"`
230229
}

0 commit comments

Comments
 (0)