Commit Graph

56 Commits

Author SHA1 Message Date
Kenneth Rodrigues dc32396180 endpoints: Remove the has_request_variables decorator.
All endpoints have been migrated to the typed_endpoint decorator,
therefore the has_request_variables decorator and the REQ function are
no longer needed and have been removed.
2024-09-05 16:02:12 -07:00
Alex Vandiver e29a455b2d avatars: Encode version into the filename.
Hash the salt, user-id, and now avatar version into the filename.
This allows the URL contents to be immutable, and thus to be marked as
immutable and cacheable.  Since avatars are served unauthenticated,
hashing with a server-side salt makes the current and past avatars not
enumerable.

This requires plumbing the current (or future) avatar version through
various parts of the upload process.

Since this already requires a full migration of current avatars, also
take the opportunity to fix the missing `.png` on S3 uploads (#12852).

We switch from SHA-1 to SHA-256, but truncate it such that avatar URL
data does not substantially increase in size.

Fixes: #12852.
2024-07-07 14:40:07 -07:00
Anders Kaseorg 975066e3f0 actions: Split out zerver.actions.message_send.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-04-14 17:14:34 -07:00
Anders Kaseorg 8d9fe9cfb0 mypy: Add types-stripe.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-01-23 22:47:30 -08:00
Vishnu KS 585d98d5a9 billing: Enforce the Stripe API version is in sync with billing system. 2021-11-05 17:23:10 -07:00
Vishnu KS 6c06858e02 billing: Migrate to Stripe hosted checkout page. 2021-11-05 17:23:10 -07:00
Vishnu KS fcab2ea5f7 billing: Add command for switching plans from Standard to Plus. 2021-10-15 17:27:50 -07:00
Anders Kaseorg 0b795e492f thumbnail: Remove unused is_camo_url parameter.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-08-19 01:51:37 -07:00
Vishnu KS 158cec84ec stripe: Upgrade stripe API to 2020-08-27 version.
This upgrades the Stripe API to the most recent version. Going through
the Git history, it looks like our current API version is at 2019-03-14.

The API version should be manually changed in Stripe dashboard at the same
time as the commit is deployed in production.

Backward incompatible changes that are relevant to our codebase between
(2019-03-14, 2020-08-27].
* 2020-08-27 - The `sources` property on Customers is no longer included by
  default.
* 2020-03-02 - Nothing applicable
* 2019-12-03 - The `id` field of all invoice line items have changed and are
  now prefixed
  with `il_`. We only rely on this while we normalize the fixtures.
* 2019-11-05 - Nothing applicable
* 2019-10-17 - The `billing` attribute on invoices, subscriptions, and
  subscription schedules is renamed to`collection_method`. The invoice
  change is the one that is relevant to us.
* The customer object’s `account_balance` value has been renamed to
  `balance`. Only used for the stubs at the moment.
* 2019-10-08 - Nothing applicable
* 2019-09-09 - Nothing applicable
* 2019-08-14 - Nothing applicable
* 2019-05-16 - Nothing applicable

https://stripe.com/docs/upgrades

Also normalize the following IDs in stripe fixtures

* price_[A-Za-z0-9]{24}
* prod_[A-Za-z0-9]{14}
* pi_[A-Za-z0-9]{24}
* il_[A-Za-z0-9]{24}
2021-07-23 21:44:41 -07:00
Anders Kaseorg a3603a865e stubs: Sort *.pyi imports with isort.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-07-11 09:20:19 -07:00
Anders Kaseorg ae655bdc69 stubs: Reformat *.pyi files with Black.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-07-11 09:20:19 -07:00
Vishnu KS e0f5fadb79 billing: Downgrade small realms that are behind on payments.
An organization with at most 5 users that is behind on payments isn't
worth spending time on investigating the situation.

For larger organizations, we likely want somewhat different logic that
at least does not void invoices.
2021-07-02 13:19:12 -07:00
Vishnu KS e64296b3e9 stripe: Create get_all_invoices function.
stripe.Invoice.list by default would only get 10 invoices at a
time. So a function like this would be really handy if we have
to go through a lot of invoices.

This also means void_all_open_invoices used to void only the last
10 invoices. The main reason we implemented this function was to
void the invoices generated by realms on free trial so I don't
think there were cases where we had to void realms with more than
10 invoices.
2021-07-02 12:04:41 -07:00
Anders Kaseorg 1275613812 requirements: Upgrade mypy to 0.790.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-11-12 15:44:30 -08:00
Anders Kaseorg 254758733e mypy: Remove unused yamole stub.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-11-12 15:44:30 -08:00
Anders Kaseorg 72d6ff3c3b docs: Fix more capitalization issues.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-10-23 11:46:55 -07:00
Vishnu KS b8b2e443bc stripe: Create void_all_open_invoices. 2020-09-28 15:37:49 -07:00
Anders Kaseorg 61d0417e75 python: Replace ujson with orjson.
Fixes #6507.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-08-11 10:55:12 -07:00
Graham Bleaney 461d5b1a3e pysa: Introduce sanitizers, models, and inline marking safe.
This commit adds three `.pysa` model files: `false_positives.pysa`
for ruling out false positive flows with `Sanitize` annotations,
`req_lib.pysa` for educating pysa about Zulip's `REQ()` pattern for
extracting user input, and `redirects.pysa` for capturing the risk
of open redirects within Zulip code. Additionally, this commit
introduces `mark_sanitized`, an identity function which can be used
to selectively clear taint in cases where `Sanitize` models will not
work. This commit also puts `mark_sanitized` to work removing known
false postive flows.
2020-06-11 12:57:49 -07:00
Graham Bleaney 89131bfcbb pysa: Add basic .pyre_configuration and taint.config for pysa.
This commit adds the initial config files needed to be able to run
Pysa on Zulip code.
2020-06-11 12:57:49 -07:00
Anders Kaseorg 99904527f5 mypy: Remove daemon mode.
mypy in daemon mode takes some 400 MiB of memory, and cannot follow
imports of type-annotated third-party packages; meanwhile, non-daemon
mode is no longer nearly as slow as it once was.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-08-25 15:04:12 -07:00
Rishi Gupta 2270d4d192 billing: Try paying invoices when user puts a new card on file.
Previously, when users got a "payment failed" email from Stripe (e.g. if
their card failed on renewal), they would enter in a new card on
/billing#payment-method, and wouldn't find out if the card worked till
Stripe retried the payment 4 days later.
2019-04-05 13:36:03 -07:00
Rishi Gupta 5d970cc09b billing: Upgrade to Stripe API version 2019-03-14.
No breaking changes.
2019-04-05 11:24:45 -07:00
Rishi Gupta db6e6472b1 billing: Set idempotency key to None when running test suite. 2019-01-30 10:35:01 -08:00
Rishi Gupta 4aa2ac1b52 billing: Add functions for automatic invoicing of plans. 2019-01-28 16:04:11 -08:00
Rishi Gupta 653416ab23 billing: Update /billing to work with new subscription model. 2018-12-23 00:18:21 -08:00
Rishi Gupta e7220fd71f billing: Do subscription management in-house instead of with Stripe Billing.
This is a major rewrite of the billing system. It moves subscription
information off of stripe Subscriptions and into a local CustomerPlan
table.

To keep this manageable, it leaves several things unimplemented
(downgrading, etc), and a variety of other TODOs in the code. There are also
some known regressions, e.g. error-handling on /upgrade is broken.
2018-12-22 13:39:30 -08:00
Rishi Gupta d813d29290 billing: Add mypy daemon warning to stripe stubs file. 2018-12-18 12:48:22 -08:00
Rishi Gupta f0538293de billing: Update test_replace_payment_source to use mock_stripe. 2018-11-28 10:45:00 -08:00
Vishnu Ks 8343ed6ceb billing: Use mock_stripe in test_downgrade_with_money_owed. 2018-11-26 15:59:19 -08:00
Vishnu Ks 1ec9097f55 billing: Use mock_stripe in test_downgrade. 2018-11-26 14:59:46 -08:00
Vishnu Ks a2c0ec207e billing: Use mock_stripe in test_attach_discount_to_realm. 2018-11-26 14:59:46 -08:00
Rishi Gupta 08daefa4a3 billing: Update payment method string to incorporate billing by invoice.
Also fixes a bug in process_initial_upgrade. If you have a card on file
(e.g. from a previous subscription), and try to upgrade by billing by
invoice, neither the if nor the elif condition applies.
2018-11-24 11:56:13 -08:00
Rishi Gupta 99506b486a billing: Add backend for paying by invoice. 2018-11-17 23:08:48 -08:00
Rishi Gupta 61e0c2693d billing: Use Subscription.save() instead of calling save on instances.
Continuation of 03d77bc.
2018-11-17 18:59:21 -08:00
Vishnu Ks 2e04cdbe5e billing: Show estimated subscription revenue on /activity.
[Substantial edits by Rishi Gupta]
2018-11-16 13:30:16 -08:00
Vishnu Ks b527c3c4ef billing: Make mock_stripe handle StripeErrors. 2018-10-30 09:55:13 -07:00
Vishnu Ks 3b026559d4 stripe: Make stripe.error stubs more similiar to stripe python lib.
This will also fix the error that is generated during
the mypy 0.641 upgrade in PR #10691.
2018-10-22 13:51:05 +05:30
Rishi Gupta 03d77bc6af billing: Replace instance.save() Stripe API calls with class.save(instance).
This will make it easier to mock the calls in our new stripe mocking
framework. I believe the two forms are equivalent, assuming the Stripe
Python bindings aren't doing anything crazy. And if not, well hopefully our
new testing framework will catch it :).

