Skip to content

Commit

Permalink
Merge pull request #35050 from dimagi/em/change-plan-check-can-change…
Browse files Browse the repository at this point in the history
…-subscription

Add can_change_subscription check to SelectPlanView, use new base class PlanViewBase instead of SelectPlanView
  • Loading branch information
nospame authored Aug 28, 2024
2 parents 0d78fd3 + c3475f7 commit 62d2f03
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions corehq/apps/domain/views/accounting.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,13 +963,10 @@ def is_form_editable(self):
)


class SelectPlanView(DomainAccountingSettings):
template_name = 'domain/select_plan.html'
urlname = 'domain_select_plan'
class PlanViewBase(DomainAccountingSettings):
page_title = gettext_lazy("Change Plan")
step_title = gettext_lazy("Select Plan")
edition = None
lead_text = gettext_lazy("Please select a plan below that fits your organization's needs.")
edition = None

@property
@memoized
Expand Down Expand Up @@ -1060,7 +1057,7 @@ def steps(self):

@property
def main_context(self):
context = super(SelectPlanView, self).main_context
context = super().main_context
context.update({
'steps': self.steps,
'step_title': self.step_title,
Expand Down Expand Up @@ -1104,7 +1101,24 @@ def page_context(self):
}


class SelectedEnterprisePlanView(SelectPlanView):
class SelectPlanView(PlanViewBase):
template_name = 'domain/select_plan.html'
urlname = 'domain_select_plan'
step_title = gettext_lazy("Select Plan")

def dispatch(self, request, *args, **kwargs):
if not self.can_change_subscription:
raise Http404()
return super().dispatch(request, *args, **kwargs)

@property
def can_change_subscription(self):
subscription = self.current_subscription
is_annual_plan = subscription.plan_version.plan.is_annual_plan
return not is_annual_plan


class SelectedEnterprisePlanView(PlanViewBase):
template_name = 'domain/selected_enterprise_plan.html'
urlname = 'enterprise_request_quote'
step_title = gettext_lazy("Contact Dimagi")
Expand Down Expand Up @@ -1146,7 +1160,7 @@ def post(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)


class SelectedAnnualPlanView(SelectPlanView):
class SelectedAnnualPlanView(PlanViewBase):
template_name = 'domain/selected_annual_plan.html'
urlname = 'annual_plan_request_quote'
step_title = gettext_lazy("Contact Dimagi")
Expand Down Expand Up @@ -1208,7 +1222,7 @@ def post(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)


class ConfirmSelectedPlanView(SelectPlanView):
class ConfirmSelectedPlanView(PlanViewBase):
template_name = 'domain/confirm_plan.html'
urlname = 'confirm_selected_plan'

Expand Down Expand Up @@ -1529,7 +1543,7 @@ def subscription(self):
return subscription


class SubscriptionRenewalView(SelectPlanView, SubscriptionMixin):
class SubscriptionRenewalView(PlanViewBase, SubscriptionMixin):
urlname = "domain_subscription_renewal"
page_title = gettext_lazy("Renew Plan")
step_title = gettext_lazy("Renew Plan")
Expand Down Expand Up @@ -1583,7 +1597,7 @@ def page_context(self):
return context


class ConfirmSubscriptionRenewalView(SelectPlanView, DomainAccountingSettings,
class ConfirmSubscriptionRenewalView(PlanViewBase, DomainAccountingSettings,
AsyncHandlerMixin, SubscriptionMixin):
template_name = 'domain/confirm_subscription_renewal.html'
urlname = 'domain_subscription_renewal_confirmation'
Expand Down

0 comments on commit 62d2f03

Please sign in to comment.