From 0afd3938c7bbf121307523409e8aeb0c8ebab4cc Mon Sep 17 00:00:00 2001 From: Lizzy Thomson Date: Sat, 5 Nov 2022 18:43:11 -0600 Subject: [PATCH] sat/console update the updateProject to set user specified limits update the updateProject function to set user specified bandwidth and storage limits fixes https://github.com/storj/storj/issues/5185 Change-Id: Ib4132487f6b7ea0afa7c57acfc358857b3e852d1 --- satellite/admin/project_test.go | 2 +- satellite/console/projects.go | 28 +++++++++++++++------------- satellite/console/service.go | 13 +++++++++++++ satellite/console/service_test.go | 2 ++ satellite/satellitedb/projects.go | 6 ++++++ 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/satellite/admin/project_test.go b/satellite/admin/project_test.go index 69ca95715..b4d85e19b 100644 --- a/satellite/admin/project_test.go +++ b/satellite/admin/project_test.go @@ -47,7 +47,7 @@ func TestProjectGet(t *testing.T) { t.Run("OK", func(t *testing.T) { link := "http://" + address.String() + "/api/projects/" + project.ID.String() expected := fmt.Sprintf( - `{"id":"%s","publicId":"%s","name":"%s","description":"%s","partnerId":"%s","userAgent":null,"ownerId":"%s","rateLimit":null,"burstLimit":null,"maxBuckets":null,"createdAt":"%s","memberCount":0,"storageLimit":"25.00 GB","bandwidthLimit":"25.00 GB","segmentLimit":150000}`, + `{"id":"%s","publicId":"%s","name":"%s","description":"%s","partnerId":"%s","userAgent":null,"ownerId":"%s","rateLimit":null,"burstLimit":null,"maxBuckets":null,"createdAt":"%s","memberCount":0,"storageLimit":"25.00 GB","bandwidthLimit":"25.00 GB","userSpecifiedStorageLimit":null,"userSpecifiedBandwidthLimit":null,"segmentLimit":150000}`, project.ID.String(), project.PublicID.String(), project.Name, diff --git a/satellite/console/projects.go b/satellite/console/projects.go index 7aec6166f..cc70d7f4f 100644 --- a/satellite/console/projects.go +++ b/satellite/console/projects.go @@ -90,19 +90,21 @@ type Project struct { ID uuid.UUID `json:"id"` PublicID uuid.UUID `json:"publicId"` - Name string `json:"name"` - Description string `json:"description"` - PartnerID uuid.UUID `json:"partnerId"` - UserAgent []byte `json:"userAgent"` - OwnerID uuid.UUID `json:"ownerId"` - RateLimit *int `json:"rateLimit"` - BurstLimit *int `json:"burstLimit"` - MaxBuckets *int `json:"maxBuckets"` - CreatedAt time.Time `json:"createdAt"` - MemberCount int `json:"memberCount"` - StorageLimit *memory.Size `json:"storageLimit"` - BandwidthLimit *memory.Size `json:"bandwidthLimit"` - SegmentLimit *int64 `json:"segmentLimit"` + Name string `json:"name"` + Description string `json:"description"` + PartnerID uuid.UUID `json:"partnerId"` + UserAgent []byte `json:"userAgent"` + OwnerID uuid.UUID `json:"ownerId"` + RateLimit *int `json:"rateLimit"` + BurstLimit *int `json:"burstLimit"` + MaxBuckets *int `json:"maxBuckets"` + CreatedAt time.Time `json:"createdAt"` + MemberCount int `json:"memberCount"` + StorageLimit *memory.Size `json:"storageLimit"` + BandwidthLimit *memory.Size `json:"bandwidthLimit"` + UserSpecifiedStorageLimit *memory.Size `json:"userSpecifiedStorageLimit"` + UserSpecifiedBandwidthLimit *memory.Size `json:"userSpecifiedBandwidthLimit"` + SegmentLimit *int64 `json:"segmentLimit"` } // ProjectInfo holds data needed to create/update Project. diff --git a/satellite/console/service.go b/satellite/console/service.go index a9f5a3ca2..a2d361bc2 100644 --- a/satellite/console/service.go +++ b/satellite/console/service.go @@ -1699,6 +1699,19 @@ func (s *Service) UpdateProject(ctx context.Context, projectID uuid.UUID, update if updatedProject.BandwidthLimit.Int64() < bandwidthUsed { return nil, Error.New("cannot set bandwidth limit below current usage") } + /* + The purpose of userSpecifiedBandwidthLimit and userSpecifiedStorageLimit is to know if a user has set a bandwidth + or storage limit in the UI (to ensure their limits are not unintentionally modified by the satellite admin), + the BandwidthLimit and StorageLimit is still used for verifying limits during uploads and downloads. + */ + if project.StorageLimit != nil && updatedProject.StorageLimit != *project.StorageLimit { + project.UserSpecifiedStorageLimit = new(memory.Size) + *project.UserSpecifiedStorageLimit = updatedProject.StorageLimit + } + if project.BandwidthLimit != nil && updatedProject.BandwidthLimit != *project.BandwidthLimit { + project.UserSpecifiedBandwidthLimit = new(memory.Size) + *project.UserSpecifiedBandwidthLimit = updatedProject.BandwidthLimit + } project.StorageLimit = new(memory.Size) *project.StorageLimit = updatedProject.StorageLimit diff --git a/satellite/console/service_test.go b/satellite/console/service_test.go index 4a2cccb1e..05c8c275c 100644 --- a/satellite/console/service_test.go +++ b/satellite/console/service_test.go @@ -119,6 +119,8 @@ func TestService(t *testing.T) { require.Equal(t, updatedStorageLimit, *updatedProject.StorageLimit) require.NotEqual(t, *up1Pro1.BandwidthLimit, *updatedProject.BandwidthLimit) require.Equal(t, updatedBandwidthLimit, *updatedProject.BandwidthLimit) + require.Equal(t, updatedStorageLimit, *updatedProject.UserSpecifiedStorageLimit) + require.Equal(t, updatedBandwidthLimit, *updatedProject.UserSpecifiedBandwidthLimit) // Updating someone else project details should not work updatedProject, err = service.UpdateProject(userCtx1, up2Pro1.ID, console.ProjectInfo{ diff --git a/satellite/satellitedb/projects.go b/satellite/satellitedb/projects.go index 200e70f6e..e2612701f 100644 --- a/satellite/satellitedb/projects.go +++ b/satellite/satellitedb/projects.go @@ -194,9 +194,15 @@ func (projects *projects) Update(ctx context.Context, project *console.Project) if project.StorageLimit != nil { updateFields.UsageLimit = dbx.Project_UsageLimit(project.StorageLimit.Int64()) } + if project.UserSpecifiedStorageLimit != nil { + updateFields.UserSpecifiedUsageLimit = dbx.Project_UserSpecifiedUsageLimit(int64(*project.UserSpecifiedStorageLimit)) + } if project.BandwidthLimit != nil { updateFields.BandwidthLimit = dbx.Project_BandwidthLimit(project.BandwidthLimit.Int64()) } + if project.UserSpecifiedBandwidthLimit != nil { + updateFields.UserSpecifiedBandwidthLimit = dbx.Project_UserSpecifiedBandwidthLimit(int64(*project.UserSpecifiedBandwidthLimit)) + } if project.SegmentLimit != nil { updateFields.SegmentLimit = dbx.Project_SegmentLimit(*project.SegmentLimit) }