Add cancancan to admins
This commit is contained in:
parent
ef5abb6324
commit
26f66f8bff
4 changed files with 10 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
||||||
require 'csv'
|
require 'csv'
|
||||||
class AdminsController < ApplicationController
|
class AdminsController < ApplicationController
|
||||||
|
|
||||||
def schulden
|
def schulden
|
||||||
|
authorize! :schulden, :admins
|
||||||
@users = User.all
|
@users = User.all
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.csv do
|
format.csv do
|
||||||
|
|
|
@ -4,6 +4,11 @@ class ApplicationController < ActionController::Base
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
before_action :configure_permitted_parameters, if: :devise_controller?
|
before_action :configure_permitted_parameters, if: :devise_controller?
|
||||||
|
|
||||||
|
rescue_from CanCan::AccessDenied do |exception|
|
||||||
|
flash[:error] = exception.message
|
||||||
|
redirect_to root_path
|
||||||
|
end
|
||||||
|
|
||||||
def after_sign_in_path_for(resource)
|
def after_sign_in_path_for(resource)
|
||||||
root_path
|
root_path
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,7 @@ class Ability
|
||||||
user ||= User.new # guest user (not logged in)
|
user ||= User.new # guest user (not logged in)
|
||||||
if user.admin?
|
if user.admin?
|
||||||
can :manage, :all
|
can :manage, :all
|
||||||
|
can :schulden, :admins
|
||||||
else
|
else
|
||||||
can :read, :all
|
can :read, :all
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
<h2>Sign in</h2>
|
<h2>Sign in</h2>
|
||||||
|
<%= render partial: 'flash' %>
|
||||||
|
|
||||||
<div class="sign-in">
|
<div class="sign-in">
|
||||||
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
|
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue