mirror of
https://github.com/ente-io/ente.git
synced 2025-08-08 23:39:30 +00:00
[server] Remove timelimit for applying referral code (#3322)
## Description ## Tests
This commit is contained in:
commit
5ce1a91146
@ -3,6 +3,7 @@ package storagebonus
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
|
goaway "github.com/TwiN/go-away"
|
||||||
"github.com/ente-io/museum/pkg/utils/random"
|
"github.com/ente-io/museum/pkg/utils/random"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -14,17 +15,14 @@ import (
|
|||||||
"github.com/ente-io/museum/pkg/repo"
|
"github.com/ente-io/museum/pkg/repo"
|
||||||
"github.com/ente-io/museum/pkg/repo/storagebonus"
|
"github.com/ente-io/museum/pkg/repo/storagebonus"
|
||||||
"github.com/ente-io/museum/pkg/utils/auth"
|
"github.com/ente-io/museum/pkg/utils/auth"
|
||||||
enteTime "github.com/ente-io/museum/pkg/utils/time"
|
|
||||||
"github.com/ente-io/stacktrace"
|
"github.com/ente-io/stacktrace"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/TwiN/go-away"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
codeLength = 6
|
codeLength = 6
|
||||||
referralAmountInGb = 10
|
referralAmountInGb = 10
|
||||||
maxClaimableReferralAmount = 2000
|
maxClaimableReferralAmount = 2000
|
||||||
numOfDaysToClaimReferral = 32
|
|
||||||
defaultPlanType = entity.TenGbOnUpgrade
|
defaultPlanType = entity.TenGbOnUpgrade
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -51,7 +49,7 @@ func (c *Controller) GetUserReferralView(ctx *gin.Context) (*entity.GetUserRefer
|
|||||||
return nil, stacktrace.Propagate(err, "")
|
return nil, stacktrace.Propagate(err, "")
|
||||||
}
|
}
|
||||||
isFamilyMember := user.FamilyAdminID != nil && *user.FamilyAdminID != userID
|
isFamilyMember := user.FamilyAdminID != nil && *user.FamilyAdminID != userID
|
||||||
enableApplyCode := !appliedReferral && user.CreationTime > enteTime.MicrosecondBeforeDays(numOfDaysToClaimReferral) && !isFamilyMember
|
enableApplyCode := !appliedReferral && !isFamilyMember
|
||||||
// Get the referral code for the user or family admin
|
// Get the referral code for the user or family admin
|
||||||
codeUser := userID
|
codeUser := userID
|
||||||
if isFamilyMember {
|
if isFamilyMember {
|
||||||
@ -102,9 +100,7 @@ func (c *Controller) ApplyReferralCode(ctx *gin.Context, code string) error {
|
|||||||
return stacktrace.Propagate(err, "failed to get user")
|
return stacktrace.Propagate(err, "failed to get user")
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.CreationTime < enteTime.MicrosecondBeforeDays(numOfDaysToClaimReferral) {
|
if user.FamilyAdminID != nil && userID != *user.FamilyAdminID {
|
||||||
return stacktrace.Propagate(entity.CanNotApplyCodeErr, "account is too old to apply code")
|
|
||||||
} else if user.FamilyAdminID != nil && userID != *user.FamilyAdminID {
|
|
||||||
return stacktrace.Propagate(entity.CanNotApplyCodeErr, "user is member of a family plan")
|
return stacktrace.Propagate(entity.CanNotApplyCodeErr, "user is member of a family plan")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user