diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-16 00:08:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-16 00:08:59 +0300 |
commit | 367e7db836dd84ee39adcca18d973c1d530088aa (patch) | |
tree | ade004c21cda52721546ad67de82455b6fbe1618 /app/finders | |
parent | fb994e98ecce2a1f1dfaa87c9c3de8535815813b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/user_recent_events_finder.rb | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/app/finders/user_recent_events_finder.rb b/app/finders/user_recent_events_finder.rb index c9a1c918365..596a413782e 100644 --- a/app/finders/user_recent_events_finder.rb +++ b/app/finders/user_recent_events_finder.rb @@ -15,27 +15,49 @@ class UserRecentEventsFinder requires_cross_project_access - attr_reader :current_user, :target_user, :params + attr_reader :current_user, :target_user, :params, :event_filter DEFAULT_LIMIT = 20 MAX_LIMIT = 100 - def initialize(current_user, target_user, params = {}) + def initialize(current_user, target_user, event_filter, params = {}) @current_user = current_user @target_user = target_user @params = params + @event_filter = event_filter || EventFilter.new(EventFilter::ALL) end def execute + if target_user.is_a? User + execute_single + else + execute_multi + end + end + + private + + def execute_single return Event.none unless can?(current_user, :read_user_profile, target_user) - target_events + event_filter.apply_filter(target_events .with_associations .limit_recent(limit, params[:offset]) - .order_created_desc + .order_created_desc) end - private + # rubocop: disable CodeReuse/ActiveRecord + def execute_multi + users = [] + @target_user.each do |user| + users.append(user.id) if can?(current_user, :read_user_profile, user) + end + + return Event.none if users.empty? + + event_filter.apply_filter(Event.where(author: users).limit_recent(limit, params[:offset] || 0)) + end + # rubocop: enable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord def target_events |