Skip to content

Commit

Permalink
Merge pull request #1145 from dradis/liquid-tylium
Browse files Browse the repository at this point in the history
Add liquid resource assigns to tylium
  • Loading branch information
caitmich authored May 16, 2023
2 parents 0b191d9 + 79b9390 commit 5cdbd4c
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[v#.#.#] ([month] [YYYY])
- Tylium:
- Extend support for Liquid Dynamic Content
- QA: Show state changes in activity feed
- Upgraded gems:
- [gem]
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/evidence_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ def autogenerate_issue
track_created(@evidence.issue)
end

def liquid_resource_assigns
{
'evidence' => EvidenceDrop.new(@evidence),
'node' => NodeDrop.new(@evidence.node)
}
end

# Look for the Evidence we are going to be working with based on the :id
# passed by the user.
def set_or_initialize_evidence
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ def import
end

private

def liquid_resource_assigns
{ 'issue' => IssueDrop.new(@issue) }
end

def set_affected_nodes
@affected_nodes = Node.joins(:evidence)
.select('nodes.id, label, type_id, count(evidence.id) as evidence_count, nodes.updated_at')
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def find_or_initialize_note
end
end

def liquid_resource_assigns
{ 'note' => NoteDrop.new(@note) }
end

def note_params
params.require(:note).permit(:category_id, :text, :node_id)
end
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/qa/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def issue_params
params.permit(:state)
end

def liquid_resource_assigns
{ 'issue' => IssueDrop.new(@issue) }
end

def set_issue
@issue = @issues.find(params[:id])
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/evidence/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</h4>

<div class="content-textile" data-behavior="content-textile">
<%= markup(@evidence.content) %>
<%= markup(@evidence.content, liquid: true) %>
</div>
<div class="author-info">
<span class="ml-auto">Author: <%= @evidence.author || 'n/a' %></span>
Expand Down
2 changes: 1 addition & 1 deletion app/views/notes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<%= render partial: 'actions' %>
</h4>
<div class="content-textile" data-behavior="content-textile">
<%= markup(@note.text) %>
<%= markup(@note.text, liquid: true) %>
</div>
<div class="author-info">
<span class="ml-auto">Author: <%= @note.author || 'n/a' %></span>
Expand Down
7 changes: 5 additions & 2 deletions spec/features/evidence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

example 'show page with wrong Node ID in URL' do
node = create(:node)
evidence = create(:evidence, node:)
evidence = create(:evidence, node: node)
wrong_node = create(:node)
expect do
visit project_node_evidence_path(current_project, wrong_node, evidence)
Expand Down Expand Up @@ -79,14 +79,17 @@

let(:model) { @evidence }
include_examples 'nodes pages breadcrumbs', :show, Evidence

let(:record) { create(:evidence, issue: @issue, node: @node, content: "#[Title]#\nTitle\n\n#[Description]#\nLiquid: {{evidence.fields['Title']}}") }
include_examples 'liquid dynamic content', :evidence, true
end

describe 'edit page', js: true do
let(:submit_form) { click_button 'Update Evidence' }

before do
issue = create(:issue, node: issue_lib)
@evidence = create(:evidence, issue:, node: @node, updated_at: 2.seconds.ago)
@evidence = create(:evidence, issue: issue, node: @node, updated_at: 2.seconds.ago)
visit edit_project_node_evidence_path(current_project, @node, @evidence)
click_link 'Source'
end
Expand Down
3 changes: 3 additions & 0 deletions spec/features/issues_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@
expect(page).to have_text "(#{@issue.state.humanize})"
end
end

let(:record) { create(:issue, node: issuelib, updated_at: 2.seconds.ago, text: "#[Title]#\nTitle\n\n#[Description]#\nLiquid: {{issue.fields['Title']}}") }
include_examples 'liquid dynamic content', :issue, false
end
end

Expand Down
7 changes: 5 additions & 2 deletions spec/features/note_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

example 'show page with wrong Node ID in URL' do
node = create(:node, project: current_project)
note = create(:note, node:)
note = create(:note, node: node)
wrong_node = create(:node, project: current_project)
expect do
visit project_node_note_path(current_project, wrong_node, note)
Expand All @@ -26,7 +26,7 @@
describe 'show page' do
before do
text = "#[Title]#\nMy note\n\n#[Description]#\nMy description"
@note = create(:note, node: @node, text:)
@note = create(:note, node: @node, text: text)
create_activities
create_comments
visit project_node_note_path(current_project, @node, @note)
Expand Down Expand Up @@ -76,6 +76,9 @@

let(:model) { @note }
include_examples 'nodes pages breadcrumbs', :show, Note

let(:record) { create(:note, node: @node, content: "#[Title]#\nTitle\n\n#[Description]#\nLiquid: {{note.fields['Title']}}") }
include_examples 'liquid dynamic content', :note, true
end

describe 'edit page', js: true do
Expand Down
1 change: 1 addition & 0 deletions spec/features/qa/issues_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
let!(:records) do
create_list(:issue, 10, state: :ready_for_review, node: current_project.issue_library)
end
let(:record) { create(:issue, state: :ready_for_review, node: current_project.issue_library, content: "#[Title]#\nTitle\n\n#[Description]#\nLiquid: {{issue.fields['Title']}}") }

include_examples 'qa pages', :issue
end
Expand Down
16 changes: 16 additions & 0 deletions spec/support/liquid_shared_examples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
shared_examples 'liquid dynamic content' do |item_type, node_association|

if node_association
it 'dynamically renders item properties' do
visit polymorphic_path([current_project, record.node, record])
expect(find('.note-text-inner')).to have_content("Liquid: #{record.fields["Title"]}")
expect(find('.note-text-inner')).not_to have_content("Liquid: {{#{item_type}.fields['Title']}}")
end
else
it 'dynamically renders item properties' do
visit polymorphic_path([current_project, record])
expect(find('.note-text-inner')).to have_content("Liquid: #{record.fields["Title"]}")
expect(find('.note-text-inner')).not_to have_content("Liquid: {{#{item_type}.fields['Title']}}")
end
end
end
12 changes: 10 additions & 2 deletions spec/support/qa_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,17 @@
end

describe 'show page' do
before do
visit polymorphic_path([current_project, :qa, record])
end

it 'shows liquid content' do
expect(find('.note-text-inner')).to have_content("Liquid: #{record.fields["Title"]}")
expect(find('.note-text-inner')).not_to have_content("Liquid: {{#{item_type}.fields['Title']}}")
end

it 'shows the record\'s content' do
visit polymorphic_path([current_project, :qa, records.first])
expect(page).to have_content(records.first.title)
expect(page).to have_content(record.title)
end

it 'updates the state' do
Expand Down

0 comments on commit 5cdbd4c

Please sign in to comment.