Skip to content

Commit

Permalink
Authentication guard clause in work reports controller (#6824)
Browse files Browse the repository at this point in the history
* authentication guard clause and test

* rubocop

* defining pageviews and downloads on the same line to get around clsss line limit

---------

Co-authored-by: Daniel Pierce <[email protected]>
  • Loading branch information
davidcam-src and dlpierce authored Jun 28, 2024
1 parent ee24216 commit 3083b6f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Admin
module Analytics
class WorkReportsController < AnalyticsController
include Hyrax::BreadcrumbsForWorksAnalytics
before_action :authenticate_user!

def index
return unless Hyrax.config.analytics_reporting?
Expand All @@ -14,10 +15,7 @@ def index
@top_works = paginate(top_works_list, rows: 10)
@top_file_set_downloads = paginate(top_files_list, rows: 10)

if current_user.ability.admin?
@pageviews = Hyrax::Analytics.daily_events('work-view')
@downloads = Hyrax::Analytics.daily_events('file-set-download')
end
@pageviews = Hyrax::Analytics.daily_events('work-view'), @downloads = Hyrax::Analytics.daily_events('file-set-download') if current_user.ability.admin?

respond_to do |format|
format.html
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe Hyrax::Admin::Analytics::WorkReportsController, type: :controller do
routes { Hyrax::Engine.routes }
describe 'GET #index' do
context 'when user is not logged in' do
it 'redirects to the login page' do
get :index
expect(response).to be_redirect
expect(flash[:alert]).to eq("You need to sign in or sign up before continuing.")
end
end
end
end

0 comments on commit 3083b6f

Please sign in to comment.