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

Project validations #3780

Merged
merged 3 commits into from
Sep 11, 2024
Merged
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
4 changes: 1 addition & 3 deletions apps/dashboard/app/models/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class ClusterNotFound < StandardError; end

class << self
def scripts_dir(project_dir)
Pathname.new("#{project_dir}/.ondemand/scripts").tap do |path|
path.mkpath unless path.exist?
end
Pathname.new("#{project_dir}/.ondemand/scripts")
end

def find(id, project_dir)
Expand Down
8 changes: 5 additions & 3 deletions apps/dashboard/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,10 @@ def project_directory_invalid

def project_template_invalid
# This validation is to prevent the template directory being manipulated in the form.
if !template.blank? && Project.templates.map { |template| template.directory.to_s }.exclude?(template.to_s)
errors.add(:template, :invalid)
end
return if template.blank?

template_path = Pathname.new(template)
errors.add(:template, :invalid) if Project.templates.map { |t| t.directory.to_s }.exclude?(template.to_s)
errors.add(:template, :invalid) unless template_path.exist? && template_path.readable?
end
end
4 changes: 3 additions & 1 deletion apps/dashboard/test/models/projects_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ class ProjectsTest < ActiveSupport::TestCase
template: '/invalid/template' })

assert_not project.save
assert_equal 2, project.errors.size
assert_equal 3, project.errors.size
assert_not_equal invalid_icon, project.icon
assert_not project.errors[:directory].empty?
assert_not project.errors[:template].empty?
assert_equal(1, project.errors[:directory].size)
assert_equal(2, project.errors[:template].size)
end
end

Expand Down
Loading