Documentation ¶
Index ¶
- Constants
- Variables
- func AskReupload(inst *instance.Instance) error
- func CheckSharings(inst *instance.Instance) ([]map[string]interface{}, error)
- func ConvertOAuthClient(c *oauth.Client) *auth.Client
- func CountNewShortcuts(inst *instance.Instance) (int, error)
- func CreateAccessToken(inst *instance.Instance, cli *oauth.Client, sharingID string, ...) (*auth.AccessToken, error)
- func CreateOAuthClient(inst *instance.Instance, m *Member) (*oauth.Client, error)
- func DeleteOAuthClient(inst *instance.Instance, m *Member, cred *Credentials) error
- func EnsureSharedWithMeDir(inst *instance.Instance) (*vfs.DirDoc, error)
- func GetSharecode(inst *instance.Instance, sharingID, clientID string) (string, error)
- func GetSharedDocsBySharingIDs(inst *instance.Instance, sharingIDs []string) (map[string][]couchdb.DocReference, error)
- func GetSharingsByDocType(inst *instance.Instance, docType string) (map[string]*Sharing, error)
- func InfoByDocTypeData(c echo.Context, statusCode int, sharings []*APISharing) error
- func MakeXorKey() []byte
- func MixupChainToResolveConflict(rev string, chain []string) []string
- func ParseRequestError(res *http.Response, body []byte) error
- func PersistInstanceURL(inst *instance.Instance, email, cozyURL string)
- func PushUploadJob(s *Sharing, inst *instance.Instance)
- func RefreshToken(inst *instance.Instance, reqErr error, s *Sharing, m *Member, ...) (*http.Response, error)
- func RemoveSharedRefs(inst *instance.Instance, sharingID string) error
- func RevGeneration(rev string) int
- func SendPublicKey(inst *instance.Instance, publicKey string) error
- func TryTokenForMovedSharing(i *instance.Instance, c *oauth.Client, token string) (string, permission.Claims, bool)
- func UpdateFileShared(db couchdb.Database, ref *SharedRef, revs RevsStruct) error
- func UpdateShared(inst *instance.Instance, msg TrackMessage, evt TrackEvent) error
- func XorID(id string, key []byte) string
- type APIBitwarden
- type APICredentials
- func (c *APICredentials) Clone() couchdb.Doc
- func (c *APICredentials) DocType() string
- func (c *APICredentials) ID() string
- func (c *APICredentials) Included() []jsonapi.Object
- func (c *APICredentials) Links() *jsonapi.LinksList
- func (c *APICredentials) Relationships() jsonapi.RelationshipMap
- func (c *APICredentials) Rev() string
- func (c *APICredentials) SetID(id string)
- func (c *APICredentials) SetRev(rev string)
- type APIDelegateAddContacts
- func (a *APIDelegateAddContacts) Clone() couchdb.Doc
- func (a *APIDelegateAddContacts) DocType() string
- func (a *APIDelegateAddContacts) ID() string
- func (a *APIDelegateAddContacts) Included() []jsonapi.Object
- func (a *APIDelegateAddContacts) Links() *jsonapi.LinksList
- func (a *APIDelegateAddContacts) Relationships() jsonapi.RelationshipMap
- func (a *APIDelegateAddContacts) Rev() string
- func (a *APIDelegateAddContacts) SetID(id string)
- func (a *APIDelegateAddContacts) SetRev(rev string)
- type APIMoved
- func (m *APIMoved) Clone() couchdb.Doc
- func (m *APIMoved) DocType() string
- func (m *APIMoved) ID() string
- func (m *APIMoved) Included() []jsonapi.Object
- func (m *APIMoved) Links() *jsonapi.LinksList
- func (m *APIMoved) Relationships() jsonapi.RelationshipMap
- func (m *APIMoved) Rev() string
- func (m *APIMoved) SetID(id string)
- func (m *APIMoved) SetRev(rev string)
- type APISharing
- type Changed
- type Changes
- type CheckSharedError
- type Credentials
- type DocsByDoctype
- type DocsList
- type FileDocWithRevisions
- type FileOpener
- func (o *FileOpener) AddShareByLinkCode(code string)
- func (o *FileOpener) CheckPermission(pdoc *permission.Permission, sharingID string) error
- func (o *FileOpener) GetSharecode(memberIndex int, readOnly bool) (string, error)
- func (o *FileOpener) OpenLocalFile(code string) OpenFileParameters
- func (o *FileOpener) PrepareRequestForSharedFile() (*PreparedRequest, error)
- func (o *FileOpener) ShouldOpenLocally() bool
- type KeyToUpload
- type Member
- func (m *Member) CreateSharingRequest(inst *instance.Instance, s *Sharing, c *Credentials, u *url.URL) error
- func (m *Member) GenerateOAuthURL(s *Sharing) (string, error)
- func (m *Member) InvitationLink(inst *instance.Instance, s *Sharing, state string, ...) string
- func (m *Member) PrimaryName() string
- func (m *Member) SendMail(inst *instance.Instance, s *Sharing, sharer, description, link string) error
- func (m *Member) SendShortcut(inst *instance.Instance, s *Sharing, link string) error
- type MissingEntry
- type Missings
- type OpenFileParameters
- type PreparedRequest
- type Removed
- type ReplicateMsg
- type RevsStruct
- type RevsTree
- type Rule
- type SharedInfo
- type SharedRef
- type Sharing
- func (s *Sharing) AddContact(inst *instance.Instance, contactID string, readOnly bool) error
- func (s *Sharing) AddContacts(inst *instance.Instance, contactIDs map[string]bool) error
- func (s *Sharing) AddDelegatedContact(inst *instance.Instance, email, instanceURL string, readOnly bool) (string, error)
- func (s *Sharing) AddReadOnlyFlag(inst *instance.Instance, index int) error
- func (s *Sharing) AddReferenceForSharingDir(inst *instance.Instance, rule *Rule) error
- func (s *Sharing) AddReplicateTrigger(inst *instance.Instance) error
- func (s *Sharing) AddShortcut(inst *instance.Instance, state string) error
- func (s *Sharing) AddTrackTriggers(inst *instance.Instance) error
- func (s *Sharing) AddUploadTrigger(inst *instance.Instance) error
- func (s *Sharing) ApplyBulkDocs(inst *instance.Instance, payload DocsByDoctype) error
- func (s *Sharing) ApplyBulkFiles(inst *instance.Instance, docs DocsList) error
- func (s *Sharing) BeOwner(inst *instance.Instance, slug string) error
- func (s *Sharing) ChangeMemberAddress(inst *instance.Instance, m *Member, params APIMoved) error
- func (s *Sharing) ChangeOwnerAddress(inst *instance.Instance, params APIMoved) error
- func (s *Sharing) ClearLastSequenceNumbers(inst *instance.Instance, m *Member) error
- func (s *Sharing) Clone() couchdb.Doc
- func (s *Sharing) ComputeRevsDiff(inst *instance.Instance, changed Changed) (*Missings, error)
- func (s *Sharing) Create(inst *instance.Instance) (*permission.Permission, error)
- func (s *Sharing) CreateDir(inst *instance.Instance, target map[string]interface{}, ...) error
- func (s *Sharing) CreateDirForSharing(inst *instance.Instance, rule *Rule, parentID string) (*vfs.DirDoc, error)
- func (s *Sharing) CreateInteractPermissions(inst *instance.Instance, m *Member) (string, error)
- func (s *Sharing) CreateInteractSet() permission.Set
- func (s *Sharing) CreatePreviewPermissions(inst *instance.Instance) (*permission.Permission, error)
- func (s *Sharing) CreateRequest(inst *instance.Instance) error
- func (s *Sharing) CreateShortcut(inst *instance.Instance, previewURL string, seen bool) error
- func (s *Sharing) DelegateAddContacts(inst *instance.Instance, contactIDs map[string]bool) error
- func (s *Sharing) DelegateAddReadOnlyFlag(inst *instance.Instance, index int) error
- func (s *Sharing) DelegateDiscovery(inst *instance.Instance, state, cozyURL string) (string, error)
- func (s *Sharing) DelegateRemoveReadOnlyFlag(inst *instance.Instance, index int) error
- func (s *Sharing) DocType() string
- func (s *Sharing) DowngradeToReadOnly(inst *instance.Instance, creds *APICredentials) error
- func (s *Sharing) EndInitial(inst *instance.Instance) error
- func (s *Sharing) FindCredentials(m *Member) *Credentials
- func (s *Sharing) FindMemberByCode(perms *permission.Permission, sharecode string) (*Member, error)
- func (s *Sharing) FindMemberByInboundClientID(clientID string) (*Member, error)
- func (s *Sharing) FindMemberByInteractCode(db prefixer.Prefixer, sharecode string) (*Member, error)
- func (s *Sharing) FindMemberBySharecode(db prefixer.Prefixer, sharecode string) (*Member, error)
- func (s *Sharing) FindMemberByState(state string) (*Member, error)
- func (s *Sharing) FirstBitwardenOrganizationRule() *Rule
- func (s *Sharing) FirstFilesRule() *Rule
- func (s *Sharing) GetFolder(inst *instance.Instance, m *Member, xoredID string) (map[string]interface{}, error)
- func (s *Sharing) GetNoLongerSharedDir(inst *instance.Instance) (*vfs.DirDoc, error)
- func (s *Sharing) GetPreviewURL(inst *instance.Instance, state string) (string, error)
- func (s *Sharing) GetSharecodeFromShortcut(inst *instance.Instance) (string, error)
- func (s *Sharing) GetSharingDir(inst *instance.Instance) (*vfs.DirDoc, error)
- func (s *Sharing) HandleFileUpload(inst *instance.Instance, key string, body io.ReadCloser) error
- func (s *Sharing) ID() string
- func (s *Sharing) InitialCopy(inst *instance.Instance, rule Rule, r int) error
- func (s *Sharing) InitialUpload(inst *instance.Instance, m *Member) error
- func (s *Sharing) NoMoreRecipient(inst *instance.Instance) error
- func (s *Sharing) NotifyMemberRevocation(inst *instance.Instance, m *Member, c *Credentials) error
- func (s *Sharing) NotifyRecipients(inst *instance.Instance, except *Member)
- func (s *Sharing) ProcessAnswer(inst *instance.Instance, creds *APICredentials) (*APICredentials, error)
- func (s *Sharing) ReadOnly() bool
- func (s *Sharing) ReadOnlyFlag() bool
- func (s *Sharing) ReadOnlyRules() bool
- func (s *Sharing) RedirectAfterAuthorizeURL(inst *instance.Instance) *url.URL
- func (s *Sharing) RegisterCozyURL(inst *instance.Instance, m *Member, cozyURL string) error
- func (s *Sharing) RemoveAllBitwardenMembers(inst *instance.Instance, orgID string) error
- func (s *Sharing) RemoveBitwardenMember(inst *instance.Instance, m *Member, orgID string) error
- func (s *Sharing) RemoveBitwardenOrganization(inst *instance.Instance, orgID string) error
- func (s *Sharing) RemoveReadOnlyFlag(inst *instance.Instance, index int) error
- func (s *Sharing) RemoveSharingDir(inst *instance.Instance) error
- func (s *Sharing) RemoveTriggers(inst *instance.Instance) error
- func (s *Sharing) Replicate(inst *instance.Instance, errors int) error
- func (s *Sharing) ReplicateTo(inst *instance.Instance, m *Member, initial bool) (bool, error)
- func (s *Sharing) Rev() string
- func (s *Sharing) Revoke(inst *instance.Instance) error
- func (s *Sharing) RevokeByNotification(inst *instance.Instance) error
- func (s *Sharing) RevokeMember(inst *instance.Instance, index int) error
- func (s *Sharing) RevokeOwner(inst *instance.Instance) error
- func (s *Sharing) RevokePreviewPermissions(inst *instance.Instance) error
- func (s *Sharing) RevokeRecipient(inst *instance.Instance, index int) error
- func (s *Sharing) RevokeRecipientByNotification(inst *instance.Instance, m *Member) error
- func (s *Sharing) RevokeRecipientBySelf(inst *instance.Instance, sharingDirTrashed bool) error
- func (s *Sharing) SaveBitwarden(inst *instance.Instance, m *Member, bw *APIBitwarden) error
- func (s *Sharing) SendAnswer(inst *instance.Instance, state string) error
- func (s *Sharing) SendInvitations(inst *instance.Instance, perms *permission.Permission) error
- func (s *Sharing) SendInvitationsToMembers(inst *instance.Instance, members []Member, states map[string]string) error
- func (s *Sharing) SendShortcutMail(inst *instance.Instance, fileDoc *vfs.FileDoc, previewURL string) error
- func (s *Sharing) SetID(id string)
- func (s *Sharing) SetRev(rev string)
- func (s *Sharing) Setup(inst *instance.Instance, m *Member)
- func (s *Sharing) SetupReceiver(inst *instance.Instance) error
- func (s *Sharing) SortFilesToSent(files []map[string]interface{})
- func (s *Sharing) SyncFile(inst *instance.Instance, target *FileDocWithRevisions) (*KeyToUpload, error)
- func (s *Sharing) TransformFileToSent(doc map[string]interface{}, xorKey []byte, ruleIndex int)
- func (s *Sharing) TrashDir(inst *instance.Instance, dir *vfs.DirDoc) error
- func (s *Sharing) TrashFile(inst *instance.Instance, file *vfs.FileDoc, rule *Rule) error
- func (s *Sharing) UpdateDir(inst *instance.Instance, target map[string]interface{}, dir *vfs.DirDoc, ...) error
- func (s *Sharing) UpdateLastSequenceNumber(inst *instance.Instance, m *Member, worker, seq string) error
- func (s *Sharing) UpdateRecipients(inst *instance.Instance, members []Member) error
- func (s *Sharing) UpgradeToReadWrite(inst *instance.Instance, creds *APICredentials) error
- func (s *Sharing) Upload(inst *instance.Instance, errors int) error
- func (s *Sharing) UploadExistingFile(inst *instance.Instance, target *FileDocWithRevisions, newdoc *vfs.FileDoc, ...) error
- func (s *Sharing) UploadNewFile(inst *instance.Instance, target *FileDocWithRevisions, body io.ReadCloser) error
- func (s *Sharing) UploadTo(inst *instance.Instance, m *Member, lastTry bool) (bool, error)
- func (s *Sharing) ValidateRules() error
- type TrackEvent
- type TrackMessage
- type Triggers
- type UploadMsg
- type UploadStore
Constants ¶
const ( // MemberStatusOwner is the status for the member that is owner MemberStatusOwner = "owner" // MemberStatusMailNotSent is the initial status for a recipient, before // the mail invitation is sent MemberStatusMailNotSent = "mail-not-sent" // MemberStatusPendingInvitation is for a recipient that has not (yet) // seen the preview of the sharing, but the invitation mail was sent MemberStatusPendingInvitation = "pending" // MemberStatusSeen is for a recipient that has seen the preview of the // sharing, but not accepted it (yet) MemberStatusSeen = "seen" // MemberStatusReady is for recipient that have accepted the sharing MemberStatusReady = "ready" // MemberStatusRevoked is for a revoked member MemberStatusRevoked = "revoked" )
const ( // NoConflict is the status when the rev is in the revisions chain (OK) NoConflict conflictStatus = iota // LostConflict is the status when rev is greater than the last revision of // the chain (the resolution is often to abort the update) LostConflict // WonConflict is the status when rev is not in the chain, // but the last revision of the chain is still (the resolution can be to // make the update but including rev in the revisions chain) WonConflict )
const ( SharingDirAlreadyTrashed = true SharingDirNotTrashed = false )
const ( // ActionRuleNone is used when an add/update/remove should not be // replicated to the other cozys ActionRuleNone = "none" // ActionRulePush is used when an add/update/remove should be replicated // only if it happened on the owner's cozy ActionRulePush = "push" // ActionRuleSync is used when an add/update/remove should be always replicated ActionRuleSync = "sync" // ActionRuleRevoke is used when a remove should revoke the sharing ActionRuleRevoke = "revoke" )
const BatchSize = 100
BatchSize is the maximal number of documents mainpulated at once by the replicator
const InitialBackoffPeriod = 1 * time.Minute
InitialBackoffPeriod is the initial duration to wait for the first retry (each next retry will wait 4 times longer than its previous retry)
const MaxDepth = 100
MaxDepth is the maximum number of revisions in a chain that we keep for a document.
const MaxRetries = 5
MaxRetries is the maximal number of retries for a replicator
const (
// StateLen is the number of bytes for the OAuth state parameter
StateLen = 16
)
Variables ¶
var ( // ErrNoRules is used when a sharing is created without a rule ErrNoRules = errors.New("A sharing must have rules") // ErrNoRecipients is used when a sharing is created without a recipient ErrNoRecipients = errors.New("A sharing must have recipients") // ErrTooManyMembers is used when a sharing has too many members ErrTooManyMembers = errors.New("There are too many members for this sharing") // ErrInvalidURL is used for invalid URL of a Cozy instance ErrInvalidURL = errors.New("The Cozy URL is invalid") // ErrInvalidRule is used when a rule is invalid when the sharing is // created ErrInvalidRule = errors.New("A rule is invalid") // ErrInvalidSharing is used when an action cannot be made on a sharing, // because this sharing is not the expected state ErrInvalidSharing = errors.New("Sharing is not in the expected state") // ErrMemberNotFound is used when trying to find a member, but there is no // member with the expected value for the criterion ErrMemberNotFound = errors.New("The member was not found") // ErrInvitationNotSent is used when the invitation shortcut or mail failed // to be sent ErrInvitationNotSent = errors.New("The invitation cannot be sent") // ErrRequestFailed is used when a cozy tries to create a sharing request // on another cozy, but it failed ErrRequestFailed = errors.New("The sharing request failed") // ErrNoOAuthClient is used when the owner of the Cozy has not yet // registered to the recipient as an OAuth client. ErrNoOAuthClient = errors.New("No OAuth client was found") // ErrInternalServerError is used for CouchDB errors ErrInternalServerError = errors.New("Internal Server Error") // ErrClientError is used when an OAuth client has made a request, and the // response was a 4xx error ErrClientError = errors.New("OAuth client request was in error") // ErrMissingID is used when _id is missing on a doc for a bulk operation ErrMissingID = errors.New("An identifier is missing") // ErrMissingRev is used when _rev is missing on a doc for a bulk operation ErrMissingRev = errors.New("A revision is missing") // ErrMissingFileMetadata is used when uploading a file and the key is not // in the cache (so no metadata and the upload can't succeed) ErrMissingFileMetadata = errors.New("The metadata for this file were not found") // ErrFolderNotFound is used when informations about a folder is asked, // but this folder was not found ErrFolderNotFound = errors.New("This folder was not found") // ErrSafety is used when an operation is aborted due to the safery principal ErrSafety = errors.New("Operation aborted") // ErrAlreadyAccepted is used when someone tries to accept twice a sharing // on the same cozy instance ErrAlreadyAccepted = errors.New("Sharing already accepted by this recipient") // ErrCannotOpenFile is used when opening a file fails ErrCannotOpenFile = errors.New("The file cannot be opened") )
Functions ¶
func AskReupload ¶
AskReupload is used when the disk quota of an instance is increased to tell to the other instances that have a sharing with it that they can retry to upload files.
func CheckSharings ¶
CheckSharings will scan all the io.cozy.sharings documents and check their triggers and members/credentials.
func ConvertOAuthClient ¶
ConvertOAuthClient converts an OAuth client from one type (model/oauth.Client) to another (client/auth.Client)
func CountNewShortcuts ¶
CountNewShortcuts returns the number of shortcuts to a sharing that have not been seen.
func CreateAccessToken ¶
func CreateAccessToken(inst *instance.Instance, cli *oauth.Client, sharingID string, verb permission.VerbSet) (*auth.AccessToken, error)
CreateAccessToken creates an access token for the given OAuth client, with a scope on this sharing.
func CreateOAuthClient ¶
CreateOAuthClient creates an OAuth client for a recipient of the given sharing
func DeleteOAuthClient ¶
func DeleteOAuthClient(inst *instance.Instance, m *Member, cred *Credentials) error
DeleteOAuthClient removes the client associated to the given member
func EnsureSharedWithMeDir ¶
EnsureSharedWithMeDir returns the shared-with-me directory, and create it if it doesn't exist
func GetSharecode ¶
GetSharecode returns a sharecode for the given client that can be used to preview the sharing.
func GetSharedDocsBySharingIDs ¶
func GetSharedDocsBySharingIDs(inst *instance.Instance, sharingIDs []string) (map[string][]couchdb.DocReference, error)
GetSharedDocsBySharingIDs returns a map associating each given sharingID to a list of DocReference, which are the shared documents
func GetSharingsByDocType ¶
GetSharingsByDocType returns all the sharings for the given doctype
func InfoByDocTypeData ¶
func InfoByDocTypeData(c echo.Context, statusCode int, sharings []*APISharing) error
InfoByDocTypeData returns the sharings info as data array in the JSON-API format
func MakeXorKey ¶
func MakeXorKey() []byte
MakeXorKey generates a key for transforming the file identifiers
func MixupChainToResolveConflict ¶
MixupChainToResolveConflict creates a new chain of revisions that can be used to resolve a conflict: the new chain will start the old rev and include other revisions from the chain with a greater generation.
func ParseRequestError ¶
ParseRequestError is used to parse an error in a request.Options, and it keeps the new instance URL when a Cozy has moved in Title.
func PersistInstanceURL ¶
PersistInstanceURL updates the io.cozy.contacts document with the Cozy instance URL
func PushUploadJob ¶
PushUploadJob pushs a job for the share-upload worker, to try again to reupload files.
func RefreshToken ¶
func RefreshToken( inst *instance.Instance, reqErr error, s *Sharing, m *Member, creds *Credentials, opts *request.Options, body []byte, ) (*http.Response, error)
RefreshToken is used after a failed request with a 4xx error code. It checks if the targeted instance has moved, and tries on the new instance if it is the case. And, if needed, it renews the access token and retries the request.
func RemoveSharedRefs ¶
RemoveSharedRefs deletes the references containing the sharingid
func RevGeneration ¶
RevGeneration returns the number before the hyphen, called the generation of a revision
func SendPublicKey ¶
SendPublicKey can be used to send the public key after it has been created/changed to the sharing owners.
func TryTokenForMovedSharing ¶
func TryTokenForMovedSharing(i *instance.Instance, c *oauth.Client, token string) (string, permission.Claims, bool)
TryTokenForMovedSharing is used when a Cozy has been moved, and a sharing was not updated on the other Cozy for some reasons. When the other Cozy will try to make a request to the source Cozy, it will get a 410 Gone error. This error will also tell it the URL of the new Cozy. Thus, it can try to refresh the token on the destination Cozy. And, as the refresh token was emitted on the source Cozy (and not the target Cozy), we need to do some tricks to manage this refresh. This function is here for that.
func UpdateFileShared ¶
func UpdateFileShared(db couchdb.Database, ref *SharedRef, revs RevsStruct) error
UpdateFileShared creates or updates the io.cozy.shared for a file with possibly multiple revisions.
func UpdateShared ¶
func UpdateShared(inst *instance.Instance, msg TrackMessage, evt TrackEvent) error
UpdateShared updates the io.cozy.shared database when a document is created/update/removed
Types ¶
type APIBitwarden ¶
APIBitwarden is used to exchange information when the sharing has a rule for bitwarden organizations. It allows to share documents with end to end encryption.
type APICredentials ¶
type APICredentials struct { *Credentials PublicName string `json:"public_name,omitempty"` CID string `json:"_id,omitempty"` Bitwarden *APIBitwarden `json:"bitwarden,omitempty"` }
APICredentials is used to serialize credentials to JSON-API. It is used for Cozy to Cozy exchange of the credentials, after a recipient has accepted a sharing.
func (*APICredentials) Clone ¶
func (c *APICredentials) Clone() couchdb.Doc
Clone is part of jsonapi.Object interface
func (*APICredentials) DocType ¶
func (c *APICredentials) DocType() string
DocType returns the sharing document type
func (*APICredentials) ID ¶
func (c *APICredentials) ID() string
ID returns the sharing qualified identifier
func (*APICredentials) Included ¶
func (c *APICredentials) Included() []jsonapi.Object
Included is part of jsonapi.Object interface
func (*APICredentials) Links ¶
func (c *APICredentials) Links() *jsonapi.LinksList
Links is part of jsonapi.Object interface
func (*APICredentials) Relationships ¶
func (c *APICredentials) Relationships() jsonapi.RelationshipMap
Relationships is part of jsonapi.Object interface
func (*APICredentials) SetID ¶
func (c *APICredentials) SetID(id string)
SetID changes the sharing qualified identifier
func (*APICredentials) SetRev ¶
func (c *APICredentials) SetRev(rev string)
SetRev changes the sharing revision
type APIDelegateAddContacts ¶
type APIDelegateAddContacts struct {
// contains filtered or unexported fields
}
APIDelegateAddContacts is used to serialize a request to add contacts to JSON-API
func (*APIDelegateAddContacts) Clone ¶
func (a *APIDelegateAddContacts) Clone() couchdb.Doc
Clone is part of jsonapi.Object interface
func (*APIDelegateAddContacts) DocType ¶
func (a *APIDelegateAddContacts) DocType() string
DocType returns the sharing document type
func (*APIDelegateAddContacts) ID ¶
func (a *APIDelegateAddContacts) ID() string
ID returns the sharing qualified identifier
func (*APIDelegateAddContacts) Included ¶
func (a *APIDelegateAddContacts) Included() []jsonapi.Object
Included is part of jsonapi.Object interface
func (*APIDelegateAddContacts) Links ¶
func (a *APIDelegateAddContacts) Links() *jsonapi.LinksList
Links is part of jsonapi.Object interface
func (*APIDelegateAddContacts) Relationships ¶
func (a *APIDelegateAddContacts) Relationships() jsonapi.RelationshipMap
Relationships is part of jsonapi.Object interface
func (*APIDelegateAddContacts) Rev ¶
func (a *APIDelegateAddContacts) Rev() string
Rev returns the sharing revision
func (*APIDelegateAddContacts) SetID ¶
func (a *APIDelegateAddContacts) SetID(id string)
SetID changes the sharing qualified identifier
func (*APIDelegateAddContacts) SetRev ¶
func (a *APIDelegateAddContacts) SetRev(rev string)
SetRev changes the sharing revision
type APIMoved ¶
type APIMoved struct { SharingID string `json:"id"` NewInstance string `json:"new_instance"` AccessToken string `json:"access_token,omitempty"` RefreshToken string `json:"refresh_token,omitempty"` }
APIMoved is used when a Cozy has been moved to a new address to inform the other members of the sharing of this new URL.
func (*APIMoved) Relationships ¶
func (m *APIMoved) Relationships() jsonapi.RelationshipMap
Relationships is part of jsonapi.Object interface
type APISharing ¶
type APISharing struct { *Sharing // XXX Hide the credentials Credentials *interface{} `json:"credentials,omitempty"` }
APISharing is used to serialize a Sharing to JSON-API
func (*APISharing) Clone ¶
func (s *APISharing) Clone() couchdb.Doc
Clone is part of the couchdb.Doc interface
func (*APISharing) Included ¶
func (s *APISharing) Included() []jsonapi.Object
Included is part of jsonapi.Object interface
func (*APISharing) Links ¶
func (s *APISharing) Links() *jsonapi.LinksList
Links is part of jsonapi.Object interface
func (*APISharing) Relationships ¶
func (s *APISharing) Relationships() jsonapi.RelationshipMap
Relationships is part of jsonapi.Object interface
type CheckSharedError ¶
type CheckSharedError struct {}
CheckSharedError is the type used when checking the io.cozy.shared, and one document has two revisions where a child don't its generation equal to the generation of the parent plus one.
func CheckShared ¶
func CheckShared(inst *instance.Instance) ([]*CheckSharedError, error)
CheckShared will scan all the io.cozy.shared documents and check their revision tree for inconsistencies.
type Credentials ¶
type Credentials struct { // OAuth state to accept the sharing (authorize phase) State string `json:"state,omitempty"` // Information needed to send data to the member Client *auth.Client `json:"client,omitempty"` AccessToken *auth.AccessToken `json:"access_token,omitempty"` // XorKey is used to transform file identifiers XorKey []byte `json:"xor_key,omitempty"` // InboundClientID is the OAuth ClientID used for authentifying incoming // requests from the member InboundClientID string `json:"inbound_client_id,omitempty"` }
Credentials is the struct with the secret stuff used for authentication & authorization.
type DocsByDoctype ¶
DocsByDoctype is a map of doctype -> slice of documents of this doctype
type FileDocWithRevisions ¶
type FileDocWithRevisions struct { *vfs.FileDoc Revisions RevsStruct `json:"_revisions"` }
FileDocWithRevisions is the struct of the payload for synchronizing a file
func (*FileDocWithRevisions) Clone ¶
func (f *FileDocWithRevisions) Clone() couchdb.Doc
Clone is part of the couchdb.Doc interface
type FileOpener ¶
type FileOpener struct { Inst *instance.Instance File *vfs.FileDoc Sharing *Sharing // can be nil Code string ClientID string MemberKey string }
FileOpener can be used to find the parameters for opening a file (shared or not), when collaborative edition is possible (like for a note or an office document).
func NewFileOpener ¶
NewFileOpener returns a FileOpener for the given file on the current instance.
func (*FileOpener) AddShareByLinkCode ¶
func (o *FileOpener) AddShareByLinkCode(code string)
AddShareByLinkCode can be used to give a sharecode that can be used to open the file, when the file is in a directory shared by link.
func (*FileOpener) CheckPermission ¶
func (o *FileOpener) CheckPermission(pdoc *permission.Permission, sharingID string) error
CheckPermission takes the permission doc, and checks that the user has the right to open the file.
func (*FileOpener) GetSharecode ¶
func (o *FileOpener) GetSharecode(memberIndex int, readOnly bool) (string, error)
GetSharecode returns a sharecode that can be used to open the note with the permissions of the member.
func (*FileOpener) OpenLocalFile ¶
func (o *FileOpener) OpenLocalFile(code string) OpenFileParameters
OpenLocalFile returns the parameters for opening the file on the local instance.
func (*FileOpener) PrepareRequestForSharedFile ¶
func (o *FileOpener) PrepareRequestForSharedFile() (*PreparedRequest, error)
PrepareRequestForSharedFile returns the parameters for making a request to open the shared file on another instance.
func (*FileOpener) ShouldOpenLocally ¶
func (o *FileOpener) ShouldOpenLocally() bool
ShouldOpenLocally returns true if the file can be opened in the current instance, and false if it is a shared file created on another instance.
type KeyToUpload ¶
type KeyToUpload struct {
Key string `json:"key"`
}
KeyToUpload contains the key for uploading a file (when syncing metadata is not enough)
type Member ¶
type Member struct { Status string `json:"status"` Name string `json:"name,omitempty"` PublicName string `json:"public_name,omitempty"` Email string `json:"email,omitempty"` Instance string `json:"instance,omitempty"` ReadOnly bool `json:"read_only,omitempty"` }
Member contains the information about a recipient (or the sharer) for a sharing
func (*Member) CreateSharingRequest ¶
func (m *Member) CreateSharingRequest(inst *instance.Instance, s *Sharing, c *Credentials, u *url.URL) error
CreateSharingRequest sends information about the sharing to the recipient's cozy
func (*Member) GenerateOAuthURL ¶
GenerateOAuthURL takes care of creating a correct OAuth request for the given member of the sharing.
func (*Member) InvitationLink ¶
func (m *Member) InvitationLink(inst *instance.Instance, s *Sharing, state string, perms *permission.Permission) string
InvitationLink generates an HTTP link where the recipient can start the process of accepting the sharing
func (*Member) PrimaryName ¶
PrimaryName returns the main name of this member
type MissingEntry ¶
type MissingEntry struct {
Missing []string `json:"missing"`
}
MissingEntry is a struct with the missing revisions for an id
type Missings ¶
type Missings map[string]MissingEntry
Missings is a struct for the response of _revs_diff
type OpenFileParameters ¶
type OpenFileParameters struct { FileID string // ID of the file on the instance where the file can be edited Subdomain string Protocol string Instance string }
OpenFileParameters is the list of parameters for building the URL where the file can be opened in the browser.
type PreparedRequest ¶
type PreparedRequest struct { Opts *request.Options // Can be nil XoredID string Creds *Credentials Creator *Member // MemberIndex and ReadOnly can be used even if Opts is nil MemberIndex int ReadOnly bool }
PreparedRequest contains the parameters to make a request to another instance for opening a shared file. If it is not possible, Opts will be empty and the MemberIndex and ReadOnly fields can be used for opening locally the file.
type ReplicateMsg ¶
ReplicateMsg is used for jobs on the share-replicate worker.
type RevsStruct ¶
RevsStruct is a struct for revisions in bulk methods of CouchDB
type RevsTree ¶
type RevsTree struct { // Rev is a revision, with the generation and the id // e.g. 1-1bad9a88f0a608ea78c12ab49882ac41 Rev string `json:"rev"` // Branches is the list of revisions that have this revision for parent. // The general case is to have only one branch, but we can have more with // conflicts. Branches []RevsTree `json:"branches,omitempty"` }
RevsTree is a tree of revisions, like CouchDB has. The revisions are sorted by growing generation (the number before the hyphen). http://docs.couchdb.org/en/stable/replication/conflicts.html#revision-tree
func (*RevsTree) Find ¶
Find returns the sub-tree for the given revision, or nil if not found. It also gives the depth of the sub-tree (how many nodes are traversed from the root of RevsTree to reach this sub-tree).
func (*RevsTree) Generation ¶
Generation returns the maximal generation of a revision in this tree
func (*RevsTree) InsertAfter ¶
InsertAfter inserts the given revision in the tree as a child of the second revision.
func (*RevsTree) InsertChain ¶
InsertChain inserts a chain of revisions, ie the first revision is the parent of the second revision, which is itself the parent of the third revision, etc. The first revisions of the chain are very probably already in the tree, the last one is certainly not. TODO ensure the MaxDepth limit is respected
type Rule ¶
type Rule struct { Title string `json:"title"` DocType string `json:"doctype"` Mime string `json:"mime,omitempty"` Selector string `json:"selector,omitempty"` Values []string `json:"values"` Local bool `json:"local,omitempty"` Add string `json:"add"` Update string `json:"update"` Remove string `json:"remove"` }
Rule describes how the sharing behave when a document matching the rule is added, updated or deleted.
func (Rule) FilesByID ¶
FilesByID returns true if the rule is for the files by doctype and the selector is an id (not a referenced_by). With such a rule, the identifiers must be xored before being sent to another cozy instance.
func (Rule) TriggerArgs ¶
TriggerArgs returns the string that can be used as an argument to create a trigger for this rule. The result can be an empty string if the rule doesn't need a trigger (a local or one-shot rule).
type SharedInfo ¶
type SharedInfo struct { int `json:"rule"` // document does no longer match the sharing rule Removed bool `json:"removed,omitempty"` // folders) with `removed: false` Binary bool `json:"binary,omitempty"` // folders when they have been removed from the sharing but can be put // again (only on the Cozy instance of the owner) Dissociated bool `json:"dissociated,omitempty"` }Rule
SharedInfo gives informations about how to apply the sharing to the shared document
type SharedRef ¶
type SharedRef struct { // SID is the identifier, it is doctype + / + id of the referenced doc Revisions *RevsTree `json:"revisions"` Infos map[string]SharedInfo `json:"infos"` }
SharedRef is the struct for the documents in io.cozy.shared. They are used to track which documents is in which sharings.
func FindReferences ¶
FindReferences returns the io.cozy.shared references to the given identifiers
type Sharing ¶
type Sharing struct { SID string `json:"_id,omitempty"` SRev string `json:"_rev,omitempty"` Triggers Triggers `json:"triggers"` Active bool `json:"active,omitempty"` Owner bool `json:"owner,omitempty"` Open bool `json:"open_sharing,omitempty"` Description string `json:"description,omitempty"` AppSlug string `json:"app_slug"` PreviewPath string `json:"preview_path,omitempty"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` NbFiles int `json:"initial_number_of_files_to_sync,omitempty"` Initial bool `json:"initial_sync,omitempty"` ShortcutID string `json:"shortcut_id,omitempty"` MovedFrom string `json:"moved_from,omitempty"` Rules []Rule `json:"rules"` // Members[0] is the owner, Members[1...] are the recipients Members []Member `json:"members"` // On the owner, credentials[i] is associated to members[i+1] // On a recipient, there is only credentials[0] (for the owner) Credentials []Credentials `json:"credentials,omitempty"` }
Sharing contains all the information about a sharing.
func FindSharing ¶
FindSharing retrieves a sharing document from its ID
func FindSharings ¶
FindSharings retrieves an array of sharing documents from their IDs
func (*Sharing) AddContact ¶
AddContact adds the contact with the given identifier
func (*Sharing) AddContacts ¶
AddContacts adds a list of contacts on the sharer cozy
func (*Sharing) AddDelegatedContact ¶
func (s *Sharing) AddDelegatedContact(inst *instance.Instance, email, instanceURL string, readOnly bool) (string, error)
AddDelegatedContact adds a contact on the owner cozy, but for a contact from a recipient (open_sharing: true only)
func (*Sharing) AddReadOnlyFlag ¶
AddReadOnlyFlag adds the read-only flag of a recipient, and send an access token with a short validity to let it synchronize its last changes.
func (*Sharing) AddReferenceForSharingDir ¶
AddReferenceForSharingDir adds a reference to the sharing on the sharing directory
func (*Sharing) AddReplicateTrigger ¶
AddReplicateTrigger creates the share-replicate trigger for this sharing: it will starts the replicator when some changes are made to the io.cozy.shared database.
func (*Sharing) AddShortcut ¶
AddShortcut creates a shortcut for this sharing on the local instance.
func (*Sharing) AddTrackTriggers ¶
AddTrackTriggers creates the share-track triggers for each rule of the sharing that will update the io.cozy.shared database.
func (*Sharing) AddUploadTrigger ¶
AddUploadTrigger creates the share-upload trigger for this sharing: it will starts the synchronization of the binaries when a file is added or updated in the io.cozy.shared database.
func (*Sharing) ApplyBulkDocs ¶
func (s *Sharing) ApplyBulkDocs(inst *instance.Instance, payload DocsByDoctype) error
ApplyBulkDocs is a multi-doctypes version of the POST _bulk_docs endpoint of CouchDB
func (*Sharing) ApplyBulkFiles ¶
ApplyBulkFiles takes a list of documents for the io.cozy.files doctype and will apply changes to the VFS according to those documents.
func (*Sharing) ChangeMemberAddress ¶
ChangeMemberAddress is used when a recipient of the sharing has moved their instance to a new URL and the owner if informed of the new URL.
func (*Sharing) ChangeOwnerAddress ¶
ChangeOwnerAddress is used when the owner of the sharing has moved their instance to a new URL and the other members of the sharing are informed of the new URL.
func (*Sharing) ClearLastSequenceNumbers ¶
ClearLastSequenceNumbers removes the last sequence numbers for a member
func (*Sharing) ComputeRevsDiff ¶
ComputeRevsDiff takes a map of id->[revisions] and returns the missing revisions for those documents on the current instance.
func (*Sharing) Create ¶
func (s *Sharing) Create(inst *instance.Instance) (*permission.Permission, error)
Create checks that the sharing is OK and it persists it in CouchDB if it is the case.
func (*Sharing) CreateDir ¶
func (s *Sharing) CreateDir(inst *instance.Instance, target map[string]interface{}, resolution nameConflictResolution) error
CreateDir creates a directory on this cozy to reflect a change on another cozy instance of this sharing.
func (*Sharing) CreateDirForSharing ¶
func (s *Sharing) CreateDirForSharing(inst *instance.Instance, rule *Rule, parentID string) (*vfs.DirDoc, error)
CreateDirForSharing creates the directory where files for this sharing will be put. This directory will be initially inside the Shared with me folder.
func (*Sharing) CreateInteractPermissions ¶
CreateInteractPermissions creates the permissions doc for reading and writing a note inside this sharing.
func (*Sharing) CreateInteractSet ¶
func (s *Sharing) CreateInteractSet() permission.Set
CreateInteractSet returns a set of permissions that can be used for share-interact.
func (*Sharing) CreatePreviewPermissions ¶
func (s *Sharing) CreatePreviewPermissions(inst *instance.Instance) (*permission.Permission, error)
CreatePreviewPermissions creates the permissions doc for previewing this sharing, or updates it with the new codes if the document already exists
func (*Sharing) CreateRequest ¶
CreateRequest prepares a sharing as just a request that the user will have to accept before it does anything.
func (*Sharing) CreateShortcut ¶
CreateShortcut is used to create a shortcut for a Cozy to Cozy sharing that has not yet been accepted.
func (*Sharing) DelegateAddContacts ¶
DelegateAddContacts adds a list of contacts on a recipient cozy. Part of the work is delegated to owner cozy, but the invitation mail is still sent from the recipient cozy.
func (*Sharing) DelegateAddReadOnlyFlag ¶
DelegateAddReadOnlyFlag is used by a recipient to ask the sharer to add the read-only falg for another member of the sharing.
func (*Sharing) DelegateDiscovery ¶
DelegateDiscovery delegates the POST discovery when a recipient has invited another person to a sharing, and this person accepts the sharing on the recipient cozy. The calls is delegated to the owner cozy.
func (*Sharing) DelegateRemoveReadOnlyFlag ¶
DelegateRemoveReadOnlyFlag is used by a recipient to ask the sharer to remove the read-only falg for another member of the sharing.
func (*Sharing) DowngradeToReadOnly ¶
func (s *Sharing) DowngradeToReadOnly(inst *instance.Instance, creds *APICredentials) error
DowngradeToReadOnly is used to receive credentials on a read-write instance to sync the last changes before going to read-only mode.
func (*Sharing) EndInitial ¶
EndInitial is used to finish the initial sync phase of a sharing
func (*Sharing) FindCredentials ¶
func (s *Sharing) FindCredentials(m *Member) *Credentials
FindCredentials returns the credentials for the given member
func (*Sharing) FindMemberByCode ¶
func (s *Sharing) FindMemberByCode(perms *permission.Permission, sharecode string) (*Member, error)
FindMemberByCode returns the member that is linked to the sharing by the given code.
func (*Sharing) FindMemberByInboundClientID ¶
FindMemberByInboundClientID returns the member that have used this client ID to make a request on the given sharing
func (*Sharing) FindMemberByInteractCode ¶
FindMemberByInteractCode returns the member that is linked to the sharing by the given sharecode via a share-interact permission.
func (*Sharing) FindMemberBySharecode ¶
FindMemberBySharecode returns the member that is linked to the sharing by the given sharecode
func (*Sharing) FindMemberByState ¶
FindMemberByState returns the member that is linked to the sharing by the given state
func (*Sharing) FirstBitwardenOrganizationRule ¶
FirstFilesRule returns the first not-local rules for the com.bitwarden.organizations doctype.
func (*Sharing) FirstFilesRule ¶
FirstFilesRule returns the first not-local rules for the files doctype.
func (*Sharing) GetFolder ¶
func (s *Sharing) GetFolder(inst *instance.Instance, m *Member, xoredID string) (map[string]interface{}, error)
GetFolder returns informations about a folder (with XORed IDs)
func (*Sharing) GetNoLongerSharedDir ¶
GetNoLongerSharedDir returns the directory used for files and folders that are removed from a sharing, but are still used via a reference. It the directory does not exist, it is created.
func (*Sharing) GetPreviewURL ¶
GetPreviewURL asks the owner's Cozy the URL for previewing the sharing.
func (*Sharing) GetSharecodeFromShortcut ¶
GetSharecodeFromShortcut returns the sharecode from the shortcut for this sharing.
func (*Sharing) GetSharingDir ¶
GetSharingDir returns the directory used by this sharing for putting files and folders that have no dir_id.
func (*Sharing) HandleFileUpload ¶
HandleFileUpload is used to receive a file upload when synchronizing just the metadata was not enough.
func (*Sharing) InitialCopy ¶
InitialCopy lists the shared documents and put a reference in the io.cozy.shared database
func (*Sharing) InitialUpload ¶
InitialUpload uploads files to just a member, for the first time
func (*Sharing) NoMoreRecipient ¶
NoMoreRecipient cleans up the sharing if there is no more active recipient
func (*Sharing) NotifyMemberRevocation ¶
NotifyMemberRevocation send a notification to this member that he/she was revoked from this sharing
func (*Sharing) NotifyRecipients ¶
NotifyRecipients will push the updated list of members of the sharing to the active recipients. It is meant to be used in a goroutine, errors are just logged (nothing critical here).
func (*Sharing) ProcessAnswer ¶
func (s *Sharing) ProcessAnswer(inst *instance.Instance, creds *APICredentials) (*APICredentials, error)
ProcessAnswer takes somes credentials and update the sharing with those.
func (*Sharing) ReadOnly ¶
ReadOnly returns true if the member has the read-only flag, or if the rules forces a read-only mode.
func (*Sharing) ReadOnlyFlag ¶
ReadOnlyFlag returns true only if the given instance is declared a read-only member of the sharing.
func (*Sharing) ReadOnlyRules ¶
ReadOnlyRules returns true if the rules forbid that a change on the recipient's cozy instance can be propagated to the sharer's cozy.
func (*Sharing) RedirectAfterAuthorizeURL ¶
RedirectAfterAuthorizeURL returns the URL for the redirection after a user has authorized a sharing.
func (*Sharing) RegisterCozyURL ¶
RegisterCozyURL saves a new Cozy URL for a member
func (*Sharing) RemoveAllBitwardenMembers ¶
RemoveAllBitwardenMembers removes all the members from the bitwarden organization (except the owner of the sharing).
func (*Sharing) RemoveBitwardenMember ¶
RemoveBitwardenMember removes a sharing member from the bitwarden organization. It is called when the owner revokes a member, or when the owner is notified that a member has left the sharing.
func (*Sharing) RemoveBitwardenOrganization ¶
RemoveBitwardenOrganization remove the shared bitwarden organization and the ciphers inside it. It is called on the recipient instance when the sharing is revoked for them.
func (*Sharing) RemoveReadOnlyFlag ¶
RemoveReadOnlyFlag removes the read-only flag of a recipient, and send credentials to their cozy so that it can push its changes.
func (*Sharing) RemoveSharingDir ¶
RemoveSharingDir removes the reference on the sharing directory, and adds a suffix to its name: the suffix will help make the user understand that the sharing has been revoked, and it will avoid conflicts if the user accepts a new sharing for the same folder. It should be called when a sharing is revoked, on the recipient Cozy.
func (*Sharing) RemoveTriggers ¶
RemoveTriggers remove all the triggers associated to this sharing
func (*Sharing) ReplicateTo ¶
ReplicateTo starts a replicator on this sharing to the given member. http://docs.couchdb.org/en/stable/replication/protocol.html https://github.com/pouchdb/pouchdb/blob/master/packages/node_modules/pouchdb-replication/src/replicate.js
func (*Sharing) Revoke ¶
Revoke remove the credentials for all members, contact them, removes the triggers and set the active flag to false.
func (*Sharing) RevokeByNotification ¶
RevokeByNotification is called on the recipient side, after a revocation performed by the sharer
func (*Sharing) RevokeMember ¶
RevokeMember revoke the access granted to a member and contact it
func (*Sharing) RevokeOwner ¶
RevokeOwner revoke the access granted to the owner and notify it
func (*Sharing) RevokePreviewPermissions ¶
RevokePreviewPermissions ensure that the permissions for the preview page are no longer valid.
func (*Sharing) RevokeRecipient ¶
RevokeRecipient revoke only one recipient on the sharer. After that, if the sharing has still at least one active member, we keep it as is. Else, we desactive the sharing.
func (*Sharing) RevokeRecipientByNotification ¶
RevokeRecipientByNotification is called on the sharer side, after a revocation performed by the recipient
func (*Sharing) RevokeRecipientBySelf ¶
RevokeRecipientBySelf revoke the sharing on the recipient side
func (*Sharing) SaveBitwarden ¶
SaveBitwarden adds the sharing member to the bitwarden organization in the sharing rules.
func (*Sharing) SendAnswer ¶
SendAnswer says to the sharer's Cozy that the sharing has been accepted, and materialize that by an exchange of credentials.
func (*Sharing) SendInvitations ¶
func (s *Sharing) SendInvitations(inst *instance.Instance, perms *permission.Permission) error
SendInvitations sends invitation mails to the recipients that were in the mail-not-sent status (owner only)
func (*Sharing) SendInvitationsToMembers ¶
func (s *Sharing) SendInvitationsToMembers(inst *instance.Instance, members []Member, states map[string]string) error
SendInvitationsToMembers sends mails from a recipient (open_sharing) to their contacts to invite them
func (*Sharing) SendShortcutMail ¶
func (s *Sharing) SendShortcutMail(inst *instance.Instance, fileDoc *vfs.FileDoc, previewURL string) error
SendShortcutMail will send a notification mail after a shortcut for a sharing has been created.
func (*Sharing) Setup ¶
Setup is used when a member accepts a sharing to prepare the io.cozy.shared database and start an initial replication. It is meant to be used in a new goroutine and, as such, does not return errors but log them.
func (*Sharing) SetupReceiver ¶
SetupReceiver is used on the receivers' cozy to make sure the cozy can receive the shared documents.
func (*Sharing) SortFilesToSent ¶
SortFilesToSent sorts the files slice that will be sent in bulk_docs:
- directories must come before files (if a file is created in a new directory, we must create directory before the file)
- directories are sorted by increasing depth (if a sub-folder is created in a new directory, we must create the parent before the child)
- deleted elements must come at the end, to efficiently cope with moves. For example, if we have A->B->C hierarchy and C is moved elsewhere and B deleted, we must make the move before deleting B and its children.
func (*Sharing) SyncFile ¶
func (s *Sharing) SyncFile(inst *instance.Instance, target *FileDocWithRevisions) (*KeyToUpload, error)
SyncFile tries to synchronize a file with just the metadata. If it can't, it will return a key to upload the content.
func (*Sharing) TransformFileToSent ¶
TransformFileToSent transforms an io.cozy.files document before sending it to another cozy instance: - its identifier is XORed - its dir_id is XORed or removed - the referenced_by are XORed or removed - the path is removed (directory only)
ruleIndexes is a map of "doctype-docid" -> rule index
func (*Sharing) TrashFile ¶
TrashFile puts the file in the trash (except if the file has a reference, in which case, we keep it in a special folder)
func (*Sharing) UpdateDir ¶
func (s *Sharing) UpdateDir( inst *instance.Instance, target map[string]interface{}, dir *vfs.DirDoc, ref *SharedRef, resolution nameConflictResolution, ) error
UpdateDir updates a directory on this cozy to reflect a change on another cozy instance of this sharing.
func (*Sharing) UpdateLastSequenceNumber ¶
func (s *Sharing) UpdateLastSequenceNumber(inst *instance.Instance, m *Member, worker, seq string) error
UpdateLastSequenceNumber updates the last sequence number for this replication if it's superior to the number in CouchDB
func (*Sharing) UpdateRecipients ¶
UpdateRecipients updates the list of recipients
func (*Sharing) UpgradeToReadWrite ¶
func (s *Sharing) UpgradeToReadWrite(inst *instance.Instance, creds *APICredentials) error
UpgradeToReadWrite is used to receive credentials on a read-only instance to upgrade it to read-write.
func (*Sharing) UploadExistingFile ¶
func (s *Sharing) UploadExistingFile(inst *instance.Instance, target *FileDocWithRevisions, newdoc *vfs.FileDoc, body io.ReadCloser) error
UploadExistingFile is used to receive new content for an existing file.
Note: if file was renamed + its content has changed, we modify the content first, then rename it, not trying to do both at the same time. We do it in this order because the difficult case is if one operation succeeds and the other fails (if the two succeeds, we are fine; if the two fails, we just retry), and in that case, it is easier to manage a conflict on dir_id+name than on content: a conflict on different content is resolved by a copy of the file (which is not what we want), a conflict of name+dir_id, the higher revision wins and it should be the good one in our case.
func (*Sharing) UploadNewFile ¶
func (s *Sharing) UploadNewFile(inst *instance.Instance, target *FileDocWithRevisions, body io.ReadCloser) error
UploadNewFile is used to receive a new file.
func (*Sharing) UploadTo ¶
UploadTo uploads one file to the given member. It returns false if there are no more files to upload to this member currently.
func (*Sharing) ValidateRules ¶
ValidateRules returns an error if the rules are invalid (the doctype is missing for example)
type TrackEvent ¶
type TrackEvent struct { Verb string `json:"verb"` Doc couchdb.JSONDoc `json:"doc"` OldDoc *couchdb.JSONDoc `json:"old,omitempty"` }
TrackEvent is used for jobs on the share-track worker. It's unique per job.
type TrackMessage ¶
type TrackMessage struct { SharingID string `json:"sharing_id"` RuleIndex int `json:"rule_index"` DocType string `json:"doctype"` }
TrackMessage is used for jobs on the share-track worker. It's the same for all the jobs of a trigger.
type Triggers ¶
type Triggers struct { TrackID string `json:"track_id,omitempty"` // Legacy TrackIDs []string `json:"track_ids,omitempty"` ReplicateID string `json:"replicate_id,omitempty"` UploadID string `json:"upload_id,omitempty"` }
Triggers keep record of which triggers are active
type UploadStore ¶
type UploadStore interface { Get(db prefixer.Prefixer, key string) (*FileDocWithRevisions, error) Save(db prefixer.Prefixer, doc *FileDocWithRevisions) (string, error) }
A UploadStore is essentially an object to store files metadata by key