share

package
v0.0.0-...-dd4be11 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package share provides file sharing functionality and permissions management for the Weblens system.

Index

Constants

View Source
const ShareCollectionKey = "shares"

ShareCollectionKey is the MongoDB collection name for shares.

Variables

View Source
var ErrShareAlreadyExists = wlerrors.New("share already exists")

ErrShareAlreadyExists is returned when attempting to create a share that already exists.

View Source
var ErrShareNotFound = wlerrors.New("share not found")

ErrShareNotFound is returned when a share cannot be found.

View Source
var IndexModels = []mongo.IndexModel{
	{
		Keys: bson.M{
			"fileID": -1,
		},
		Options: options.Index().SetUnique(true),
	},
}

IndexModels defines MongoDB indexes for the shares collection.

Functions

func DeleteShare

func DeleteShare(ctx context.Context, shareID primitive.ObjectID) error

DeleteShare deletes a FileShare from the database.

func IDFromString

func IDFromString(shareID string) primitive.ObjectID

IDFromString parses a share ID string into a MongoDB ObjectID.

func SaveFileShare

func SaveFileShare(ctx context.Context, share *FileShare) error

SaveFileShare saves a FileShare to the database.

Types

type FileShare

type FileShare struct {
	// Accessors is a list of users that have access to the share
	Accessors []string `bson:"accessors"`
	// Permissions maps usernames to their specific permissions
	Permissions  map[string]*Permissions `bson:"permissions"`
	Enabled      bool                    `bson:"enabled"`
	Expires      time.Time               `bson:"expires"`
	FileID       string                  `bson:"fileID"`
	Owner        string                  `bson:"owner"`
	Public       bool                    `bson:"public"`
	ShareID      primitive.ObjectID      `bson:"_id"`
	ShareName    string                  `bson:"shareName"`
	Updated      time.Time               `bson:"updated"`
	Wormhole     bool                    `bson:"wormhole"`
	TimelineOnly bool                    `bson:"timelineOnly"`
}

FileShare represents a file share configuration.

func GetShareByFileID

func GetShareByFileID(ctx context.Context, fileID string) (*FileShare, error)

GetShareByFileID retrieves a FileShare by the file ID it shares.

func GetShareByID

func GetShareByID(ctx context.Context, shareID primitive.ObjectID) (*FileShare, error)

GetShareByID retrieves a FileShare by its ID.

func GetSharedWithUser

func GetSharedWithUser(ctx context.Context, username string) ([]FileShare, error)

GetSharedWithUser retrieves all FileShares that are shared with a specific user.

func NewFileShare

func NewFileShare(_ context.Context, fileID string, owner *user_model.User, accessors []*user_model.User, public bool, wormhole bool, timelineOnly bool) (*FileShare, error)

NewFileShare creates a new FileShare with the given parameters.

func (*FileShare) AddUser

func (s *FileShare) AddUser(ctx context.Context, username string, perms *Permissions) error

AddUser adds a user to the share with the specified permissions.

func (*FileShare) GetAccessors

func (s *FileShare) GetAccessors() []string

GetAccessors returns the list of users who have access to this share.

func (*FileShare) GetItemID

func (s *FileShare) GetItemID() string

GetItemID returns the file ID associated with this share.

func (*FileShare) GetOwner

func (s *FileShare) GetOwner() string

GetOwner returns the username of the share's owner.

func (*FileShare) GetUserPermissions

func (s *FileShare) GetUserPermissions(username string) *Permissions

GetUserPermissions returns the permissions for a specific user on this share.

func (*FileShare) HasPermission

func (s *FileShare) HasPermission(username string, perm Permission) bool

HasPermission checks if a user has a specific permission on this share.

func (*FileShare) ID

func (s *FileShare) ID() primitive.ObjectID

ID returns the share's unique identifier.

func (*FileShare) IsEnabled

func (s *FileShare) IsEnabled() bool

IsEnabled returns true if the share is enabled.

func (*FileShare) IsPublic

func (s *FileShare) IsPublic() bool

IsPublic returns true if the share is public.

func (*FileShare) IsWormhole

func (s *FileShare) IsWormhole() bool

