Merge branch 'master' into origin-8019-crunchrun-log-throttle
[arvados.git] / services / api / lib / whitelist_update.rb
1 module WhitelistUpdate
2   def check_update_whitelist permitted_fields
3     attribute_names.each do |field|
4       if !permitted_fields.include?(field.to_sym) && really_changed(field)
5         errors.add field, "cannot be modified in this state (#{send(field+"_was").inspect}, #{send(field).inspect})"
6       end
7     end
8   end
9
10   def really_changed(attr)
11     return false if !send(attr+"_changed?")
12     old = send(attr+"_was")
13     new = send(attr)
14     if (old.nil? || old == [] || old == {}) && (new.nil? || new == [] || new == {})
15       false
16     else
17       old != new
18     end
19   end
20
21   def validate_state_change
22     if self.state_changed?
23       unless state_transitions[self.state_was].andand.include? self.state
24         errors.add :state, "cannot change from #{self.state_was} to #{self.state}"
25         return false
26       end
27     end
28   end
29 end