diff options
Diffstat (limited to 'app/finders/concerns/finder_methods.rb')
-rw-r--r-- | app/finders/concerns/finder_methods.rb | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/app/finders/concerns/finder_methods.rb b/app/finders/concerns/finder_methods.rb index 193b52b1694..ce6001a01d7 100644 --- a/app/finders/concerns/finder_methods.rb +++ b/app/finders/concerns/finder_methods.rb @@ -13,16 +13,23 @@ module FinderMethods end # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def find(*args) - raise_not_found_unless_authorized model.find(*args) + raise_not_found_unless_authorized execute.reorder(nil).find(*args) end + # rubocop: enable CodeReuse/ActiveRecord private def raise_not_found_unless_authorized(result) result = if_authorized(result) - raise(ActiveRecord::RecordNotFound, "Couldn't find #{model}") unless result + unless result + # This fetches the model from the `ActiveRecord::Relation` but does not + # actually execute the query. + model = execute.model + raise ActiveRecord::RecordNotFound, "Couldn't find #{model}" + end result end @@ -32,11 +39,7 @@ module FinderMethods # this is currently the case in the `MilestoneFinder` return result unless respond_to?(:current_user, true) - if can_read_object?(result) - result - else - nil - end + result if can_read_object?(result) end def can_read_object?(object) @@ -53,10 +56,4 @@ module FinderMethods # Not all objects define `#to_ability_name`, so attempt to derive it: object.model_name.singular end - - # This fetches the model from the `ActiveRecord::Relation` but does not - # actually execute the query. - def model - execute.model - end end |