model

package
v3.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 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 ItemType

type ItemType string

ItemType is the type of the shared resource.

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

func (ItemType) String

func (i ItemType) String() string

type OcmProtocol added in v3.5.0

type OcmProtocol int

OcmProtocol is the protocol used by the recipient of an OCM share (both incoming and outgoing) to access the shared resource.

const (
	// WebDAVProtocol is the OCM `webdav` protocol.
	WebDAVProtocol OcmProtocol = iota
	// WebappProtocol is the OCM `webapp` protocol.
	WebappProtocol
	// TransferProtocol is the OCM `datatx` protocol.
	TransferProtocol
)

type OcmReceivedShare added in v3.4.0

type OcmReceivedShare struct {
	gorm.Model
	RemoteShareID string             `gorm:"index:i_ocmrecshare_remoteshareid;not null"`
	Name          string             `gorm:"size:255;not null"`
	ItemType      ItemType           `gorm:"size:16;not null"`
	ShareWith     string             `gorm:"size:255;not null"`
	Owner         string             `gorm:"index:i_ocmrecshare_owner;size:255;not null"`
	Initiator     string             `gorm:"index:i_ocmrecshare_initiator;size:255;not null"`
	Ctime         uint64             `gorm:"not null"`
	Mtime         uint64             `gorm:"not null"`
	Expiration    datatypes.NullTime `gorm:"index"`
	RecipientType OcmShareType       `gorm:"index:i_ocmrecshare_type;not null"`
	State         OcmShareState      `gorm:"index:i_ocmrecshare_state;not null"`
	Alias         string             `gorm:"size:64"`
	Hidden        bool
}

OcmReceivedShare represents an OCM share received from a remote user.

type OcmReceivedShareProtocol added in v3.4.0

type OcmReceivedShareProtocol struct {
	gorm.Model
	OcmReceivedShareID uint             `gorm:"not null;uniqueIndex:u_ocmrecshare_protocol"`
	OcmReceivedShare   OcmReceivedShare `gorm:"constraint:OnDelete:CASCADE;foreignKey:OcmReceivedShareID;references:ID"`
	Type               OcmProtocol      `gorm:"not null;uniqueIndex:u_ocmrecshare_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"`
}

OcmReceivedShareProtocol represents the protocol used to access an OCM share received from a remote user.

type OcmShare added in v3.4.0

type OcmShare struct {
	ProtoShare
	DeletedAt     gorm.DeletedAt     `gorm:"uniqueIndex:u_ocmshare"`
	Inode         string             `gorm:"size:64;not null;uniqueIndex:u_ocmshare"`
	Instance      string             `gorm:"size:64;not null;uniqueIndex:u_ocmshare"`
	Token         string             `gorm:"size:255;not null;uniqueIndex:u_ocmshare_token"`
	Name          string             `gorm:"type:text;not null"`
	ShareWith     string             `gorm:"size:255;not null;uniqueIndex:u_ocmshare"`
	Owner         string             `gorm:"size:255;not null"`
	Initiator     string             `gorm:"type:text;not null"`
	Ctime         uint64             `gorm:"not null"`
	Mtime         uint64             `gorm:"not null"`
	RecipientType OcmShareType       `gorm:"not null"`
	Protocols     []OcmShareProtocol `gorm:"constraint:OnDelete:CASCADE;"`
}

OcmShare represents an OCM share for a remote user. The unique index ensures that there can only be one share per (inode, instance, recipient) tuple, unless the share is deleted. In addition, tokens must be unique. TODO(lopresti) see if we can consolidate Owner and Initiator with UIDOwner and UIDInitiator in ProtoShare

type OcmShareProtocol added in v3.5.0

type OcmShareProtocol struct {
	gorm.Model
	OcmShareID  uint        `gorm:"not null;uniqueIndex:u_ocm_share_protocol"`
	Type        OcmProtocol `gorm:"not null;uniqueIndex:u_ocm_share_protocol"`
	Permissions int         `gorm:"default:null"`
}

OcmShareProtocol represents the protocol used to access an OCM share, named AccessMethod in the OCM CS3 APIs.

type OcmShareState added in v3.4.0

type OcmShareState int

For OCM shares, OcmShareState is their state.

const (
	// OcmShareStatePending is the state for a pending share.
	OcmShareStatePending OcmShareState = iota
	// OcmShareStateAccepted is the share for an accepted share.
	OcmShareStateAccepted
	// OcmShareStateRejected is the share for a rejected share.
	OcmShareStateRejected
)

type OcmShareType added in v3.5.0

type OcmShareType int

For OCM shares, OcmShareType is the type of the recipient.

const (
	// OcmShareTypeUser is used for a share to an user.
	OcmShareTypeUser OcmShareType = iota
	// OcmShareTypeGroup is used for a share to a group.
	OcmShareTypeGroup
)

type ProtoShare

type ProtoShare 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"`
	//Inode      string `gorm:"size:32;index"`
	//Instance   string `gorm:"size:32;index"`
	UIDOwner     string   `gorm:"size:64"`
	UIDInitiator string   `gorm:"size:64;index"`
	ItemType     ItemType `gorm:"size:16;index"` // file | folder | reference | symlink
	InitialPath  string
	Permissions  uint8
	Orphan       bool
	Expiration   datatypes.NullTime `gorm:"index"`
}

This is the base model for all share types and embeds parts of gorm.Model. We can't use it, because we want our ID to be a foreign key to ShareID, but we incorporate the date fields from GORM. The commented-out fields would logically belong here, but we define them in each specific type to control the unique indexes to be enforced in the corresponding tables.

type PublicLink struct {
	ProtoShare
	DeletedAt                    gorm.DeletedAt `gorm:"index"`
	Inode                        string         `gorm:"size:32"`
	Instance                     string         `gorm:"size:32"`
	Token                        string         `gorm:"uniqueIndex:u_link_token;size:32"` // Current tokens are only 16 chars long, but old tokens used to be 32 characters
	Quicklink                    bool
	NotifyUploads                bool
	NotifyUploadsExtraRecipients string
	Password                     string `gorm:"size:255"`
	LinkName                     string `gorm:"size:512"` // Users can give a name to a share
}

PublicLink is a public link share. We only enforce a unique constraint on the token.

func (*PublicLink) AsCS3PublicShare

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

type Share

type Share struct {
	ProtoShare
	DeletedAt         gorm.DeletedAt `gorm:"uniqueIndex:u_share"`
	Inode             string         `gorm:"size:32;uniqueIndex:u_share"`
	Instance          string         `gorm:"size:32;uniqueIndex:u_share"`
	ShareWith         string         `gorm:"size:255;uniqueIndex:u_share"` // 255 because this can be an external account, which has a long representation
	SharedWithIsGroup bool
	Description       string `gorm:"size:1024"`
}

Share is a regular share between users or groups. The unique index ensures that there can only be one share per (inode, instance, recipient) tuple, unless the share is deleted.

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"`
}

ShareID only contains IDs of shares and public links. This is because the Web UI requires that shares and public links do not share an ID, so we need a shared table to make sure that there are no duplicates. This is implemented by having ShareID have an ID that is auto-increment, and shares and public links will have their ID be a foreign key to ShareID When creating a new share, we will then first create an ID entry and use this for the ID

type ShareState

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

ShareState represents the state of a share for a specific recipient.

Jump to

Keyboard shortcuts

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