satellite/{console,satellitedb}: increase project limit on paid tier upgrade
Update the user to the default paid tier project limit, which is currently 3 projects, when the user upgrades to a paid account. Change-Id: I95b19d62cebc7d878b716355f2ebcaf0b51ca3f7
This commit is contained in:
parent
29fd36a20e
commit
715077d04a
@ -458,7 +458,7 @@ func TestProjectCheckUsage_withUsage(t *testing.T) {
|
||||
require.NoError(t, response.Body.Close())
|
||||
|
||||
// Make User paid tier.
|
||||
err = planet.Satellites[0].DB.Console().Users().UpdatePaidTier(ctx, planet.Uplinks[0].Projects[0].Owner.ID, true, memory.PB, memory.PB, 1000000)
|
||||
err = planet.Satellites[0].DB.Console().Users().UpdatePaidTier(ctx, planet.Uplinks[0].Projects[0].Owner.ID, true, memory.PB, memory.PB, 1000000, 3)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Ensure User is paid tier.
|
||||
@ -613,7 +613,7 @@ func TestProjectDelete_withUsageCurrentMonth(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Make User paid tier.
|
||||
err = planet.Satellites[0].DB.Console().Users().UpdatePaidTier(ctx, planet.Uplinks[0].Projects[0].Owner.ID, true, memory.PB, memory.PB, 1000000)
|
||||
err = planet.Satellites[0].DB.Console().Users().UpdatePaidTier(ctx, planet.Uplinks[0].Projects[0].Owner.ID, true, memory.PB, memory.PB, 1000000, 3)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Ensure User is paid tier.
|
||||
@ -636,7 +636,7 @@ func TestProjectDelete_withUsageCurrentMonth(t *testing.T) {
|
||||
require.NoError(t, response.Body.Close())
|
||||
|
||||
// Make User free tier again.
|
||||
err = planet.Satellites[0].DB.Console().Users().UpdatePaidTier(ctx, planet.Uplinks[0].Projects[0].Owner.ID, false, memory.TB, memory.TB, 100000)
|
||||
err = planet.Satellites[0].DB.Console().Users().UpdatePaidTier(ctx, planet.Uplinks[0].Projects[0].Owner.ID, false, memory.TB, memory.TB, 100000, 3)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Ensure User is free tier.
|
||||
@ -715,7 +715,7 @@ func TestProjectDelete_withUsagePreviousMonth(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Make User paid tier.
|
||||
err = planet.Satellites[0].DB.Console().Users().UpdatePaidTier(ctx, planet.Uplinks[0].Projects[0].Owner.ID, true, memory.PB, memory.PB, 1000000)
|
||||
err = planet.Satellites[0].DB.Console().Users().UpdatePaidTier(ctx, planet.Uplinks[0].Projects[0].Owner.ID, true, memory.PB, memory.PB, 1000000, 3)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Ensure User is paid tier.
|
||||
@ -736,7 +736,7 @@ func TestProjectDelete_withUsagePreviousMonth(t *testing.T) {
|
||||
require.Equal(t, http.StatusConflict, response.StatusCode)
|
||||
|
||||
// Make User free tier again.
|
||||
err = planet.Satellites[0].DB.Console().Users().UpdatePaidTier(ctx, planet.Uplinks[0].Projects[0].Owner.ID, false, memory.TB, memory.TB, 100000)
|
||||
err = planet.Satellites[0].DB.Console().Users().UpdatePaidTier(ctx, planet.Uplinks[0].Projects[0].Owner.ID, false, memory.TB, memory.TB, 100000, 3)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Ensure User is free tier.
|
||||
|
@ -54,6 +54,7 @@ type UsageLimitsConfig struct {
|
||||
Storage StorageLimitConfig
|
||||
Bandwidth BandwidthLimitConfig
|
||||
Segment SegmentLimitConfig
|
||||
Project ProjectLimitConfig
|
||||
}
|
||||
|
||||
// StorageLimitConfig is a configuration struct for default storage per-project usage limits.
|
||||
@ -74,6 +75,12 @@ type SegmentLimitConfig struct {
|
||||
Paid int64 `help:"the default paid-tier segment usage limit" default:"100000000"`
|
||||
}
|
||||
|
||||
// ProjectLimitConfig is a configuration struct for default project limits.
|
||||
type ProjectLimitConfig struct {
|
||||
Free int `help:"the default free-tier project limit" default:"1"`
|
||||
Paid int `help:"the default paid-tier project limit" default:"3"`
|
||||
}
|
||||
|
||||
// Project is a database object that describes Project entity.
|
||||
type Project struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
|
@ -276,6 +276,7 @@ func (paymentService PaymentsService) AddCreditCard(ctx context.Context, creditC
|
||||
paymentService.service.config.UsageLimits.Bandwidth.Paid,
|
||||
paymentService.service.config.UsageLimits.Storage.Paid,
|
||||
paymentService.service.config.UsageLimits.Segment.Paid,
|
||||
paymentService.service.config.UsageLimits.Project.Paid,
|
||||
)
|
||||
if err != nil {
|
||||
return Error.Wrap(err)
|
||||
@ -644,7 +645,7 @@ func (s *Service) CreateUser(ctx context.Context, user CreateUser, tokenSecret R
|
||||
if registrationToken != nil {
|
||||
newUser.ProjectLimit = registrationToken.ProjectLimit
|
||||
} else {
|
||||
newUser.ProjectLimit = s.config.DefaultProjectLimit
|
||||
newUser.ProjectLimit = s.config.UsageLimits.Project.Free
|
||||
}
|
||||
|
||||
// TODO: move the project limits into the registration token.
|
||||
|
@ -318,6 +318,10 @@ func TestPaidTier(t *testing.T) {
|
||||
Free: 10,
|
||||
Paid: 50,
|
||||
},
|
||||
Project: console.ProjectLimitConfig{
|
||||
Free: 1,
|
||||
Paid: 3,
|
||||
},
|
||||
}
|
||||
|
||||
testplanet.Run(t, testplanet.Config{
|
||||
@ -336,6 +340,7 @@ func TestPaidTier(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, usageConfig.Storage.Free, *proj1.StorageLimit)
|
||||
require.Equal(t, usageConfig.Bandwidth.Free, *proj1.BandwidthLimit)
|
||||
require.Equal(t, usageConfig.Segment.Free, *proj1.SegmentLimit)
|
||||
|
||||
// user should be in free tier
|
||||
user, err := service.GetUser(ctx, proj1.OwnerID)
|
||||
@ -353,6 +358,7 @@ func TestPaidTier(t *testing.T) {
|
||||
user, err = service.GetUser(ctx, user.ID)
|
||||
require.NoError(t, err)
|
||||
require.True(t, user.PaidTier)
|
||||
require.Equal(t, usageConfig.Project.Paid, user.ProjectLimit)
|
||||
|
||||
// update auth ctx
|
||||
authCtx, err = sat.AuthenticatedContext(ctx, user.ID)
|
||||
@ -363,6 +369,7 @@ func TestPaidTier(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, usageConfig.Storage.Paid, *proj1.StorageLimit)
|
||||
require.Equal(t, usageConfig.Bandwidth.Paid, *proj1.BandwidthLimit)
|
||||
require.Equal(t, usageConfig.Segment.Paid, *proj1.SegmentLimit)
|
||||
|
||||
// expect new project to be created with paid tier usage limits
|
||||
proj2, err := service.CreateProject(authCtx, console.ProjectInfo{Name: "Project 2"})
|
||||
|
@ -31,7 +31,7 @@ type Users interface {
|
||||
// Update is a method for updating user entity.
|
||||
Update(ctx context.Context, user *User) error
|
||||
// UpdatePaidTier sets whether the user is in the paid tier.
|
||||
UpdatePaidTier(ctx context.Context, id uuid.UUID, paidTier bool, projectBandwidthLimit, projectStorageLimit memory.Size, projectSegmentLimit int64) error
|
||||
UpdatePaidTier(ctx context.Context, id uuid.UUID, paidTier bool, projectBandwidthLimit, projectStorageLimit memory.Size, projectSegmentLimit int64, projectLimit int) error
|
||||
// GetProjectLimit is a method to get the users project limit
|
||||
GetProjectLimit(ctx context.Context, id uuid.UUID) (limit int, err error)
|
||||
// GetUserProjectLimits is a method to get the users storage and bandwidth limits for new projects.
|
||||
|
@ -130,6 +130,7 @@ func TestUserUpdatePaidTier(t *testing.T) {
|
||||
password := "password"
|
||||
projectBandwidthLimit := memory.Size(50000000000)
|
||||
storageStorageLimit := memory.Size(50000000000)
|
||||
projectLimit := 3
|
||||
segmentLimit := int64(100)
|
||||
newUser := &console.User{
|
||||
ID: testrand.UUID(),
|
||||
@ -147,7 +148,7 @@ func TestUserUpdatePaidTier(t *testing.T) {
|
||||
require.Equal(t, shortName, createdUser.ShortName)
|
||||
require.False(t, createdUser.PaidTier)
|
||||
|
||||
err = db.Console().Users().UpdatePaidTier(ctx, createdUser.ID, true, projectBandwidthLimit, storageStorageLimit, segmentLimit)
|
||||
err = db.Console().Users().UpdatePaidTier(ctx, createdUser.ID, true, projectBandwidthLimit, storageStorageLimit, segmentLimit, projectLimit)
|
||||
require.NoError(t, err)
|
||||
|
||||
retrievedUser, err := db.Console().Users().Get(ctx, createdUser.ID)
|
||||
@ -157,7 +158,7 @@ func TestUserUpdatePaidTier(t *testing.T) {
|
||||
require.Equal(t, shortName, retrievedUser.ShortName)
|
||||
require.True(t, retrievedUser.PaidTier)
|
||||
|
||||
err = db.Console().Users().UpdatePaidTier(ctx, createdUser.ID, false, projectBandwidthLimit, storageStorageLimit, segmentLimit)
|
||||
err = db.Console().Users().UpdatePaidTier(ctx, createdUser.ID, false, projectBandwidthLimit, storageStorageLimit, segmentLimit, projectLimit)
|
||||
require.NoError(t, err)
|
||||
|
||||
retrievedUser, err = db.Console().Users().Get(ctx, createdUser.ID)
|
||||
|
@ -157,7 +157,7 @@ func (users *users) Update(ctx context.Context, user *console.User) (err error)
|
||||
}
|
||||
|
||||
// UpdatePaidTier sets whether the user is in the paid tier.
|
||||
func (users *users) UpdatePaidTier(ctx context.Context, id uuid.UUID, paidTier bool, projectBandwidthLimit, projectStorageLimit memory.Size, projectSegmentLimit int64) (err error) {
|
||||
func (users *users) UpdatePaidTier(ctx context.Context, id uuid.UUID, paidTier bool, projectBandwidthLimit, projectStorageLimit memory.Size, projectSegmentLimit int64, projectLimit int) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
_, err = users.db.Update_User_By_Id(
|
||||
@ -165,6 +165,7 @@ func (users *users) UpdatePaidTier(ctx context.Context, id uuid.UUID, paidTier b
|
||||
dbx.User_Id(id[:]),
|
||||
dbx.User_Update_Fields{
|
||||
PaidTier: dbx.User_PaidTier(paidTier),
|
||||
ProjectLimit: dbx.User_ProjectLimit(projectLimit),
|
||||
ProjectBandwidthLimit: dbx.User_ProjectBandwidthLimit(projectBandwidthLimit.Int64()),
|
||||
ProjectStorageLimit: dbx.User_ProjectStorageLimit(projectStorageLimit.Int64()),
|
||||
ProjectSegmentLimit: dbx.User_ProjectSegmentLimit(projectSegmentLimit),
|
||||
|
12
scripts/testdata/satellite-config.yaml.lock
vendored
12
scripts/testdata/satellite-config.yaml.lock
vendored
@ -31,6 +31,12 @@
|
||||
# the default paid-tier bandwidth usage limit
|
||||
# admin.console-config.usage-limits.bandwidth.paid: 100.00 TB
|
||||
|
||||
# the default free-tier project limit
|
||||
# admin.console-config.usage-limits.project.free: 1
|
||||
|
||||
# the default paid-tier project limit
|
||||
# admin.console-config.usage-limits.project.paid: 3
|
||||
|
||||
# the default free-tier segment usage limit
|
||||
# admin.console-config.usage-limits.segment.free: 150000
|
||||
|
||||
@ -265,6 +271,12 @@ compensation.withheld-percents: 75,75,75,50,50,50,25,25,25,0,0,0,0,0,0
|
||||
# the default paid-tier bandwidth usage limit
|
||||
# console.usage-limits.bandwidth.paid: 100.00 TB
|
||||
|
||||
# the default free-tier project limit
|
||||
# console.usage-limits.project.free: 1
|
||||
|
||||
# the default paid-tier project limit
|
||||
# console.usage-limits.project.paid: 3
|
||||
|
||||
# the default free-tier segment usage limit
|
||||
# console.usage-limits.segment.free: 150000
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user