Commit 657eb7ba authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'bug/filtering_service' into 'master'

Fix wrong issues appears at Dashboard#issues page

Fixes #1028
parents c10a35c4 5e30f4d5
...@@ -54,12 +54,12 @@ class DashboardController < ApplicationController ...@@ -54,12 +54,12 @@ class DashboardController < ApplicationController
def merge_requests def merge_requests
@merge_requests = FilteringService.new.execute(MergeRequest, current_user, params) @merge_requests = FilteringService.new.execute(MergeRequest, current_user, params)
@merge_requests = @merge_requests.recent.page(params[:page]).per(20) @merge_requests = @merge_requests.page(params[:page]).per(20)
end end
def issues def issues
@issues = FilteringService.new.execute(Issue, current_user, params) @issues = FilteringService.new.execute(Issue, current_user, params)
@issues = @issues.recent.page(params[:page]).per(20) @issues = @issues.page(params[:page]).per(20)
@issues = @issues.includes(:author, :project) @issues = @issues.includes(:author, :project)
respond_to do |format| respond_to do |format|
......
...@@ -48,13 +48,13 @@ module Issuable ...@@ -48,13 +48,13 @@ module Issuable
def sort(method) def sort(method)
case method.to_s case method.to_s
when 'newest' then reorder('created_at DESC') when 'newest' then reorder("#{table_name}.created_at DESC")
when 'oldest' then reorder('created_at ASC') when 'oldest' then reorder("#{table_name}.created_at ASC")
when 'recently_updated' then reorder('updated_at DESC') when 'recently_updated' then reorder("#{table_name}.updated_at DESC")
when 'last_updated' then reorder('updated_at ASC') when 'last_updated' then reorder("#{table_name}.updated_at ASC")
when 'milestone_due_soon' then joins(:milestone).reorder("milestones.due_date ASC") when 'milestone_due_soon' then joins(:milestone).reorder("milestones.due_date ASC")
when 'milestone_due_later' then joins(:milestone).reorder("milestones.due_date DESC") when 'milestone_due_later' then joins(:milestone).reorder("milestones.due_date DESC")
else reorder('created_at DESC') else reorder("#{table_name}.created_at DESC")
end end
end end
end end
......
...@@ -57,11 +57,11 @@ class FilteringService ...@@ -57,11 +57,11 @@ class FilteringService
def by_scope(items) def by_scope(items)
case params[:scope] case params[:scope]
when 'created-by-me', 'authored' then when 'created-by-me', 'authored' then
klass.where(author_id: current_user.id) items.where(author_id: current_user.id)
when 'all' then when 'all' then
klass items
when 'assigned-to-me' then when 'assigned-to-me' then
klass.where(assignee_id: current_user.id) items.where(assignee_id: current_user.id)
else else
raise 'You must specify default scope' raise 'You must specify default scope'
end end
......
...@@ -8,6 +8,11 @@ describe "Dashboard Issues Feed" do ...@@ -8,6 +8,11 @@ describe "Dashboard Issues Feed" do
let!(:issue1) { create(:issue, author: user, assignee: user, project: project1) } let!(:issue1) { create(:issue, author: user, assignee: user, project: project1) }
let!(:issue2) { create(:issue, author: user, assignee: user, project: project2) } let!(:issue2) { create(:issue, author: user, assignee: user, project: project2) }
before do
project1.team << [user, :master]
project2.team << [user, :master]
end
describe "atom feed" do describe "atom feed" do
it "should render atom feed via private token" do it "should render atom feed via private token" do
visit issues_dashboard_path(:atom, private_token: user.private_token) visit issues_dashboard_path(:atom, private_token: user.private_token)
......
...@@ -15,6 +15,7 @@ describe FilteringService do ...@@ -15,6 +15,7 @@ describe FilteringService do
before do before do
project1.team << [user, :master] project1.team << [user, :master]
project2.team << [user, :developer] project2.team << [user, :developer]
project2.team << [user2, :developer]
end end
describe 'merge requests' do describe 'merge requests' do
...@@ -61,5 +62,20 @@ describe FilteringService do ...@@ -61,5 +62,20 @@ describe FilteringService do
issues = FilteringService.new.execute(Issue, user, params) issues = FilteringService.new.execute(Issue, user, params)
issues.size.should == 1 issues.size.should == 1
end end
it 'should be empty for unauthorized user' do
params = { scope: "all", state: 'opened' }
issues = FilteringService.new.execute(Issue, nil, params)
issues.size.should be_zero
end
it 'should not include unauthorized issues' do
params = { scope: "all", state: 'opened' }
issues = FilteringService.new.execute(Issue, user2, params)
issues.size.should == 2
issues.should_not include(issue1)
issues.should include(issue2)
issues.should include(issue3)
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment