Merge branch '12414-delete-trashed-project-contents'
[arvados.git] / services / api / lib / whitelist_update.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 module WhitelistUpdate
6   def check_update_whitelist permitted_fields
7     attribute_names.each do |field|
8       if !permitted_fields.include?(field.to_sym) && really_changed(field)
9         errors.add field, "cannot be modified in this state (#{send(field+"_was").inspect}, #{send(field).inspect})"
10       end
11     end
12   end
13
14   def really_changed(attr)
15     return false if !send(attr+"_changed?")
16     old = send(attr+"_was")
17     new = send(attr)
18     if (old.nil? || old == [] || old == {}) && (new.nil? || new == [] || new == {})
19       false
20     else
21       old != new
22     end
23   end
24
25   def validate_state_change
26     if self.state_changed?
27       unless state_transitions[self.state_was].andand.include? self.state
28         errors.add :state, "cannot change from #{self.state_was} to #{self.state}"
29         return false
30       end
31     end
32   end
33 end