sharing

package
v0.0.0-...-4b98c26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2021 License: AGPL-3.0 Imports: 50 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
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
)
View Source
const (
	SharingDirAlreadyTrashed = true
	SharingDirNotTrashed     = false
)
View Source
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"
)
View Source
const BatchSize = 100

BatchSize is the maximal number of documents mainpulated at once by the replicator

View Source
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)

View Source
const MaxDepth = 100

MaxDepth is the maximum number of revisions in a chain that we keep for a document.

View Source
const MaxRetries = 5

MaxRetries is the maximal number of retries for a replicator

View Source
const (
	// StateLen is the number of bytes for the OAuth state parameter
	StateLen = 16
)

Variables

View Source
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

func AskReupload(inst *instance.Instance) error

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

func CheckSharings(inst *instance.Instance) ([]map[string]interface{}, error)

CheckSharings will scan all the io.cozy.sharings documents and check their triggers and members/credentials.

func ConvertOAuthClient

func ConvertOAuthClient(c *oauth.Client) *auth.Client

ConvertOAuthClient converts an OAuth client from one type (model/oauth.Client) to another (client/auth.Client)

func CountNewShortcuts

func CountNewShortcuts(inst *instance.Instance) (int, error)

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

func CreateOAuthClient(inst *instance.Instance, m *Member) (*oauth.Client, error)

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

func EnsureSharedWithMeDir(inst *instance.Instance) (*vfs.DirDoc, error)

EnsureSharedWithMeDir returns the shared-with-me directory, and create it if it doesn't exist

func GetSharecode

func GetSharecode(inst *instance.Instance, sharingID, clientID string) (string, error)

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

func GetSharingsByDocType(inst *instance.Instance, docType string) (map[string]*Sharing, error)

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

func MixupChainToResolveConflict(rev string, chain []string) []string

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

func ParseRequestError(res *http.Response, body []byte) error

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

func PersistInstanceURL(inst *instance.Instance, email, cozyURL string)

PersistInstanceURL updates the io.cozy.contacts document with the Cozy instance URL

func PushUploadJob

func PushUploadJob(s *Sharing, inst *instance.Instance)

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

func RemoveSharedRefs(inst *instance.Instance, sharingID string) error

RemoveSharedRefs deletes the references containing the sharingid

func RevGeneration

func RevGeneration(rev string) int

RevGeneration returns the number before the hyphen, called the generation of a revision

func SendPublicKey

func SendPublicKey(inst *instance.Instance, publicKey string) error

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

func XorID

func XorID(id string, key []byte) string

XorID transforms the identifier of a file to a new identifier, in a reversible way: it makes a XOR on the hexadecimal characters

Types

type APIBitwarden

type APIBitwarden struct {
	UserID    string `json:"user_id"`
	PublicKey string `json:"public_key"`
}

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 (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) Rev

func (c *APICredentials) Rev() string

Rev returns the sharing revision

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

ID returns the sharing qualified identifier

func (*APIDelegateAddContacts) Included

func (a *APIDelegateAddContacts) Included() []jsonapi.Object

Included is part of jsonapi.Object interface

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) Clone

func (m *APIMoved) Clone() couchdb.Doc

Clone is part of jsonapi.Object interface

func (*APIMoved) DocType

func (m *APIMoved) DocType() string

DocType returns the sharing document type

func (*APIMoved) ID

func (m *APIMoved) ID() string

ID returns the sharing qualified identifier

func (*APIMoved) Included

func (m *APIMoved) Included() []jsonapi.Object

Included is part of jsonapi.Object interface

func (m *APIMoved) Links() *jsonapi.LinksList

Links is part of jsonapi.Object interface

func (*APIMoved) Relationships

func (m *APIMoved) Relationships() jsonapi.RelationshipMap

Relationships is part of jsonapi.Object interface

func (*APIMoved) Rev

func (m *APIMoved) Rev() string

Rev returns the sharing revision

func (*APIMoved) SetID

func (m *APIMoved) SetID(id string)

SetID changes the sharing qualified identifier

func (*APIMoved) SetRev

func (m *APIMoved) SetRev(rev string)

SetRev changes the sharing revision

type APISharing

