class UserController < ApplicationController

  def list_perms
    @users = User.find(:all, :order => "login")
    @roles = Role.find(:all, :order => "name") 
  end

  def update_perms
    Permission.transaction do
      Permission.delete_all
      for user in User.find(:all)
        for role in Role.find(:all)
          if params[:perm]["#{user.id}-#{role.id}"] == "on" 
            Permission.create(:user_id => user.id, :role_id => role.id)
          end     
        end     
      end     
    end
    flash[:notice] = "Zaktualizowano uprawnienia."
    redirect_to :action => "list_perms"
  end
end