Pārlūkot izejas kodu

Linting and more sandbox checks

Mauricio Araujo 2 gadi atpakaļ
vecāks
revīzija
0559d7a123

+ 3 - 2
api/server/handlers/billing/create.go

@@ -70,8 +70,9 @@ func (c *CreateBillingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
 		// Grant a reward to the project that referred this user after linking a payment method
 		err = c.grantRewardIfReferral(ctx, user.ID)
 		if err != nil {
-			// Only log the error in case the reward grant fails, but don't return an error to the fe
-			telemetry.Error(ctx, span, err, "error granting credits reward")
+			err := telemetry.Error(ctx, span, err, "error granting credits reward")
+			c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
+			return
 		}
 	}
 

+ 1 - 1
api/server/handlers/project/referrals.go

@@ -35,7 +35,7 @@ func (c *GetProjectReferralDetailsHandler) ServeHTTP(w http.ResponseWriter, r *h
 	proj, _ := ctx.Value(types.ProjectScope).(*models.Project)
 
 	if !c.Config().BillingManager.MetronomeConfigLoaded || !proj.GetFeatureFlag(models.MetronomeEnabled, c.Config().LaunchDarklyClient) ||
-		proj.UsageID == uuid.Nil || proj.EnableSandbox {
+		proj.UsageID == uuid.Nil || !proj.EnableSandbox {
 		c.WriteResult(w, r, "")
 
 		telemetry.WithAttributes(span,

+ 1 - 0
api/types/billing_metronome.go

@@ -159,6 +159,7 @@ type PaidAmount struct {
 	CreditTypeID uuid.UUID `json:"credit_type_id"`
 }
 
+// PricingUnit represents the unit of the pricing (e.g. USD, MXN, CPU hours)
 type PricingUnit struct {
 	ID         uuid.UUID `json:"id"`
 	Name       string    `json:"name"`

+ 6 - 4
dashboard/src/main/home/project-settings/ProjectSettings.tsx

@@ -96,10 +96,12 @@ function ProjectSettings(props: any) {
         });
       }
 
-      tabOpts.push({
-        value: "referrals",
-        label: "Referrals",
-      });
+      if (currentProject?.sandbox_enabled && currentProject?.billing_enabled) {
+        tabOpts.push({
+          value: "referrals",
+          label: "Referrals",
+        });
+      }
 
       tabOpts.push({
         value: "additional-settings",

+ 1 - 1
internal/repository/gorm/referrals.go

@@ -49,7 +49,7 @@ func (repo *ReferralRepository) CountReferralsByProjectID(projectID uint, status
 	return count, nil
 }
 
-// GetReferralByCode returns the number of referrals a user has made
+// GetReferralByReferredID returns a referral by the referred user's ID
 func (repo *ReferralRepository) GetReferralByReferredID(referredID uint) (*models.Referral, error) {
 	referral := &models.Referral{}
 	if err := repo.db.Where("referred_user_id = ?", referredID).First(&referral).Error; err != nil {

+ 1 - 0
internal/repository/gorm/repository.go

@@ -294,6 +294,7 @@ func (t *GormRepository) Ipam() repository.IpamRepository {
 	return t.ipam
 }
 
+// Referral returns the ReferralRepository interface implemented by gorm
 func (t *GormRepository) Referral() repository.ReferralRepository {
 	return t.referral
 }