[Idea originally from Vishnu KS.]
2018-10-18 11:16:00 -07:00
Vishnu Ks 50de59102d billing: Add system to generate fixture data from the billing tests.
This will improve both the maintainability and accuracy of the fixture
data. It also makes it less scary to upgrade Stripe API versions.

[With significant changes by Rishi Gupta.]
2018-10-17 20:35:42 -07:00
Vishnu Ks 5a6b2ebb1f billing: Add ability for users to change their card. 2018-09-24 19:25:26 -07:00
Rishi Gupta bd0487d503 billing: Fix mypy stubs to use keyword args instead of positional args. 2018-08-31 17:51:16 -07:00
Rishi Gupta 31ed4492ce billing: Add backend for downgrading. 2018-08-31 17:49:34 -07:00
Rishi Gupta eec07072ee billing: Add coupons. 2018-08-24 17:27:26 -07:00
Rishi Gupta d229948a43 billing: Make source optional when creating stripe customer. 2018-08-24 16:40:34 -07:00
Rishi Gupta 3cf9cd00d6 billing: Remove idempotency key from upgrade process.
This would be relevant if we retried on network failure, but we don't.
2018-08-22 19:18:32 -07:00
Rishi Gupta 56d4034db4 billing: Require successful charge to establish billing relationship.
There are several situations in which we want to create a Customer and
stripe.Customer object before we really have a billing relationship with a
customer. The main one is giving non-profit or educational discounts.
2018-08-13 20:24:08 -07:00
Rishi Gupta 27d4b1a5f0 billing: Add RealmAuditLogProcessor. 2018-08-13 17:12:50 -07:00
Rishi Gupta e804c563a8 billing: Update stripe error handling code. 2018-08-13 17:12:50 -07:00
Vishnu Ks 132480c031 billing: Pass email to stripe.Customer.create. 2018-08-10 13:52:35 -07:00