IsWormhole returns true if the share is a wormhole share.

func (*FileShare) LastUpdated

func (s *FileShare) LastUpdated() time.Time

LastUpdated returns the last modified timestamp of the share.

func (*FileShare) RemoveUsers

func (s *FileShare) RemoveUsers(ctx context.Context, usernames []string) error

RemoveUsers removes specified users from the share.

func (*FileShare) SetAccessors

func (s *FileShare) SetAccessors(usernames []string)

SetAccessors sets the list of users who have access to this share.

func (*FileShare) SetEnabled

func (s *FileShare) SetEnabled(enable bool)

SetEnabled sets whether the share is enabled.

func (*FileShare) SetItemID

func (s *FileShare) SetItemID(fileID string)

SetItemID sets the file ID associated with this share.

func (*FileShare) SetPublic

func (s *FileShare) SetPublic(ctx context.Context, pub bool) error

SetPublic sets whether the share is public.

func (*FileShare) SetTimelineOnly

func (s *FileShare) SetTimelineOnly(ctx context.Context, timelineOnly bool) error

SetTimelineOnly sets whether the share is timeline-only.

func (*FileShare) SetUserPermissions

func (s *FileShare) SetUserPermissions(ctx context.Context, username string, perms *Permissions) error

SetUserPermissions sets the permissions for a specific user on this share.

func (*FileShare) SetUserPerms

func (s *FileShare) SetUserPerms(ctx context.Context, perms map[string]*Permissions) error

SetUserPerms sets permissions for multiple users on the share.

func (*FileShare) UpdatedNow

func (s *FileShare) UpdatedNow()

UpdatedNow updates the share's last modified timestamp to the current time.

type Permission

type Permission string

Permission represents a specific type of access permission for file shares.

const (
	// SharePermissionViewMedia allows read access to the media content of the file share, if applicable.
	SharePermissionViewMedia Permission = "viewMedia"
	// SharePermissionView allows read access to the file share.
	SharePermissionView Permission = "view"
	// SharePermissionDownload allows download access to the file share.
	SharePermissionDownload Permission = "download"
	// SharePermissionEdit allows write access to the file share.
	SharePermissionEdit Permission = "edit"
	// SharePermissionDelete allows delete access to the file share.
	SharePermissionDelete Permission = "delete"
)

type Permissions

type Permissions struct {
	CanViewMedia bool `bson:"canViewMedia"` // Indicates if the user can view media content of the share
	CanView      bool `bson:"canView"`      // Indicates if the user can view files in the share
	CanEdit      bool `bson:"canEdit"`
	CanDownload  bool `bson:"canDownload"`
	CanDelete    bool `bson:"canDelete"`
}

Permissions represents the specific permissions a user can have on a file share.

func NewEmptyPermissions

func NewEmptyPermissions() *Permissions

NewEmptyPermissions creates a new Permissions instance with all permissions disabled.

func NewFullPermissions

func NewFullPermissions() *Permissions

NewFullPermissions creates a new Permissions instance with all permissions enabled.

func NewPermissions

func NewPermissions() *Permissions

NewPermissions creates a new Permissions instance with default values.

func (*Permissions) AddPermission

func (p *Permissions) AddPermission(permission Permission, value bool)

AddPermission dynamically adds a new permission to the Permissions struct.

func (*Permissions) HasPermission

func (p *Permissions) HasPermission(permission Permission) bool

HasPermission checks if a specific permission is granted.

func (*Permissions) MarshalZerologObject

func (p *Permissions) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject implements the zerolog LogObjectMarshaler interface

func (*Permissions) RemovePermission

func (p *Permissions) RemovePermission(permission Permission)

RemovePermission dynamically removes a permission by setting it to false.

func (*Permissions) SetDelete

func (p *Permissions) SetDelete(canDelete bool)

SetDelete sets the delete permission.

func (*Permissions) SetDownload

func (p *Permissions) SetDownload(canDownload bool)

SetDownload sets the download permission.

func (*Permissions) SetEdit

func (p *Permissions) SetEdit(canEdit bool)

SetEdit sets the edit permission.

Jump to

Keyboard shortcuts

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