Skip to content

Commit

Permalink
Merge pull request #2079 from ks-ci-bot/cherry-pick-1969-to-release-3.1
Browse files Browse the repository at this point in the history
[release-3.1] fix: Fix receiver mail sync error
  • Loading branch information
ks-ci-bot committed Jul 1, 2021
2 parents e58c2eb + 3f75e35 commit da9fb1b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/pages/settings/containers/Notification/Mail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import React from 'react'
import { observer } from 'mobx-react'
import { isEmpty, get, set, cloneDeep } from 'lodash'
import { isEmpty, get, set, cloneDeep, flatten } from 'lodash'

import { Notify } from '@kube-design/components'
import { Banner, Panel } from 'components/Base'
Expand All @@ -29,7 +29,6 @@ import ReceiverStore from 'stores/notification/receiver'
import SecretStore from 'stores/notification/secret'
import UserStore from 'stores/user'

import { safeParseJSON } from 'utils'
import { safeBtoa } from 'utils/base64'
import FORM_TEMPLATES from 'utils/form.templates'

Expand Down Expand Up @@ -95,18 +94,25 @@ export default class Mail extends React.Component {
}),
this.secretStore.fetchList({ name: SECRET_NAME }),
])
const receiverMail = safeParseJSON(
get(
receivers[0],
'metadata.annotations["kubesphere.io/receiver-mail"]',
[]
)
)

let receiverMail = get(receivers[0], 'spec.email.to', [])
if (!isEmpty(receiverMail)) {
const reqs = []
receiverMail.forEach(email => {
reqs.push(this.userStore.fetchList({ email }))
})
const result = await Promise.all(reqs)
receiverMail = receiverMail.map(email => {
const data = flatten(result).find(v => v.email === email)
return !isEmpty(data) ? data : { email }
})
}
set(
receivers[0],
'metadata.annotations["kubesphere.io/receiver-mail"]',
receiverMail
)

this.formData = {
config: set(this.configFormTemplate, 'spec', config.spec),
receiver: receivers[0],
Expand Down

0 comments on commit da9fb1b

Please sign in to comment.