BigW Consortium Gitlab

Commit 07250508 by Toon Claes

Change ProjectFinder so starred can be combined with other filters

The `starred` parameter couldn't be used in combination with `trending` or `non_public`. But this is changed now.
parent 8e72ad70
...@@ -31,6 +31,7 @@ class ProjectsFinder < UnionFinder ...@@ -31,6 +31,7 @@ class ProjectsFinder < UnionFinder
items = by_ids(items) items = by_ids(items)
items = union(items) items = union(items)
items = by_personal(items) items = by_personal(items)
items = by_starred(items)
items = by_visibilty_level(items) items = by_visibilty_level(items)
items = by_tags(items) items = by_tags(items)
items = by_search(items) items = by_search(items)
...@@ -45,8 +46,6 @@ class ProjectsFinder < UnionFinder ...@@ -45,8 +46,6 @@ class ProjectsFinder < UnionFinder
if params[:trending].present? if params[:trending].present?
projects << Project.trending projects << Project.trending
elsif params[:starred].present? && current_user
projects << current_user.viewable_starred_projects
else else
projects << current_user.authorized_projects if current_user projects << current_user.authorized_projects if current_user
projects << Project.unscoped.public_to_user(current_user) unless params[:non_public].present? projects << Project.unscoped.public_to_user(current_user) unless params[:non_public].present?
...@@ -67,6 +66,10 @@ class ProjectsFinder < UnionFinder ...@@ -67,6 +66,10 @@ class ProjectsFinder < UnionFinder
(params[:personal].present? && current_user) ? items.personal(current_user) : items (params[:personal].present? && current_user) ? items.personal(current_user) : items
end end
def by_starred(items)
(params[:starred].present? && current_user) ? items.starred_by(current_user) : items
end
def by_visibilty_level(items) def by_visibilty_level(items)
params[:visibility_level].present? ? items.where(visibility_level: params[:visibility_level]) : items params[:visibility_level].present? ? items.where(visibility_level: params[:visibility_level]) : items
end end
......
...@@ -146,13 +146,19 @@ describe ProjectsFinder do ...@@ -146,13 +146,19 @@ describe ProjectsFinder do
it { is_expected.to eq([private_project]) } it { is_expected.to eq([private_project]) }
end end
describe 'filter by viewable_starred_projects' do describe 'filter by starred' do
let(:params) { { starred: true } } let(:params) { { starred: true } }
before do before do
current_user.toggle_star(public_project) current_user.toggle_star(public_project)
end end
it { is_expected.to eq([public_project]) } it { is_expected.to eq([public_project]) }
it 'returns only projects the user has access to' do
current_user.toggle_star(private_project)
is_expected.to eq([public_project])
end
end end
describe 'sorting' do describe 'sorting' do
......
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