Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saved imported directory into lookup_file for shared projects #4189

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/dashboard/app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ def create

# POST /projects/import
def import_save
# TODO: Call Project to save directory to lookup file
success = true
success = Project.import_to_lookup(params[:project][:directory])
if success
redirect_to projects_path, notice: I18n.t('dashboard.jobs_project_imported')
else
Expand Down
28 changes: 28 additions & 0 deletions apps/dashboard/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,34 @@ def lookup_table
{}
end

def from_directory(dir)
# fetch "id" by opening .ondemand/manifest.yml
manifest_path = Pathname("#{dir.to_s}/.ondemand/manifest.yml")
unless manifest_path.exist?
Rails.logger.warn("Imported directory is not a Open OnDemand project")
nil
end

contents = File.read(manifest_path)
raw_opts = YAML.safe_load(contents)
id = raw_opts["id"]

project = Project.find(id)
if project.nil?
Project.new({ id: id, directory: dir })
else
nil
end
rescue StandardError => e
Rails.logger.warn("Cannot import project from dir #{dir} due to error #{e}")
false
end

def import_to_lookup(dir)
project = from_directory(dir)
project ? project.add_to_lookup(:import) : false
end

def next_id
SecureRandom.alphanumeric(8).downcase
end
Expand Down
Loading