Do not extend query for scope

pull/5054/head
Oliver Günther 8 years ago
parent 528fce0e21
commit 65ca248914
No known key found for this signature in database
GPG Key ID: 88872239EB414F99
  1. 6
      app/models/queries/base_query.rb
  2. 9
      app/services/api/v3/params_to_query_service.rb
  3. 3
      lib/api/v3/work_packages/watchers_api.rb

@ -38,8 +38,6 @@ class Queries::BaseQuery
validate :filters_valid, validate :filters_valid,
:sortation_valid :sortation_valid
attr_accessor :scope
def initialize def initialize
@scope = self.class.default_scope @scope = self.class.default_scope
@filters = [] @filters = []
@ -85,7 +83,9 @@ class Queries::BaseQuery
protected protected
attr_accessor :filters, :orders attr_accessor :scope,
:filters,
:orders
def filters_valid def filters_valid
filters.each do |filter| filters.each do |filter|

@ -29,20 +29,15 @@
module API module API
module V3 module V3
class ParamsToQueryService class ParamsToQueryService
attr_accessor :model, :scope attr_accessor :model
def initialize(model, scope: nil) def initialize(model)
self.model = model self.model = model
self.scope = scope
end end
def call(params) def call(params)
query = new_query query = new_query
unless scope.nil?
query.scope = scope
end
query = apply_filters(query, params) query = apply_filters(query, params)
query = apply_order(query, params) query = apply_order(query, params)

@ -40,11 +40,10 @@ module API
authorize(:add_work_package_watchers, context: @work_package.project) authorize(:add_work_package_watchers, context: @work_package.project)
service = ::API::V3::ParamsToQueryService.new(User) service = ::API::V3::ParamsToQueryService.new(User)
service.scope = @work_package.addable_watcher_users
query = service.call(params) query = service.call(params)
if query.valid? if query.valid?
users = query.results.includes(:preference) users = query.results.merge(@work_package.addable_watcher_users).includes(:preference)
::API::V3::Users::PaginatedUserCollectionRepresenter.new( ::API::V3::Users::PaginatedUserCollectionRepresenter.new(
users, users,
api_v3_paths.users, api_v3_paths.users,

Loading…
Cancel
Save