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 ¶
- Constants
- Variables
- func CheckFieldLength[T any](field []T, fieldName string, minLength int, maxLength int) error
- func CheckObjectAccess(requireEdit bool, objectId string, objectType protos.ObjectType, ...) (*protos.OwnershipItem, error)
- func CheckObjectAccessForUser(requireEdit bool, objectId string, objectType protos.ObjectType, userId string, ...) (*protos.OwnershipItem, error)
- func CheckStringField(field *string, fieldName string, minLength int, maxLength int) error
- func DeleteUserObject[T any](objectId string, objectType protos.ObjectType, collectionName string, ...) ([]*T, error)
- func FetchOwnershipSummary(ownership *protos.OwnershipItem, sessionUser SessionUser, db *mongo.Database, ...) *protos.OwnershipSummary
- func FindUserIdsFor(objectId string, mongoDB *mongo.Database) ([]string, error)
- func GetCachedUserGroupMembership(userId string) ([]string, bool)
- func GetCachedUserGroupViewership(userId string) ([]string, bool)
- func GetDBUser(userId string, db *mongo.Database) (*protos.UserDBItem, error)
- func GetUserIdsForGroup(groupIds []string, mongoDB *mongo.Database) ([]string, error)
- func GetUserObjectById[T any](forEditing bool, objectId string, objectType protos.ObjectType, ...) (*T, *protos.OwnershipItem, error)
- func HasPermission(userPermissions map[string]bool, toCheck protos.Permission) bool
- func ListAccessibleIDs(requireEdit bool, objectType protos.ObjectType, svcs *services.APIServices, ...) (map[string]*protos.OwnershipItem, error)
- func ListGroupAccessibleIDs(requireEdit bool, objectType protos.ObjectType, groupID string, ...) (map[string]*protos.OwnershipItem, error)
- func MakeFilter(searchParams *protos.SearchParams, requireEdit bool, ...) (bson.M, map[string]*protos.OwnershipItem, error)
- func MakeFullOwnerSummary(ownership *protos.OwnershipItem, sessionUser SessionUser, db *mongo.Database, ...) *protos.OwnershipSummary
- func MakeOwnerForWrite(objectId string, objectType protos.ObjectType, creatorUserId string, ...) *protos.OwnershipItem
- func MakeOwnerSummary(ownership *protos.OwnershipItem, sessionUser SessionUser, db *mongo.Database, ...) *protos.OwnershipSummary
- func NotifyUserInfoChange(userId string)
- func ReadDatasetFile(scanId string, svcs *services.APIServices) (*protos.Experiment, error)
- func ReadDiffractionFile(scanId string, svcs *services.APIServices) (*protos.Diffraction, error)
- func ReadQuantificationFile(quantId string, quantPath string, svcs *services.APIServices) (*protos.Quantification, error)
- func SendForSession(s *melody.Session, wsmsg *protos.WSMessage)
- type HandlerContext
- type SessionUser
Examples ¶
Constants ¶
const Auth0UserIdFieldMaxLength = 32
const DescriptionFieldMaxLength = 1024 * 5
const IdFieldMaxLength = 32
const SourceCodeMaxLength = 1024 * 1024 * 5 // Trying to be very generous here, but maybe this is not enough?
const TagListMaxLength = 100
Variables ¶
var MaxFileCacheAgeSec = int64(60 * 5)
var MaxFileCacheSizeBytes = uint64(200 * 1024 * 1024)
Functions ¶
func CheckFieldLength ¶
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 CheckStringField ¶
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 GetCachedUserGroupViewership ¶ added in v4.8.1
func GetUserIdsForGroup ¶
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)
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