diff --git a/app/assets/javascripts/statistics_graphs.js b/app/assets/javascripts/statistics_graphs.js index 3dbf79b8..506e3432 100644 --- a/app/assets/javascripts/statistics_graphs.js +++ b/app/assets/javascripts/statistics_graphs.js @@ -60,7 +60,7 @@ $(document).ready(function () { if (! ($.isController('statistics') && $('#user-activity').isPresent())) { clearInterval(refreshInterval); } else { - var jqxhr = $.ajax({ + var jqxhr = $.ajax('graphs/user-activity', { dataType: 'json', method: 'GET' }); diff --git a/app/controllers/statistics_controller.rb b/app/controllers/statistics_controller.rb index 448fa1d8..a2e4baec 100644 --- a/app/controllers/statistics_controller.rb +++ b/app/controllers/statistics_controller.rb @@ -1,12 +1,13 @@ class StatisticsController < ApplicationController include StatisticsHelper + before_action :authorize!, only: [:graphs, :user_activity, :rfc_activity] + def policy_class StatisticsPolicy end def show - authorize self respond_to do |format| format.html format.json { render(json: statistics_data) } @@ -14,11 +15,23 @@ class StatisticsController < ApplicationController end def graphs - authorize self + end + + def user_activity respond_to do |format| - format.html - format.json { render(json: graph_live_data) } + format.json { render(json: user_activity_live_data) } end end + def rfc_activity + respond_to do |format| + format.json { render(json: rfc_activity_live_data) } + end + end + + def authorize! + authorize self + end + private :authorize! + end diff --git a/app/helpers/statistics_helper.rb b/app/helpers/statistics_helper.rb index a740f3a0..581a2b19 100644 --- a/app/helpers/statistics_helper.rb +++ b/app/helpers/statistics_helper.rb @@ -122,7 +122,7 @@ module StatisticsHelper ] end - def graph_live_data + def user_activity_live_data [ { key: 'active_in_last_hour', @@ -140,4 +140,8 @@ module StatisticsHelper ] end + def rfc_activity_live_data + [] + end + end diff --git a/app/policies/statistics_policy.rb b/app/policies/statistics_policy.rb index 2cfdc301..9486c79a 100644 --- a/app/policies/statistics_policy.rb +++ b/app/policies/statistics_policy.rb @@ -4,4 +4,12 @@ class StatisticsPolicy < AdminOnlyPolicy admin? end + def user_activity? + admin? + end + + def rfc_activity? + admin? + end + end diff --git a/config/routes.rb b/config/routes.rb index 4da4a0ed..499120ec 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -44,6 +44,8 @@ Rails.application.routes.draw do get 'statistics/', to: 'statistics#show' get 'statistics/graphs', to: 'statistics#graphs' + get 'statistics/graphs/user-activity', to: 'statistics#user_activity' + get 'statistics/graphs/rfc-activity', to: 'statistics#rfc_activity' concern :statistics do member do