wsHelpers

package
v4.10.2 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Example (OrderCacheItems)
items := map[string]fileCacheItem{
	"one": {
		localPath:        "path/one.bin",
		fileSize:         10 * 1024 * 1024,
		timestampUnixSec: 1234567891,
	},
	"three": {
		localPath:        "path/three.bin",
		fileSize:         30 * 1024 * 1024,
		timestampUnixSec: 1234567893,
	},
	"two": {
		localPath:        "path/two.bin",
		fileSize:         20 * 1024 * 1024,
		timestampUnixSec: 1234567892,
	},
	"four": {
		localPath:        "path/four.bin",
		fileSize:         40 * 1024 * 1024,
		timestampUnixSec: 1234567894,
	},
}

byAge, totalSize := orderCacheItems(items)
fmt.Printf("Total size: %v\n", totalSize)

for _, i := range byAge {
	fmt.Printf("path: %v, ts: %v, size: %v\n", i.localPath, i.timestampUnixSec, i.fileSize)
}
Output:

Total size: 104857600
path: path/four.bin, ts: 1234567894, size: 41943040
path: path/three.bin, ts: 1234567893, size: 31457280
path: path/two.bin, ts: 1234567892, size: 20971520
path: path/one.bin, ts: 1234567891, size: 10485760

Index

Examples

Constants

View Source
const Auth0UserIdFieldMaxLength = 32
View Source
const DescriptionFieldMaxLength = 1024 * 5
View Source
const IdFieldMaxLength = 32
View Source
const SourceCodeMaxLength = 1024 * 1024 * 5 // Trying to be very generous here, but maybe this is not enough?
View Source
const TagListMaxLength = 100

Variables

View Source
var MaxFileCacheAgeSec = int64(60 * 5)
View Source
var MaxFileCacheSizeBytes = uint64(200 * 1024 * 1024)

Functions

func CheckFieldLength

func CheckFieldLength[T any](field []T, fieldName string, minLength int, maxLength int) error

func CheckObjectAccess

func CheckObjectAccess(requireEdit bool, objectId string, objectType protos.ObjectType, hctx HandlerContext) (*protos.OwnershipItem, error)

Checks object access - if requireEdit is true, it checks for edit access otherwise just checks for view access. Returns an error if it failed to determine or if access is not granted, returns error formed with MakeUnauthorisedError

func CheckObjectAccessForUser

func CheckObjectAccessForUser(requireEdit bool, objectId string, objectType protos.ObjectType, userId string, memberOfGroupIds []string, viewerOfGroupIds []string, db *mongo.Database) (*protos.OwnershipItem, error)

func CheckStringField

func CheckStringField(field *string, fieldName string, minLength int, maxLength int) error

func DeleteUserObject

func DeleteUserObject[T any](objectId string, objectType protos.ObjectType, collectionName string, hctx HandlerContext) (*T, error)

func FetchOwnershipSummary added in v4.3.12

func FetchOwnershipSummary(ownership *protos.OwnershipItem, sessionUser SessionUser, db *mongo.Database, ts timestamper.ITimeStamper, fullDetails bool) *protos.OwnershipSummary

func FindUserIdsFor

func FindUserIdsFor(objectId string, mongoDB *mongo.Database) ([]string, error)

func GetCachedUserGroupMembership

func GetCachedUserGroupMembership(userId string) ([]string, bool)

func GetCachedUserGroupViewership added in v4.8.1

func GetCachedUserGroupViewership(userId string) ([]string, bool)

func GetDBUser

func GetDBUser(userId string, db *mongo.Database) (*protos.UserDBItem, error)

func GetUserIdsForGroup

func GetUserIdsForGroup(groupIds []string, mongoDB *mongo.Database) ([]string, error)

func GetUserObjectById

func GetUserObjectById[T any](forEditing bool, objectId string, objectType protos.ObjectType, collectionName string, hctx HandlerContext) (*T, *protos.OwnershipItem, error)

func HasPermission

func HasPermission(userPermissions map[string]bool, toCheck protos.Permission) bool

func ListAccessibleIDs

func ListAccessibleIDs(requireEdit bool, objectType protos.ObjectType, svcs *services.APIServices, requestorSession SessionUser) (map[string]*protos.OwnershipItem, error)

Gets all object IDs which the user has access to - if requireEdit is true, it checks for edit access otherwise just checks for view access Returns a map of object id->creator user id

func ListGroupAccessibleIDs

func ListGroupAccessibleIDs(requireEdit bool, objectType protos.ObjectType, groupID string, mongoDB *mongo.Database) (map[string]*protos.OwnershipItem, error)

func MakeFilter

func MakeFilter(
	searchParams *protos.SearchParams,
	requireEdit bool,
	objectType protos.ObjectType,
	hctx HandlerContext) (bson.M, map[string]*protos.OwnershipItem, error)

func MakeFullOwnerSummary added in v4.3.12

func MakeFullOwnerSummary(ownership *protos.OwnershipItem, sessionUser SessionUser, db *mongo.Database, ts timestamper.ITimeStamper) *protos.OwnershipSummary

func MakeOwnerForWrite

func MakeOwnerForWrite(objectId string, objectType protos.ObjectType, creatorUserId string, createTimeUnixSec int64) *protos.OwnershipItem

func MakeOwnerSummary

func MakeOwnerSummary(ownership *protos.OwnershipItem, sessionUser SessionUser, db *mongo.Database, ts timestamper.ITimeStamper) *protos.OwnershipSummary

func NotifyUserInfoChange

func NotifyUserInfoChange(userId string)

func ReadDatasetFile

func ReadDatasetFile(scanId string, svcs *services.APIServices) (*protos.Experiment, error)

func ReadDiffractionFile

func ReadDiffractionFile(scanId string, svcs *services.APIServices) (*protos.Diffraction, error)

func ReadQuantificationFile

func ReadQuantificationFile(quantId string, quantPath string, svcs *services.APIServices) (*protos.Quantification, error)

func SendForSession

func SendForSession(s *melody.Session, wsmsg *protos.WSMessage)

Types

type HandlerContext

type HandlerContext struct {
	Session  *melody.Session
	SessUser SessionUser
	Melody   *melody.Melody
	Svcs     *services.APIServices
}

type SessionUser

type SessionUser struct {
	SessionId              string
	User                   *protos.UserInfo
	Permissions            map[string]bool
	MemberOfGroupIds       []string
	ViewerOfGroupIds       []string
	NotificationSubscribed bool
}

func CreateDBUser

func CreateDBUser(sessionId string, jwtUser jwtparser.JWTUserInfo, db *mongo.Database) (*SessionUser, error)

If we have a successful login and the user is not in our DB, we write a default record for them, so if they change their details we have a spot to save it already NOTE: This is (at time of writing) the only way to add a user to the DB

func GetSessionUser

func GetSessionUser(s *melody.Session) (SessionUser, error)

func MakeSessionUser

func MakeSessionUser(sessionId string, jwtUser jwtparser.JWTUserInfo, db *mongo.Database) (*SessionUser, error)

JWT user has the user ID and permissions that we get from Auth0. The rest is handled within PIXLISE, so lets read our DB to see if this user exists and get their user name, email, icon, etc

Jump to

Keyboard shortcuts

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