From bf14fc16cdc4b9080a6a11131fca1dd42db0f05b Mon Sep 17 00:00:00 2001 From: Matt Budz Date: Wed, 22 May 2024 12:41:06 +0200 Subject: [PATCH 01/41] update nokogiri --- CHANGELOG | 2 +- Gemfile.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cc7752cff..5cd515d06 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,7 +2,7 @@ - [entity]: - [future tense verb] [feature] - Upgraded gems: - - [gem] + - nokogiri - Bugs fixes: - [entity]: - [future tense verb] [bug fix] diff --git a/Gemfile.lock b/Gemfile.lock index 74b3a10ee..faf697527 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -279,7 +279,7 @@ GEM matrix (0.4.2) method_source (0.9.2) mini_mime (1.1.5) - mini_portile2 (2.8.5) + mini_portile2 (2.8.6) mini_racer (0.6.2) libv8-node (~> 16.10.0.0) minitest (5.22.2) @@ -299,14 +299,14 @@ GEM net-smtp (0.4.0.1) net-protocol nio4r (2.7.0) - nokogiri (1.16.2) + nokogiri (1.16.5) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.16.2-arm64-darwin) + nokogiri (1.16.5-arm64-darwin) racc (~> 1.4) - nokogiri (1.16.2-x86_64-darwin) + nokogiri (1.16.5-x86_64-darwin) racc (~> 1.4) - nokogiri (1.16.2-x86_64-linux) + nokogiri (1.16.5-x86_64-linux) racc (~> 1.4) notiffany (0.1.3) nenv (~> 0.1) @@ -327,7 +327,7 @@ GEM public_suffix (5.0.3) puma (6.4.2) nio4r (~> 2.0) - racc (1.7.3) + racc (1.8.0) rack (2.2.8.1) rack-mini-profiler (2.3.0) rack (>= 1.2.0) From 363e25b963f3afb6c89069c97e78910bbba7c621 Mon Sep 17 00:00:00 2001 From: Matt Budz Date: Wed, 22 May 2024 12:56:44 +0200 Subject: [PATCH 02/41] update rexml --- Gemfile.lock | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index faf697527..9f91c496a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -389,7 +389,8 @@ GEM vegas (~> 0.1.2) resque-status (0.5.0) resque (~> 1.19) - rexml (3.2.5) + rexml (3.2.8) + strscan (>= 3.0.9) rinku (2.0.6) rprogram (0.3.2) rspec (3.10.0) @@ -471,6 +472,7 @@ GEM activesupport (>= 5.2) sprockets (>= 3.0.0) sqlite3 (1.4.2) + strscan (3.1.0) terser (1.1.15) execjs (>= 0.3.0, < 3) thor (1.2.2) From c24e5312cfd6348843a38971d2b005911e97c1a1 Mon Sep 17 00:00:00 2001 From: Matt Budz Date: Wed, 22 May 2024 12:57:10 +0200 Subject: [PATCH 03/41] update changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 5cd515d06..4afa4e6c0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ - [future tense verb] [feature] - Upgraded gems: - nokogiri + - rexml - Bugs fixes: - [entity]: - [future tense verb] [bug fix] From 73dce9f92a922e13cecca10c4c557ef2ab49b29e Mon Sep 17 00:00:00 2001 From: Matt Budz Date: Wed, 22 May 2024 14:10:08 +0200 Subject: [PATCH 04/41] Update CHANGELOG --- CHANGELOG | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4afa4e6c0..e3e1a5825 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,7 @@ [v#.#.#] ([month] [YYYY]) - [entity]: - [future tense verb] [feature] - - Upgraded gems: - - nokogiri - - rexml + - Upgraded gems: nokogiri, rexml - Bugs fixes: - [entity]: - [future tense verb] [bug fix] From 571c3882f3ff45c93ce1fe67bf7c62996ca6e2f2 Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Thu, 30 May 2024 17:42:40 +0800 Subject: [PATCH 05/41] Add project_records method to liquid assigns service --- app/services/liquid_assigns_service.rb | 25 +++++++++++++++++++- spec/services/liquid_assigns_service_spec.rb | 13 ++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/services/liquid_assigns_service.rb b/app/services/liquid_assigns_service.rb index 79f8d48ba..454708076 100644 --- a/app/services/liquid_assigns_service.rb +++ b/app/services/liquid_assigns_service.rb @@ -6,7 +6,7 @@ def initialize(project) end def assigns - result = { 'project' => ProjectDrop.new(project) } + result = project_drops result.merge!(assigns_pro) if defined?(Dradis::Pro) result end @@ -15,4 +15,27 @@ def assigns def assigns_pro end + + def project_drops + { + 'evidence' => project_records(type: :evidence), + 'issues' => project_records(type: :issue), + 'nodes' => project_records(type: :node), + 'notes' => project_records(type: :note), + 'project' => ProjectDrop.new(project), + 'tags' => project_records(type: :tag) + } + end + + def project_records(type:) + records = project.send(type.to_s.pluralize) + records = records.user_nodes if type == :node + + cache_key = "liquid-project-#{type.to_s.pluralize}#{records.maximum(:updated_at)}/#{records.pluck(:id).join('-')}" + drop_class = "#{type.to_s.capitalize}Drop".constantize + + Rails.cache.fetch(cache_key) do + records.map { |record| drop_class.new(record) } + end + end end diff --git a/spec/services/liquid_assigns_service_spec.rb b/spec/services/liquid_assigns_service_spec.rb index 581bb8a52..a26da85ef 100644 --- a/spec/services/liquid_assigns_service_spec.rb +++ b/spec/services/liquid_assigns_service_spec.rb @@ -5,8 +5,21 @@ let(:liquid_assigns) { described_class.new(project).assigns } + before do + node = create(:node, project: project) + issue = create(:issue, node: project.issue_library) + create(:evidence, issue: issue, node: node) + create(:note, node: node) + create(:tag) + end + it 'builds a hash of liquid assigns' do expect(liquid_assigns['project'].name).to eq(project.name) + expect(liquid_assigns['issues'].map(&:title)).to eq(project.issues.map(&:title)) + expect(liquid_assigns['evidence'].map(&:title)).to eq(project.evidence.map(&:title)) + expect(liquid_assigns['nodes'].map(&:label)).to eq(project.nodes.user_nodes.map(&:label)) + expect(liquid_assigns['notes'].map(&:title)).to eq(project.notes.map(&:title)) + expect(liquid_assigns['tags'].map(&:display_name)).to eq(project.tags.map(&:display_name)) end context 'with pro records', skip: !defined?(Dradis::Pro) do From 418d85e3948086f8bff0d6238c3264c5e7082ee6 Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Thu, 30 May 2024 18:10:46 +0800 Subject: [PATCH 06/41] Update changelog --- CHANGELOG | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e3e1a5825..c4c00b69f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,5 @@ [v#.#.#] ([month] [YYYY]) - - [entity]: - - [future tense verb] [feature] + - Liquid: Make project-level drops available for Liquid syntax - Upgraded gems: nokogiri, rexml - Bugs fixes: - [entity]: From ea2baa0c9793a2b588f167786d2dd9ad55704e81 Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Thu, 30 May 2024 18:27:52 +0800 Subject: [PATCH 07/41] Update spec for parity --- spec/services/liquid_assigns_service_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/services/liquid_assigns_service_spec.rb b/spec/services/liquid_assigns_service_spec.rb index a26da85ef..3ff178fc3 100644 --- a/spec/services/liquid_assigns_service_spec.rb +++ b/spec/services/liquid_assigns_service_spec.rb @@ -29,11 +29,14 @@ report_content = project.content_library report_content.properties = { 'dradis.project' => project.name } report_content.save + + create(:content_block, project: project) end it 'builds a hash with Dradis::Pro assigns' do expect(liquid_assigns['document_properties'].available_properties).to eq({ 'dradis.project' => project.name }) expect(liquid_assigns['team'].name).to eq(project.team.name) + expect(liquid_assigns['content_blocks'].map(&:content)).to eq(project.content_blocks.map(&:content)) end end end From c148482534e7629070fa79d64b75f1a2756eefd3 Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Thu, 30 May 2024 18:33:08 +0800 Subject: [PATCH 08/41] Use camelize --- app/services/liquid_assigns_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/liquid_assigns_service.rb b/app/services/liquid_assigns_service.rb index 454708076..42818c93d 100644 --- a/app/services/liquid_assigns_service.rb +++ b/app/services/liquid_assigns_service.rb @@ -32,7 +32,7 @@ def project_records(type:) records = records.user_nodes if type == :node cache_key = "liquid-project-#{type.to_s.pluralize}#{records.maximum(:updated_at)}/#{records.pluck(:id).join('-')}" - drop_class = "#{type.to_s.capitalize}Drop".constantize + drop_class = "#{type.to_s.camelize}Drop".constantize Rails.cache.fetch(cache_key) do records.map { |record| drop_class.new(record) } From 8929784ce948a6a712a0d35cb685bae046fc41e6 Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Fri, 31 May 2024 16:31:28 +0800 Subject: [PATCH 09/41] Simplify cache key --- app/services/liquid_assigns_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/liquid_assigns_service.rb b/app/services/liquid_assigns_service.rb index 42818c93d..f0cb4a343 100644 --- a/app/services/liquid_assigns_service.rb +++ b/app/services/liquid_assigns_service.rb @@ -31,7 +31,7 @@ def project_records(type:) records = project.send(type.to_s.pluralize) records = records.user_nodes if type == :node - cache_key = "liquid-project-#{type.to_s.pluralize}#{records.maximum(:updated_at)}/#{records.pluck(:id).join('-')}" + cache_key = "liquid-project-#{project.id}-#{type.to_s.pluralize}:#{records.maximum(:updated_at).to_i}-#{records.count}" drop_class = "#{type.to_s.camelize}Drop".constantize Rails.cache.fetch(cache_key) do From c7fe6238ad67ad6958934004c6bb908dd6967430 Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Mon, 3 Jun 2024 16:13:52 +0800 Subject: [PATCH 10/41] Bump rails to 7.0.8.3 --- CHANGELOG | 2 +- Gemfile | 2 +- Gemfile.lock | 130 +++++++++++++++++++++++++-------------------------- 3 files changed, 67 insertions(+), 67 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e3e1a5825..7fcf2dc20 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,7 @@ [v#.#.#] ([month] [YYYY]) - [entity]: - [future tense verb] [feature] - - Upgraded gems: nokogiri, rexml + - Upgraded gems: nokogiri, rails, rexml - Bugs fixes: - [entity]: - [future tense verb] [bug fix] diff --git a/Gemfile b/Gemfile index 941b986cb..49d7fafc6 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '3.1.2' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 7.0.8' +gem 'rails', '~> 7.0.8.3' # Use SCSS for stylesheets gem 'sass-rails', '~> 6.0' diff --git a/Gemfile.lock b/Gemfile.lock index 9f91c496a..401303803 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,67 +8,67 @@ GEM remote: https://rubygems.org/ specs: RedCloth (4.3.2) - actioncable (7.0.8.1) - actionpack (= 7.0.8.1) - activesupport (= 7.0.8.1) + actioncable (7.0.8.3) + actionpack (= 7.0.8.3) + activesupport (= 7.0.8.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.8.1) - actionpack (= 7.0.8.1) - activejob (= 7.0.8.1) - activerecord (= 7.0.8.1) - activestorage (= 7.0.8.1) - activesupport (= 7.0.8.1) + actionmailbox (7.0.8.3) + actionpack (= 7.0.8.3) + activejob (= 7.0.8.3) + activerecord (= 7.0.8.3) + activestorage (= 7.0.8.3) + activesupport (= 7.0.8.3) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.8.1) - actionpack (= 7.0.8.1) - actionview (= 7.0.8.1) - activejob (= 7.0.8.1) - activesupport (= 7.0.8.1) + actionmailer (7.0.8.3) + actionpack (= 7.0.8.3) + actionview (= 7.0.8.3) + activejob (= 7.0.8.3) + activesupport (= 7.0.8.3) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) - actionpack (7.0.8.1) - actionview (= 7.0.8.1) - activesupport (= 7.0.8.1) + actionpack (7.0.8.3) + actionview (= 7.0.8.3) + activesupport (= 7.0.8.3) rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.8.1) - actionpack (= 7.0.8.1) - activerecord (= 7.0.8.1) - activestorage (= 7.0.8.1) - activesupport (= 7.0.8.1) + actiontext (7.0.8.3) + actionpack (= 7.0.8.3) + activerecord (= 7.0.8.3) + activestorage (= 7.0.8.3) + activesupport (= 7.0.8.3) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.8.1) - activesupport (= 7.0.8.1) + actionview (7.0.8.3) + activesupport (= 7.0.8.3) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.8.1) - activesupport (= 7.0.8.1) + activejob (7.0.8.3) + activesupport (= 7.0.8.3) globalid (>= 0.3.6) - activemodel (7.0.8.1) - activesupport (= 7.0.8.1) - activerecord (7.0.8.1) - activemodel (= 7.0.8.1) - activesupport (= 7.0.8.1) - activestorage (7.0.8.1) - actionpack (= 7.0.8.1) - activejob (= 7.0.8.1) - activerecord (= 7.0.8.1) - activesupport (= 7.0.8.1) + activemodel (7.0.8.3) + activesupport (= 7.0.8.3) + activerecord (7.0.8.3) + activemodel (= 7.0.8.3) + activesupport (= 7.0.8.3) + activestorage (7.0.8.3) + actionpack (= 7.0.8.3) + activejob (= 7.0.8.3) + activerecord (= 7.0.8.3) + activesupport (= 7.0.8.3) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.8.1) + activesupport (7.0.8.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -119,7 +119,7 @@ GEM activesupport (>= 3.0.0) railties (>= 3.0.0) thor (>= 0.14.6) - concurrent-ruby (1.2.3) + concurrent-ruby (1.3.1) crass (1.0.6) database_cleaner (1.8.2) date (3.3.4) @@ -223,7 +223,7 @@ GEM html-pipeline (2.12.3) activesupport (>= 2) nokogiri (>= 1.4) - i18n (1.14.1) + i18n (1.14.5) concurrent-ruby (~> 1.0) image_size (1.3.1) importmap-rails (1.2.1) @@ -275,30 +275,30 @@ GEM net-imap net-pop net-smtp - marcel (1.0.2) + marcel (1.0.4) matrix (0.4.2) method_source (0.9.2) mini_mime (1.1.5) - mini_portile2 (2.8.6) + mini_portile2 (2.8.7) mini_racer (0.6.2) libv8-node (~> 16.10.0.0) - minitest (5.22.2) + minitest (5.23.1) mono_logger (1.1.1) msgpack (1.5.2) multi_json (1.15.0) mustermann (2.0.2) ruby2_keywords (~> 0.0.1) nenv (0.3.0) - net-imap (0.4.10) + net-imap (0.4.12) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout - net-smtp (0.4.0.1) + net-smtp (0.5.0) net-protocol - nio4r (2.7.0) + nio4r (2.7.3) nokogiri (1.16.5) mini_portile2 (~> 2.8.2) racc (~> 1.4) @@ -328,27 +328,27 @@ GEM puma (6.4.2) nio4r (~> 2.0) racc (1.8.0) - rack (2.2.8.1) + rack (2.2.9) rack-mini-profiler (2.3.0) rack (>= 1.2.0) rack-protection (2.2.3) rack rack-test (2.1.0) rack (>= 1.3) - rails (7.0.8.1) - actioncable (= 7.0.8.1) - actionmailbox (= 7.0.8.1) - actionmailer (= 7.0.8.1) - actionpack (= 7.0.8.1) - actiontext (= 7.0.8.1) - actionview (= 7.0.8.1) - activejob (= 7.0.8.1) - activemodel (= 7.0.8.1) - activerecord (= 7.0.8.1) - activestorage (= 7.0.8.1) - activesupport (= 7.0.8.1) + rails (7.0.8.3) + actioncable (= 7.0.8.3) + actionmailbox (= 7.0.8.3) + actionmailer (= 7.0.8.3) + actionpack (= 7.0.8.3) + actiontext (= 7.0.8.3) + actionview (= 7.0.8.3) + activejob (= 7.0.8.3) + activemodel (= 7.0.8.3) + activerecord (= 7.0.8.3) + activestorage (= 7.0.8.3) + activesupport (= 7.0.8.3) bundler (>= 1.15.0) - railties (= 7.0.8.1) + railties (= 7.0.8.3) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -359,15 +359,15 @@ GEM actionview (> 3.1) activesupport (> 3.1) railties (> 3.1) - railties (7.0.8.1) - actionpack (= 7.0.8.1) - activesupport (= 7.0.8.1) + railties (7.0.8.3) + actionpack (= 7.0.8.3) + activesupport (= 7.0.8.3) method_source rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) rainbow (3.1.1) - rake (13.1.0) + rake (13.2.1) rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) @@ -504,7 +504,7 @@ GEM chronic (>= 0.6.3) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.13) + zeitwerk (2.6.15) PLATFORMS arm64-darwin @@ -581,7 +581,7 @@ DEPENDENCIES pg puma (>= 6.4.2) rack-mini-profiler (~> 2.0) - rails (~> 7.0.8) + rails (~> 7.0.8.3) rails-html-sanitizer (~> 1.4.4) record_tag_helper rerun From 825eb27c3cf4c936c46e5eedb076f9085416f5d1 Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Mon, 3 Jun 2024 16:53:40 +0800 Subject: [PATCH 11/41] Apply requested changes --- app/services/liquid_assigns_service.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/services/liquid_assigns_service.rb b/app/services/liquid_assigns_service.rb index f0cb4a343..ceed78075 100644 --- a/app/services/liquid_assigns_service.rb +++ b/app/services/liquid_assigns_service.rb @@ -6,7 +6,7 @@ def initialize(project) end def assigns - result = project_drops + result = project_assigns result.merge!(assigns_pro) if defined?(Dradis::Pro) result end @@ -16,23 +16,23 @@ def assigns def assigns_pro end - def project_drops + def project_assigns { - 'evidence' => project_records(type: :evidence), - 'issues' => project_records(type: :issue), - 'nodes' => project_records(type: :node), - 'notes' => project_records(type: :note), + 'evidences' => cached_drops(project.evidence), + 'issues' => cached_drops(project.issues), + 'nodes' => cached_drops(project.nodes.user_nodes), + 'notes' => cached_drops(project.notes), 'project' => ProjectDrop.new(project), - 'tags' => project_records(type: :tag) + 'tags' => cached_drops(project.tags) } end - def project_records(type:) - records = project.send(type.to_s.pluralize) - records = records.user_nodes if type == :node + def cached_drops(records) + return [] if records.empty? - cache_key = "liquid-project-#{project.id}-#{type.to_s.pluralize}:#{records.maximum(:updated_at).to_i}-#{records.count}" - drop_class = "#{type.to_s.camelize}Drop".constantize + type = records.first.class.to_s.underscore + cache_key = "liquid-project-#{project.id}-#{type.pluralize}:#{records.maximum(:updated_at).to_i}-#{records.count}" + drop_class = "#{type.camelize}Drop".constantize Rails.cache.fetch(cache_key) do records.map { |record| drop_class.new(record) } From ce03ecb209184efefcb0b5f6533a32ce5aff46ec Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Mon, 3 Jun 2024 17:06:06 +0800 Subject: [PATCH 12/41] Update assigns spec --- spec/services/liquid_assigns_service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/liquid_assigns_service_spec.rb b/spec/services/liquid_assigns_service_spec.rb index 3ff178fc3..418cdc0c3 100644 --- a/spec/services/liquid_assigns_service_spec.rb +++ b/spec/services/liquid_assigns_service_spec.rb @@ -16,7 +16,7 @@ it 'builds a hash of liquid assigns' do expect(liquid_assigns['project'].name).to eq(project.name) expect(liquid_assigns['issues'].map(&:title)).to eq(project.issues.map(&:title)) - expect(liquid_assigns['evidence'].map(&:title)).to eq(project.evidence.map(&:title)) + expect(liquid_assigns['evidences'].map(&:title)).to eq(project.evidence.map(&:title)) expect(liquid_assigns['nodes'].map(&:label)).to eq(project.nodes.user_nodes.map(&:label)) expect(liquid_assigns['notes'].map(&:title)).to eq(project.notes.map(&:title)) expect(liquid_assigns['tags'].map(&:display_name)).to eq(project.tags.map(&:display_name)) From 305cab0150ac95663b69c053781604dfe32263d9 Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Tue, 4 Jun 2024 15:31:18 +0800 Subject: [PATCH 13/41] Parse liquid asynchronously in tylium --- app/assets/javascripts/tylium.js | 1 + .../javascripts/tylium/modules/liquid_async.js | 18 ++++++++++++++++++ .../concerns/liquid_enabled_resource.rb | 2 ++ app/views/evidence/show.html.erb | 5 ++--- app/views/issues/show.html.erb | 4 ++-- app/views/notes/show.html.erb | 4 ++-- app/views/qa/issues/show.html.erb | 4 ++-- 7 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 app/assets/javascripts/tylium/modules/liquid_async.js diff --git a/app/assets/javascripts/tylium.js b/app/assets/javascripts/tylium.js index d05374de6..a2f393ba6 100644 --- a/app/assets/javascripts/tylium.js +++ b/app/assets/javascripts/tylium.js @@ -51,6 +51,7 @@ //= require tylium/modules/export //= require tylium/modules/fileupload //= require tylium/modules/issues +//= require tylium/modules/liquid_async //= require tylium/modules/nodes //= require tylium/modules/search //= require tylium/modules/sidebar diff --git a/app/assets/javascripts/tylium/modules/liquid_async.js b/app/assets/javascripts/tylium/modules/liquid_async.js new file mode 100644 index 000000000..aee7cf23b --- /dev/null +++ b/app/assets/javascripts/tylium/modules/liquid_async.js @@ -0,0 +1,18 @@ +document.addEventListener('turbolinks:load', function () { + $('[data-behavior~=liquid-async]').each(function() { + var that = this, + data = { text: $(that).attr('data-content') }; + + $.ajax($(that).attr('data-path'), { + method: 'POST', + headers: { + "Accept": "text/html", + "Content-Type": "application/json" + }, + data: JSON.stringify(data) + }). + done(function(html){ + $(that).html(html); + }); + }); +}); diff --git a/app/controllers/concerns/liquid_enabled_resource.rb b/app/controllers/concerns/liquid_enabled_resource.rb index a8f8216e3..e23863ce9 100644 --- a/app/controllers/concerns/liquid_enabled_resource.rb +++ b/app/controllers/concerns/liquid_enabled_resource.rb @@ -15,6 +15,8 @@ def liquid_resource_assigns end def preview + # Artificial load time for testing + sleep 3 @text = params[:text] render 'markup/preview', layout: false end diff --git a/app/views/evidence/show.html.erb b/app/views/evidence/show.html.erb index 15721d50c..b1576fd03 100644 --- a/app/views/evidence/show.html.erb +++ b/app/views/evidence/show.html.erb @@ -32,9 +32,8 @@ Evidence for this instance <%= render partial: 'actions' %> - -
- <%= markup(@evidence.content, liquid: true) %> +
+ <%= markup(@evidence.content) %>
Author: <%= @evidence.author || 'n/a' %> diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index fedc5f79b..6ff2ec3d3 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -35,8 +35,8 @@ <%= @issue.title %> <%= render partial: 'actions' %> -
- <%= markup(@issue.text, liquid: true) %> +
+ <%= markup(@issue.text) %>
Author: <%= @issue.author || 'n/a' %> diff --git a/app/views/notes/show.html.erb b/app/views/notes/show.html.erb index 95c269968..2dcdf7714 100644 --- a/app/views/notes/show.html.erb +++ b/app/views/notes/show.html.erb @@ -23,8 +23,8 @@ <%= @note.title %> <%= render partial: 'actions' %> -
- <%= markup(@note.text, liquid: true) %> +
+ <%= markup(@note.text) %>
Author: <%= @note.author || 'n/a' %> diff --git a/app/views/qa/issues/show.html.erb b/app/views/qa/issues/show.html.erb index 7e1b2fb37..d7b32177c 100644 --- a/app/views/qa/issues/show.html.erb +++ b/app/views/qa/issues/show.html.erb @@ -29,8 +29,8 @@ -
- <%= markup(@issue.text, liquid: true) %> +
+ <%= markup(@issue.text) %>
Author: <%= @issue.author || 'n/a' %> From aeddb6b51813eb83480864a8c7be521438e61ebc Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Tue, 4 Jun 2024 16:01:13 +0800 Subject: [PATCH 14/41] Fix path for notes --- app/views/notes/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/notes/show.html.erb b/app/views/notes/show.html.erb index 2dcdf7714..6772b83a2 100644 --- a/app/views/notes/show.html.erb +++ b/app/views/notes/show.html.erb @@ -23,7 +23,7 @@ <%= @note.title %> <%= render partial: 'actions' %> -
+
<%= markup(@note.text) %>
From b0c2a9b6770e35d69966f19d8df91af14ef2913f Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Tue, 4 Jun 2024 18:54:35 +0800 Subject: [PATCH 15/41] Use fetch --- app/assets/javascripts/tylium/modules/liquid_async.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/tylium/modules/liquid_async.js b/app/assets/javascripts/tylium/modules/liquid_async.js index aee7cf23b..d1cc4984a 100644 --- a/app/assets/javascripts/tylium/modules/liquid_async.js +++ b/app/assets/javascripts/tylium/modules/liquid_async.js @@ -3,15 +3,17 @@ document.addEventListener('turbolinks:load', function () { var that = this, data = { text: $(that).attr('data-content') }; - $.ajax($(that).attr('data-path'), { + fetch($(that).attr('data-path'), { method: 'POST', headers: { "Accept": "text/html", - "Content-Type": "application/json" + "Content-Type": "application/json", + "X-CSRF-Token": $('meta[name="csrf-token"]').attr('content') }, - data: JSON.stringify(data) + body: JSON.stringify(data) }). - done(function(html){ + then(response => response.text()). + then(function(html) { $(that).html(html); }); }); From 365e714a606045180698922616c3b49a30dc3a40 Mon Sep 17 00:00:00 2001 From: Matt Budz Date: Tue, 4 Jun 2024 16:41:06 +0200 Subject: [PATCH 16/41] add `liquid_loading` partial --- app/assets/stylesheets/tylium/modules.scss | 1 + app/helpers/application_helper.rb | 6 +++--- app/views/shared/_liquid_loading.html.erb | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 app/views/shared/_liquid_loading.html.erb diff --git a/app/assets/stylesheets/tylium/modules.scss b/app/assets/stylesheets/tylium/modules.scss index ca1fd5cbf..7553cf419 100644 --- a/app/assets/stylesheets/tylium/modules.scss +++ b/app/assets/stylesheets/tylium/modules.scss @@ -149,6 +149,7 @@ } .header-underline { + align-items: center; border-bottom: 1px solid $borderColor; display: flex; margin-bottom: 0.5em; diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d0d4e237c..e4ba04e65 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,5 @@ module ApplicationHelper # :nodoc: - def markup(text, options={}) + def markup(text, options = {}) return unless text.present? context = {} @@ -38,8 +38,8 @@ def render_view_hooks(partial, locals: {}, feature: :addon) ;nil end - def spinner_tag(spinner_class: 'text-primary') - content_tag :div, class: 'd-flex align-items-center justify-content-center spinner-container' do + def spinner_tag(spinner_class: 'text-primary', align: 'center', inline: false) + content_tag :div, class: "#{inline ? 'd-inline-flex' : 'd-flex' } align-items-center justify-content-#{align} spinner-container" do content_tag :div, nil, class: "spinner-border #{spinner_class}" end end diff --git a/app/views/shared/_liquid_loading.html.erb b/app/views/shared/_liquid_loading.html.erb new file mode 100644 index 000000000..fa5c8d635 --- /dev/null +++ b/app/views/shared/_liquid_loading.html.erb @@ -0,0 +1,8 @@ +
+ - + <%= spinner_tag spinner_class: 'spinner-border-sm text-primary', align: 'start', inline: true %> + Loading liquid dynamic content +
From 340196802e945db42005492a93b414b2a70fd3c9 Mon Sep 17 00:00:00 2001 From: Matt Budz Date: Tue, 4 Jun 2024 16:46:13 +0200 Subject: [PATCH 17/41] use partial in views --- app/views/evidence/show.html.erb | 1 + app/views/issues/show.html.erb | 1 + app/views/notes/show.html.erb | 1 + app/views/qa/issues/show.html.erb | 1 + 4 files changed, 4 insertions(+) diff --git a/app/views/evidence/show.html.erb b/app/views/evidence/show.html.erb index b1576fd03..9dbfddc86 100644 --- a/app/views/evidence/show.html.erb +++ b/app/views/evidence/show.html.erb @@ -30,6 +30,7 @@

Evidence for this instance + <%= render partial: 'shared/liquid_loading' %> <%= render partial: 'actions' %>

diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index 6ff2ec3d3..1ebbe1fc5 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -33,6 +33,7 @@

<%= @issue.title %> + <%= render partial: 'shared/liquid_loading' %> <%= render partial: 'actions' %>

diff --git a/app/views/notes/show.html.erb b/app/views/notes/show.html.erb index 6772b83a2..db589456c 100644 --- a/app/views/notes/show.html.erb +++ b/app/views/notes/show.html.erb @@ -21,6 +21,7 @@

<%= @note.title %> + <%= render partial: 'shared/liquid_loading' %> <%= render partial: 'actions' %>

diff --git a/app/views/qa/issues/show.html.erb b/app/views/qa/issues/show.html.erb index d7b32177c..f834f9262 100644 --- a/app/views/qa/issues/show.html.erb +++ b/app/views/qa/issues/show.html.erb @@ -21,6 +21,7 @@

<%= @issue.title %> + <%= render partial: 'shared/liquid_loading' %> <%= link_to edit_project_qa_issue_path(current_project, @issue) do %> From 499c2ac94a4e34ffa5b032ffe3b1832ce2c95595 Mon Sep 17 00:00:00 2001 From: Matt Budz Date: Tue, 4 Jun 2024 16:51:15 +0200 Subject: [PATCH 18/41] hide spinner once liquid is rendered --- .../tylium/modules/liquid_async.js | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/tylium/modules/liquid_async.js b/app/assets/javascripts/tylium/modules/liquid_async.js index d1cc4984a..c3551f3a0 100644 --- a/app/assets/javascripts/tylium/modules/liquid_async.js +++ b/app/assets/javascripts/tylium/modules/liquid_async.js @@ -1,20 +1,22 @@ document.addEventListener('turbolinks:load', function () { - $('[data-behavior~=liquid-async]').each(function() { - var that = this, - data = { text: $(that).attr('data-content') }; + $('[data-behavior~=liquid-async]').each(function () { + const that = this, + data = { text: $(that).attr('data-content') }, + $spinner = $(that).prev().find('[data-behavior~=liquid-spinner'); fetch($(that).attr('data-path'), { method: 'POST', headers: { - "Accept": "text/html", - "Content-Type": "application/json", - "X-CSRF-Token": $('meta[name="csrf-token"]').attr('content') + Accept: 'text/html', + 'Content-Type': 'application/json', + 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content'), }, - body: JSON.stringify(data) - }). - then(response => response.text()). - then(function(html) { - $(that).html(html); - }); + body: JSON.stringify(data), + }) + .then((response) => response.text()) + .then(function (html) { + $(that).html(html); + $spinner.addClass('d-none'); + }); }); }); From f18b19004b75f0a62261df4800ddb3ee1ba1efcb Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Wed, 5 Jun 2024 15:18:38 +0800 Subject: [PATCH 19/41] Fix specs and remove artificial sleep --- app/controllers/concerns/liquid_enabled_resource.rb | 2 -- spec/features/evidence_spec.rb | 2 +- spec/features/issues_spec.rb | 2 +- spec/features/note_pages_spec.rb | 2 +- spec/support/liquid_shared_examples.rb | 3 ++- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/controllers/concerns/liquid_enabled_resource.rb b/app/controllers/concerns/liquid_enabled_resource.rb index e23863ce9..a8f8216e3 100644 --- a/app/controllers/concerns/liquid_enabled_resource.rb +++ b/app/controllers/concerns/liquid_enabled_resource.rb @@ -15,8 +15,6 @@ def liquid_resource_assigns end def preview - # Artificial load time for testing - sleep 3 @text = params[:text] render 'markup/preview', layout: false end diff --git a/spec/features/evidence_spec.rb b/spec/features/evidence_spec.rb index de5866929..7246b19cc 100644 --- a/spec/features/evidence_spec.rb +++ b/spec/features/evidence_spec.rb @@ -80,7 +80,7 @@ let(:model) { @evidence } include_examples 'nodes pages breadcrumbs', :show, Evidence - describe 'when including liquid content' do + describe 'when including liquid content', js: true do let(:record) { create(:evidence, :with_liquid, issue: @issue, node: @node) } include_examples 'liquid dynamic content', 'evidence', true end diff --git a/spec/features/issues_spec.rb b/spec/features/issues_spec.rb index 178702dd8..a2642cb10 100644 --- a/spec/features/issues_spec.rb +++ b/spec/features/issues_spec.rb @@ -412,7 +412,7 @@ end end - describe 'when including liquid content' do + describe 'when including liquid content', js: true do let(:record) { create(:issue, :with_liquid, node: issuelib) } include_examples 'liquid dynamic content', 'issue', false end diff --git a/spec/features/note_pages_spec.rb b/spec/features/note_pages_spec.rb index c71b53881..bb9a71d28 100644 --- a/spec/features/note_pages_spec.rb +++ b/spec/features/note_pages_spec.rb @@ -77,7 +77,7 @@ let(:model) { @note } include_examples 'nodes pages breadcrumbs', :show, Note - describe 'when including liquid content' do + describe 'when including liquid content', js: true do let(:record) { create(:note, :with_liquid, node: @node) } include_examples 'liquid dynamic content', 'note', true end diff --git a/spec/support/liquid_shared_examples.rb b/spec/support/liquid_shared_examples.rb index 713c1e731..7216e3eb2 100644 --- a/spec/support/liquid_shared_examples.rb +++ b/spec/support/liquid_shared_examples.rb @@ -10,13 +10,14 @@ end it 'dynamically renders item properties' do + expect(page).to have_no_css('span.text-nowrap', text: 'Loading liquid dynamic content', wait: 10) + expect(find('.note-text-inner')).to have_content("Liquid: #{record.title}") expect(find('.note-text-inner')).not_to have_content("Liquid: {{#{item_type}.title}}") end end shared_examples 'liquid preview' do |item_type, node_association| - before do @path = if node_association polymorphic_path([:edit, current_project, record.node, record]) From 89c96ebe96587615a248691bcb31022d3bf99a43 Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Wed, 5 Jun 2024 15:56:55 +0800 Subject: [PATCH 20/41] Fix QA issues spec --- spec/support/qa_shared_examples.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/support/qa_shared_examples.rb b/spec/support/qa_shared_examples.rb index de078dba6..ff7ad5395 100644 --- a/spec/support/qa_shared_examples.rb +++ b/spec/support/qa_shared_examples.rb @@ -78,7 +78,9 @@ visit polymorphic_path([current_project, :qa, record]) end - it 'parses liquid content' do + it 'parses liquid content', js: true do + expect(page).to have_no_css('span.text-nowrap', text: 'Loading liquid dynamic content', wait: 10) + expect(find('.note-text-inner')).to have_content("Liquid: #{record.title}") expect(find('.note-text-inner')).not_to have_content("Liquid: {{#{item_type.to_s}.title}}") end From a87d0bfdc091d08c6dd122484049c9af2d227bd3 Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Wed, 5 Jun 2024 19:08:57 +0800 Subject: [PATCH 21/41] Move js: true to the shared example --- spec/features/evidence_spec.rb | 2 +- spec/features/issues_spec.rb | 2 +- spec/features/note_pages_spec.rb | 2 +- spec/support/liquid_shared_examples.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/features/evidence_spec.rb b/spec/features/evidence_spec.rb index 7246b19cc..de5866929 100644 --- a/spec/features/evidence_spec.rb +++ b/spec/features/evidence_spec.rb @@ -80,7 +80,7 @@ let(:model) { @evidence } include_examples 'nodes pages breadcrumbs', :show, Evidence - describe 'when including liquid content', js: true do + describe 'when including liquid content' do let(:record) { create(:evidence, :with_liquid, issue: @issue, node: @node) } include_examples 'liquid dynamic content', 'evidence', true end diff --git a/spec/features/issues_spec.rb b/spec/features/issues_spec.rb index a2642cb10..178702dd8 100644 --- a/spec/features/issues_spec.rb +++ b/spec/features/issues_spec.rb @@ -412,7 +412,7 @@ end end - describe 'when including liquid content', js: true do + describe 'when including liquid content' do let(:record) { create(:issue, :with_liquid, node: issuelib) } include_examples 'liquid dynamic content', 'issue', false end diff --git a/spec/features/note_pages_spec.rb b/spec/features/note_pages_spec.rb index bb9a71d28..c71b53881 100644 --- a/spec/features/note_pages_spec.rb +++ b/spec/features/note_pages_spec.rb @@ -77,7 +77,7 @@ let(:model) { @note } include_examples 'nodes pages breadcrumbs', :show, Note - describe 'when including liquid content', js: true do + describe 'when including liquid content' do let(:record) { create(:note, :with_liquid, node: @node) } include_examples 'liquid dynamic content', 'note', true end diff --git a/spec/support/liquid_shared_examples.rb b/spec/support/liquid_shared_examples.rb index 7216e3eb2..d49f39beb 100644 --- a/spec/support/liquid_shared_examples.rb +++ b/spec/support/liquid_shared_examples.rb @@ -9,7 +9,7 @@ visit @path end - it 'dynamically renders item properties' do + it 'dynamically renders item properties', js: true do expect(page).to have_no_css('span.text-nowrap', text: 'Loading liquid dynamic content', wait: 10) expect(find('.note-text-inner')).to have_content("Liquid: #{record.title}") From 79a26dc3d0163d1c76903d2d5ae03aed5b0de563 Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Thu, 6 Jun 2024 16:46:34 +0800 Subject: [PATCH 22/41] Use Liquid::VariableLookup to determine which liquid assign we need --- .../concerns/liquid_enabled_resource.rb | 2 +- app/services/liquid_assigns_service.rb | 43 ++++++++++++++----- spec/services/liquid_assigns_service_spec.rb | 35 +++++++++++---- 3 files changed, 59 insertions(+), 21 deletions(-) diff --git a/app/controllers/concerns/liquid_enabled_resource.rb b/app/controllers/concerns/liquid_enabled_resource.rb index a8f8216e3..1dac5829e 100644 --- a/app/controllers/concerns/liquid_enabled_resource.rb +++ b/app/controllers/concerns/liquid_enabled_resource.rb @@ -35,6 +35,6 @@ def project_assigns project = Project.find(params[:project_id]) authorize! :use, project - LiquidAssignsService.new(project).assigns + LiquidAssignsService.new(project: project, text: params[:text]).assigns end end diff --git a/app/services/liquid_assigns_service.rb b/app/services/liquid_assigns_service.rb index ceed78075..88cf164af 100644 --- a/app/services/liquid_assigns_service.rb +++ b/app/services/liquid_assigns_service.rb @@ -1,8 +1,11 @@ class LiquidAssignsService - attr_accessor :project + AVAILABLE_PROJECT_ASSIGNS = %w{ evidences issues nodes notes tags }.freeze - def initialize(project) + attr_accessor :project, :text + + def initialize(project:, text: nil) @project = project + @text = text end def assigns @@ -16,15 +19,13 @@ def assigns def assigns_pro end - def project_assigns - { - 'evidences' => cached_drops(project.evidence), - 'issues' => cached_drops(project.issues), - 'nodes' => cached_drops(project.nodes.user_nodes), - 'notes' => cached_drops(project.notes), - 'project' => ProjectDrop.new(project), - 'tags' => cached_drops(project.tags) - } + # This method uses Liquid::VariableLookup to find all liquid variables from + # a given text. We use the list to know which project assign we need. + def assigns_from_content + return AVAILABLE_PROJECT_ASSIGNS if text.nil? + + variable_lookup = Liquid::VariableLookup.parse(text) + return (variable_lookup.lookups & AVAILABLE_PROJECT_ASSIGNS) end def cached_drops(records) @@ -38,4 +39,24 @@ def cached_drops(records) records.map { |record| drop_class.new(record) } end end + + def project_assigns + project_assigns = { 'project' => ProjectDrop.new(project) } + + assigns_from_content.each do |var| + records = + case var + when 'evidences' + project.evidence + when 'nodes' + project.nodes.user_nodes + else + project.send(var.to_sym) + end + + project_assigns.merge!(var => cached_drops(records)) + end + + project_assigns + end end diff --git a/spec/services/liquid_assigns_service_spec.rb b/spec/services/liquid_assigns_service_spec.rb index 418cdc0c3..5e1fd0796 100644 --- a/spec/services/liquid_assigns_service_spec.rb +++ b/spec/services/liquid_assigns_service_spec.rb @@ -3,8 +3,6 @@ RSpec.describe LiquidAssignsService do let!(:project) { create(:project) } - let(:liquid_assigns) { described_class.new(project).assigns } - before do node = create(:node, project: project) issue = create(:issue, node: project.issue_library) @@ -13,16 +11,35 @@ create(:tag) end - it 'builds a hash of liquid assigns' do - expect(liquid_assigns['project'].name).to eq(project.name) - expect(liquid_assigns['issues'].map(&:title)).to eq(project.issues.map(&:title)) - expect(liquid_assigns['evidences'].map(&:title)).to eq(project.evidence.map(&:title)) - expect(liquid_assigns['nodes'].map(&:label)).to eq(project.nodes.user_nodes.map(&:label)) - expect(liquid_assigns['notes'].map(&:title)).to eq(project.notes.map(&:title)) - expect(liquid_assigns['tags'].map(&:display_name)).to eq(project.tags.map(&:display_name)) + describe '#project_assigns' do + context 'with the :text argument' do + LiquidAssignsService::AVAILABLE_PROJECT_ASSIGNS.each do |assign| + it "adds #{assign} to the project_assigns if present in the text" do + text = "#[Description]#\n {% for #{assign.singularize} in #{assign} %}{% endfor %}\n" + liquid_assigns = described_class.new(project: project, text: text).assigns + + expect(liquid_assigns.keys).to include(assign) + end + end + end + + context 'without the :text argument' do + let(:liquid_assigns) { described_class.new(project: project).assigns } + + it 'builds a hash of liquid assigns' do + expect(liquid_assigns['project'].name).to eq(project.name) + expect(liquid_assigns['issues'].map(&:title)).to eq(project.issues.map(&:title)) + expect(liquid_assigns['evidences'].map(&:title)).to eq(project.evidence.map(&:title)) + expect(liquid_assigns['nodes'].map(&:label)).to eq(project.nodes.user_nodes.map(&:label)) + expect(liquid_assigns['notes'].map(&:title)).to eq(project.notes.map(&:title)) + expect(liquid_assigns['tags'].map(&:display_name)).to eq(project.tags.map(&:display_name)) + end + end end context 'with pro records', skip: !defined?(Dradis::Pro) do + let(:liquid_assigns) { described_class.new(project: project).assigns } + let!(:project) { create(:project, :with_team) } before do From 8f292f22e2e98e5c6707852cacb48ec17ef6d387 Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Thu, 6 Jun 2024 16:49:16 +0800 Subject: [PATCH 23/41] Bump rails to 7.0.8.4 --- Gemfile | 2 +- Gemfile.lock | 108 +++++++++++++++++++++++++-------------------------- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/Gemfile b/Gemfile index 49d7fafc6..c9a27905b 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '3.1.2' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 7.0.8.3' +gem 'rails', '~> 7.0.8.4' # Use SCSS for stylesheets gem 'sass-rails', '~> 6.0' diff --git a/Gemfile.lock b/Gemfile.lock index 401303803..09df6b029 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,67 +8,67 @@ GEM remote: https://rubygems.org/ specs: RedCloth (4.3.2) - actioncable (7.0.8.3) - actionpack (= 7.0.8.3) - activesupport (= 7.0.8.3) + actioncable (7.0.8.4) + actionpack (= 7.0.8.4) + activesupport (= 7.0.8.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.8.3) - actionpack (= 7.0.8.3) - activejob (= 7.0.8.3) - activerecord (= 7.0.8.3) - activestorage (= 7.0.8.3) - activesupport (= 7.0.8.3) + actionmailbox (7.0.8.4) + actionpack (= 7.0.8.4) + activejob (= 7.0.8.4) + activerecord (= 7.0.8.4) + activestorage (= 7.0.8.4) + activesupport (= 7.0.8.4) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.8.3) - actionpack (= 7.0.8.3) - actionview (= 7.0.8.3) - activejob (= 7.0.8.3) - activesupport (= 7.0.8.3) + actionmailer (7.0.8.4) + actionpack (= 7.0.8.4) + actionview (= 7.0.8.4) + activejob (= 7.0.8.4) + activesupport (= 7.0.8.4) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) - actionpack (7.0.8.3) - actionview (= 7.0.8.3) - activesupport (= 7.0.8.3) + actionpack (7.0.8.4) + actionview (= 7.0.8.4) + activesupport (= 7.0.8.4) rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.8.3) - actionpack (= 7.0.8.3) - activerecord (= 7.0.8.3) - activestorage (= 7.0.8.3) - activesupport (= 7.0.8.3) + actiontext (7.0.8.4) + actionpack (= 7.0.8.4) + activerecord (= 7.0.8.4) + activestorage (= 7.0.8.4) + activesupport (= 7.0.8.4) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.8.3) - activesupport (= 7.0.8.3) + actionview (7.0.8.4) + activesupport (= 7.0.8.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.8.3) - activesupport (= 7.0.8.3) + activejob (7.0.8.4) + activesupport (= 7.0.8.4) globalid (>= 0.3.6) - activemodel (7.0.8.3) - activesupport (= 7.0.8.3) - activerecord (7.0.8.3) - activemodel (= 7.0.8.3) - activesupport (= 7.0.8.3) - activestorage (7.0.8.3) - actionpack (= 7.0.8.3) - activejob (= 7.0.8.3) - activerecord (= 7.0.8.3) - activesupport (= 7.0.8.3) + activemodel (7.0.8.4) + activesupport (= 7.0.8.4) + activerecord (7.0.8.4) + activemodel (= 7.0.8.4) + activesupport (= 7.0.8.4) + activestorage (7.0.8.4) + actionpack (= 7.0.8.4) + activejob (= 7.0.8.4) + activerecord (= 7.0.8.4) + activesupport (= 7.0.8.4) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.8.3) + activesupport (7.0.8.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -335,20 +335,20 @@ GEM rack rack-test (2.1.0) rack (>= 1.3) - rails (7.0.8.3) - actioncable (= 7.0.8.3) - actionmailbox (= 7.0.8.3) - actionmailer (= 7.0.8.3) - actionpack (= 7.0.8.3) - actiontext (= 7.0.8.3) - actionview (= 7.0.8.3) - activejob (= 7.0.8.3) - activemodel (= 7.0.8.3) - activerecord (= 7.0.8.3) - activestorage (= 7.0.8.3) - activesupport (= 7.0.8.3) + rails (7.0.8.4) + actioncable (= 7.0.8.4) + actionmailbox (= 7.0.8.4) + actionmailer (= 7.0.8.4) + actionpack (= 7.0.8.4) + actiontext (= 7.0.8.4) + actionview (= 7.0.8.4) + activejob (= 7.0.8.4) + activemodel (= 7.0.8.4) + activerecord (= 7.0.8.4) + activestorage (= 7.0.8.4) + activesupport (= 7.0.8.4) bundler (>= 1.15.0) - railties (= 7.0.8.3) + railties (= 7.0.8.4) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -359,9 +359,9 @@ GEM actionview (> 3.1) activesupport (> 3.1) railties (> 3.1) - railties (7.0.8.3) - actionpack (= 7.0.8.3) - activesupport (= 7.0.8.3) + railties (7.0.8.4) + actionpack (= 7.0.8.4) + activesupport (= 7.0.8.4) method_source rake (>= 12.2) thor (~> 1.0) @@ -581,7 +581,7 @@ DEPENDENCIES pg puma (>= 6.4.2) rack-mini-profiler (~> 2.0) - rails (~> 7.0.8.3) + rails (~> 7.0.8.4) rails-html-sanitizer (~> 1.4.4) record_tag_helper rerun From 3cfd946c9112226d066da9f62d49f2efeda2553f Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Mon, 10 Jun 2024 15:58:41 +0800 Subject: [PATCH 24/41] Apply requested changes --- CHANGELOG | 2 +- app/services/liquid_assigns_service.rb | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 34dfcb4f4..4968516d7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,5 @@ [v#.#.#] ([month] [YYYY]) - - Liquid: Make project-level drops available for Liquid syntax + - Liquid: Make project-level collections available for Liquid syntax - Upgraded gems: nokogiri, rails, rexml - Bugs fixes: - [entity]: diff --git a/app/services/liquid_assigns_service.rb b/app/services/liquid_assigns_service.rb index 88cf164af..b781c77b6 100644 --- a/app/services/liquid_assigns_service.rb +++ b/app/services/liquid_assigns_service.rb @@ -28,12 +28,11 @@ def assigns_from_content return (variable_lookup.lookups & AVAILABLE_PROJECT_ASSIGNS) end - def cached_drops(records) + def cached_drops(records, record_type) return [] if records.empty? - type = records.first.class.to_s.underscore - cache_key = "liquid-project-#{project.id}-#{type.pluralize}:#{records.maximum(:updated_at).to_i}-#{records.count}" - drop_class = "#{type.camelize}Drop".constantize + cache_key = "liquid-project-#{project.id}-#{record_type.pluralize}:#{records.maximum(:updated_at).to_i}-#{records.count}" + drop_class = "#{record_type.camelize}Drop".constantize Rails.cache.fetch(cache_key) do records.map { |record| drop_class.new(record) } @@ -43,18 +42,18 @@ def cached_drops(records) def project_assigns project_assigns = { 'project' => ProjectDrop.new(project) } - assigns_from_content.each do |var| + assigns_from_content.each do |record_type| records = - case var + case record_type when 'evidences' project.evidence when 'nodes' project.nodes.user_nodes else - project.send(var.to_sym) + project.send(record_type.to_sym) end - project_assigns.merge!(var => cached_drops(records)) + project_assigns.merge!(record_type => cached_drops(records, record_type.singularize)) end project_assigns From 1c77ace083ff42952e6984416c41aceec6476476 Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Thu, 13 Jun 2024 15:38:54 +0800 Subject: [PATCH 25/41] Add textile_content partial --- app/views/evidence/show.html.erb | 4 +--- app/views/issues/show.html.erb | 4 +--- app/views/notes/show.html.erb | 4 +--- app/views/qa/issues/show.html.erb | 4 +--- app/views/shared/_textile_content.html.erb | 5 +++++ 5 files changed, 9 insertions(+), 12 deletions(-) create mode 100644 app/views/shared/_textile_content.html.erb diff --git a/app/views/evidence/show.html.erb b/app/views/evidence/show.html.erb index 9dbfddc86..f971355f3 100644 --- a/app/views/evidence/show.html.erb +++ b/app/views/evidence/show.html.erb @@ -33,9 +33,7 @@ <%= render partial: 'shared/liquid_loading' %> <%= render partial: 'actions' %>

-
- <%= markup(@evidence.content) %> -
+ <%= render partial: 'shared/textile_content', locals: { record: @evidence, preview_path: preview_project_node_evidence_path(current_project, @evidence.node, @evidence) } %>
Author: <%= @evidence.author || 'n/a' %>
diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index 1ebbe1fc5..23f9ac46d 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -36,9 +36,7 @@ <%= render partial: 'shared/liquid_loading' %> <%= render partial: 'actions' %> -
- <%= markup(@issue.text) %> -
+ <%= render partial: 'shared/textile_content', locals: { record: @issue, preview_path: preview_project_issue_path(current_project, @issue) } %>
Author: <%= @issue.author || 'n/a' %>
diff --git a/app/views/notes/show.html.erb b/app/views/notes/show.html.erb index db589456c..4a65d4564 100644 --- a/app/views/notes/show.html.erb +++ b/app/views/notes/show.html.erb @@ -24,9 +24,7 @@ <%= render partial: 'shared/liquid_loading' %> <%= render partial: 'actions' %> -
- <%= markup(@note.text) %> -
+ <%= render partial: 'shared/textile_content', locals: { record: @note, preview_path: preview_project_node_note_path(current_project, @note.node, @note) } %>
Author: <%= @note.author || 'n/a' %>
diff --git a/app/views/qa/issues/show.html.erb b/app/views/qa/issues/show.html.erb index f834f9262..96123a8a4 100644 --- a/app/views/qa/issues/show.html.erb +++ b/app/views/qa/issues/show.html.erb @@ -30,9 +30,7 @@ -
- <%= markup(@issue.text) %> -
+ <%= render partial: 'shared/textile_content', locals: { record: @issue, preview_path: preview_project_issue_path(current_project, @issue) } %>
Author: <%= @issue.author || 'n/a' %>
diff --git a/app/views/shared/_textile_content.html.erb b/app/views/shared/_textile_content.html.erb new file mode 100644 index 000000000..63cc85ee5 --- /dev/null +++ b/app/views/shared/_textile_content.html.erb @@ -0,0 +1,5 @@ +<% content = record.is_a?(Note) ? record.text : record.content %> + +<%= content_tag :div, class: 'content-textile', data: { behavior: 'content-textile liquid-async', path: preview_path, content: content } do %> + <%= markup(content) %> +<% end %> From eb563248b50e41d32dc4b5a3ceea937621012715 Mon Sep 17 00:00:00 2001 From: Daniel Martin <53006+etdsoft@users.noreply.github.com> Date: Fri, 14 Jun 2024 17:20:01 +0200 Subject: [PATCH 26/41] README.md - add Follow X badge --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e5ab3ce76..9ab7ac52c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Welcome to the Dradis Framework -[ ![CI](https://github.com/dradis/dradis-ce/actions/workflows/ci.yml/badge.svg)](https://github.com/dradis/dradis-ce/actions/workflows/ci.yml) -[ ![Code quality](https://codeclimate.com/github/dradis/dradis-ce/badges/gpa.svg)](https://codeclimate.com/github/dradis/dradis-ce) -[ ![Black Hat Arsenal](https://www.toolswatch.org/badges/arsenal/2016.svg)](https://www.blackhat.com/us-16/arsenal.html#dradis-framework) +[![CI](https://github.com/dradis/dradis-ce/actions/workflows/ci.yml/badge.svg)](https://github.com/dradis/dradis-ce/actions/workflows/ci.yml) +[![Black Hat Arsenal](https://www.toolswatch.org/badges/arsenal/2016.svg)](https://www.blackhat.com/us-16/arsenal.html#dradis-framework) +[![@dradisfw on X](https://img.shields.io/twitter/follow/dradisfw?style=social)](https://twitter.com/dradisfw) Dradis is an open-source collaboration framework, tailored to InfoSec teams. From 0eeb76811139f1ccbc4c0734d7ccb211a5c9df58 Mon Sep 17 00:00:00 2001 From: Matt Budz Date: Fri, 14 Jun 2024 17:44:00 +0200 Subject: [PATCH 27/41] add trigger to manually run CI on any branch --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1bf1a64eb..67412b781 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,7 @@ on: branches: ['*'] push: branches: [develop, main] + workflow_dispatch: jobs: audits: From 4448e45f057d5d9a89fb724ce7e841698b67e882 Mon Sep 17 00:00:00 2001 From: Caitlin Date: Fri, 14 Jun 2024 15:42:43 -0400 Subject: [PATCH 28/41] add service properties constant so that we can reuse it across the application --- app/models/concerns/node_properties.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/node_properties.rb b/app/models/concerns/node_properties.rb index 8a9dd3166..ca92c7661 100644 --- a/app/models/concerns/node_properties.rb +++ b/app/models/concerns/node_properties.rb @@ -19,12 +19,13 @@ def self.included(base) end SERVICE_KEYS = %i[protocol port state product reason name version] + SERVICE_PROPERTIES = %i[services services_extras] # -------------------------------------------- Individual property management # Sets a property, storing value as Array when needed # and taking care of duplications def set_property(key, value) - if [:services, :services_extras].include?(key.to_sym) # let's get defensive + if SERVICE_PROPERTIES.include?(key.to_sym) # let's get defensive raise ArgumentError, 'don\'t use set_property for :services or '\ ':services_extras, use set_service instead' end @@ -101,7 +102,6 @@ def set_service(data) end end - # -------------------------------------- :raw_properties accessors for the UI def raw_properties if self.has_any_property? From 385e1a3b5467a9656bd9f855472293e0085f1f56 Mon Sep 17 00:00:00 2001 From: Caitlin Date: Fri, 14 Jun 2024 15:54:09 -0400 Subject: [PATCH 29/41] use strings instead of symbols --- app/models/concerns/node_properties.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/node_properties.rb b/app/models/concerns/node_properties.rb index ca92c7661..54c547e00 100644 --- a/app/models/concerns/node_properties.rb +++ b/app/models/concerns/node_properties.rb @@ -19,13 +19,13 @@ def self.included(base) end SERVICE_KEYS = %i[protocol port state product reason name version] - SERVICE_PROPERTIES = %i[services services_extras] + SERVICE_PROPERTIES = %w[services services_extras] # -------------------------------------------- Individual property management # Sets a property, storing value as Array when needed # and taking care of duplications def set_property(key, value) - if SERVICE_PROPERTIES.include?(key.to_sym) # let's get defensive + if SERVICE_PROPERTIES.include?(key.to_s) # let's get defensive raise ArgumentError, 'don\'t use set_property for :services or '\ ':services_extras, use set_service instead' end From 43eabd7dad727d2d30552cdfd1eff9cd9cc1584a Mon Sep 17 00:00:00 2001 From: Matt Budz Date: Mon, 17 Jun 2024 14:47:19 +0200 Subject: [PATCH 30/41] prevent multiple eventListener binds on tab change --- app/assets/javascripts/shared/behaviors.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/shared/behaviors.js b/app/assets/javascripts/shared/behaviors.js index cd6ac4f75..f2d3267ce 100644 --- a/app/assets/javascripts/shared/behaviors.js +++ b/app/assets/javascripts/shared/behaviors.js @@ -81,11 +81,13 @@ } // Update address bar with current tab param - $('[data-bs-toggle~=tab]').on('shown.bs.tab', function (e) { - let currentTab = $(e.target).attr('href').substring(1); - searchParams.set('tab', currentTab); - history.pushState(null, null, `?${searchParams.toString()}`); - }); + $('[data-bs-toggle~=tab]') + .unbind() + .on('shown.bs.tab', function (e) { + let currentTab = $(e.target).attr('href').substring(1); + searchParams.set('tab', currentTab); + history.pushState(null, null, `?${searchParams.toString()}`); + }); } document.addEventListener('turbolinks:load', function () { From 63c6e82de67871f622b1e64724e658f3f7d0e339 Mon Sep 17 00:00:00 2001 From: Matt Budz Date: Mon, 17 Jun 2024 14:49:07 +0200 Subject: [PATCH 31/41] navigate to tabbed pages using browser back button --- app/assets/javascripts/shared/behaviors.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/assets/javascripts/shared/behaviors.js b/app/assets/javascripts/shared/behaviors.js index f2d3267ce..a78b53c84 100644 --- a/app/assets/javascripts/shared/behaviors.js +++ b/app/assets/javascripts/shared/behaviors.js @@ -88,6 +88,14 @@ searchParams.set('tab', currentTab); history.pushState(null, null, `?${searchParams.toString()}`); }); + + // Allows users to navigate using the native browser back/forward buttons + // even when we manipulate the browser history with pushState() + $(window) + .unbind() + .on('popstate', function () { + location.reload(); + }); } document.addEventListener('turbolinks:load', function () { From 0c6ae00d962d18680c78e3d31b830b1e6d120794 Mon Sep 17 00:00:00 2001 From: Matt Budz Date: Mon, 17 Jun 2024 14:50:58 +0200 Subject: [PATCH 32/41] update changelog --- CHANGELOG | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4968516d7..3a90ae93a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,8 +2,7 @@ - Liquid: Make project-level collections available for Liquid syntax - Upgraded gems: nokogiri, rails, rexml - Bugs fixes: - - [entity]: - - [future tense verb] [bug fix] + - Navigation: Restore functionality of native browser back/forward buttons - Bug tracker items: - [item] - New integrations: From af6882bc5ba7c048b33716cb435edefeaf64ab28 Mon Sep 17 00:00:00 2001 From: Caitlin Date: Mon, 17 Jun 2024 17:35:34 -0400 Subject: [PATCH 33/41] include dradis-pentera --- Gemfile | 1 + Gemfile.lock | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Gemfile b/Gemfile index c9a27905b..371456986 100644 --- a/Gemfile +++ b/Gemfile @@ -254,6 +254,7 @@ gem 'dradis-nipper', '~> 4.12.0' gem 'dradis-nmap', '~> 4.12.0' gem 'dradis-ntospider', '~> 4.12.0' gem 'dradis-openvas', '~> 4.12.0' +gem 'dradis-pentera', '~> 4.12.0' gem 'dradis-qualys', '~> 4.12.0' gem 'dradis-saint', '~> 4.12.0' gem 'dradis-veracode', '~> 4.12.0' diff --git a/Gemfile.lock b/Gemfile.lock index 09df6b029..1116cb2a2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -171,6 +171,8 @@ GEM dradis-plugins (~> 4.0) dradis-openvas (4.12.0) dradis-plugins (~> 4.0) + dradis-pentera (4.12.0) + dradis-plugins (~> 4.0) dradis-plugins (4.12.1) dradis-projects (4.12.0) dradis-plugins (>= 4.8.0) @@ -546,6 +548,7 @@ DEPENDENCIES dradis-nmap (~> 4.12.0) dradis-ntospider (~> 4.12.0) dradis-openvas (~> 4.12.0) + dradis-pentera (~> 4.12.0) dradis-plugins (~> 4.12.1) dradis-projects (~> 4.12.0) dradis-qualys (~> 4.12.0) From 2b28481b6675a63bf75db35ad961a93dbe675239 Mon Sep 17 00:00:00 2001 From: Matt Budz Date: Tue, 18 Jun 2024 11:53:53 +0200 Subject: [PATCH 34/41] limit scope of eventLister to prevent N bindings --- app/assets/javascripts/shared/behaviors.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/shared/behaviors.js b/app/assets/javascripts/shared/behaviors.js index a78b53c84..059d14f4e 100644 --- a/app/assets/javascripts/shared/behaviors.js +++ b/app/assets/javascripts/shared/behaviors.js @@ -81,8 +81,8 @@ } // Update address bar with current tab param - $('[data-bs-toggle~=tab]') - .unbind() + $(parentElement) + .find('[data-bs-toggle~=tab]') .on('shown.bs.tab', function (e) { let currentTab = $(e.target).attr('href').substring(1); searchParams.set('tab', currentTab); @@ -91,11 +91,9 @@ // Allows users to navigate using the native browser back/forward buttons // even when we manipulate the browser history with pushState() - $(window) - .unbind() - .on('popstate', function () { - location.reload(); - }); + $(window).on('popstate', function () { + location.reload(); + }); } document.addEventListener('turbolinks:load', function () { From 2980a098270a0415388ef0fa77725a1a4f54f6b3 Mon Sep 17 00:00:00 2001 From: Matt Budz Date: Wed, 19 Jun 2024 15:09:57 +0200 Subject: [PATCH 35/41] navigate with `Turbolinks` vs `location.reload()` --- app/assets/javascripts/shared/behaviors.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/shared/behaviors.js b/app/assets/javascripts/shared/behaviors.js index 059d14f4e..6563983fd 100644 --- a/app/assets/javascripts/shared/behaviors.js +++ b/app/assets/javascripts/shared/behaviors.js @@ -86,14 +86,19 @@ .on('shown.bs.tab', function (e) { let currentTab = $(e.target).attr('href').substring(1); searchParams.set('tab', currentTab); - history.pushState(null, null, `?${searchParams.toString()}`); + let urlWithTab = `?${searchParams.toString()}`; + history.replaceState(null, null, urlWithTab); }); // Allows users to navigate using the native browser back/forward buttons // even when we manipulate the browser history with pushState() - $(window).on('popstate', function () { - location.reload(); - }); + $(window) + .off() + .on('popstate', function () { + if (location.search.length) { + Turbolinks.visit(location, { action: 'replace' }); + } + }); } document.addEventListener('turbolinks:load', function () { From 28fee462776e26a3b962cce57f8f5c2082e2e34d Mon Sep 17 00:00:00 2001 From: Matt Budz Date: Wed, 19 Jun 2024 15:14:30 +0200 Subject: [PATCH 36/41] add tab to history rather than replacing current history --- app/assets/javascripts/shared/behaviors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/shared/behaviors.js b/app/assets/javascripts/shared/behaviors.js index 6563983fd..29bdaa231 100644 --- a/app/assets/javascripts/shared/behaviors.js +++ b/app/assets/javascripts/shared/behaviors.js @@ -87,7 +87,7 @@ let currentTab = $(e.target).attr('href').substring(1); searchParams.set('tab', currentTab); let urlWithTab = `?${searchParams.toString()}`; - history.replaceState(null, null, urlWithTab); + history.pushState(null, null, urlWithTab); }); // Allows users to navigate using the native browser back/forward buttons From bbe4ba8203b390b9b0639b36c782c9ce2b41bb20 Mon Sep 17 00:00:00 2001 From: Caitlin Date: Wed, 19 Jun 2024 15:48:02 -0400 Subject: [PATCH 37/41] don't proceed if mappings table doesn't exist --- config/initializers/z_11_plugin_templates.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/config/initializers/z_11_plugin_templates.rb b/config/initializers/z_11_plugin_templates.rb index 13033bd46..65231ef56 100644 --- a/config/initializers/z_11_plugin_templates.rb +++ b/config/initializers/z_11_plugin_templates.rb @@ -11,9 +11,11 @@ # ---------------------------------------------------------------- 3.1 Upload template_dir = Configuration.paths_templates_plugins - Dradis::Plugins::with_feature(:upload).each do |integration| - integration.copy_samples(to: template_dir) - integration.migrate_templates_to_mappings(from: template_dir) + if Mapping.table_exists? + Dradis::Plugins::with_feature(:upload).each do |integration| + integration.copy_samples(to: template_dir) + integration.migrate_templates_to_mappings(from: template_dir) + end end # ---------------------------------------------------------------- 3.2 Export From a843e049ebf6ae88d6fd59c351a63f7496bc2998 Mon Sep 17 00:00:00 2001 From: Caitlin Date: Wed, 19 Jun 2024 15:48:48 -0400 Subject: [PATCH 38/41] add comment --- config/initializers/z_11_plugin_templates.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/z_11_plugin_templates.rb b/config/initializers/z_11_plugin_templates.rb index 65231ef56..ff2771fc9 100644 --- a/config/initializers/z_11_plugin_templates.rb +++ b/config/initializers/z_11_plugin_templates.rb @@ -10,7 +10,7 @@ if (ActiveRecord::Base.connection rescue false) && Configuration.table_exists? && Configuration.paths_templates.exist? # ---------------------------------------------------------------- 3.1 Upload template_dir = Configuration.paths_templates_plugins - + # mappings table may not exist when migrating from an old OVA to a new one so we need this guard if Mapping.table_exists? Dradis::Plugins::with_feature(:upload).each do |integration| integration.copy_samples(to: template_dir) From 5a18f7c5dec6892244df211768168f63a77f4b92 Mon Sep 17 00:00:00 2001 From: Caitlin Date: Wed, 19 Jun 2024 15:51:40 -0400 Subject: [PATCH 39/41] (backport) don't run migrate templates in test env --- config/initializers/z_11_plugin_templates.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/z_11_plugin_templates.rb b/config/initializers/z_11_plugin_templates.rb index ff2771fc9..14c00cbee 100644 --- a/config/initializers/z_11_plugin_templates.rb +++ b/config/initializers/z_11_plugin_templates.rb @@ -14,7 +14,7 @@ if Mapping.table_exists? Dradis::Plugins::with_feature(:upload).each do |integration| integration.copy_samples(to: template_dir) - integration.migrate_templates_to_mappings(from: template_dir) + integration.migrate_templates_to_mappings(from: template_dir) if !Rails.env.test? end end From d539c2d5ed068804487c7d41d5fe61e3298ed3e2 Mon Sep 17 00:00:00 2001 From: Caitlin Date: Thu, 20 Jun 2024 09:59:57 -0400 Subject: [PATCH 40/41] move mappings table existence check to existing if block --- config/initializers/z_11_plugin_templates.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/config/initializers/z_11_plugin_templates.rb b/config/initializers/z_11_plugin_templates.rb index 14c00cbee..4bfbb23f7 100644 --- a/config/initializers/z_11_plugin_templates.rb +++ b/config/initializers/z_11_plugin_templates.rb @@ -7,15 +7,16 @@ # Unless the DB is already migrated, do nothing Rails.application.reloader.to_prepare do - if (ActiveRecord::Base.connection rescue false) && Configuration.table_exists? && Configuration.paths_templates.exist? + if (ActiveRecord::Base.connection rescue false) && + Configuration.table_exists? && + Configuration.paths_templates.exist? && + Mapping.table_exists? # ---------------------------------------------------------------- 3.1 Upload template_dir = Configuration.paths_templates_plugins # mappings table may not exist when migrating from an old OVA to a new one so we need this guard - if Mapping.table_exists? - Dradis::Plugins::with_feature(:upload).each do |integration| - integration.copy_samples(to: template_dir) - integration.migrate_templates_to_mappings(from: template_dir) if !Rails.env.test? - end + Dradis::Plugins::with_feature(:upload).each do |integration| + integration.copy_samples(to: template_dir) + integration.migrate_templates_to_mappings(from: template_dir) if !Rails.env.test? end # ---------------------------------------------------------------- 3.2 Export From 489b982d4387894490c86ef25d9d13c06d5151d7 Mon Sep 17 00:00:00 2001 From: Matt Budz Date: Mon, 24 Jun 2024 18:11:12 +0200 Subject: [PATCH 41/41] set data in pushState to load page with tab param --- app/assets/javascripts/shared/behaviors.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/shared/behaviors.js b/app/assets/javascripts/shared/behaviors.js index 29bdaa231..9aa1e52a0 100644 --- a/app/assets/javascripts/shared/behaviors.js +++ b/app/assets/javascripts/shared/behaviors.js @@ -87,17 +87,11 @@ let currentTab = $(e.target).attr('href').substring(1); searchParams.set('tab', currentTab); let urlWithTab = `?${searchParams.toString()}`; - history.pushState(null, null, urlWithTab); - }); - - // Allows users to navigate using the native browser back/forward buttons - // even when we manipulate the browser history with pushState() - $(window) - .off() - .on('popstate', function () { - if (location.search.length) { - Turbolinks.visit(location, { action: 'replace' }); - } + history.pushState( + { turbolinks: true, url: urlWithTab }, + '', + urlWithTab + ); }); }