Skip to content

Commit

Permalink
Fixed quota check when users dont exist in DB
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-Hollister committed May 8, 2024
1 parent b863a4e commit e73aa5b
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions pipelines/_steps/quota/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e73aa5b

Please sign in to comment.