Commit edc18e77 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'bug/filtering' into 'master'

Bug in issue and merge request filtering

Fixes #1006
parents 6addb15b 6a87daed
......@@ -24,7 +24,8 @@ class FilteringService
@current_user = current_user
@params = params
items = by_scope
items = init_collection
items = by_scope(items)
items = by_state(items)
items = by_group(items)
items = by_project(items)
......@@ -37,20 +38,30 @@ class FilteringService
private
def by_scope
def init_collection
table_name = klass.table_name
return klass.of_projects(Project.public_only) unless current_user
if project
if current_user.can?(:read_project, project)
project.send(table_name)
else
[]
end
else
klass.of_projects(current_user.authorized_projects)
end
end
def by_scope(items)
case params[:scope]
when 'created-by-me', 'authored' then
current_user.send(table_name)
klass.where(author_id: current_user.id)
when 'all' then
if current_user
klass.of_projects(current_user.authorized_projects.pluck(:id))
else
klass.of_projects(Project.public_only)
end
klass
when 'assigned-to-me' then
current_user.send("assigned_#{table_name}")
klass.where(assignee_id: current_user.id)
else
raise 'You must specify default scope'
end
......@@ -120,4 +131,8 @@ class FilteringService
items
end
def project
Project.where(id: params[:project_id]).first if params[:project_id].present?
end
end
......@@ -62,3 +62,40 @@ Feature: Public Projects Feature
Given public empty project "Empty Public Project"
When I visit empty project page
Then I should see empty public project details
Scenario: I visit public project issues page as a non authorized user
Given I visit project "Community" page
And I visit "Community" issues page
Then I should see list of issues for "Community" project
Scenario: I visit public project issues page as authorized user
Given I sign in as a user
Given I visit project "Community" page
And I visit "Community" issues page
Then I should see list of issues for "Community" project
Scenario: I visit internal project issues page as authorized user
Given I sign in as a user
Given I visit project "Internal" page
And I visit "Internal" issues page
Then I should see list of issues for "Internal" project
Scenario: I visit public project merge requests page as an authorized user
Given I sign in as a user
Given I visit project "Community" page
And I visit "Community" merge requests page
And project "Community" has "Bug fix" open merge request
Then I should see list of merge requests for "Community" project
Scenario: I visit public project merge requests page as a non authorized user
Given I visit project "Community" page
And I visit "Community" merge requests page
And project "Community" has "Bug fix" open merge request
Then I should see list of merge requests for "Community" project
Scenario: I visit internal project merge requests page as an authorized user
Given I sign in as a user
Given I visit project "Internal" page
And I visit "Internal" merge requests page
And project "Internal" has "Feature implemented" open merge request
Then I should see list of merge requests for "Internal" project
......@@ -107,5 +107,94 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps
project = Project.find_by(name: 'Community')
page.should have_field('project_clone', with: project.url_to_repo)
end
step 'I visit "Community" issues page' do
create(:issue,
title: "Bug",
project: public_project
)
create(:issue,
title: "New feature",
project: public_project
)
visit project_issues_path(public_project)
end
step 'I should see list of issues for "Community" project' do
page.should have_content "Bug"
page.should have_content public_project.name
page.should have_content "New feature"
end
step 'I visit "Internal" issues page' do
create(:issue,
title: "Internal Bug",
project: internal_project
)
create(:issue,
title: "New internal feature",
project: internal_project
)
visit project_issues_path(internal_project)
end
step 'I should see list of issues for "Internal" project' do
page.should have_content "Internal Bug"
page.should have_content internal_project.name
page.should have_content "New internal feature"
end
step 'I visit "Community" merge requests page' do
visit project_merge_requests_path(public_project)
end
step 'project "Community" has "Bug fix" open merge request' do
create(:merge_request,
title: "Bug fix for public project",
source_project: public_project,
target_project: public_project,
)
end
step 'I should see list of merge requests for "Community" project' do
page.should have_content public_project.name
page.should have_content public_merge_request.source_project.name
end
step 'I visit "Internal" merge requests page' do
visit project_merge_requests_path(internal_project)
end
step 'project "Internal" has "Feature implemented" open merge request' do
create(:merge_request,
title: "Feature implemented",
source_project: internal_project,
target_project: internal_project
)
end
step 'I should see list of merge requests for "Internal" project' do
page.should have_content internal_project.name
page.should have_content internal_merge_request.source_project.name
end
def internal_project
@internal_project ||= Project.find_by!(name: 'Internal')
end
def public_project
@public_project ||= Project.find_by!(name: 'Community')
end
def internal_merge_request
@internal_merge_request ||= MergeRequest.find_by!(title: 'Feature implemented')
end
def public_merge_request
@public_merge_request ||= MergeRequest.find_by!(title: 'Bug fix for public project')
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