Skip to content

Commit

Permalink
refactor: Fix note trigger upon sharing revocation
Browse files Browse the repository at this point in the history
  Don't wait until the user tries to open a note from a revoked sharing
  to recreate its trigger but do it instead upon the sharing revocation.
  • Loading branch information
taratatach committed Feb 27, 2024
1 parent 8c60876 commit 3cb3a85
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions model/sharing/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,12 @@ func (s *Sharing) FixRevokedNotes(inst *instance.Instance) error {

var errm error
for _, doc := range docs {
// If the note came from another cozy via a sharing that is now revoked, we
// may need to recreate the trigger.
if err := note.SetupTrigger(inst, doc.ID()); err != nil {
errm = multierror.Append(errm, fmt.Errorf("failed to setup revoked note trigger: %w", err))
}

if err := note.ImportImages(inst, doc); err != nil {
errm = multierror.Append(errm, fmt.Errorf("failed to import revoked note images: %w", err))
}
Expand Down
3 changes: 3 additions & 0 deletions model/sharing/open_note.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func (o *NoteOpener) GetResult(memberIndex int, readOnly bool) (jsonapi.Object,
func (o *NoteOpener) openLocalNote(memberIndex int, readOnly bool) (*apiNoteURL, error) {
// If the note came from another cozy via a sharing that is now revoked, we
// may need to recreate the trigger.
// This should be taken care of when revoking the sharing now but we leave
// this call to make sure notes from previously revoked sharings will
// continue to work.
_ = note.SetupTrigger(o.Inst, o.File.ID())

code, err := o.GetSharecode(memberIndex, readOnly)
Expand Down

0 comments on commit 3cb3a85

Please sign in to comment.