From 1504c8655cdc1e45e1d28cd70c3d0df6ba1cd6da Mon Sep 17 00:00:00 2001 From: Kristian Garza Date: Mon, 1 Jul 2019 09:55:53 +0200 Subject: [PATCH 1/2] added condition to get more info in totals api help to get doi production stats for billing. drafts and and extra year needed for a projection. --- app/controllers/clients_controller.rb | 3 ++- app/controllers/concerns/facetable.rb | 4 +++- app/controllers/providers_controller.rb | 3 ++- app/models/doi.rb | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index 0ed458beb..71551621c 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -145,7 +145,8 @@ def totals page = { size: 0, number: 1} response = nil bmt = Benchmark.ms { - response = Doi.query(nil, provider_id: params[:provider_id], state: "findable,registered", page: page, totals_agg: true) + state = authenticate_user!.present? && authenticate_user!.is_admin? && params[:state].present? ? params[:state] : "registered,findable" + response = Doi.query(nil, provider_id: params[:provider_id], state: state, page: page, totals_agg: true) } if bmt > 10000 logger.warn "[Benchmark Warning] clients totals " + bmt.to_s + " ms" diff --git a/app/controllers/concerns/facetable.rb b/app/controllers/concerns/facetable.rb index e0d30615b..74a61d823 100644 --- a/app/controllers/concerns/facetable.rb +++ b/app/controllers/concerns/facetable.rb @@ -276,6 +276,7 @@ def providers_totals(arr) "this_month" => facet_anual(hsh.this_month.buckets), "this_year" => facet_anual(hsh.this_year.buckets), "last_year" => facet_anual(hsh.last_year.buckets)}, + "two_years_ago" => facet_anual(hsh.two_years_ago.buckets), "states" => facet_by_key(hsh.states.buckets) } end @@ -309,7 +310,8 @@ def clients_totals(arr) "temporal" => { "this_month" => facet_anual(hsh.this_month.buckets), "this_year" => facet_anual(hsh.this_year.buckets), - "last_year" => facet_anual(hsh.last_year.buckets) + "last_year" => facet_anual(hsh.last_year.buckets), + "two_years_ago" => facet_anual(hsh.two_years_ago.buckets) }, "states" => facet_by_key(hsh.states.buckets) } diff --git a/app/controllers/providers_controller.rb b/app/controllers/providers_controller.rb index e02d6469c..5c6eadc2b 100644 --- a/app/controllers/providers_controller.rb +++ b/app/controllers/providers_controller.rb @@ -201,7 +201,8 @@ def totals page = { size: 0, number: 1 } response = nil bmt = Benchmark.ms { - response = Doi.query(nil, state: "findable,registered", page: page, totals_agg: true) + state = authenticate_user!.present? && authenticate_user!.is_admin? && params[:state].present? ? params[:state] : "registered,findable" + response = Doi.query(nil, state: state, page: page, totals_agg: true) } if bmt > 10000 diff --git a/app/models/doi.rb b/app/models/doi.rb index 2017a6c6e..2fa32a666 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -385,7 +385,8 @@ def self.sub_aggregations states: { terms: { field: 'aasm_state', size: 4, min_doc_count: 1 } }, this_month: { date_range: { field: 'created', ranges: { from: "now/M", to: "now/d" } } }, this_year: { date_range: { field: 'created', ranges: { from: "now/y", to: "now/d" } } }, - last_year: { date_range: { field: 'created', ranges: { from: "now-1y/y", to: "now/y-1d" } } } + last_year: { date_range: { field: 'created', ranges: { from: "now-1y/y", to: "now/y-1d" } } }, + two_years_ago: { date_range: { field: 'created', ranges: { from: "now-2y/y", to: "now-1y/y-1d" } } } } end From 61134c2d68b09ac1b9b30eb04fd369f566707b70 Mon Sep 17 00:00:00 2001 From: Kristian Garza Date: Mon, 1 Jul 2019 11:35:48 +0200 Subject: [PATCH 2/2] use different methods for filtering drafts use different methods for filtering drafts --- app/controllers/clients_controller.rb | 2 +- app/controllers/providers_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index 71551621c..951439357 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -145,7 +145,7 @@ def totals page = { size: 0, number: 1} response = nil bmt = Benchmark.ms { - state = authenticate_user!.present? && authenticate_user!.is_admin? && params[:state].present? ? params[:state] : "registered,findable" + state = current_user.present? && current_user.is_admin_or_staff? && params[:state].present? ? params[:state] : "registered,findable" response = Doi.query(nil, provider_id: params[:provider_id], state: state, page: page, totals_agg: true) } if bmt > 10000 diff --git a/app/controllers/providers_controller.rb b/app/controllers/providers_controller.rb index 5c6eadc2b..ca1c9c044 100644 --- a/app/controllers/providers_controller.rb +++ b/app/controllers/providers_controller.rb @@ -201,7 +201,7 @@ def totals page = { size: 0, number: 1 } response = nil bmt = Benchmark.ms { - state = authenticate_user!.present? && authenticate_user!.is_admin? && params[:state].present? ? params[:state] : "registered,findable" + state = current_user.present? && current_user.is_admin_or_staff? && params[:state].present? ? params[:state] : "registered,findable" response = Doi.query(nil, state: state, page: page, totals_agg: true) }