From b3b364680e119723125e149e8af35746b7e9b28e Mon Sep 17 00:00:00 2001 From: Robin Karlsson <61623634+robinkar@users.noreply.github.com> Date: Fri, 30 Aug 2024 17:43:23 +0300 Subject: [PATCH] Add support for interactive app form descriptions (#3763) * Add support for interactive app form description Allows providing longer descriptions as a form header in Markdown format in form.yml.erb for interactive app forms. * Sanitize rendered Markdown instead of html_safe * Replace div in test with span Div elements and ids are sanitized. --- apps/dashboard/app/models/batch_connect/app.rb | 4 ++++ .../views/batch_connect/session_contexts/_form.html.erb | 2 ++ apps/dashboard/test/fixtures/apps/bc_with_subapps/form.yml | 1 + .../test/fixtures/apps/bc_with_subapps/local/owens.yml | 1 + .../fixtures/sys_with_gateway_apps/bc_jupyter/form.yml | 4 ++++ apps/dashboard/test/integration/batch_connect_test.rb | 7 +++++++ apps/dashboard/test/models/batch_connect/app_test.rb | 4 +++- 7 files changed, 22 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/app/models/batch_connect/app.rb b/apps/dashboard/app/models/batch_connect/app.rb index 7b42352bc1..4d34285e3b 100644 --- a/apps/dashboard/app/models/batch_connect/app.rb +++ b/apps/dashboard/app/models/batch_connect/app.rb @@ -133,6 +133,10 @@ def metadata ood_app.metadata.merge(form_config.fetch(:metadata, {})) end + def form_header + form_config.fetch(:form_header, '') + end + def ssh_allow? form_config[:ssh_allow] end diff --git a/apps/dashboard/app/views/batch_connect/session_contexts/_form.html.erb b/apps/dashboard/app/views/batch_connect/session_contexts/_form.html.erb index 0b5d387772..51f67e4059 100644 --- a/apps/dashboard/app/views/batch_connect/session_contexts/_form.html.erb +++ b/apps/dashboard/app/views/batch_connect/session_contexts/_form.html.erb @@ -1,4 +1,6 @@ +<%= sanitize OodAppkit.markdown.render(@app.form_header) %> + <%= render "prefill_templates" if Configuration.bc_saved_settings? %> <%= bootstrap_form_for(@session_context, html: { autocomplete: "off" }) do |f| %> diff --git a/apps/dashboard/test/fixtures/apps/bc_with_subapps/form.yml b/apps/dashboard/test/fixtures/apps/bc_with_subapps/form.yml index ac876491ce..79a2edadb7 100644 --- a/apps/dashboard/test/fixtures/apps/bc_with_subapps/form.yml +++ b/apps/dashboard/test/fixtures/apps/bc_with_subapps/form.yml @@ -1,5 +1,6 @@ --- description: BC with sub apps description +form_header: BC with sub apps form header attributes: desktop: "mate" diff --git a/apps/dashboard/test/fixtures/apps/bc_with_subapps/local/owens.yml b/apps/dashboard/test/fixtures/apps/bc_with_subapps/local/owens.yml index 6a30548f84..b2af9750ea 100644 --- a/apps/dashboard/test/fixtures/apps/bc_with_subapps/local/owens.yml +++ b/apps/dashboard/test/fixtures/apps/bc_with_subapps/local/owens.yml @@ -1,6 +1,7 @@ --- title: "Owens Desktop" description: "Owens Description" +form_header: "Owens Form Header" icon: fa://clock caption: 'gnome desktop on the owens cluster' category: Interactive Apps Overridden diff --git a/apps/dashboard/test/fixtures/sys_with_gateway_apps/bc_jupyter/form.yml b/apps/dashboard/test/fixtures/sys_with_gateway_apps/bc_jupyter/form.yml index 4bb285b0a4..7c1e1057c5 100644 --- a/apps/dashboard/test/fixtures/sys_with_gateway_apps/bc_jupyter/form.yml +++ b/apps/dashboard/test/fixtures/sys_with_gateway_apps/bc_jupyter/form.yml @@ -5,6 +5,10 @@ cluster: - "oakley" description: | This is a test jupyter app. +form_header: | + + This is Markdown with [a link](https://openondemand.org). + attributes: mode: widget: "radio" diff --git a/apps/dashboard/test/integration/batch_connect_test.rb b/apps/dashboard/test/integration/batch_connect_test.rb index 2f3af38bd5..970075702e 100644 --- a/apps/dashboard/test/integration/batch_connect_test.rb +++ b/apps/dashboard/test/integration/batch_connect_test.rb @@ -109,4 +109,11 @@ def setup assert_equal 'edit_name', css_select('input[name="template_name"]').first['value'] end end + + test 'form header is rendered correctly' do + get new_batch_connect_session_context_url('sys/bc_jupyter') + header_link = css_select('span.form_header_supports_some_html>a').first + assert_equal 'a link', header_link.text + assert_equal 'https://openondemand.org', header_link['href'] + end end diff --git a/apps/dashboard/test/models/batch_connect/app_test.rb b/apps/dashboard/test/models/batch_connect/app_test.rb index 8237ec0869..e6c057140e 100644 --- a/apps/dashboard/test/models/batch_connect/app_test.rb +++ b/apps/dashboard/test/models/batch_connect/app_test.rb @@ -295,7 +295,7 @@ def expected_clusters(*args) end end - test 'subapps can override title, description, icon, caption, category, subcategory, and metadata from form' do + test 'subapps can override title, description, icon, caption, category, subcategory, metadata and form_header from form' do r = PathRouter.new('test/fixtures/apps/bc_with_subapps/') app = BatchConnect::App.new(router: r) sub_apps = app.sub_app_list @@ -304,6 +304,7 @@ def expected_clusters(*args) # Oakley uses defaults assert_equal'Desktops: Oakley', sub_apps[0].title assert_equal'BC with sub apps description', sub_apps[0].description + assert_equal'BC with sub apps form header', sub_apps[0].form_header assert_equal'fa://desktop', sub_apps[0].icon_uri assert_equal'Interactive Apps', sub_apps[0].category assert_equal'Desktops', sub_apps[0].subcategory @@ -319,6 +320,7 @@ def expected_clusters(*args) # Owens uses overrides assert_equal'Owens Desktop', sub_apps[1].title assert_equal'Owens Description', sub_apps[1].description + assert_equal'Owens Form Header', sub_apps[1].form_header assert_equal'fa://clock', sub_apps[1].icon_uri assert_equal'Interactive Apps Overridden', sub_apps[1].category assert_equal'Desktops Overridden', sub_apps[1].subcategory