Changeset 233

Show
Ignore:
Timestamp:
01/17/06 03:36:10 (3 years ago)
Author:
tomafro
Message:

Adds permissions to a role for given method group

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • user_engine/trunk/lib/user_engine.rb

    r193 r233  
    107107  end 
    108108 
     109  def self.add_permissions_to_role(role, controller, *groups) 
     110    role = Role.find_or_create_by_name(role.to_s) unless role.is_a? Role 
     111    groups.each do |group|  
     112      controller.action_group.send(group).each do |action| 
     113        unless role.permissions.find_by_controller_and_action(controller.controller_name, action.to_s) 
     114          role.permissions << Permission.find_or_create_by_controller_and_action(controller.controller_name, action.to_s) 
     115        end 
     116      end 
     117    end 
     118  end 
     119 
    109120  #-- 
    110121  # The methods to be included in both ApplicationController and ApplicationHelper