Skip to content

Commit

Permalink
sat/console update the updateProject to set user specified limits
Browse files Browse the repository at this point in the history
update the updateProject function to set user specified bandwidth and storage limits

fixes #5185

Change-Id: Ib4132487f6b7ea0afa7c57acfc358857b3e852d1
  • Loading branch information
Lizzy Thomson authored and Storj Robot committed Dec 13, 2022
1 parent 17db59e commit 0afd393
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion satellite/admin/project_test.go
Expand Up @@ -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,
Expand Down
28 changes: 15 additions & 13 deletions satellite/console/projects.go
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions satellite/console/service.go
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions satellite/console/service_test.go
Expand Up @@ -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{
Expand Down
6 changes: 6 additions & 0 deletions satellite/satellitedb/projects.go
Expand Up @@ -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)
}
Expand Down

0 comments on commit 0afd393

Please sign in to comment.