debian-mirror-gitlab/app/finders/resource_state_event_finder.rb

31 lines
624 B
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
class ResourceStateEventFinder
include FinderMethods
def initialize(current_user, eventable)
@current_user = current_user
@eventable = eventable
end
def execute
return ResourceStateEvent.none unless can_read_eventable?
eventable.resource_state_events.includes(:user) # rubocop: disable CodeReuse/ActiveRecord
end
def can_read_eventable?
return unless eventable
Ability.allowed?(current_user, read_ability, eventable)
end
private
attr_reader :current_user, :eventable
def read_ability
:"read_#{eventable.class.to_ability_name}"
end
end