From e73aa5bc3991587205914c439120c4f670351225 Mon Sep 17 00:00:00 2001 From: Michael Hollister Date: Wed, 8 May 2024 15:19:06 -0500 Subject: [PATCH] Fixed quota check when users dont exist in DB --- pipelines/_steps/quota/check.go | 50 +++++++++++++++++---------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/pipelines/_steps/quota/check.go b/pipelines/_steps/quota/check.go index 31727553..7d539ec9 100644 --- a/pipelines/_steps/quota/check.go +++ b/pipelines/_steps/quota/check.go @@ -93,31 +93,33 @@ func Limit(ctx rcontext.RequestContext, userId string, quotaType Type) (int64, e record, err := db.GetUserQuota([]string{userId}) if err != nil { ctx.Log.Warn("Error querying DB quota for user " + userId + ": " + err.Error()) - } - - // DB quotas takes precedence over config quotas if value is not -1 - quota := record[0].UserQuota - switch quotaType { - case MaxBytes: - if quota.MaxBytes > 0 { - return quota.MaxBytes, nil - } else if quota.MaxBytes == 0 { - return defaultLimit(ctx, quotaType) - } - case MaxPending: - if quota.MaxPending > 0 { - return quota.MaxPending, nil - } else if quota.MaxPending == 0 { - return defaultLimit(ctx, quotaType) - } - case MaxCount: - if quota.MaxFiles > 0 { - return quota.MaxFiles, nil - } else if quota.MaxFiles == 0 { - return defaultLimit(ctx, quotaType) + } else if len(record) == 0 { + ctx.Log.Warn("User " + userId + " does not exist in DB. Skipping DB quota check...") + } else { + // DB quotas takes precedence over config quotas if value is not -1 + quota := record[0].UserQuota + switch quotaType { + case MaxBytes: + if quota.MaxBytes > 0 { + return quota.MaxBytes, nil + } else if quota.MaxBytes == 0 { + return defaultLimit(ctx, quotaType) + } + case MaxPending: + if quota.MaxPending > 0 { + return quota.MaxPending, nil + } else if quota.MaxPending == 0 { + return defaultLimit(ctx, quotaType) + } + case MaxCount: + if quota.MaxFiles > 0 { + return quota.MaxFiles, nil + } else if quota.MaxFiles == 0 { + return defaultLimit(ctx, quotaType) + } + default: + return 0, errors.New("missing db switch for quota type - contact developer") } - default: - return 0, errors.New("missing db switch for quota type - contact developer") } for _, q := range ctx.Config.Uploads.Quota.UserQuotas {