Module: SimplePermissionsHelper

Included in:
SimplePermissions::ControllerMethods
Defined in:
lib/helpers.rb

Instance Method Summary collapse

Instance Method Details

#has_permission(p_permissions) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/helpers.rb', line 7

def has_permission(p_permissions)
  logged_user = self.send SimplePermissions::Config.current_user_method
has_access = false

if (p_permissions.class == String)
  permissions = [p_permissions]
 else
   permissions = p_permissions
  end

if SimplePermissions::Config.permission_type == :read_write
    permissions.each do |permission, read_write|
      if logged_user.has_permission_read_write(permission, read_write)
        has_access = true
      end
    end
  elsif SimplePermissions::Config.permission_type == :role
    permissions.each do |permission|
      if logged_user.has_permission_role(permission)
        has_access = true
      end
    end
  end
  
return has_access
end

#has_permission!(permissions) ⇒ Object



3
4
5
# File 'lib/helpers.rb', line 3

def has_permission!(permissions)
  raise SimplePermissions::AccessDeniedException if !self.has_permission(permissions)
end