Module: SimplePermissions::UserModelMethods

Defined in:
lib/user_model.rb

Instance Method Summary collapse

Instance Method Details

#has_permission_read_write(permission_code, read_write) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/user_model.rb', line 23

def has_permission_read_write(permission_code, read_write)
  profile_permissions = self.send SimplePermissions::Config.permissions_method

  profile_permissions.each do |per_code, per_read_write|
    if permission_code.to_s == per_code.to_s
      if read_write.to_s == 'w'
        if per_read_write.to_s == 'w'
          return true
        end
      else
        return true
      end
    end
  end
  return false
end

#has_permission_read_write!(permission_code, read_write) ⇒ Object



19
20
21
# File 'lib/user_model.rb', line 19

def has_permission_read_write!(permission_code, read_write)
  raise SimplePermissions::AccessDeniedException if !self.has_permission_read_write(permission_code, read_write)
end

#has_permission_role(permission_code) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/user_model.rb', line 8

def has_permission_role(permission_code)
  profile_permissions = self.send SimplePermissions::Config.permissions_method
  
  profile_permissions.each do |per_code|
    if permission_code.to_s == per_code.to_s
      return true
    end
  end
  return false
end

#has_permission_role!(permission_code) ⇒ Object



4
5
6
# File 'lib/user_model.rb', line 4

def has_permission_role!(permission_code)
  raise SimplePermissions::AccessDeniedException if !self.has_permission_role(permission_code)
end