model

package
v3.4.2 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessMethod added in v3.4.0

type AccessMethod int

AccessMethod is method granted by the sharer to access the shared resource.

const (
	// WebDAVAccessMethod indicates an access using WebDAV to the share.
	WebDAVAccessMethod AccessMethod = iota
	// WebappAccessMethod indicates an access using a collaborative
	// application to the share.
	WebappAccessMethod
	// TransferAccessMethod indicates a share for a transfer.
	TransferAccessMethod
)

type BaseModel

type BaseModel struct {
	// Id has to be called Id and not ID, otherwise the foreign key will not work
	// ID is a special field in GORM, which it uses as the default Primary Key
	Id        uint    `gorm:"primaryKey;not null;autoIncrement:false"`
	ShareId   ShareID `gorm:"foreignKey:Id;references:ID;constraint:OnDelete:CASCADE"` //;references:ID
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

We cannot use gorm.Model, because we want our ID to be a foreign key to ShareID

type ItemType

type ItemType string
const (
	ItemTypeFile      ItemType = "file"
	ItemTypeFolder    ItemType = "folder"
	ItemTypeReference ItemType = "reference"
	ItemTypeSymlink   ItemType = "symlink"
)

func (ItemType) String

func (i ItemType) String() string

type OcmItemType added in v3.4.0

type OcmItemType int

ItemType is the type of the shares resource.

const (
	// ItemTypeFile is used when the shared resource is a file.
	OcmItemTypeFile OcmItemType = iota
	// ItemTypeFolder is used when the shared resource is a folder.
	OcmItemTypeFolder
)

type OcmReceivedShare added in v3.4.0

type OcmReceivedShare struct {
	gorm.Model
	RemoteShareID string        `gorm:"not null"`
	Name          string        `gorm:"size:255;not null"`
	FileidPrefix  string        `gorm:"size:255;not null"`
	ItemSource    string        `gorm:"size:255;not null"`
	ItemType      OcmItemType   `gorm:"not null"`
	ShareWith     string        `gorm:"size:255;not null"`
	Owner         string        `gorm:"size:255;not null"`
	Initiator     string        `gorm:"size:255;not null"`
	Ctime         uint64        `gorm:"not null"`
	Mtime         uint64        `gorm:"not null"`
	Expiration    sql.NullInt64 `gorm:"default:null"`
	Type          ShareType     `gorm:"not null"`
	State         OcmShareState `gorm:"not null"`
}

OCM Received Shares

type OcmReceivedShareProtocol added in v3.4.0

type OcmReceivedShareProtocol struct {
	gorm.Model
	OcmReceivedShareID uint             `gorm:"not null;uniqueIndex:idx_received_share_protocol"`
	OcmReceivedShare   OcmReceivedShare `gorm:"constraint:OnDelete:CASCADE;foreignKey:OcmReceivedShareID;references:ID"`
	Type               Protocol         `gorm:"not null;uniqueIndex:idx_received_share_protocol"`
	Uri                string           `gorm:"size:255"`
	SharedSecret       string           `gorm:"type:text;not null"`
	// WebDAV and WebApp Protocol fields
	Permissions int `gorm:"default:null"`
	// Transfer Protocol fields
	Size uint64 `gorm:"default:null"`
}

OCM Received Share Protocols

type OcmShare added in v3.4.0

type OcmShare struct {
	// The fields of the base model had to be copied since we need an index on DeletedAt + unique constraints
	// Id has to be called Id and not ID, otherwise the foreign key will not work
	// ID is a special field in GORM, which it uses as the default Primary Key
	Id        uint    `gorm:"primaryKey;not null;autoIncrement:false"`
	ShareId   ShareID `gorm:"foreignKey:Id;references:ID;constraint:OnDelete:CASCADE"`
	CreatedAt time.Time
	UpdatedAt time.Time
	// Needs to be indexed because shares that are deleted need to be unique so we can add a new share after it was deleted
	DeletedAt     gorm.DeletedAt          `gorm:"index;uniqueIndex:idx_fileid_source_share_with_deletedat"`
	Token         string                  `gorm:"size:255;not null;uniqueIndex"`
	FileidPrefix  string                  `gorm:"size:64;not null;uniqueIndex:idx_fileid_source_share_with_deletedat"`
	ItemSource    string                  `gorm:"size:64;not null;uniqueIndex:idx_fileid_source_share_with_deletedat"`
	Name          string                  `gorm:"type:text;not null"`
	ShareWith     string                  `gorm:"size:255;not null;uniqueIndex:idx_fileid_source_share_with_deletedat"`
	Owner         string                  `gorm:"size:255;not null;uniqueIndex:idx_fileid_source_share_with_deletedat"`
	Initiator     string                  `gorm:"type:text;not null"`
	Ctime         uint64                  `gorm:"not null"`
	Mtime         uint64                  `gorm:"not null"`
	Expiration    sql.NullInt64           `gorm:"default:null"`
	Type          ShareType               `gorm:"not null"`
	AccessMethods []OcmSharesAccessMethod `gorm:"constraint:OnDelete:CASCADE;"`
}

type OcmShareState added in v3.4.0

type OcmShareState int

ShareState is the state of the share.

const (
	// ShareStatePending is the state for a pending share.
	ShareStatePending OcmShareState = iota
	// ShareStateAccepted is the share for an accepted share.
	ShareStateAccepted
	// ShareStateRejected is the share for a rejected share.
	ShareStateRejected
)

type OcmSharesAccessMethod added in v3.4.0

type OcmSharesAccessMethod struct {
	gorm.Model
	OcmShareID uint `gorm:"not null;uniqueIndex:idx_ocm_share_method"`
	//OcmShare   OcmShare     `gorm:"constraint:OnDelete:CASCADE;foreignKey:OcmShareID;references:Id"`
	Type AccessMethod `gorm:"not null;uniqueIndex:idx_ocm_share_method"`
	// WebDAV and WebApp fields
	Permissions int `gorm:"default:null"`
}

OCM Shares Access Methods

type ProtoShare

type ProtoShare struct {
	// Including gorm.Model will embed a number of gorm-default fields
	BaseModel
	UIDOwner     string   `gorm:"size:64"`
	UIDInitiator string   `gorm:"size:64;index"`
	ItemType     ItemType `gorm:"size:16;index"` // file | folder | reference | symlink
	InitialPath  string
	Inode        string `gorm:"size:32;index"`
	Instance     string `gorm:"size:32;index"`
	Permissions  uint8
	Orphan       bool
	Expiration   datatypes.NullTime
}

ProtoShare contains fields that are shared between PublicLinks and Shares. Unfortunately, because these are shared, we cannot name our indexes because then two indexes with the same name would be created

type Protocol added in v3.4.0

type Protocol int

Protocol is the protocol the recipient of the share uses to access the shared resource.

const (
	// WebDAVProtocol is the WebDav protocol.
	WebDAVProtocol Protocol = iota
	// WebappProtocol is the Webapp protocol.
	WebappProtocol
	// TransferProtocol is the Transfer protocol.
	TransferProtocol
)
type PublicLink struct {
	ProtoShare
	// Current tokens are only 16 chars long, but old tokens used to be 32 characters
	Token                        string `gorm:"uniqueIndex:i_token;size:32"`
	Quicklink                    bool
	NotifyUploads                bool
	NotifyUploadsExtraRecipients string
	Password                     string `gorm:"size:255"`
	// Users can give a name to a share
	LinkName string `gorm:"size:512"`
}

func (*PublicLink) AsCS3PublicShare

func (p *PublicLink) AsCS3PublicShare() *link.PublicShare

type Share

type Share struct {
	ProtoShare
	ShareWith         string `gorm:"size:255;index:i_share_with"` // 255 because this can be a lw account, which are mapped from email addresses / ...
	SharedWithIsGroup bool
	Description       string `gorm:"size:1024"`
}

func (*Share) AsCS3ReceivedShare

func (s *Share) AsCS3ReceivedShare(state *ShareState, granteeType userpb.UserType) *collaboration.ReceivedShare

func (*Share) AsCS3Share

func (s *Share) AsCS3Share(granteeType userpb.UserType) *collaboration.Share

type ShareID

type ShareID struct {
	ID uint `gorm:"primarykey"`
}

type ShareState

type ShareState struct {
	gorm.Model
	ShareID uint  `gorm:"uniqueIndex:i_shareid_user"`       // Define the foreign key field
	Share   Share `gorm:"foreignKey:ShareID;references:Id"` // Define the association
	// Can not be uid because of lw accs
	User   string `gorm:"uniqueIndex:i_shareid_user;size:255"`
	Synced bool
	Hidden bool
	Alias  string `gorm:"size:64"`
}

type ShareType added in v3.4.0

type ShareType int

ShareType is the type of the share.

const (
	// ShareTypeUser is used for a share to an user.
	ShareTypeUser ShareType = iota
	// ShareTypeGroup is used for a share to a group.
	ShareTypeGroup
)

Jump to

Keyboard shortcuts

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