-
Notifications
You must be signed in to change notification settings - Fork 117
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
base: master
Are you sure you want to change the base?
Conversation
apps/dashboard/app/models/project.rb
Outdated
manifest_path = Pathname("#{dir.to_s}/.ondemand/manifest.yml") | ||
unless manifest_path.exist? | ||
Rails.logger.warn("Imported directory is not a Open OnDemand project") | ||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some sort of class method helper that's like self.from_directory
. I feel like that would clean some of this up. Let it return nil if it can't make a project out of the directory, and a real Project object if it can.
apps/dashboard/app/models/project.rb
Outdated
contents = File.read(manifest_path) | ||
raw_opts = YAML.safe_load(contents) | ||
id = raw_opts["id"] | ||
new_table = Project.lookup_table.merge(Hash[id, dir.to_s]) | ||
|
||
@project = Project.find(id) | ||
if @project.nil? | ||
File.write(Project.lookup_file, new_table.to_yaml) | ||
else | ||
Rails.logger.info("Imported project #{dir} already exists in lookup file") | ||
end | ||
true | ||
rescue StandardError => e | ||
Rails.logger.warn("Cannot import project #{dir} to lookup file due to error #{e}") | ||
false | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you instantiate a Project, if it's valid you can use the member function add_to_lookup
like so:
project = Project.from_directory(dir)
project.nil? ? false : project.add_to_lookup(:import)
Related to Issue #4120
This is the second PR, to add the directory of shared project path into a user's own project lookup file.
First PR: #4178
Later, we will show the list of shared projects in import form based upon user's group-id.