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

Removes NavConfig class & Replaces its use #3475

Merged
merged 4 commits into from
Apr 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
8 changes: 0 additions & 8 deletions apps/dashboard/app/apps/nav_config.rb

This file was deleted.

8 changes: 4 additions & 4 deletions apps/dashboard/app/models/user_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ def announcement_path
end
end

# Filtering is controlled with NavConfig.categories_allowlist? unless the configuration property categories is defined.
# If categories are defined, filter_nav_categories? will always be true.
DEFAULT_NAV_CATEGORIES = ["Apps", "Files", "Jobs", "Clusters", "Interactive Apps"].freeze

def filter_nav_categories?
fetch(:nav_categories, nil).nil? ? NavConfig.categories_whitelist? : true
!!fetch(:nav_categories, nil)
end

def nav_categories
fetch(:nav_categories, nil) || NavConfig.categories
fetch(:nav_categories, DEFAULT_NAV_CATEGORIES)
end

# Create support ticket service class based on the configuration
Expand Down
73 changes: 1 addition & 72 deletions apps/dashboard/test/integration/dashboard_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,55 +148,9 @@ def teardown
assert_select "nav a[href='#{batch_connect_sessions_path}']", 0
end

test 'should not create app menus if NavConfig.categories is empty and whitelist is enabled' do
test 'UserConfiguration.categories should filter and order the navigation' do
SysRouter.stubs(:base_path).returns(Rails.root.join('test/fixtures/sys_with_gateway_apps'))
OodAppkit.stubs(:clusters).returns(OodCore::Clusters.load_file('test/fixtures/config/clusters.d'))
NavConfig.stubs(:categories_whitelist?).returns(true)
NavConfig.stubs(:categories).returns([])

get root_path
assert_response :success
assert_select dropdown_links, 1 # +1 here is 'Help'
assert_select dropdown_link(1), text: 'Help' # ensure is Help
end

test 'should exclude gateway apps if NavConfig.categories is set to default and whitelist is enabled' do
SysRouter.stubs(:base_path).returns(Rails.root.join('test/fixtures/sys_with_gateway_apps'))
OodAppkit.stubs(:clusters).returns(OodCore::Clusters.load_file('test/fixtures/config/clusters.d'))
NavConfig.stubs(:categories_whitelist?).returns(true)
NavConfig.stubs(:categories).returns(['Files', 'Jobs', 'Clusters', 'Interactive Apps'])

get root_path
assert_response :success
assert_select dropdown_links, 5 # +1 here is 'Help'
assert_select dropdown_link(1), text: 'Files'
assert_select dropdown_link(2), text: 'Jobs'
assert_select dropdown_link(3), text: 'Clusters'
assert_select dropdown_link(4), text: 'Interactive Apps'
assert_select dropdown_link(5), text: 'Help'
end

test 'uses NavConfig.categories as sort order if whitelist is false' do
SysRouter.stubs(:base_path).returns(Rails.root.join('test/fixtures/sys_with_gateway_apps'))
OodAppkit.stubs(:clusters).returns(OodCore::Clusters.load_file('test/fixtures/config/clusters.d'))
NavConfig.stubs(:categories_whitelist?).returns(false)
NavConfig.stubs(:categories).returns(['Jobs', 'Interactive Apps', 'Files', 'Clusters'])

get root_path
assert_response :success
assert_select dropdown_links, 6 # +1 here is 'Help'
assert_select dropdown_link(1), text: 'Jobs'
assert_select dropdown_link(2), text: 'Interactive Apps'
assert_select dropdown_link(3), text: 'Files'
assert_select dropdown_link(4), text: 'Clusters'
assert_select dropdown_link(5), text: 'Gateway Apps'
end

test 'UserConfiguration.categories should filter and order the navigation and have precedence over NavConfig' do
SysRouter.stubs(:base_path).returns(Rails.root.join('test/fixtures/sys_with_gateway_apps'))
OodAppkit.stubs(:clusters).returns(OodCore::Clusters.load_file('test/fixtures/config/clusters.d'))
NavConfig.stubs(:categories_whitelist?).returns(false)
NavConfig.stubs(:categories).returns(['Jobs', 'Interactive Apps', 'Files', 'Clusters'])

stub_user_configuration({
nav_categories: ['Files', 'Interactive Apps', 'Clusters']
Expand All @@ -213,8 +167,6 @@ def teardown
test 'should not create app menus if UserConfiguration.categories is empty' do
SysRouter.stubs(:base_path).returns(Rails.root.join('test/fixtures/sys_with_gateway_apps'))
OodAppkit.stubs(:clusters).returns(OodCore::Clusters.load_file('test/fixtures/config/clusters.d'))
NavConfig.stubs(:categories_whitelist?).returns(false)
NavConfig.stubs(:categories).returns(['Jobs', 'Interactive Apps', 'Files', 'Clusters'])

stub_user_configuration({
nav_categories: []
Expand All @@ -226,32 +178,9 @@ def teardown
assert_select dropdown_link(1), text: 'Help' # ensure is Help
end

test 'verify default values for NavConfig' do
refute NavConfig.categories_whitelist?
assert NavConfig
end

test 'display all app menus in alphabetical order if NavConfig.whitelist false & NavConfig.categories nil or []' do
SysRouter.stubs(:base_path).returns(Rails.root.join('test/fixtures/sys_with_gateway_apps'))
OodAppkit.stubs(:clusters).returns(OodCore::Clusters.load_file('test/fixtures/config/clusters.d'))
NavConfig.stubs(:categories_whitelist?).returns(false)
NavConfig.stubs(:categories).returns([])

get root_path
assert_response :success
assert_select dropdown_links, 6 # +1 here is 'Help'

assert_select dropdown_link(1), text: 'Clusters'
assert_select dropdown_link(2), text: 'Files'
assert_select dropdown_link(3), text: 'Gateway Apps'
assert_select dropdown_link(4), text: 'Interactive Apps'
assert_select dropdown_link(5), text: 'Jobs'
end

test 'apps with no category should not appear in menu' do
SysRouter.stubs(:base_path).returns(Rails.root.join('test/fixtures/sys_with_gateway_apps'))
OodAppkit.stubs(:clusters).returns(OodCore::Clusters.load_file('test/fixtures/config/clusters.d'))
NavConfig.stubs(:categories_whitelist?).returns(false)

get root_path

Expand Down
5 changes: 2 additions & 3 deletions apps/dashboard/test/models/user_configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,11 @@ def teardown
assert_equal true, UserConfiguration.new.filter_nav_categories?
end

test "filter_nav_categories? should return default value NavConfig.categories_whitelist? when categories is not set in config" do
test "filter_nav_categories? should return false when nav_categories is nil" do
Configuration.stubs(:config).returns({})
NavConfig.stubs(:categories_whitelist?).returns(false)
assert_equal false, UserConfiguration.new.filter_nav_categories?

NavConfig.stubs(:categories_whitelist?).returns(true)
Configuration.stubs(:config).returns({nav_categories: []})
assert_equal true, UserConfiguration.new.filter_nav_categories?
end

Expand Down
Loading