-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add missing imports + refactor to call 1 query
- Loading branch information
1 parent
16f7fba
commit 3a5b3af
Showing
7 changed files
with
29 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
) | ||
from shared.plan.service import PlanService | ||
|
||
from codecov_auth.models import Owner | ||
from codecov_auth.models import Owner, Plan | ||
from services.billing import BillingService | ||
from services.sentry import send_user_webhook as send_sentry_webhook | ||
|
||
|
@@ -147,10 +147,18 @@ def validate(self, plan: Dict[str, Any]) -> Dict[str, Any]: | |
detail="You cannot update your plan manually, for help or changes to plan, connect with [email protected]" | ||
) | ||
|
||
active_plans = list( | ||
Plan.objects.filter(paid_plan=True, is_active=True).values_list( | ||
"name", "tier" | ||
) | ||
) | ||
active_plan_names = {name for name, _ in active_plans} | ||
team_tier_plans = { | ||
name for name, tier in active_plans if tier == TierName.TEAM.value | ||
} | ||
|
||
# Validate quantity here because we need access to whole plan object | ||
if plan["value"] in Plan.objects.filter( | ||
paid_plan=True, is_active=True | ||
).values_list("name", flat=True): | ||
if plan["value"] in active_plan_names: | ||
if "quantity" not in plan: | ||
raise serializers.ValidationError( | ||
"Field 'quantity' required for updating to paid plans" | ||
|
@@ -179,8 +187,7 @@ def validate(self, plan: Dict[str, Any]) -> Dict[str, Any]: | |
"Quantity or plan for paid plan must be different from the existing one" | ||
) | ||
if ( | ||
plan["value"] | ||
in Plan.objects.filter(tier=TierName.TEAM.value, is_active=True) | ||
plan["value"] in team_tier_plans | ||
and plan["quantity"] > TEAM_PLAN_MAX_USERS | ||
): | ||
raise serializers.ValidationError( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters