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.
92 93 94 95 96 97 98 99 100 |
# File 'lib/fat_free_crm/permissions.rb', line 92 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.
66 67 68 69 70 71 |
# File 'lib/fat_free_crm/permissions.rb', line 66 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.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fat_free_crm/permissions.rb', line 75 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 |