From ded5efad1ffddb5f1bf8585802bb25e588eee6ea Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Fri, 15 Apr 2016 21:35:48 -0500 Subject: Allow filtering by Owned projects --- app/controllers/concerns/filter_projects.rb | 5 +++++ app/views/shared/projects/_dropdown.html.haml | 10 +++++++++- features/dashboard/dashboard.feature | 5 +++++ features/steps/shared/issuable.rb | 14 ++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/app/controllers/concerns/filter_projects.rb b/app/controllers/concerns/filter_projects.rb index f63b703d101..091412a7c93 100644 --- a/app/controllers/concerns/filter_projects.rb +++ b/app/controllers/concerns/filter_projects.rb @@ -10,6 +10,11 @@ module FilterProjects def filter_projects(projects) projects = projects.search(params[:filter_projects]) if params[:filter_projects].present? projects = projects.non_archived if params[:archived].blank? + + if params[:personal].present? and current_user + projects = projects.personal(current_user) + end + projects end end diff --git a/app/views/shared/projects/_dropdown.html.haml b/app/views/shared/projects/_dropdown.html.haml index e7e04621ff4..681d182daee 100644 --- a/app/views/shared/projects/_dropdown.html.haml +++ b/app/views/shared/projects/_dropdown.html.haml @@ -1,4 +1,5 @@ - @sort ||= sort_value_recently_updated +- personal = params[:personal] - archived = params[:archived] .dropdown.inline %button.dropdown-toggle.btn{type: 'button', 'data-toggle' => 'dropdown'} @@ -10,7 +11,7 @@ Sort by - projects_sort_options_hash.each do |value, title| %li - = link_to filter_projects_path(sort: value, archived: archived), class: ("is-active" if @sort == value) do + = link_to filter_projects_path(sort: value, archived: archived, personal: personal), class: ("is-active" if @sort == value) do = title %li.divider @@ -20,3 +21,10 @@ %li = link_to filter_projects_path(sort: @sort, archived: true), class: ("is-active" if params[:archived].present?) do Show archived projects + %li.divider + %li + = link_to filter_projects_path(sort: @sort, personal: nil), class: ("is-active" unless personal) do + Owned by anyone + %li + = link_to filter_projects_path(sort: @sort, personal: true), class: ("is-active" if personal) do + Owned by me diff --git a/features/dashboard/dashboard.feature b/features/dashboard/dashboard.feature index db73309804c..c88cd0c9c22 100644 --- a/features/dashboard/dashboard.feature +++ b/features/dashboard/dashboard.feature @@ -79,3 +79,8 @@ Feature: Dashboard And I sort the list by "Oldest updated" And I visit project "Shop" merge requests page Then The list should be sorted by "Oldest updated" + + @javascript @focus + Scenario: Sort owned Projects + Then I filter the list by "Owned by me" + Then The list should be filtered by "Owned by me" diff --git a/features/steps/shared/issuable.rb b/features/steps/shared/issuable.rb index a58b3cb7e16..c09be48080c 100644 --- a/features/steps/shared/issuable.rb +++ b/features/steps/shared/issuable.rb @@ -138,6 +138,20 @@ module SharedIssuable end end + step 'I filter the list by "Owned by me"' do + find('button.dropdown-toggle.btn').click + + page.within('ul.dropdown-menu.dropdown-menu-align-right') do + click_link "Owned by me" + end + end + + step 'The list should be filtered by "Owned by me"' do + page.within('ul.dropdown-menu.dropdown-menu-align-right') do + expect(page).to have_selector('a', text: 'Owned by me') + end + end + step 'I should see "1 of 1" in the sidebar' do expect_sidebar_content('1 of 1') end -- cgit v1.2.1 From 9bd29a772604d9ea9aa7f9a5e6d4482e6fc81d6b Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Mon, 18 Apr 2016 19:53:49 -0500 Subject: Remove Spinach feature --- features/dashboard/dashboard.feature | 5 ----- features/steps/shared/issuable.rb | 14 -------------- 2 files changed, 19 deletions(-) diff --git a/features/dashboard/dashboard.feature b/features/dashboard/dashboard.feature index c88cd0c9c22..db73309804c 100644 --- a/features/dashboard/dashboard.feature +++ b/features/dashboard/dashboard.feature @@ -79,8 +79,3 @@ Feature: Dashboard And I sort the list by "Oldest updated" And I visit project "Shop" merge requests page Then The list should be sorted by "Oldest updated" - - @javascript @focus - Scenario: Sort owned Projects - Then I filter the list by "Owned by me" - Then The list should be filtered by "Owned by me" diff --git a/features/steps/shared/issuable.rb b/features/steps/shared/issuable.rb index c09be48080c..a58b3cb7e16 100644 --- a/features/steps/shared/issuable.rb +++ b/features/steps/shared/issuable.rb @@ -138,20 +138,6 @@ module SharedIssuable end end - step 'I filter the list by "Owned by me"' do - find('button.dropdown-toggle.btn').click - - page.within('ul.dropdown-menu.dropdown-menu-align-right') do - click_link "Owned by me" - end - end - - step 'The list should be filtered by "Owned by me"' do - page.within('ul.dropdown-menu.dropdown-menu-align-right') do - expect(page).to have_selector('a', text: 'Owned by me') - end - end - step 'I should see "1 of 1" in the sidebar' do expect_sidebar_content('1 of 1') end -- cgit v1.2.1 From c0ce49861510e73194760a4251858437abaedc03 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Mon, 18 Apr 2016 19:54:53 -0500 Subject: Add tests --- spec/features/dashboard_filter_spec.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 spec/features/dashboard_filter_spec.rb diff --git a/spec/features/dashboard_filter_spec.rb b/spec/features/dashboard_filter_spec.rb new file mode 100644 index 00000000000..3d20813161a --- /dev/null +++ b/spec/features/dashboard_filter_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe "Dashboard projects filters", feature: true, js: true do + + context 'filtering personal projects' do + before do + user = create(:user) + project = create(:project, name: "Victorialand", namespace: user.namespace) + project.team << [user, :master] + + login_as(user) + visit dashboard_projects_path + + open_filter_dropdown + click_link "Owned by me" + end + + it 'filters by projects "Owned by me"' do + sleep 1 + open_filter_dropdown + page.within('ul.dropdown-menu.dropdown-menu-align-right') do + expect(page).to have_css('.is-active', text: 'Owned by me') + end + end + end + + def open_filter_dropdown + find('button.dropdown-toggle.btn').click + end +end -- cgit v1.2.1 From 3f574c4db958f2d1ea4d6475cb027dc005fbae87 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Thu, 21 Apr 2016 16:02:00 -0500 Subject: Use compact syntax --- app/controllers/concerns/filter_projects.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/controllers/concerns/filter_projects.rb b/app/controllers/concerns/filter_projects.rb index 091412a7c93..586f97c5eb4 100644 --- a/app/controllers/concerns/filter_projects.rb +++ b/app/controllers/concerns/filter_projects.rb @@ -10,10 +10,7 @@ module FilterProjects def filter_projects(projects) projects = projects.search(params[:filter_projects]) if params[:filter_projects].present? projects = projects.non_archived if params[:archived].blank? - - if params[:personal].present? and current_user - projects = projects.personal(current_user) - end + projects = projects.personal(current_user) if params[:personal].present? && current_user projects end -- cgit v1.2.1 From 41cee8c38e61d3f00e1c79b2d170d6fc5f8bea0e Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Thu, 21 Apr 2016 16:03:14 -0500 Subject: Do not display filters if user if there's no current_user --- app/views/shared/projects/_dropdown.html.haml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/views/shared/projects/_dropdown.html.haml b/app/views/shared/projects/_dropdown.html.haml index 681d182daee..1169bed0382 100644 --- a/app/views/shared/projects/_dropdown.html.haml +++ b/app/views/shared/projects/_dropdown.html.haml @@ -21,10 +21,11 @@ %li = link_to filter_projects_path(sort: @sort, archived: true), class: ("is-active" if params[:archived].present?) do Show archived projects - %li.divider - %li - = link_to filter_projects_path(sort: @sort, personal: nil), class: ("is-active" unless personal) do - Owned by anyone - %li - = link_to filter_projects_path(sort: @sort, personal: true), class: ("is-active" if personal) do - Owned by me + - if current_user + %li.divider + %li + = link_to filter_projects_path(sort: @sort, personal: nil), class: ("is-active" unless personal) do + Owned by anyone + %li + = link_to filter_projects_path(sort: @sort, personal: true), class: ("is-active" if personal) do + Owned by me -- cgit v1.2.1 From 80ae3790b456b12314243c75632ed6024ac16424 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Thu, 21 Apr 2016 16:03:21 -0500 Subject: Update CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 290c9568149..669a26bf042 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -86,6 +86,7 @@ v 8.7.0 (unreleased) - Updated print style for issues - Use GitHub Issue/PR number as iid to keep references - Import GitHub labels + - Add option to filter by "Owned projects" on dashboard page v 8.6.6 - Expire the exists cache before deletion to ensure project dir actually exists (Stan Hu). !3413 -- cgit v1.2.1