diff --git a/config/owner.go b/config/owner.go index 867e1969..6f7605f7 100644 --- a/config/owner.go +++ b/config/owner.go @@ -11,3 +11,7 @@ type Owner struct { func NewOwner() Owner { return Owner{} } + +func (owner Owner) IsEmpty() bool { + return owner.Username == "" +} diff --git a/config/owner_accessors.go b/config/owner_accessors.go index fd0dd60a..92b64a38 100644 --- a/config/owner_accessors.go +++ b/config/owner_accessors.go @@ -7,9 +7,9 @@ import ( func OwnerSchema() schema.Element { return schema.Object{ Properties: schema.ElementMap{ - "displayName": schema.String{MaxLength: 100, Required: true}, - "username": schema.String{MaxLength: 255, Required: true}, - "emailAddress": schema.String{MaxLength: 255, Format: "email", Required: true}, + "displayName": schema.String{MaxLength: 100}, + "username": schema.String{MaxLength: 255}, + "emailAddress": schema.String{MaxLength: 255, Format: "email"}, "phoneNumber": schema.String{MaxLength: 20}, "mailingAddress": schema.String{MaxLength: 1000}, }, diff --git a/service/user.go b/service/user.go index fae65bb6..7e8ed2a2 100644 --- a/service/user.go +++ b/service/user.go @@ -366,6 +366,11 @@ func (service *User) CalcRuleCount(userID primitive.ObjectID) { func (service *User) SetOwner(owner config.Owner) error { + // If there is no owner data, then do not create/update an owner record. + if owner.IsEmpty() { + return nil + } + // Try to read the owner from the database users, err := service.ListUsernameOrOwner(owner.Username)