X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a95f899d7ac84f29b3d019aa410d265bb40833e5..9f487917d8c2aa3958473dd1c11dc584485c1229:/services/api/lib/whitelist_update.rb diff --git a/services/api/lib/whitelist_update.rb b/services/api/lib/whitelist_update.rb index 8fccd0f45c..17aed4b48d 100644 --- a/services/api/lib/whitelist_update.rb +++ b/services/api/lib/whitelist_update.rb @@ -1,12 +1,27 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + module WhitelistUpdate def check_update_whitelist permitted_fields attribute_names.each do |field| - if not permitted_fields.include? field.to_sym and self.send((field.to_s + "_changed?").to_sym) - errors.add field, "cannot be modified in this state" + if !permitted_fields.include?(field.to_sym) && really_changed(field) + errors.add field, "cannot be modified in state '#{self.state}' (#{send(field+"_was").inspect}, #{send(field).inspect})" end end end + def really_changed(attr) + return false if !send(attr+"_changed?") + old = send(attr+"_was") + new = send(attr) + if (old.nil? || old == [] || old == {}) && (new.nil? || new == [] || new == {}) + false + else + old != new + end + end + def validate_state_change if self.state_changed? unless state_transitions[self.state_was].andand.include? self.state