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
This commit is contained in:
Lizzy Thomson 2022-11-05 18:43:11 -06:00 committed by Storj Robot
parent 17db59e27a
commit 0afd3938c7
5 changed files with 37 additions and 14 deletions

View File

@ -47,7 +47,7 @@ func TestProjectGet(t *testing.T) {
t.Run("OK", func(t *testing.T) { t.Run("OK", func(t *testing.T) {
link := "http://" + address.String() + "/api/projects/" + project.ID.String() link := "http://" + address.String() + "/api/projects/" + project.ID.String()
expected := fmt.Sprintf( 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.ID.String(),
project.PublicID.String(), project.PublicID.String(),
project.Name, project.Name,

View File

@ -102,6 +102,8 @@ type Project struct {
MemberCount int `json:"memberCount"` MemberCount int `json:"memberCount"`
StorageLimit *memory.Size `json:"storageLimit"` StorageLimit *memory.Size `json:"storageLimit"`
BandwidthLimit *memory.Size `json:"bandwidthLimit"` BandwidthLimit *memory.Size `json:"bandwidthLimit"`
UserSpecifiedStorageLimit *memory.Size `json:"userSpecifiedStorageLimit"`
UserSpecifiedBandwidthLimit *memory.Size `json:"userSpecifiedBandwidthLimit"`
SegmentLimit *int64 `json:"segmentLimit"` SegmentLimit *int64 `json:"segmentLimit"`
} }

View File

@ -1699,6 +1699,19 @@ func (s *Service) UpdateProject(ctx context.Context, projectID uuid.UUID, update
if updatedProject.BandwidthLimit.Int64() < bandwidthUsed { if updatedProject.BandwidthLimit.Int64() < bandwidthUsed {
return nil, Error.New("cannot set bandwidth limit below current usage") 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 = new(memory.Size)
*project.StorageLimit = updatedProject.StorageLimit *project.StorageLimit = updatedProject.StorageLimit

View File

@ -119,6 +119,8 @@ func TestService(t *testing.T) {
require.Equal(t, updatedStorageLimit, *updatedProject.StorageLimit) require.Equal(t, updatedStorageLimit, *updatedProject.StorageLimit)
require.NotEqual(t, *up1Pro1.BandwidthLimit, *updatedProject.BandwidthLimit) require.NotEqual(t, *up1Pro1.BandwidthLimit, *updatedProject.BandwidthLimit)
require.Equal(t, updatedBandwidthLimit, *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 // Updating someone else project details should not work
updatedProject, err = service.UpdateProject(userCtx1, up2Pro1.ID, console.ProjectInfo{ updatedProject, err = service.UpdateProject(userCtx1, up2Pro1.ID, console.ProjectInfo{

View File

@ -194,9 +194,15 @@ func (projects *projects) Update(ctx context.Context, project *console.Project)
if project.StorageLimit != nil { if project.StorageLimit != nil {
updateFields.UsageLimit = dbx.Project_UsageLimit(project.StorageLimit.Int64()) updateFields.UsageLimit = dbx.Project_UsageLimit(project.StorageLimit.Int64())
} }
if project.UserSpecifiedStorageLimit != nil {
updateFields.UserSpecifiedUsageLimit = dbx.Project_UserSpecifiedUsageLimit(int64(*project.UserSpecifiedStorageLimit))
}
if project.BandwidthLimit != nil { if project.BandwidthLimit != nil {
updateFields.BandwidthLimit = dbx.Project_BandwidthLimit(project.BandwidthLimit.Int64()) updateFields.BandwidthLimit = dbx.Project_BandwidthLimit(project.BandwidthLimit.Int64())
} }
if project.UserSpecifiedBandwidthLimit != nil {
updateFields.UserSpecifiedBandwidthLimit = dbx.Project_UserSpecifiedBandwidthLimit(int64(*project.UserSpecifiedBandwidthLimit))
}
if project.SegmentLimit != nil { if project.SegmentLimit != nil {
updateFields.SegmentLimit = dbx.Project_SegmentLimit(*project.SegmentLimit) updateFields.SegmentLimit = dbx.Project_SegmentLimit(*project.SegmentLimit)
} }