type APISharing struct {
	*Sharing
	// XXX Hide the credentials
	Credentials *interface{}           `json:"credentials,omitempty"`
	SharedDocs  []couchdb.DocReference `json:"-"`
}

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 (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 Changed

type Changed map[string][]string

Changed is a map of "doctype/docid" -> [revisions]

type Changes

type Changes struct {
	Changed Changed
	Removed Removed
}

Changes is a struct with informations from the changes feed of io.cozy.shared

type CheckSharedError

type CheckSharedError struct {
	Type   string `json:"type"`
	ID     string `json:"_id"`
	Parent string `json:"parent_rev"`
	Child  string `json:"child_rev"`
}

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.

func (*Credentials) Refresh

func (c *Credentials) Refresh(inst *instance.Instance, s *Sharing, m *Member) error

Refresh will refresh the access token, and persist the new access token in the sharing

type DocsByDoctype

type DocsByDoctype map[string]DocsList

DocsByDoctype is a map of doctype -> slice of documents of this doctype

type DocsList

type DocsList []map[string]interface{}

DocsList is a slice of raw documents

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

func NewFileOpener(inst *instance.Instance, file *vfs.FileDoc) (*FileOpener, error)

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

func (m *Member) GenerateOAuthURL(s *Sharing) (string, error)

GenerateOAuthURL takes care of creating a correct OAuth request for the given member of the sharing.

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

func (m *Member) PrimaryName() string

PrimaryName returns the main name of this member

func (*Member) SendMail

func (m *Member) SendMail(inst *instance.Instance, s *Sharing, sharer, description, link string) error

SendMail sends an invitation mail to a recipient

func (*Member) SendShortcut

func (m *Member) SendShortcut(inst *instance.Instance, s *Sharing, link string) error

SendShortcut sends the HTTP request to the cozy of the recipient for adding a shortcut on the recipient's instance.

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
	Sharecode 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 Removed

type Removed map[string]struct{}

Removed is a set of "doctype/docid"

type ReplicateMsg

type ReplicateMsg struct {
	SharingID string `json:"sharing_id"`
	Errors    int    `json:"errors"`
}

ReplicateMsg is used for jobs on the share-replicate worker.

type RevsStruct

type RevsStruct struct {
	Start int      `json:"start"`
	IDs   []string `json:"ids"`
}

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) Add

func (rt *RevsTree) Add(rev string) *RevsTree

Add inserts the given revision in the main branch

func (*RevsTree) Clone

func (rt *RevsTree) Clone() RevsTree

Clone duplicates the RevsTree

func (*RevsTree) Find

func (rt *RevsTree) Find(rev string) (*RevsTree, int)

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

func (rt *RevsTree) Generation() int

Generation returns the maximal generation of a revision in this tree

func (*RevsTree) InsertAfter

func (rt *RevsTree) InsertAfter(rev, parent string)

InsertAfter inserts the given revision in the tree as a child of the second revision.

func (*RevsTree) InsertChain

func (rt *RevsTree) InsertChain(chain []string)

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) Accept

func (r Rule) Accept(doctype string, doc map[string]interface{}) bool

Accept returns true if the document matches the rule criteria

func (Rule) FilesByID

func (r Rule) FilesByID() bool

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) HasPush

func (r *Rule) HasPush() bool

HasPush returns true if the rule has a push behaviour

func (*Rule) HasSync

func (r *Rule) HasSync() bool

HasSync returns true if the rule has a sync behaviour

func (Rule) TriggerArgs

func (r Rule) TriggerArgs() string

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 {
	// Rule is the index of the rule inside the sharing rules
	Rule int `json:"rule"`

	// Removed is true for a deleted document, a trashed file, or if the
	// document does no longer match the sharing rule
	Removed bool `json:"removed,omitempty"`

	// Binary is a boolean flag that is true only for files (and not even
	// folders) with `removed: false`
	Binary bool `json:"binary,omitempty"`

	// Dissociated is a boolean flag that can be true only for files and
	// 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"`
}

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
	SID  string `json:"_id,omitempty"`
	SRev string `json:"_rev,omitempty"`

	// Revisions is a tree with the last known _rev of the shared object.
	Revisions *RevsTree `json:"revisions"`

	// Infos is a map of sharing ids -> informations
	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

func FindReferences(inst *instance.Instance, ids []string) ([]*SharedRef, error)

FindReferences returns the io.cozy.shared references to the given identifiers

func (*SharedRef) Clone

func (s *SharedRef) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (*SharedRef) DocType

