Module: FatFreeCRM::Permissions::InstanceMethods
- Defined in:
- lib/fat_free_crm/permissions.rb
Instance Method Summary collapse
-
#save_with_model_permissions(model) ⇒ Object
Save the model copying other model’s permissions.
-
#save_with_permissions(users) ⇒ Object
Save the model along with its permissions if any.
-
#update_with_permissions(attributes, users) ⇒ Object
Update the model along with its permissions if any.
Instance Method Details
#save_with_model_permissions(model) ⇒ Object
Save the model copying other model’s permissions.
79 80 81 82 83 84 85 86 87 |
# File 'lib/fat_free_crm/permissions.rb', line 79 def (model) self.access = model.access if model.access == "Shared" model..each do || self. << Permission.new(:user_id => .user_id, :asset => self) end end save end |
#save_with_permissions(users) ⇒ Object
Save the model along with its permissions if any.
53 54 55 56 57 58 |
# File 'lib/fat_free_crm/permissions.rb', line 53 def (users) if users && self[:access] == "Shared" users.each { |id| self. << Permission.new(:user_id => id, :asset => self) } end save end |
#update_with_permissions(attributes, users) ⇒ Object
Update the model along with its permissions if any.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fat_free_crm/permissions.rb', line 62 def (attributes, users) if attributes[:access] != "Shared" self..delete_all elsif !users.blank? # Check if we have the same users this time around. existing_users = self..map(&:user_id) if (existing_users.size != users.size) || (existing_users - users != []) self..delete_all users.each do |id| self. << Permission.new(:user_id => id, :asset => self) end end end update_attributes(attributes) end |