diff options
Diffstat (limited to 'app/finders/resource_state_event_finder.rb')
-rw-r--r-- | app/finders/resource_state_event_finder.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/finders/resource_state_event_finder.rb b/app/finders/resource_state_event_finder.rb new file mode 100644 index 00000000000..7f4ac3332cd --- /dev/null +++ b/app/finders/resource_state_event_finder.rb @@ -0,0 +1,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 |