diff --git a/model/sharing/group.go b/model/sharing/group.go index d9926f4b84f..408b58a51aa 100644 --- a/model/sharing/group.go +++ b/model/sharing/group.go @@ -110,8 +110,14 @@ func UpdateGroups(inst *instance.Instance, msg job.ShareGroupMessage) error { for _, added := range msg.GroupsAdded { for idx, group := range s.Groups { if group.ID == added { - if err := s.AddMemberToGroup(inst, idx, contact); err != nil { - errm = multierror.Append(errm, err) + if s.Owner { + if err := s.AddMemberToGroup(inst, idx, contact); err != nil { + errm = multierror.Append(errm, err) + } + } else { + if err := s.DelegateAddMemberToGroup(inst, idx, contact); err != nil { + errm = multierror.Append(errm, err) + } } } } @@ -136,7 +142,7 @@ func UpdateGroups(inst *instance.Instance, msg job.ShareGroupMessage) error { return errm } -// AddMemberToGroup adds a contact to a sharing via a group. +// AddMemberToGroup adds a contact to a sharing via a group (on the owner). func (s *Sharing) AddMemberToGroup(inst *instance.Instance, groupIndex int, contact *contact.Contact) error { readOnly := s.Groups[groupIndex].ReadOnly m, err := buildMemberFromContact(contact, readOnly) @@ -168,6 +174,22 @@ func (s *Sharing) AddMemberToGroup(inst *instance.Instance, groupIndex int, cont return nil } +// DelegateAddMemberToGroup adds a contact to a sharing via a group (on a recipient). +func (s *Sharing) DelegateAddMemberToGroup(inst *instance.Instance, groupIndex int, contact *contact.Contact) error { + readOnly := s.Groups[groupIndex].ReadOnly + m, err := buildMemberFromContact(contact, readOnly) + if err != nil { + return err + } + m.OnlyInGroups = true + m.Groups = []int{groupIndex} + api := &APIDelegateAddContacts{ + sid: s.ID(), + members: []Member{m}, + } + return s.SendDelegated(inst, api) +} + // RemoveMemberFromGroup removes a member of a group. func (s *Sharing) RemoveMemberFromGroup(inst *instance.Instance, groupIndex int, contact *contact.Contact) error { var email string diff --git a/model/sharing/member.go b/model/sharing/member.go index 5ef3cdcaa18..cff16dcd3c3 100644 --- a/model/sharing/member.go +++ b/model/sharing/member.go @@ -335,6 +335,12 @@ func (s *Sharing) DelegateAddContactsAndGroups(inst *instance.Instance, groupIDs } } + return s.SendDelegated(inst, api) +} + +// SendDelegated calls the delegated endpoint on the sharer to adds +// contacts/groups. +func (s *Sharing) SendDelegated(inst *instance.Instance, api *APIDelegateAddContacts) error { data, err := jsonapi.MarshalObject(api) if err != nil { return err