Skip to content

Commit

Permalink
Merge 9dd417a into d9dcef8
Browse files Browse the repository at this point in the history
  • Loading branch information
pkomanek committed Dec 4, 2018
2 parents d9dcef8 + 9dd417a commit e02d5f6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/models/miq_ae_yaml_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit e02d5f6

Please sign in to comment.