From 65ca2489144310eb5113bfa5eae2dfd3c22c7daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 16 Nov 2016 08:09:20 +0100 Subject: [PATCH] Do not extend query for scope --- app/models/queries/base_query.rb | 6 +++--- app/services/api/v3/params_to_query_service.rb | 9 ++------- lib/api/v3/work_packages/watchers_api.rb | 3 +-- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/app/models/queries/base_query.rb b/app/models/queries/base_query.rb index 398426d29e..ead68a5929 100644 --- a/app/models/queries/base_query.rb +++ b/app/models/queries/base_query.rb @@ -38,8 +38,6 @@ class Queries::BaseQuery validate :filters_valid, :sortation_valid - attr_accessor :scope - def initialize @scope = self.class.default_scope @filters = [] @@ -85,7 +83,9 @@ class Queries::BaseQuery protected - attr_accessor :filters, :orders + attr_accessor :scope, + :filters, + :orders def filters_valid filters.each do |filter| diff --git a/app/services/api/v3/params_to_query_service.rb b/app/services/api/v3/params_to_query_service.rb index f6e6d74efa..3c780e8e45 100644 --- a/app/services/api/v3/params_to_query_service.rb +++ b/app/services/api/v3/params_to_query_service.rb @@ -29,20 +29,15 @@ module API module V3 class ParamsToQueryService - attr_accessor :model, :scope + attr_accessor :model - def initialize(model, scope: nil) + def initialize(model) self.model = model - self.scope = scope end def call(params) query = new_query - unless scope.nil? - query.scope = scope - end - query = apply_filters(query, params) query = apply_order(query, params) diff --git a/lib/api/v3/work_packages/watchers_api.rb b/lib/api/v3/work_packages/watchers_api.rb index a67950b7f3..3ef89cf067 100644 --- a/lib/api/v3/work_packages/watchers_api.rb +++ b/lib/api/v3/work_packages/watchers_api.rb @@ -40,11 +40,10 @@ module API authorize(:add_work_package_watchers, context: @work_package.project) service = ::API::V3::ParamsToQueryService.new(User) - service.scope = @work_package.addable_watcher_users query = service.call(params) if query.valid? - users = query.results.includes(:preference) + users = query.results.merge(@work_package.addable_watcher_users).includes(:preference) ::API::V3::Users::PaginatedUserCollectionRepresenter.new( users, api_v3_paths.users,