module FatFreeCRM::Permissions::InstanceMethods

Public Instance Methods

access=(value) click to toggle source

Remove all shared permissions if no longer shared

Calls superclass method
# File lib/fat_free_crm/permissions.rb, line 61
def access=(value)
  remove_permissions unless value == 'Shared'
  super(value)
end
remove_permissions() click to toggle source

Removes all permissions on an object

# File lib/fat_free_crm/permissions.rb, line 68
def remove_permissions
  # we don't use dependent => :destroy so must manually remove
  permissions_to_remove = if id && self.class
                            Permission.where(asset_id: id, asset_type: self.class.name).to_a
                          else
                            []
                          end

  permissions_to_remove.each do |p|
    permissions.delete(p)
    p.destroy
  end
end
save_with_model_permissions(model) click to toggle source

Save the model copying other model’s permissions.

# File lib/fat_free_crm/permissions.rb, line 84
def save_with_model_permissions(model)
  self.access    = model.access
  self.user_ids  = model.user_ids
  self.group_ids = model.group_ids
  save
end