mirror of https://github.com/zulip/zulip.git
sponsorship: Use customer instead of realm to store sponsorship data.
Since Customer already stores the realm it is linked to and customer is always created to store sponsorship request, we directly use customer to link to the sponsorship data for the realm.
This commit is contained in:
parent
fce35fc53b
commit
3615fa4745
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 4.2.7 on 2023-11-26 16:00
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("corporate", "0022_session_is_manual_license_management_upgrade_session"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="zulipsponsorshiprequest",
|
||||
name="customer",
|
||||
field=models.ForeignKey(
|
||||
null=True, on_delete=django.db.models.deletion.CASCADE, to="corporate.customer"
|
||||
),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("corporate", "0023_zulipsponsorshiprequest_customer"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunSQL(
|
||||
"""
|
||||
UPDATE corporate_zulipsponsorshiprequest
|
||||
SET customer_id = (
|
||||
SELECT id FROM corporate_customer WHERE corporate_customer.realm_id = corporate_zulipsponsorshiprequest.realm_id
|
||||
)
|
||||
"""
|
||||
),
|
||||
]
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 4.2.7 on 2023-11-26 16:13
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("corporate", "0024_zulipsponsorshiprequest_fill_customer_data"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="zulipsponsorshiprequest",
|
||||
name="customer",
|
||||
field=models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="corporate.customer"
|
||||
),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,16 @@
|
|||
# Generated by Django 4.2.7 on 2023-11-26 16:14
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("corporate", "0025_alter_zulipsponsorshiprequest_customer"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name="zulipsponsorshiprequest",
|
||||
name="realm",
|
||||
),
|
||||
]
|
|
@ -358,7 +358,7 @@ class LicenseLedger(models.Model):
|
|||
|
||||
|
||||
class ZulipSponsorshipRequest(models.Model):
|
||||
realm = models.ForeignKey(Realm, on_delete=CASCADE)
|
||||
customer = models.ForeignKey(Customer, on_delete=CASCADE)
|
||||
requested_by = models.ForeignKey(UserProfile, on_delete=CASCADE)
|
||||
|
||||
org_type = models.PositiveSmallIntegerField(
|
||||
|
|
|
@ -1804,8 +1804,10 @@ class StripeTest(StripeTestCase):
|
|||
response = self.client_post("/json/billing/sponsorship", data)
|
||||
self.assert_json_success(response)
|
||||
|
||||
customer = get_customer_by_realm(user.realm)
|
||||
assert customer is not None
|
||||
sponsorship_request = ZulipSponsorshipRequest.objects.filter(
|
||||
realm=user.realm, requested_by=user
|
||||
customer=customer, requested_by=user
|
||||
).first()
|
||||
assert sponsorship_request is not None
|
||||
self.assertEqual(sponsorship_request.org_website, data["website"])
|
||||
|
|
|
@ -167,8 +167,10 @@ def sponsorship(
|
|||
|
||||
if form.is_valid():
|
||||
with transaction.atomic():
|
||||
# Ensures customer is created first before updating sponsorship status.
|
||||
billing_session.update_customer_sponsorship_status(True)
|
||||
sponsorship_request = ZulipSponsorshipRequest(
|
||||
realm=realm,
|
||||
customer=billing_session.get_customer(),
|
||||
requested_by=user,
|
||||
org_website=form.cleaned_data["website"],
|
||||
org_description=form.cleaned_data["description"],
|
||||
|
@ -184,7 +186,6 @@ def sponsorship(
|
|||
realm.org_type = org_type
|
||||
realm.save(update_fields=["org_type"])
|
||||
|
||||
billing_session.update_customer_sponsorship_status(True)
|
||||
do_change_is_billing_admin(user, True)
|
||||
|
||||
org_type_display_name = get_org_type_display_name(org_type)
|
||||
|
|
Loading…
Reference in New Issue