Commit 56f989e53e80fe7545a3400ba7ee98a0cd2cf259

Authored by Dmitriy Zaporozhets
1 parent 5a098e84

Fix wrong issues appears at Dashboard#issues page

Filtering service used klass instead of passed items.
Because of this you see list of all issues intead of authorized ones.
This commit fixes it so people see only issues they are authorized to
see.

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
app/controllers/dashboard_controller.rb
... ... @@ -54,12 +54,12 @@ class DashboardController &lt; ApplicationController
54 54  
55 55 def merge_requests
56 56 @merge_requests = FilteringService.new.execute(MergeRequest, current_user, params)
57   - @merge_requests = @merge_requests.recent.page(params[:page]).per(20)
  57 + @merge_requests = @merge_requests.page(params[:page]).per(20)
58 58 end
59 59  
60 60 def issues
61 61 @issues = FilteringService.new.execute(Issue, current_user, params)
62   - @issues = @issues.recent.page(params[:page]).per(20)
  62 + @issues = @issues.page(params[:page]).per(20)
63 63 @issues = @issues.includes(:author, :project)
64 64  
65 65 respond_to do |format|
... ...
app/models/concerns/issuable.rb
... ... @@ -48,13 +48,13 @@ module Issuable
48 48  
49 49 def sort(method)
50 50 case method.to_s
51   - when 'newest' then reorder('created_at DESC')
52   - when 'oldest' then reorder('created_at ASC')
53   - when 'recently_updated' then reorder('updated_at DESC')
54   - when 'last_updated' then reorder('updated_at ASC')
  51 + when 'newest' then reorder("#{table_name}.created_at DESC")
  52 + when 'oldest' then reorder("#{table_name}.created_at ASC")
  53 + when 'recently_updated' then reorder("#{table_name}.updated_at DESC")
  54 + when 'last_updated' then reorder("#{table_name}.updated_at ASC")
55 55 when 'milestone_due_soon' then joins(:milestone).reorder("milestones.due_date ASC")
56 56 when 'milestone_due_later' then joins(:milestone).reorder("milestones.due_date DESC")
57   - else reorder('created_at DESC')
  57 + else reorder("#{table_name}.created_at DESC")
58 58 end
59 59 end
60 60 end
... ...
app/services/filtering_service.rb
... ... @@ -57,11 +57,11 @@ class FilteringService
57 57 def by_scope(items)
58 58 case params[:scope]
59 59 when 'created-by-me', 'authored' then
60   - klass.where(author_id: current_user.id)
  60 + items.where(author_id: current_user.id)
61 61 when 'all' then
62   - klass
  62 + items
63 63 when 'assigned-to-me' then
64   - klass.where(assignee_id: current_user.id)
  64 + items.where(assignee_id: current_user.id)
65 65 else
66 66 raise 'You must specify default scope'
67 67 end
... ...