basic admin policy start

This commit is contained in:
Mark Moser
2016-09-19 16:40:56 -05:00
parent 0a69eb578e
commit 12c7e9e77c
7 changed files with 64 additions and 0 deletions

View File

@ -1,9 +1,13 @@
# frozen_string_literal: true
class AdminController < ApplicationController
include Pundit
layout 'admin'
before_action :authorize_user
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
def dashboard
authorize :admin, :dashboard?
@quizzes = Quiz.includes(:questions).all
@users = User.order(:role, :name)
end
@ -18,4 +22,9 @@ class AdminController < ApplicationController
def authorize_user
redirect_to admin_login_path unless current_user
end
def user_not_authorized
flash[:error] = "You are not authorized to perform this action."
redirect_to(request.referer || root_path)
end
end