Skip to content

Commit

Permalink
Fix: Fix alias api when email receiver is first created
Browse files Browse the repository at this point in the history
Signed-off-by: Daishan Peng <daishan@acorn.io>
  • Loading branch information
StrongMonkey committed Jan 23, 2025
1 parent 439d793 commit 4affd02
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions apiclient/types/emailreceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package types
type EmailReceiver struct {
Metadata
EmailReceiverManifest
AddressAssigned *bool `json:"aliasAssigned,omitempty"`
EmailAddress string `json:"emailAddress,omitempty"`
AliasAssigned *bool `json:"aliasAssigned,omitempty"`
EmailAddress string `json:"emailAddress,omitempty"`
}

type EmailReceiverManifest struct {
Expand Down
4 changes: 2 additions & 2 deletions apiclient/types/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions pkg/api/handlers/emailreceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,19 @@ func convertEmailReceiver(emailReceiver v1.EmailReceiver, hostname string) *type

var aliasAssigned *bool
if emailReceiver.Generation == emailReceiver.Status.ObservedGeneration {
aliasAssigned = &emailReceiver.Status.AliasAssigned
aliasAssigned = emailReceiver.Status.AliasAssigned
}
er := &types.EmailReceiver{
Metadata: MetadataFrom(&emailReceiver),
EmailReceiverManifest: manifest,
AddressAssigned: aliasAssigned,
AliasAssigned: aliasAssigned,
}
if hostname != "" {
name := emailReceiver.Name
if er.AddressAssigned != nil && *er.AddressAssigned {
// We should use the alias if the following is true
// 1. Alias is assigned and set to true
// 2. Alias is not assigned but Alias is set at the initial creation.
if (er.AliasAssigned != nil && *er.AliasAssigned) || (er.AliasAssigned == nil && er.Alias != "") {
name = er.Alias
}
er.EmailAddress = fmt.Sprintf("%s@%s", name, hostname)
Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/apis/obot.obot.ai/v1/emailaddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func (in *EmailReceiver) GetAliasName() string {
}

func (in *EmailReceiver) SetAssigned(assigned bool) {
in.Status.AliasAssigned = assigned
in.Status.AliasAssigned = &assigned
}

func (in *EmailReceiver) IsAssigned() bool {
return in.Status.AliasAssigned
return in.Status.AliasAssigned != nil && *in.Status.AliasAssigned
}

func (in *EmailReceiver) GetObservedGeneration() int64 {
Expand Down Expand Up @@ -88,7 +88,7 @@ type EmailReceiverSpec struct {
}

type EmailReceiverStatus struct {
AliasAssigned bool `json:"aliasAssigned,omitempty"`
AliasAssigned *bool `json:"aliasAssigned,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

Expand Down

0 comments on commit 4affd02

Please sign in to comment.