zulip/analytics
Alex Vandiver 536bd3188e middleware: Move locale-setting before domain checking.
Calling `render()` in a middleware before LocaleMiddleware has run
will pick up the most-recently-set locale.  This may be from the
_previous_ request, since the current language is thread-local.  This
results in the "Organization does not exist" page occasionally being
in not-English, depending on the preferences of the request which that
thread just finished serving.

Move HostDomainMiddleware below LocaleMiddleware; none of the earlier
middlewares call `render()`, so are safe.  This will also allow the
"Organization does not exist" page to be localized based on the user's
browser preferences.

Unfortunately, it also means that the default LocaleMiddleware catches
the 404 from the HostDomainMiddlware and helpfully tries to check if
the failure is because the URL lacks a language component (e.g.
`/en/`) by turning it into a 304 to that new URL.  We must subclass
the default LocaleMiddleware to remove this unwanted functionality.

Doing so exposes a two places in tests that relied (directly or
indirectly) upon the redirection: '/confirmation_key'
was redirected to '/en/confirmation_key', since the non-i18n version
did not exist; and requests to `/stats/realm/not_existing_realm/`
incorrectly were expecting a 302, not a 404.

This regression likely came in during f00ff1ef62, since prior to
that, the HostDomainMiddleware ran _after_ the rest of the request had
completed.
2020-09-14 22:16:09 -07:00
..
lib python: Replace unnecessary intermediate lists with generators. 2020-09-02 11:15:41 -07:00
management python: Elide type=str from argparse arguments. 2020-09-03 16:17:14 -07:00
migrations migrations: Upgrade migrations to remove duplicates in all Count tables. 2020-07-30 15:18:00 -07:00
tests middleware: Move locale-setting before domain checking. 2020-09-14 22:16:09 -07:00
__init__.py Create "analytics" app with activity reports. 2013-11-06 12:07:32 -05:00
models.py python: Sort imports with isort. 2020-06-11 16:45:32 -07:00
urls.py urls: Elide str converter, which is the default. 2020-09-12 11:21:40 -07:00
views.py python: Replace unnecessary intermediate lists with generators. 2020-09-02 11:15:41 -07:00