diff --git a/app/models/miq_ae_yaml_import.rb b/app/models/miq_ae_yaml_import.rb index 231ac5865..dcdc74898 100644 --- a/app/models/miq_ae_yaml_import.rb +++ b/app/models/miq_ae_yaml_import.rb @@ -13,8 +13,12 @@ def initialize(domain, options) end def import + domain_name = domain_name_for_import if @options.key?('import_dir') && !File.directory?(@options['import_dir']) raise MiqAeException::DirectoryNotFound, "Directory [#{@options['import_dir']}] not found" + elsif !User.current_user.nil? && @options['zip_file'] && domain_locked?(domain_name) + # raise exception only for a local import into the locked domain + raise MiqAeException::DomainNotAccessible, 'locked domain' end start_import(@options['preview'], @domain_name) end @@ -247,4 +251,15 @@ def update_attributes(domain_obj) attrs = @options.slice('enabled', 'source') domain_obj.update_attributes(attrs) unless attrs.empty? end + + private + + def domain_name_for_import + # Getting a domain_name based on user choice to 'import into the same domain as import from' or not + @options['import_as'] || domain_files('*').first.split('/').first + end + + def domain_locked?(domain_name) + MiqAeDomain.find_by(:name => domain_name)&.contents_locked? ? true : false + end end # class