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:
parent
17db59e27a
commit
0afd3938c7
@ -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,
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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{
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user