diff options
-rw-r--r-- | app/services/filtering_service.rb | 33 | ||||
-rw-r--r-- | features/public/public_projects.feature | 37 | ||||
-rw-r--r-- | features/steps/public/projects_feature.rb | 89 |
3 files changed, 150 insertions, 9 deletions
diff --git a/app/services/filtering_service.rb b/app/services/filtering_service.rb index b339065890b..ebd394ee758 100644 --- a/app/services/filtering_service.rb +++ b/app/services/filtering_service.rb @@ -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 diff --git a/features/public/public_projects.feature b/features/public/public_projects.feature index d6574ca900e..57fe834b4bf 100644 --- a/features/public/public_projects.feature +++ b/features/public/public_projects.feature @@ -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 diff --git a/features/steps/public/projects_feature.rb b/features/steps/public/projects_feature.rb index c3ec10b87d3..84a5ebbf7a7 100644 --- a/features/steps/public/projects_feature.rb +++ b/features/steps/public/projects_feature.rb @@ -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 |