rosa-build/app/controllers/roles_controller.rb

73 lines
1.6 KiB
Ruby
Raw Normal View History

2011-10-18 19:31:59 +01:00
class RolesController < ApplicationController
2011-10-24 14:01:15 +01:00
before_filter :authenticate_user!
2011-10-18 19:31:59 +01:00
before_filter :find_role, :only => [:show, :edit, :update, :destroy]
2011-10-23 22:39:44 +01:00
before_filter :find_visibilities, :only => [:new, :edit]
2011-10-18 19:31:59 +01:00
def index
@roles = Role.all
end
def show
end
def new
@role = Role.new
end
def edit
end
def create
@role = Role.new(params[:role])
if @role.save
for right in params[:right][:id]
Permission.create(:role_id => @role.id, :right_id => right)
end
flash[:notice] = t('flash.role.saved')
redirect_to roles_path
else
flash[:error] = t('flash.role.save_error')
render :action => :new
end
end
def update
2011-10-23 22:39:44 +01:00
puts params[:inspect]
2011-10-18 19:31:59 +01:00
if @role.update_attributes(params[:role])
2011-10-23 22:39:44 +01:00
if params[:rights] and params[:rights][:id]
@role.rights = Right.find(params[:rights][:id])
2011-10-18 19:31:59 +01:00
end
flash[:notice] = t('flash.role.saved')
redirect_to roles_path
else
flash[:error] = t('flash.role.save_error')
render :action => :edit
end
end
def destroy
@role.destroy
Permission.destroy_all(:role_id => params[:id])
flash[:notice] = t("flash.role.destroyed")
redirect_to roles_path
end
protected
def find_role
@role = Role.find(params[:id])
end
2011-10-23 22:39:44 +01:00
def find_visibilities
@visibilities = ActiveRecord::Base.descendants.inject({}) do |h, m|
if m.public_instance_methods.include? 'visibility'
begin
h[m.name] = m::VISIBILITIES
rescue
nil
end
end
h
end
end
end