Module: Aegis::PermissionFilter

Defined in:
lib/aegis/permission_filter.rb

Class Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/aegis/permission_filter.rb', line 3

def self.extended(base)
  base.instance_eval do
    def authorize_first!(current_user, options = {})
      before_filter{authorize_action(current_user,options)}
    end

    protected
      def authorize_action(current_user,options = {})
        options = {:except => []}.merge(options)
        options[:except] << "application"
        return if options[:except].include? controller_name
        permission_type = ""
        case action_name
        when "index","show"
          permission_type = Aegis::Constants::CRUD_VERBS[1]
        when "edit","update"
          permission_type = Aegis::Constants::CRUD_VERBS[2]
        when "new,","create"
          permission_type = Aegis::Constants::CRUD_VERBS[0]
        when "destroy"
          permission_type = Aegis::Constants::CRUD_VERBS[3]
        else
          permission_type = action_name
        end
        eval "#{current_user}.#{Aegis::Constants::PERMISSION_PREFIX}_#{permission_type}_#{controller_name}?"
      end
  end
end