Skip to content

Commit 60522fc

Browse files
authored
packages: Calculate package size quota using package creator ID instead of owner ID (#28007)
Changed behavior to calculate package quota limit using package `creator ID` instead of `owner ID`. Currently, users are allowed to create an unlimited number of organizations, each of which has its own package limit quota, resulting in the ability for users to have unlimited package space in different organization scopes. This fix will calculate package quota based on `package version creator ID` instead of `package version owner ID` (which might be organization), so that users are not allowed to take more space than configured package settings. Also, there is a side case in which users can publish packages to a specific package version, initially published by different user, taking that user package size quota. Version in fix should be better because the total amount of space is limited to the quota for users sharing the same organization scope.
1 parent c636608 commit 60522fc

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

models/packages/package_file.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,15 @@ func CalculateFileSize(ctx context.Context, opts *PackageFileSearchOptions) (int
230230
Join("INNER", "package_blob", "package_blob.id = package_file.blob_id").
231231
SumInt(new(PackageBlob), "size")
232232
}
233+
234+
// CalculateCreatorPackageQuota sums up all blob sizes related to package
235+
// version creator id.
236+
// It does NOT respect the deduplication of blobs.
237+
func CalculateCreatorPackageQuota(ctx context.Context, creatorID int64) (int64, error) {
238+
return db.GetEngine(ctx).
239+
Table("package_version").
240+
Where(builder.Eq{"creator_id": creatorID}).
241+
Join("INNER", "package_file", "package_version.id = package_file.version_id").
242+
Join("INNER", "package_blob", "package_blob.id = package_file.blob_id").
243+
SumInt(new(PackageBlob), "size")
244+
}

services/packages/packages.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,7 @@ func CheckSizeQuotaExceeded(ctx context.Context, doer, owner *user_model.User, p
401401
}
402402

403403
if setting.Packages.LimitTotalOwnerSize > -1 {
404-
totalSize, err := packages_model.CalculateFileSize(ctx, &packages_model.PackageFileSearchOptions{
405-
OwnerID: owner.ID,
406-
})
404+
totalSize, err := packages_model.CalculateCreatorPackageQuota(ctx, doer.ID)
407405
if err != nil {
408406
log.Error("CalculateFileSize failed: %v", err)
409407
return err

0 commit comments

Comments
 (0)