Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

billing/sponsorship: Allow blank organization URLs.

Eeshan Garga808f02a2215
diff --git a/corporate/migrations/0013_alter_zulipsponsorshiprequest_org_website.py b/corporate/migrations/0013_alter_zulipsponsorshiprequest_org_website.py
new file mode 100644
index 00000000000..c61efee7833
--- /dev/null
+++ b/corporate/migrations/0013_alter_zulipsponsorshiprequest_org_website.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.5 on 2021-08-06 19:18
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("corporate", "0012_zulipsponsorshiprequest"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="zulipsponsorshiprequest",
+ name="org_website",
+ field=models.URLField(blank=True, null=True),
+ ),
+ ]
diff --git a/corporate/models.py b/corporate/models.py
index dab326ab212..1b6ae79eaf1 100644
--- a/corporate/models.py
+++ b/corporate/models.py
@@ -204,6 +204,6 @@ class ZulipSponsorshipRequest(models.Model):
)
MAX_ORG_URL_LENGTH: int = 200
- org_website: str = models.URLField(max_length=MAX_ORG_URL_LENGTH)
+ org_website: str = models.URLField(max_length=MAX_ORG_URL_LENGTH, blank=True, null=True)
org_description: str = models.TextField(default="")
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index e1f9b7590f2..d9d31522a35 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -1461,6 +1461,32 @@ class StripeTest(StripeTestCase):
orjson.loads(response.content)["error_description"], "uncaught exception during upgrade"
)
+ def test_request_sponsorship_form_with_invalid_url(self) -> None:
+ user = self.example_user("hamlet")
+ self.login_user(user)
+ data = {
+ "organization-type": Realm.ORG_TYPES["opensource"]["id"],
+ "website": "invalid-url",
+ "description": "Infinispan is a distributed in-memory key/value data store with optional schema.",
+ }
+
+ response = self.client_post("/json/billing/sponsorship", data)
+
+ self.assert_json_error(response, "Enter a valid URL.")
+
+ def test_request_sponsorship_form_with_blank_url(self) -> None:
+ user = self.example_user("hamlet")
+ self.login_user(user)
+ data = {
+ "organization-type": Realm.ORG_TYPES["opensource"]["id"],
+ "website": "",
+ "description": "Infinispan is a distributed in-memory key/value data store with optional schema.",
+ }
+
+ response = self.client_post("/json/billing/sponsorship", data)
+
+ self.assert_json_success(response)
+
def test_request_sponsorship(self) -> None:
user = self.example_user("hamlet")
self.assertIsNone(get_customer_by_realm(user.realm))
diff --git a/corporate/views/upgrade.py b/corporate/views/upgrade.py
index 1c55e8ad91c..33d53105a3b 100644
--- a/corporate/views/upgrade.py
+++ b/corporate/views/upgrade.py
@@ -203,7 +203,7 @@ def initial_upgrade(
class SponsorshipRequestForm(forms.Form):
- website = forms.URLField(max_length=ZulipSponsorshipRequest.MAX_ORG_URL_LENGTH)
+ website = forms.URLField(max_length=ZulipSponsorshipRequest.MAX_ORG_URL_LENGTH, required=False)
organization_type = forms.IntegerField()
description = forms.CharField(widget=forms.Textarea)
@@ -235,8 +235,8 @@ def sponsorship(
post_data.update(organization_type=organization_type)
form = SponsorshipRequestForm(post_data)
- with transaction.atomic():
- if form.is_valid():
+ if form.is_valid():
+ with transaction.atomic():
sponsorship_request = ZulipSponsorshipRequest(
realm=realm,
requested_by=user,
@@ -251,27 +251,34 @@ def sponsorship(
realm.org_type = org_type
realm.save(update_fields=["org_type"])
- update_sponsorship_status(realm, True, acting_user=user)
- do_make_user_billing_admin(user)
-
- org_type_display_name = get_org_type_display_name(org_type)
-
- context = {
- "requested_by": requested_by,
- "user_role": user_role,
- "string_id": realm.string_id,
- "support_url": support_url,
- "organization_type": org_type_display_name,
- "website": website,
- "description": description,
- }
- send_email(
- "zerver/emails/sponsorship_request",
- to_emails=[FromAddress.SUPPORT],
- from_name="Zulip sponsorship",
- from_address=FromAddress.tokenized_no_reply_address(),
- reply_to_email=user.delivery_email,
- context=context,
- )
+ update_sponsorship_status(realm, True, acting_user=user)
+ do_make_user_billing_admin(user)
+
+ org_type_display_name = get_org_type_display_name(org_type)
+
+ context = {
+ "requested_by": requested_by,
+ "user_role": user_role,
+ "string_id": realm.string_id,
+ "support_url": support_url,
+ "organization_type": org_type_display_name,
+ "website": website,
+ "description": description,
+ }
+ send_email(
+ "zerver/emails/sponsorship_request",
+ to_emails=[FromAddress.SUPPORT],
+ from_name="Zulip sponsorship",
+ from_address=FromAddress.tokenized_no_reply_address(),
+ reply_to_email=user.delivery_email,
+ context=context,
+ )
- return json_success()
+ return json_success()
+ else:
+ messages = []
+ for error_list in form.errors.get_json_data().values():
+ for error in error_list:
+ messages.append(error["message"])
+ message = " ".join(messages)
+ raise BillingError("Form validation error", message=message)
diff --git a/templates/corporate/upgrade.html b/templates/corporate/upgrade.html
index 3a4bfeb4351..bd28a3e2732 100644
--- a/templates/corporate/upgrade.html
+++ b/templates/corporate/upgrade.html
@@ -238,7 +238,7 @@
<label>
<h4>Organization website</h4>
</label>
- <input name="website" style="width: 100%;" type="text" class="input-large" required/>
+ <input name="website" style="width: 100%;" type="text" class="input-large" placeholder="{{ _('Leave blank if your organization does not have a website.') }}"/>
<label>
<h4>Describe your organization briefly</h4>
</label>