func (s *SharedRef) DocType() string

DocType returns the sharing document type

func (*SharedRef) Fetch

func (s *SharedRef) Fetch(field string) []string

Fetch implements the permission.Fetcher interface

func (*SharedRef) ID

func (s *SharedRef) ID() string

ID returns the sharing qualified identifier

func (*SharedRef) Rev

func (s *SharedRef) Rev() string

Rev returns the sharing revision

func (*SharedRef) SetID

func (s *SharedRef) SetID(id string)

SetID changes the sharing qualified identifier

func (*SharedRef) SetRev

func (s *SharedRef) SetRev(rev string)

SetRev changes the sharing revision

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

func FindSharing(db prefixer.Prefixer, sharingID string) (*Sharing, error)

FindSharing retrieves a sharing document from its ID

func FindSharings

func FindSharings(db prefixer.Prefixer, sharingIDs []string) ([]*Sharing, error)

FindSharings retrieves an array of sharing documents from their IDs

func (*Sharing) AddContact

func (s *Sharing) AddContact(inst *instance.Instance, contactID string, readOnly bool) error

AddContact adds the contact with the given identifier

func (*Sharing) AddContacts

func (s *Sharing) AddContacts(inst *instance.Instance, contactIDs map[string]bool) error

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

func (s *Sharing) AddReadOnlyFlag(inst *instance.Instance, index int) error

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

func (s *Sharing) AddReferenceForSharingDir(inst *instance.Instance, rule *Rule) error

AddReferenceForSharingDir adds a reference to the sharing on the sharing directory

func (*Sharing) AddReplicateTrigger

func (s *Sharing) AddReplicateTrigger(inst *instance.Instance) error

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

func (s *Sharing) AddShortcut(inst *instance.Instance, state string) error

AddShortcut creates a shortcut for this sharing on the local instance.

func (*Sharing) AddTrackTriggers

func (s *Sharing) AddTrackTriggers(inst *instance.Instance) error

AddTrackTriggers creates the share-track triggers for each rule of the sharing that will update the io.cozy.shared database.

func (*Sharing) AddUploadTrigger

func (s *Sharing) AddUploadTrigger(inst *instance.Instance) error

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

func (s *Sharing) ApplyBulkFiles(inst *instance.Instance, docs DocsList) error

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) BeOwner

func (s *Sharing) BeOwner(inst *instance.Instance, slug string) error

BeOwner initializes a sharing on the cozy of its owner

func (*Sharing) ChangeMemberAddress

func (s *Sharing) ChangeMemberAddress(inst *instance.Instance, m *Member, params APIMoved) error

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

func (s *Sharing) ChangeOwnerAddress(inst *instance.Instance, params APIMoved) error

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

func (s *Sharing) ClearLastSequenceNumbers(inst *instance.Instance, m *Member) error

ClearLastSequenceNumbers removes the last sequence numbers for a member

func (*Sharing) Clone

func (s *Sharing) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (*Sharing) ComputeRevsDiff

func (s *Sharing) ComputeRevsDiff(inst *instance.Instance, changed Changed) (*Missings, error)

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

func (s *Sharing) CreateInteractPermissions(inst *instance.Instance, m *Member) (string, error)

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

func (s *Sharing) CreateRequest(inst *instance.Instance) error

CreateRequest prepares a sharing as just a request that the user will have to accept before it does anything.

func (*Sharing) CreateShortcut

func (s *Sharing) CreateShortcut(inst *instance.Instance, previewURL string, seen bool) error

CreateShortcut is used to create a shortcut for a Cozy to Cozy sharing that has not yet been accepted.

func (*Sharing) DelegateAddContacts

func (s *Sharing) DelegateAddContacts(inst *instance.Instance, contactIDs map[string]bool) error

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

func (s *Sharing) DelegateAddReadOnlyFlag(inst *instance.Instance, index int) error

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

func (s *Sharing) DelegateDiscovery(inst *instance.Instance, state, cozyURL string) (string, error)

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

func (s *Sharing) DelegateRemoveReadOnlyFlag(inst *instance.Instance, index int) error

DelegateRemoveReadOnlyFlag is used by a recipient to ask the sharer to remove the read-only falg for another member of the sharing.

func (*Sharing) DocType

func (s *Sharing) DocType() string

DocType returns the sharing document type

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

