From cfb2d7a61d1c29da08d9dd000d7d9039fe2af54e Mon Sep 17 00:00:00 2001 From: f Date: Fri, 8 Oct 2021 18:33:31 -0300 Subject: [PATCH] todas las peticiones necesitan une usuarie --- app/controllers/stats_controller.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 8d1575bd..0c185329 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -4,6 +4,7 @@ class StatsController < ApplicationController include Pundit before_action :authenticate_usuarie! + before_action :authorize_stats INTERVALS = %i[hour day week month].freeze @@ -14,9 +15,6 @@ class StatsController < ApplicationController end def index - @site = find_site - authorize SiteStat.new(@site) - @chart_params = { interval: interval } hostnames last_stat @@ -24,8 +22,6 @@ class StatsController < ApplicationController # Genera un gráfico de visitas por dominio asociado a este sitio def host - @site = find_site - authorize SiteStat.new(@site) @stats = Rollup.where_dimensions(host: hostnames).multi_series('host', interval: interval).tap do |series| series.each do |serie| @@ -45,6 +41,11 @@ class StatsController < ApplicationController @last_stat ||= Stat.last end + def authorize_stats + @site = find_site + authorize SiteStat.new(@site) + end + # TODO: Eliminar cuando mergeemos referer-origin def hostnames @hostnames ||= [@site.hostname, @site.alternative_hostnames].flatten