github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/model/sharing/revoke_trashed.go (about) 1 // Package sharing is where all the magic happen when documents/files are 2 // shared between several Cozy instances, from managing the recipients to 3 // replicating the changes. 4 package sharing 5 6 import ( 7 "github.com/cozy/cozy-stack/model/instance" 8 "github.com/cozy/cozy-stack/model/vfs" 9 "github.com/cozy/cozy-stack/pkg/consts" 10 "github.com/cozy/cozy-stack/pkg/prefixer" 11 ) 12 13 func init() { 14 vfs.RevokeSharingFunc = revokeTrashed 15 } 16 17 const ( 18 SharingDirAlreadyTrashed = true 19 SharingDirNotTrashed = false 20 ) 21 22 func revokeTrashed(db prefixer.Prefixer, sharingID string) { 23 s, err := FindSharing(db, sharingID) 24 if err != nil { 25 return 26 } 27 28 // XXX: we simulate an instance from the information of the prefixer. It is 29 // an hack, but I don't see a better way to do that for the moment. Maybe 30 // it is something we can improve later. I hope it should have all the 31 // fields that are used for revoking the sharing. 32 inst := &instance.Instance{ 33 Prefix: db.DBPrefix(), 34 Domain: db.DomainName(), 35 } 36 37 log := inst.Logger().WithNamespace("sharing") 38 log.Infof("revokeTrashed called for sharing %s", sharingID) 39 if s.Owner { 40 err = s.Revoke(inst) 41 } else { 42 err = s.RevokeRecipientBySelf(inst, SharingDirAlreadyTrashed) 43 } 44 if err != nil { 45 log.Errorf("revokeTrashed failed for sharing %s: %s", sharingID, err) 46 } 47 } 48 49 // RevokeCipherSharings revoke all the sharings with the bitwarden ciphers. 50 func RevokeCipherSharings(inst *instance.Instance) error { 51 sharings, err := GetSharingsByDocType(inst, consts.BitwardenCiphers) 52 if err != nil { 53 return err 54 } 55 for _, s := range sharings { 56 if s.Owner { 57 err = s.Revoke(inst) 58 } else { 59 err = s.RevokeRecipientBySelf(inst, SharingDirNotTrashed) 60 } 61 if err != nil { 62 return err 63 } 64 } 65 return nil 66 }