Skip to content

Commit

Permalink
Fix the myself contact at instance creation (#4474)
Browse files Browse the repository at this point in the history
- add the displayName
- add the index.byFamilyNameGivenNameEmailCozyUrl

In theory, there is a service from the contacts webapp that adds them,
launched via an `@vevent` trigger on the io.cozy.contacts. But, the
stack creates the myself contact before installing the contacts webapp
at instance creation. Thus, the service is not launched. The easy fix is
to just add the missing field when creating the myself contact.
  • Loading branch information
nono authored Oct 15, 2024
2 parents 194c038 + 52734ba commit 092abce
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions model/contact/contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,33 @@ func FindByEmail(db prefixer.Prefixer, email string) (*Contact, error) {
func CreateMyself(inst *instance.Instance, settings *couchdb.JSONDoc) (*Contact, error) {
doc := New()
doc.JSONDoc.M["me"] = true
if name, ok := settings.M["public_name"]; ok {
doc.JSONDoc.M["fullname"] = name
}
if email, ok := settings.M["email"]; ok {
email, ok := settings.M["email"].(string)
if ok {
doc.JSONDoc.M["email"] = []map[string]interface{}{
{"address": email, "primary": true},
}
}
name, _ := settings.M["public_name"].(string)
displayName := name
if name == "" {
parts := strings.SplitN(email, "@", 2)
name = parts[0]
displayName = email
}
if name != "" {
doc.JSONDoc.M["fullname"] = name
doc.JSONDoc.M["displayName"] = displayName
}
cozyURL := inst.PageURL("", nil)
doc.JSONDoc.M["cozy"] = []map[string]interface{}{
{"url": inst.PageURL("", nil), "primary": true},
{"url": cozyURL, "primary": true},
}
index := email
if index == "" {
index = cozyURL
}
doc.JSONDoc.M["indexes"] = map[string]interface{}{
"byFamilyNameGivenNameEmailCozyUrl": index,
}
if err := couchdb.CreateDoc(inst, doc); err != nil {
return nil, err
Expand Down

0 comments on commit 092abce

Please sign in to comment.