Skip to content

Restrict access to admin stats by constraint in Sufia

Hui Zhang edited this page Oct 12, 2015 · 5 revisions

In config/initializer/stats_admin.rb, use constraint to make sure only accessible to user in certain group

Sufia::StatsAdmin def self.matches?(request) current_user = request.env['warden'].user return false if current_user.blank? current_user.groups.include? 'umg/up.dlt.scholarsphere-admin-viewers' end end

the route to Sufia:StatsAdmin is defined in config/routes.rb,

if defined?(Sufia::StatsAdmin) namespace :admin do constraints Sufia::StatsAdmin do get 'stats' => 'stats#index', as: :stats end end end

  • check the existence of Sufia::StatsAdmin
  • routing /admin based on Sufia:StatsAdmin