Fix rendering the admin sidebar when in an extension's database views.

Review Request #11497 — Created March 1, 2021 and submitted

Information

Review Board
release-4.0.x

Reviewers

When accessing an extension's database views (such as Review Bot's
Tools entries), URL lookups for pages in Review Board's main database
pages would fail to resolve, breaking rendering of the page.

This happens due to the usage of the current_app support in URL
rendering. This is a method that's used to limit which URLs may be
matched when resolving a URL. If request.current_app is set in a view
(which is the case for any given AdminSite), then any calls to
{% url %} will pass it in to reverse().

In this particular case, reversing admin:XYZ with a
current_app='test' would match only in test's admin:... URLs, and
would fail to find an admin:XYZ in some other app.

The solution in our case is to precompute the URLs before rendering the
template, letting us bypass the current_app mechanism. This is being
done in the {% admin_sidebar %} template tag, which handles the
rendering.

Accessed the Review Bot database views. The pages rendered correctly,
and all sidebar links worked.

Tested the main admin UI pages. They also worked correctly.

Summary ID
Fix rendering the admin sidebar when in an extension's database views.
When accessing an extension's database views (such as Review Bot's Tools entries), URL lookups for pages in Review Board's main database pages would fail to resolve, breaking rendering of the page. This happens due to the usage of the `current_app` support in URL rendering. This is a method that's used to limit which URLs may be matched when resolving a URL. If `request.current_app` is set in a view (which is the case for any given `AdminSite`), then any calls to `{% url %}` will pass it in to `reverse()`. In this particular case, reversing `admin:XYZ` with a `current_app='test'` would match only in `test`'s `admin:...` URLs, and would fail to find an `admin:XYZ` in some other app. The solution in our case is to precompute the URLs before rendering the template, letting us bypass the `current_app` mechanism. This is being done in the `{% admin_sidebar %}` template tag, which handles the rendering.
d098392210e49930220bbead3565c034c2166d25
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-4.0.x (6e36a42)
Loading...