Skip to content
代码片段 群组 项目
未验证 提交 aedb0bb7 编辑于 作者: Rutger Wessels's avatar Rutger Wessels 提交者: GitLab
浏览文件

Sort projects on contributions page by most recent activity

Changelog: changed

Related issue: https://gitlab.com/gitlab-org/gitlab/-/issues/432410
上级 21406515
No related branches found
No related tags found
无相关合并请求
......@@ -224,7 +224,7 @@ def personal_projects
end
def contributed_projects
ContributedProjectsFinder.new(user).execute(current_user)
ContributedProjectsFinder.new(user).execute(current_user, order_by: 'latest_activity_desc')
end
def starred_projects
......
......@@ -15,13 +15,13 @@ def initialize(user)
# projects, regardless of their visibility to the current_user
#
# Returns an ActiveRecord::Relation.
def execute(current_user = nil, ignore_visibility: false)
def execute(current_user = nil, ignore_visibility: false, order_by: 'id_desc')
# Do not show contributed projects if the user profile is private.
return Project.none unless can_read_profile?(current_user)
segments = all_projects(current_user, ignore_visibility)
find_union(segments, Project).with_namespace.order_id_desc
find_union(segments, Project).with_namespace.sort_by_attribute(order_by)
end
private
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe ContributedProjectsFinder do
RSpec.describe ContributedProjectsFinder, feature_category: :groups_and_projects do
let(:source_user) { create(:user) }
let(:current_user) { create(:user) }
......@@ -12,14 +12,22 @@
let!(:private_project) { create(:project, :private) }
let!(:internal_project) { create(:project, :internal) }
let(:default_ordering) { [internal_project, private_project, public_project] }
before do
private_project.add_maintainer(source_user)
private_project.add_developer(current_user)
public_project.add_maintainer(source_user)
create(:push_event, project: public_project, author: source_user)
create(:push_event, project: private_project, author: source_user)
create(:push_event, project: internal_project, author: source_user)
travel_to(4.hours.from_now) { create(:push_event, project: private_project, author: source_user) }
travel_to(3.hours.from_now) { create(:push_event, project: internal_project, author: source_user) }
travel_to(2.hours.from_now) { create(:push_event, project: public_project, author: source_user) }
end
context 'when order_by is specified' do
subject { finder.execute(current_user, order_by: 'latest_activity_desc') }
it { is_expected.to eq([private_project, internal_project, public_project]) }
end
describe 'activity without a current user' do
......@@ -30,14 +38,14 @@
it 'does return all projects when visibility gets ignored' do
projects = finder.execute(ignore_visibility: true)
expect(projects).to match_array([private_project, internal_project, public_project])
expect(projects).to eq(default_ordering)
end
end
describe 'activity with a current user' do
subject { finder.execute(current_user) }
it { is_expected.to match_array([private_project, internal_project, public_project]) }
it { is_expected.to eq(default_ordering) }
end
context 'user with private profile' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册