@@ -10,21 +10,12 @@ def index
1010
1111 scope = scope . where ( 'issues.created_at > ?' , 1 . day . ago ) if params [ :recent ] . present?
1212
13- # Define allowed sort fields with database expressions
14- allowed_sort_fields = {
15- 'created_at' => 'issues.created_at' ,
16- 'updated_at' => 'issues.updated_at' ,
17- 'stars' => "CAST(projects.repository->>'stargazers_count' AS INTEGER)"
18- }
19-
2013 if params [ :sort ] . present? || params [ :order ] . present?
21- sort_key = params [ :sort ] . presence || 'created_at'
22- sort_field = allowed_sort_fields [ sort_key ] || 'issues.created_at'
23-
14+ sort = sanitize_sort ( Issue . sortable_columns , default : 'created_at' )
2415 if params [ :order ] == 'asc'
25- scope = scope . order ( Arel . sql ( sort_field ) . asc . nulls_last )
16+ scope = scope . order ( sort . asc . nulls_last )
2617 else
27- scope = scope . order ( Arel . sql ( sort_field ) . desc . nulls_last )
18+ scope = scope . order ( sort . desc . nulls_last )
2819 end
2920 else
3021 scope = scope . order ( 'issues.created_at DESC' )
@@ -39,11 +30,11 @@ def openclimateaction
3930 scope = Project . where ( id : project_ids ) . active . reviewed . includes ( :climatetriage_issues )
4031
4132 if params [ :sort ] . present? || params [ :order ] . present?
42- sort = params [ :sort ] . presence || 'projects.updated_at'
33+ sort = sanitize_sort ( Project . sortable_columns , default : 'projects.updated_at' )
4334 if params [ :order ] == 'asc'
44- scope = scope . order ( Arel . sql ( sort ) . asc . nulls_last )
35+ scope = scope . order ( sort . asc . nulls_last )
4536 else
46- scope = scope . order ( Arel . sql ( sort ) . desc . nulls_last )
37+ scope = scope . order ( sort . desc . nulls_last )
4738 end
4839 else
4940 scope = scope . order ( 'projects.updated_at DESC' )
0 commit comments