Commit c85591e6 authored by Jarka Košanová's avatar Jarka Košanová Committed by Mayra Cabrera

Display epic related events on user activity feed

- change the query
- add specs for issues & epics erlated queries
parent f192d901
......@@ -26,42 +26,23 @@ class UserRecentEventsFinder
@params = params
end
# rubocop: disable CodeReuse/ActiveRecord
def execute
return Event.none unless can?(current_user, :read_user_profile, target_user)
recent_events(params[:offset] || 0)
.joins(:project)
target_events
.with_associations
.limit_recent(limit, params[:offset])
.order_created_desc
end
# rubocop: enable CodeReuse/ActiveRecord
private
# rubocop: disable CodeReuse/ActiveRecord
def recent_events(offset)
sql = <<~SQL
(#{projects}) AS projects_for_join
JOIN (#{target_events.to_sql}) AS #{Event.table_name}
ON #{Event.table_name}.project_id = projects_for_join.id
SQL
# Workaround for https://github.com/rails/rails/issues/24193
Event.from([Arel.sql(sql)])
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def target_events
Event.where(author: target_user)
end
# rubocop: enable CodeReuse/ActiveRecord
def projects
target_user.project_interactions.to_sql
end
def limit
return DEFAULT_LIMIT unless params[:limit].present?
......
---
title: Display epic related events on user activity feed
merge_request: 52611
author:
type: added
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe UserRecentEventsFinder do
describe '#execute' do
let_it_be(:current_user) { create(:user) }
let_it_be(:user) { create(:user) }
let_it_be(:epic) { create(:epic) }
let_it_be(:private_epic) { create(:epic, group: create(:group, :private)) }
let_it_be(:note) { create(:note_on_epic, noteable: epic) }
let_it_be(:public_event) { create(:event, :commented, target: note, author: user, project: nil) }
let_it_be(:private_event) { create(:event, :closed, target: private_epic, author: user, project: nil) }
subject { described_class.new(current_user, user, {}).execute }
context 'epic related activities' do
context 'when profile is public' do
it { is_expected.to match_array([public_event, private_event]) }
end
context 'when profile is private' do
before do
allow(Ability).to receive(:allowed?).and_call_original
allow(Ability).to receive(:allowed?).with(current_user, :read_user_profile, user).and_return(false)
end
it { is_expected.to be_empty }
end
end
end
end
......@@ -51,6 +51,20 @@ RSpec.describe UserRecentEventsFinder do
end
end
describe 'issue activity events' do
let(:issue) { create(:issue, project: public_project) }
let(:note) { create(:note_on_issue, noteable: issue, project: public_project) }
let!(:event_a) { create(:event, :commented, target: note, author: project_owner) }
let!(:event_b) { create(:event, :closed, target: issue, author: project_owner) }
it 'includes all issue related events', :aggregate_failures do
events = finder.execute
expect(events).to include(event_a)
expect(events).to include(event_b)
end
end
context 'limits' do
before do
stub_const("#{described_class}::DEFAULT_LIMIT", 1)
......
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