func (s *Sharing) EndInitial(inst *instance.Instance) error

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

func (s *Sharing) FindMemberByInboundClientID(clientID string) (*Member, error)

FindMemberByInboundClientID returns the member that have used this client ID to make a request on the given sharing

func (*Sharing) FindMemberByInteractCode

func (s *Sharing) FindMemberByInteractCode(db prefixer.Prefixer, sharecode string) (*Member, error)

FindMemberByInteractCode returns the member that is linked to the sharing by the given sharecode via a share-interact permission.

func (*Sharing) FindMemberBySharecode

func (s *Sharing) FindMemberBySharecode(db prefixer.Prefixer, sharecode string) (*Member, error)

FindMemberBySharecode returns the member that is linked to the sharing by the given sharecode

func (*Sharing) FindMemberByState

func (s *Sharing) FindMemberByState(state string) (*Member, error)

FindMemberByState returns the member that is linked to the sharing by the given state

func (*Sharing) FirstBitwardenOrganizationRule

func (s *Sharing) FirstBitwardenOrganizationRule() *Rule

FirstFilesRule returns the first not-local rules for the com.bitwarden.organizations doctype.

func (*Sharing) FirstFilesRule

func (s *Sharing) FirstFilesRule() *Rule

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

func (s *Sharing) GetNoLongerSharedDir(inst *instance.Instance) (*vfs.DirDoc, error)

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

func (s *Sharing) GetPreviewURL(inst *instance.Instance, state string) (string, error)

GetPreviewURL asks the owner's Cozy the URL for previewing the sharing.

func (*Sharing) GetSharecodeFromShortcut

func (s *Sharing) GetSharecodeFromShortcut(inst *instance.Instance) (string, error)

GetSharecodeFromShortcut returns the sharecode from the shortcut for this sharing.

func (*Sharing) GetSharingDir

func (s *Sharing) GetSharingDir(inst *instance.Instance) (*vfs.DirDoc, error)

GetSharingDir returns the directory used by this sharing for putting files and folders that have no dir_id.

func (*Sharing) HandleFileUpload

func (s *Sharing) HandleFileUpload(inst *instance.Instance, key string, body io.ReadCloser) error

HandleFileUpload is used to receive a file upload when synchronizing just the metadata was not enough.

func (*Sharing) ID

func (s *Sharing) ID() string

ID returns the sharing qualified identifier

func (*Sharing) InitialCopy

func (s *Sharing) InitialCopy(inst *instance.Instance, rule Rule, r int) error

InitialCopy lists the shared documents and put a reference in the io.cozy.shared database

func (*Sharing) InitialUpload

func (s *Sharing) InitialUpload(inst *instance.Instance, m *Member) error

InitialUpload uploads files to just a member, for the first time

func (*Sharing) NoMoreRecipient

func (s *Sharing) NoMoreRecipient(inst *instance.Instance) error

NoMoreRecipient cleans up the sharing if there is no more active recipient

func (*Sharing) NotifyMemberRevocation

func (s *Sharing) NotifyMemberRevocation(inst *instance.Instance, m *Member, c *Credentials) error

NotifyMemberRevocation send a notification to this member that he/she was revoked from this sharing

func (*Sharing) NotifyRecipients

func (s *Sharing) NotifyRecipients(inst *instance.Instance, except *Member)

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

func (s *Sharing) ReadOnly() bool

ReadOnly returns true if the member has the read-only flag, or if the rules forces a read-only mode.

func (*Sharing) ReadOnlyFlag

func (s *Sharing) ReadOnlyFlag() bool

ReadOnlyFlag returns true only if the given instance is declared a read-only member of the sharing.

func (*Sharing) ReadOnlyRules

func (s *Sharing) ReadOnlyRules() bool

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

func (s *Sharing) RedirectAfterAuthorizeURL(inst *instance.Instance) *url.URL

RedirectAfterAuthorizeURL returns the URL for the redirection after a user has authorized a sharing.

func (*Sharing) RegisterCozyURL

func (s *Sharing) RegisterCozyURL(inst *instance.Instance, m *Member, cozyURL string) error

RegisterCozyURL saves a new Cozy URL for a member

func (*Sharing) RemoveAllBitwardenMembers

func (s *Sharing) RemoveAllBitwardenMembers(inst *instance.Instance, orgID string) error

RemoveAllBitwardenMembers removes all the members from the bitwarden organization (except the owner of the sharing).

