forked from cozy/cozy-stack
/
revoke_trashed.go
42 lines (36 loc) · 1 KB
/
revoke_trashed.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package sharing
import (
"github.com/cozy/cozy-stack/model/instance"
"github.com/cozy/cozy-stack/model/vfs"
"github.com/cozy/cozy-stack/pkg/prefixer"
)
func init() {
vfs.RevokeSharingFunc = revokeTrashed
}
const (
SharingDirAlreadyTrashed = true
SharingDirNotTrashed = false
)
func revokeTrashed(db prefixer.Prefixer, sharingID string) {
s, err := FindSharing(db, sharingID)
if err != nil {
return
}
// XXX: we simulate an instance from the information of the prefixer. It is
// an hack, but I don't see a better way to do that for the moment. Maybe
// it is something we can improve later. I hope it should have all the
// fields that are used for revoking the sharing.
inst := &instance.Instance{
Prefix: db.DBPrefix(),
Domain: db.DomainName(),
}
if s.Owner {
err = s.Revoke(inst)
} else {
err = s.RevokeRecipientBySelf(inst, SharingDirAlreadyTrashed)
}
if err != nil {
inst.Logger().WithNamespace("sharing").
Errorf("revokeTrashed failed for sharing %s: %s", sharingID, err)
}
}