Skip to content

Commit

Permalink
Merge branch 'master' into update-jest
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom committed Sep 16, 2024
2 parents d3a45b0 + 11d1179 commit f08d1be
Show file tree
Hide file tree
Showing 11 changed files with 308 additions and 35 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- XDMoD jobs panel uses plain js now in [3706](https://github.com/OSC/ondemand/pull/3706).
- Esbuild now has a plugin for to use source code for minified dependencies in [3693](https://github.com/OSC/ondemand/pull/3693).
- Remote file uploads now move the tempfile asychronously in [3739](https://github.com/OSC/ondemand/pull/3739).
- Modals no longer pop up for some errors in the files app in [3769](https://github.com/OSC/ondemand/pull/3769).

### Fixed
- Ensure that the asset directory is clean when building in [3356](https://github.com/OSC/ondemand/pull/3356).
Expand All @@ -61,7 +62,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Download buttons will now be hidden for certain files like pipes in [3654](https://github.com/OSC/ondemand/pull/3654).
- Favorite file paths now consult the Allowlist in [3526](https://github.com/OSC/ondemand/pull/3526).
- The ood_portal.conf now accounts for /dex (dex_uri) when enabling maintenance mode in [3736](https://github.com/OSC/ondemand/pull/3736).
- mod_ood_proxy now correctly proxies for httpd 2.4.62 in [3728](https://github.com/OSC/ondemand/pull/3728).
- mod_ood_proxy now correctly proxies for httpd 2.4.62 in [3728](https://github.com/OSC/ondemand/pull/3728)
and [3776](https://github.com/OSC/ondemand/pull/3776).
- ood_auth_map now accounts for more than just \w for usernames in [3753](https://github.com/OSC/ondemand/pull/3753).
- Pipes and fifos no longer show as downloadable in [3718](https://github.com/OSC/ondemand/pull/3718).

Expand Down
10 changes: 4 additions & 6 deletions apps/dashboard/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ GEM
method_source (1.1.0)
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2024.0820)
mime-types-data (3.2024.0903)
mini_mime (1.1.5)
mini_portile2 (2.8.7)
minitest (5.25.1)
mocha (2.4.5)
ruby2_keywords (>= 0.0.5)
multi_json (1.15.0)
mustermann (3.0.2)
mustermann (3.0.3)
ruby2_keywords (~> 0.0.1)
net-imap (0.3.7)
date
Expand Down Expand Up @@ -232,8 +232,7 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.3.6)
strscan
rexml (3.3.7)
rss (0.3.1)
rexml
ruby2_keywords (0.0.5)
Expand Down Expand Up @@ -264,7 +263,6 @@ GEM
activesupport (>= 6.1)
sprockets (>= 3.0.0)
stringio (3.1.1)
strscan (3.1.0)
thor (1.3.2)
tilt (2.4.0)
timecop (0.9.10)
Expand All @@ -282,7 +280,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.17)
zeitwerk (2.6.18)
zip_kit (6.3.1)

PLATFORMS
Expand Down
17 changes: 10 additions & 7 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 Expand Up @@ -60,14 +58,13 @@ def scripts?(project_dir)

ID_REX = /\A\w{8}\Z/.freeze

validates(:id, format: { with: ID_REX, allow_blank: true, message: :format }, on: [:save])
validates(:id, format: { with: ID_REX, message: :format }, on: [:update])
validates(:id, format: { with: ID_REX, message: "ID does not match #{Launcher::ID_REX.inspect}" }, on: [:save])

def initialize(opts = {})
opts = opts.to_h.with_indifferent_access

@project_dir = opts[:project_dir] || raise(StandardError, 'You must set the project directory')
@id = opts[:id] if opts[:id].to_s.empty? || opts[:id].to_s.match?(ID_REX)
@id = opts[:id].to_s.match?(ID_REX) ? opts[:id].to_s : Launcher.next_id
@title = opts[:title].to_s
@created_at = opts[:created_at]
sm_opts = {
Expand Down Expand Up @@ -149,9 +146,11 @@ def []=(_id, value)
end

def save
@id = Launcher.next_id if @id.nil? || !@id.to_s.match?(ID_REX)
return false unless valid?(:save)

@created_at = Time.now.to_i if @created_at.nil?
script_path = Launcher.script_path(project_dir, id)

script_path.mkpath unless script_path.exist?
File.write(Launcher.script_form_file(script_path), to_yaml)

Expand Down Expand Up @@ -223,6 +222,10 @@ def create_default_script
private

def self.script_path(root_dir, script_id)
unless script_id.to_s.match?(ID_REX)
raise(StandardError, "#{script_id} is invalid. Does not match #{ID_REX.inspect}")
end

Pathname.new(File.join(Launcher.scripts_dir(root_dir), script_id.to_s))
end

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
29 changes: 26 additions & 3 deletions apps/dashboard/test/models/launcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,16 @@ class LauncherTest < ActiveSupport::TestCase
end
end

test 'launchers will not assign wrong id' do
test 'launchers will re-assign wrong id' do
Dir.mktmpdir do |tmp|
projects_path = Pathname.new(tmp)
OodAppkit.stubs(:dataroot).returns(projects_path)
launcher = Launcher.new({ project_dir: projects_path.to_s, id: '1234', title: 'Test Script' })
assert_nil(launcher.id)
bad_id = '1234'
launcher = Launcher.new({ project_dir: projects_path.to_s, id: bad_id, title: 'Test Script' })

assert(launcher.id.to_s.match?(Launcher::ID_REX))
refute(bad_id.match?(Launcher::ID_REX))
refute(bad_id.to_s == launcher.id)
end
end

Expand Down Expand Up @@ -130,4 +134,23 @@ class LauncherTest < ActiveSupport::TestCase
assert_equal false, Pathname(File.join(projects_path, 'hello_world.sh')).exist?
end
end

test 'will not save even if id is resest' do
Dir.mktmpdir do |tmp|
bad_id = '1234'
launcher = Launcher.new({ project_dir: tmp.to_s, id: bad_id, title: 'Default Script' })

# initializer reset the id, but we can reset it
refute(launcher.id.to_s == bad_id.to_s)
launcher.instance_variable_set('@id', bad_id)
assert_equal(launcher.id, bad_id)
assert(launcher.errors.size, 0)

# now try to save it, and it fails
refute(launcher.save)
assert(launcher.errors.size, 1)
assert_equal(launcher.errors.full_messages[0], "Id ID does not match #{Launcher::ID_REX.inspect}")
assert(Dir.empty?(Launcher.scripts_dir(tmp).to_s))
end
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
8 changes: 4 additions & 4 deletions apps/dashboard/test/system/project_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -727,18 +727,18 @@ def add_auto_environment_variable(project_id, script_id, save: true)
test 'cant show invalid script' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
visit project_launcher_path(project_id, '1')
visit project_launcher_path(project_id, '12345678')
assert_current_path("/projects/#{project_id}")
assert_selector('.alert-danger', text: "Close\nCannot find script 1")
assert_selector('.alert-danger', text: "Close\nCannot find script 12345678")
end
end

test 'cant edit invalid script' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
visit edit_project_launcher_path(project_id, '1')
visit edit_project_launcher_path(project_id, '12345678')
assert_current_path("/projects/#{project_id}")
assert_selector('.alert-danger', text: "Close\nCannot find script 1")
assert_selector('.alert-danger', text: "Close\nCannot find script 12345678")
end
end

Expand Down
12 changes: 6 additions & 6 deletions apps/dashboard/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,9 @@ retry@^0.13.1:
integrity sha512-XQBQ3I8W1Cge0Seh+6gjj03LbmRFWuoszgK9ooCpwYIrhhoO80pfq4cUkU5DkknwfOfFteRwlZ56PYOGYyFWdg==

sass@^1.50.0:
version "1.77.8"
resolved "https://registry.yarnpkg.com/sass/-/sass-1.77.8.tgz#9f18b449ea401759ef7ec1752a16373e296b52bd"
integrity sha512-4UHg6prsrycW20fqLGPShtEvo/WyHRVRHwOP4DzkUrObWoWI05QBSfzU71TVB7PFaL104TwNaHpjlWXAZbQiNQ==
version "1.78.0"
resolved "https://registry.yarnpkg.com/sass/-/sass-1.78.0.tgz#cef369b2f9dc21ea1d2cf22c979f52365da60841"
integrity sha512-AaIqGSrjo5lA2Yg7RvFZrlXDBCp3nV4XP73GrLGvdRWWwk+8H3l0SDvq/5bA4eF+0RFPLuWUk3E+P1U/YqnpsQ==
dependencies:
chokidar ">=3.0.0 <4.0.0"
immutable "^4.0.0"
Expand All @@ -592,9 +592,9 @@ shallow-equal@^3.0.0:
integrity sha512-pfVOw8QZIXpMbhBWvzBISicvToTiM5WBF1EeAUZDDSb5Dt29yl4AYbyywbJFSEsRUMr7gJaxqCdr4L3tQf9wVg==

"source-map-js@>=0.6.2 <2.0.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.2.0.tgz#16b809c162517b5b8c3e7dcd315a2a5c2612b2af"
integrity sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==
version "1.2.1"
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.2.1.tgz#1ce5650fddd87abc099eda37dcff024c2667ae46"
integrity sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==

source-map@^0.6.1:
version "0.6.1"
Expand Down
6 changes: 2 additions & 4 deletions apps/myjobs/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ GEM
redcarpet (3.6.0)
request_store (1.7.0)
rack (>= 1.4)
rexml (3.3.6)
strscan
rexml (3.3.7)
ruby2_keywords (0.0.5)
sass (3.7.4)
sass-listen (~> 4.0.0)
Expand All @@ -243,7 +242,6 @@ GEM
activesupport (>= 6.1)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
strscan (3.1.0)
thor (1.3.2)
tilt (2.4.0)
timecop (0.9.10)
Expand All @@ -255,7 +253,7 @@ GEM
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.17)
zeitwerk (2.6.18)

PLATFORMS
ruby
Expand Down
2 changes: 2 additions & 0 deletions apps/myjobs/config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Load the Rails application.
require_relative 'application'

Expand Down
Loading

0 comments on commit f08d1be

Please sign in to comment.