Only sort a DataGrid if the column's sortable is set True
Review Request #10168 — Created Sept. 22, 2018 and submitted — Latest diff uploaded
Previously, all arguments to self.request.GET.get('sort', ...) were
passed toself.sort_listeven if they were invalid. This could cause
issues where columns collided with methods, such as when giving
?sort=fullnameto/users/which resulted in an Error 500.Now, in
load_state(), a set of sort keys are computed based on what
columns are set sortable, and the column'sdb_fieldis only added to
self.sort_listif the corresponding column is in this set.
Two unit tests have been added to exercise this functionality in
ascending and descending order, passing in an invalidsortkey and
checking thatself.sort_listis empty.Two additional unit tests sort on one valid and one invalid key in
ascending and descending order and check thatself.sort_listonly
contains the valid key. All four of these unit tests pass.All tests in
djblets.datagrid.testsand
reviewboard.datagrids.testspassed without problems.