Module: FatFreeCRM::Permissions::InstanceMethods

Defined in:
lib/fat_free_crm/permissions.rb

Instance Method Summary collapse

Instance Method Details

#access=(value) ⇒ Object

Remove all shared permissions if no longer shared




62
63
64
65
# File 'lib/fat_free_crm/permissions.rb', line 62

def access=(value)
  remove_permissions unless value == 'Shared'
  super(value)
end

#remove_permissionsObject

Removes all permissions on an object




69
70
71
72
73
74
75
76
77
78
# File 'lib/fat_free_crm/permissions.rb', line 69

def remove_permissions
  # we don't use dependent => :destroy so must manually remove
  if id && self.class
    permissions_to_remove = Permission.where(asset_id: id, asset_type: self.class.to_s).to_a
  else
    permissions_to_remove = []
  end

  permissions_to_remove.each { |p| (permissions.delete(p); p.destroy) }
end

#save_with_model_permissions(model) ⇒ Object

Save the model copying other model’s permissions.




96
97
98
99
100
101
# File 'lib/fat_free_crm/permissions.rb', line 96

def save_with_model_permissions(model)
  self.access    = model.access
  self.user_ids  = model.user_ids
  self.group_ids = model.group_ids
  save
end

#save_with_permissions(_users = nil) ⇒ Object

Save the model along with its permissions if any.




82
83
84
85
# File 'lib/fat_free_crm/permissions.rb', line 82

def save_with_permissions(_users = nil)
  ActiveSupport::Deprecation.warn "save_with_permissions is deprecated and may be removed from future releases, use user_ids and group_ids inside attributes instead."
  save
end

#update_with_permissions(attributes, _users = nil) ⇒ Object

Update the model along with its permissions if any.




89
90
91
92
# File 'lib/fat_free_crm/permissions.rb', line 89

def update_with_permissions(attributes, _users = nil)
  ActiveSupport::Deprecation.warn "update_with_permissions is deprecated and may be removed from future releases, use user_ids and group_ids inside attributes instead."
  update_attributes(attributes)
end