Documentation
¶
Overview ¶
Package share provides file sharing functionality and permissions management for the Weblens system.
Index ¶
- Constants
- Variables
- func DeleteShare(ctx context.Context, shareID primitive.ObjectID) error
- func IDFromString(shareID string) primitive.ObjectID
- func SaveFileShare(ctx context.Context, share *FileShare) error
- type FileShare
- func GetShareByFileID(ctx context.Context, fileID string) (*FileShare, error)
- func GetShareByID(ctx context.Context, shareID primitive.ObjectID) (*FileShare, error)
- func GetSharedWithUser(ctx context.Context, username string) ([]FileShare, error)
- func NewFileShare(_ context.Context, fileID string, owner *user_model.User, ...) (*FileShare, error)
- func (s *FileShare) AddUser(ctx context.Context, username string, perms *Permissions) error
- func (s *FileShare) GetAccessors() []string
- func (s *FileShare) GetItemID() string
- func (s *FileShare) GetOwner() string
- func (s *FileShare) GetUserPermissions(username string) *Permissions
- func (s *FileShare) HasPermission(username string, perm Permission) bool
- func (s *FileShare) ID() primitive.ObjectID
- func (s *FileShare) IsEnabled() bool
- func (s *FileShare) IsPublic() bool
- func (s *FileShare) IsWormhole() bool
- func (s *FileShare) LastUpdated() time.Time
- func (s *FileShare) RemoveUsers(ctx context.Context, usernames []string) error
- func (s *FileShare) SetAccessors(usernames []string)
- func (s *FileShare) SetEnabled(enable bool)
- func (s *FileShare) SetItemID(fileID string)
- func (s *FileShare) SetPublic(ctx context.Context, pub bool) error
- func (s *FileShare) SetTimelineOnly(ctx context.Context, timelineOnly bool) error
- func (s *FileShare) SetUserPermissions(ctx context.Context, username string, perms *Permissions) error
- func (s *FileShare) SetUserPerms(ctx context.Context, perms map[string]*Permissions) error
- func (s *FileShare) UpdatedNow()
- type Permission
- type Permissions
- func (p *Permissions) AddPermission(permission Permission, value bool)
- func (p *Permissions) HasPermission(permission Permission) bool
- func (p *Permissions) MarshalZerologObject(e *zerolog.Event)
- func (p *Permissions) RemovePermission(permission Permission)
- func (p *Permissions) SetDelete(canDelete bool)
- func (p *Permissions) SetDownload(canDownload bool)
- func (p *Permissions) SetEdit(canEdit bool)
Constants ¶
ShareCollectionKey is the MongoDB collection name for shares.
Variables ¶
ErrShareAlreadyExists is returned when attempting to create a share that already exists.
ErrShareNotFound is returned when a share cannot be found.
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 ¶
DeleteShare deletes a FileShare from the database.
func IDFromString ¶
IDFromString parses a share ID string into a MongoDB ObjectID.
Types ¶
type FileShare ¶
type FileShare struct {
Accessors []string `bson:"accessors"`
// Permissions maps usernames to their specific permissions
}
FileShare represents a file share configuration.
func GetShareByFileID ¶
GetShareByFileID retrieves a FileShare by the file ID it shares.
func GetShareByID ¶
GetShareByID retrieves a FileShare by its ID.
func GetSharedWithUser ¶
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) GetAccessors ¶
GetAccessors returns the list of users who have access to this share.
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) IsWormhole ¶
IsWormhole returns true if the share is a wormhole share.
func (*FileShare) LastUpdated ¶
LastUpdated returns the last modified timestamp of the share.
func (*FileShare) RemoveUsers ¶
RemoveUsers removes specified users from the share.
func (*FileShare) SetAccessors ¶
SetAccessors sets the list of users who have access to this share.
func (*FileShare) SetEnabled ¶
SetEnabled sets whether the share is enabled.
func (*FileShare) SetTimelineOnly ¶
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 ¶
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 Permission = "viewMedia" SharePermissionView Permission = "view" SharePermissionDownload Permission = "download" SharePermissionEdit Permission = "edit" 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.