Class: DefaultPermissionSet

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Joinable::PermissionsAttributeWrapper
Defined in:
app/models/default_permission_set.rb

Instance Method Summary collapse

Methods included from Joinable::PermissionsAttributeWrapper

#allowed_permissions, #doesnt_have_permission?, #grant_permissions, #has_permission?, included, #method_missing, #no_permissions?, #only_permission_to?, #permission_attributes=, #permissions, #permissions=, #permissions_string, #respond_to?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Joinable::PermissionsAttributeWrapper

Instance Method Details

#access_modelObject



9
10
11
12
13
14
15
16
17
# File 'app/models/default_permission_set.rb', line 9

def access_model
  if has_permission?(:view)
    return 'open'
  elsif has_permission?(:find)
    return 'closed'
  else
    return 'private'
  end
end

#access_model=(model) ⇒ Object

Easy way to choose basic permission sets



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/default_permission_set.rb', line 20

def access_model=(model)
  case model.to_s
  when 'open'
    # Additional permissions are set explicitly so just grant the find and view permissions
    self.grant_permissions([:find, :view])
  when 'closed'
    self.permissions = [:find]
  when 'private'
    self.permissions = []
  else
    raise "Access model invalid: #{model}"
  end
end