From bf164924fae43a1a4a2872284cb205021b693908 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Wed, 12 Jun 2019 09:51:05 +0200 Subject: [PATCH] exclude registration agencies from legacy API endpoints. datacite/levriero#56 --- app/controllers/data_centers_controller.rb | 8 +++++++- app/controllers/members_controller.rb | 2 +- app/models/concerns/indexable.rb | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/controllers/data_centers_controller.rb b/app/controllers/data_centers_controller.rb index 87323581e..9004c0faa 100644 --- a/app/controllers/data_centers_controller.rb +++ b/app/controllers/data_centers_controller.rb @@ -19,7 +19,13 @@ def index elsif params[:ids].present? response = Client.find_by_id(params[:ids], page: page, sort: sort) else - response = Client.query(params[:query], year: params[:year], provider_id: params[:member_id], fields: params[:fields], page: page, sort: sort) + response = Client.query(params[:query], + exclude_registration_agencies: true, + year: params[:year], + provider_id: params[:member_id], + fields: params[:fields], + page: page, + sort: sort) end begin diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index ca92338bf..b710b2270 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -18,7 +18,7 @@ def index elsif params[:ids].present? response = Provider.find_by_id(params[:ids], page: page, sort: sort) else - response = Provider.query(params[:query], year: params[:year], region: params[:region], organization_type: params[:organization_type], focus_area: params[:focus_area], fields: params[:fields], page: page, sort: sort) + response = Provider.query(params[:query], exclude_registration_agencies: true, year: params[:year], region: params[:region], organization_type: params[:organization_type], focus_area: params[:focus_area], fields: params[:fields], page: page, sort: sort) end begin diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index 3931ba7f0..d607857ca 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -165,11 +165,16 @@ def query(query, options={}) must << { term: { focus_area: options[:focus_area] }} if options[:focus_area].present? must_not << { exists: { field: "deleted_at" }} unless options[:include_deleted] - must_not << { term: { role_name: "ROLE_ADMIN" }} + if options[:exclude_registration_agencies] + must_not << { terms: { role_name: ["ROLE_ADMIN", "ROLE_REGISTRATION_AGENCY"] }} + else + must_not << { term: { role_name: "ROLE_ADMIN" }} + end elsif self.name == "Client" must << { range: { created: { gte: "#{options[:year].split(",").min}||/y", lte: "#{options[:year].split(",").max}||/y", format: "yyyy" }}} if options[:year].present? must << { terms: { "software.raw" => options[:software].split(",") }} if options[:software].present? must_not << { exists: { field: "deleted_at" }} unless options[:include_deleted] + must_not << { terms: { provider_id: ["crossref"] }} if options[:exclude_registration_agencies] elsif self.name == "Doi" must << { terms: { aasm_state: options[:state].to_s.split(",") }} if options[:state].present? must << { range: { registered: { gte: "#{options[:registered].split(",").min}||/y", lte: "#{options[:registered].split(",").max}||/y", format: "yyyy" }}} if options[:registered].present?