Commit ebe84166 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'project-topics-projects-finder' into 'master'

ProjectsFinder: add parameter 'topic' in place of 'tag' [RUN ALL RSPEC]

See merge request gitlab-org/gitlab!62093
parents b91754b9 434b1281
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
# starred: boolean # starred: boolean
# sort: string # sort: string
# visibility_level: int # visibility_level: int
# tags: string[] # tag: string[] - deprecated, use 'topic' instead
# topic: string[]
# personal: boolean # personal: boolean
# search: string # search: string
# search_namespaces: boolean # search_namespaces: boolean
...@@ -37,6 +38,8 @@ class ProjectsFinder < UnionFinder ...@@ -37,6 +38,8 @@ class ProjectsFinder < UnionFinder
@params = params @params = params
@current_user = current_user @current_user = current_user
@project_ids_relation = project_ids_relation @project_ids_relation = project_ids_relation
@params[:topic] ||= @params.delete(:tag) if @params[:tag].present?
end end
def execute def execute
...@@ -76,7 +79,7 @@ class ProjectsFinder < UnionFinder ...@@ -76,7 +79,7 @@ class ProjectsFinder < UnionFinder
collection = by_starred(collection) collection = by_starred(collection)
collection = by_trending(collection) collection = by_trending(collection)
collection = by_visibility_level(collection) collection = by_visibility_level(collection)
collection = by_tags(collection) collection = by_topics(collection)
collection = by_search(collection) collection = by_search(collection)
collection = by_archived(collection) collection = by_archived(collection)
collection = by_custom_attributes(collection) collection = by_custom_attributes(collection)
...@@ -176,8 +179,8 @@ class ProjectsFinder < UnionFinder ...@@ -176,8 +179,8 @@ class ProjectsFinder < UnionFinder
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def by_tags(items) def by_topics(items)
params[:tag].present? ? items.tagged_with(params[:tag]) : items params[:topic].present? ? items.tagged_with(params[:topic]) : items
end end
def by_search(items) def by_search(items)
......
...@@ -25,14 +25,14 @@ ...@@ -25,14 +25,14 @@
%span.access-request-links.gl-ml-3 %span.access-request-links.gl-ml-3
= render 'shared/members/access_request_links', source: @project = render 'shared/members/access_request_links', source: @project
- if @project.tag_list.present? - if @project.topic_list.present?
= cache_if(cache_enabled, [@project, :tag_list], expires_in: 1.day) do = cache_if(cache_enabled, [@project, :topic_list], expires_in: 1.day) do
%span.home-panel-topic-list.mt-2.w-100.d-inline-flex.gl-font-base.gl-font-weight-normal.gl-align-items-center %span.home-panel-topic-list.mt-2.w-100.d-inline-flex.gl-font-base.gl-font-weight-normal.gl-align-items-center
= sprite_icon('tag', css_class: 'icon gl-relative gl-mr-2') = sprite_icon('tag', css_class: 'icon gl-relative gl-mr-2')
- @project.topics_to_show.each do |topic| - @project.topics_to_show.each do |topic|
- project_topics_classes = "badge badge-pill badge-secondary gl-mr-2" - project_topics_classes = "badge badge-pill badge-secondary gl-mr-2"
- explore_project_topic_path = explore_projects_path(tag: topic) - explore_project_topic_path = explore_projects_path(topic: topic)
- if topic.length > max_project_topic_length - if topic.length > max_project_topic_length
%a{ class: "#{ project_topics_classes } str-truncated-30 has-tooltip", data: { container: "body" }, title: topic, href: explore_project_topic_path, itemprop: 'keywords' } %a{ class: "#{ project_topics_classes } str-truncated-30 has-tooltip", data: { container: "body" }, title: topic, href: explore_project_topic_path, itemprop: 'keywords' }
= topic.titleize = topic.titleize
......
...@@ -599,6 +599,7 @@ module API ...@@ -599,6 +599,7 @@ module API
:custom_attributes, :custom_attributes,
:last_activity_after, :last_activity_after,
:last_activity_before, :last_activity_before,
:topic,
:repository_storage) :repository_storage)
.symbolize_keys .symbolize_keys
.compact .compact
...@@ -611,7 +612,6 @@ module API ...@@ -611,7 +612,6 @@ module API
finder_params[:user] = params.delete(:user) if params[:user] finder_params[:user] = params.delete(:user) if params[:user]
finder_params[:id_after] = sanitize_id_param(params[:id_after]) if params[:id_after] finder_params[:id_after] = sanitize_id_param(params[:id_after]) if params[:id_after]
finder_params[:id_before] = sanitize_id_param(params[:id_before]) if params[:id_before] finder_params[:id_before] = sanitize_id_param(params[:id_before]) if params[:id_before]
finder_params[:tag] = params[:topic] if params[:topic].present?
finder_params finder_params
end end
......
...@@ -128,23 +128,23 @@ RSpec.describe 'Project' do ...@@ -128,23 +128,23 @@ RSpec.describe 'Project' do
end end
it 'shows project topics' do it 'shows project topics' do
project.update_attribute(:tag_list, 'topic1') project.update_attribute(:topic_list, 'topic1')
visit path visit path
expect(page).to have_css('.home-panel-topic-list') expect(page).to have_css('.home-panel-topic-list')
expect(page).to have_link('Topic1', href: explore_projects_path(tag: 'topic1')) expect(page).to have_link('Topic1', href: explore_projects_path(topic: 'topic1'))
end end
it 'shows up to 3 project tags' do it 'shows up to 3 project topics' do
project.update_attribute(:tag_list, 'topic1, topic2, topic3, topic4') project.update_attribute(:topic_list, 'topic1, topic2, topic3, topic4')
visit path visit path
expect(page).to have_css('.home-panel-topic-list') expect(page).to have_css('.home-panel-topic-list')
expect(page).to have_link('Topic1', href: explore_projects_path(tag: 'topic1')) expect(page).to have_link('Topic1', href: explore_projects_path(topic: 'topic1'))
expect(page).to have_link('Topic2', href: explore_projects_path(tag: 'topic2')) expect(page).to have_link('Topic2', href: explore_projects_path(topic: 'topic2'))
expect(page).to have_link('Topic3', href: explore_projects_path(tag: 'topic3')) expect(page).to have_link('Topic3', href: explore_projects_path(topic: 'topic3'))
expect(page).to have_content('+ 1 more') expect(page).to have_content('+ 1 more')
end end
end end
......
...@@ -137,9 +137,9 @@ RSpec.describe ProjectsFinder do ...@@ -137,9 +137,9 @@ RSpec.describe ProjectsFinder do
end end
end end
describe 'filter by tags' do describe 'filter by tags (deprecated)' do
before do before do
public_project.tag_list = 'foo' public_project.topic_list = 'foo'
public_project.save! public_project.save!
end end
...@@ -148,6 +148,17 @@ RSpec.describe ProjectsFinder do ...@@ -148,6 +148,17 @@ RSpec.describe ProjectsFinder do
it { is_expected.to eq([public_project]) } it { is_expected.to eq([public_project]) }
end end
describe 'filter by topics' do
before do
public_project.topic_list = 'foo'
public_project.save!
end
let(:params) { { topic: 'foo' } }
it { is_expected.to eq([public_project]) }
end
describe 'filter by personal' do describe 'filter by personal' do
let!(:personal_project) { create(:project, namespace: user.namespace) } let!(:personal_project) { create(:project, namespace: user.namespace) }
let(:params) { { personal: true } } let(:params) { { personal: true } }
......
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