func (*Sharing) RemoveBitwardenMember

func (s *Sharing) RemoveBitwardenMember(inst *instance.Instance, m *Member, orgID string) error

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

func (s *Sharing) RemoveBitwardenOrganization(inst *instance.Instance, orgID string) error

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

func (s *Sharing) RemoveReadOnlyFlag(inst *instance.Instance, index int) error

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

func (s *Sharing) RemoveSharingDir(inst *instance.Instance) error

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

func (s *Sharing) RemoveTriggers(inst *instance.Instance) error

RemoveTriggers remove all the triggers associated to this sharing

func (*Sharing) Replicate

func (s *Sharing) Replicate(inst *instance.Instance, errors int) error

Replicate starts a replicator on this sharing.

func (*Sharing) Rev

func (s *Sharing) Rev() string

Rev returns the sharing revision

func (*Sharing) Revoke

func (s *Sharing) Revoke(inst *instance.Instance) error

Revoke remove the credentials for all members, contact them, removes the triggers and set the active flag to false.

func (*Sharing) RevokeByNotification

func (s *Sharing) RevokeByNotification(inst *instance.Instance) error

RevokeByNotification is called on the recipient side, after a revocation performed by the sharer

func (*Sharing) RevokeMember

func (s *Sharing) RevokeMember(inst *instance.Instance, index int) error

RevokeMember revoke the access granted to a member and contact it

func (*Sharing) RevokeOwner

func (s *Sharing) RevokeOwner(inst *instance.Instance) error

RevokeOwner revoke the access granted to the owner and notify it

func (*Sharing) RevokePreviewPermissions

func (s *Sharing) RevokePreviewPermissions(inst *instance.Instance) error

RevokePreviewPermissions ensure that the permissions for the preview page are no longer valid.

func (*Sharing) RevokeRecipient

func (s *Sharing) RevokeRecipient(inst *instance.Instance, index int) error

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

func (s *Sharing) RevokeRecipientByNotification(inst *instance.Instance, m *Member) error

RevokeRecipientByNotification is called on the sharer side, after a revocation performed by the recipient

func (*Sharing) RevokeRecipientBySelf

func (s *Sharing) RevokeRecipientBySelf(inst *instance.Instance, sharingDirTrashed bool) error

RevokeRecipientBySelf revoke the sharing on the recipient side

func (*Sharing) SaveBitwarden

func (s *Sharing) SaveBitwarden(inst *instance.Instance, m *Member, bw *APIBitwarden) error

SaveBitwarden adds the sharing member to the bitwarden organization in the sharing rules.

func (*Sharing) SendAnswer

func (s *Sharing) SendAnswer(inst *instance.Instance, state string) error

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) SetID

func (s *Sharing) SetID(id string)

SetID changes the sharing qualified identifier

func (*Sharing) SetRev

func (s *Sharing) SetRev(rev string)

SetRev changes the sharing revision

func (*Sharing) Setup

func (s *Sharing) Setup(inst *instance.Instance, m *Member)

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

func (s *Sharing) SetupReceiver(inst *instance.Instance) error

SetupReceiver is used on the receivers' cozy to make sure the cozy can receive the shared documents.

func (*Sharing) SortFilesToSent

func (s *Sharing) SortFilesToSent(files []map[string]interface{})

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

func (s *Sharing) TransformFileToSent(doc map[string]interface{}, xorKey []byte, ruleIndex int)

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) TrashDir

func (s *Sharing) TrashDir(inst *instance.Instance, dir *vfs.DirDoc) error

TrashDir puts the directory in the trash

func (*Sharing) TrashFile

func (s *Sharing) TrashFile(inst *instance.Instance, file *vfs.FileDoc, rule *Rule) error

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

func (s *Sharing) UpdateRecipients(inst *instance.Instance, members []Member) error

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) Upload

func (s *Sharing) Upload(inst *instance.Instance, errors int) error

Upload starts uploading files for this sharing

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

func (s *Sharing) UploadTo(inst *instance.Instance, m *Member, lastTry bool) (bool, error)

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

func (s *Sharing) ValidateRules() error

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 UploadMsg

type UploadMsg struct {
	SharingID string `json:"sharing_id"`
	Errors    int    `json:"errors"`
}

UploadMsg is used for jobs on the share-upload worker.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL