Skip to content

Commit

Permalink
Align issues in load_from_xml and to_xml for Patchinfo
Browse files Browse the repository at this point in the history
to_xml didn't have the issue URL. The fields were also not in the same
order in these 2 methods. This caused problems when updating a patchinfo
failed, which then rendered the edit view again, but with the missing
URL and fields in a different order. This resulted in issues not being
correctly rendered.

This happens because the edit action is initializing the patchinfo with
load_from_xml while the update action takes the data from the submitted
form without calling load_from_xml (to not override what the user
entered when validation errors happen). This wouldn't be an issue with
ActiveRecord.
  • Loading branch information
dmarcoux committed Apr 24, 2019
1 parent d3dee6e commit 5d6bbe4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/api/app/models/patchinfo.rb
Expand Up @@ -278,13 +278,10 @@ def load_from_xml(patchinfo_xml)
end
end

issue_tracker = IssueTracker.find_by_name(issue_element['tracker']).
try(:show_url_for, issue_element['id']).to_s

issues << [
issue_element['tracker'],
issue_element['id'],
issue_tracker,
issue_element['tracker'],
IssueTracker.find_by_name(issue_element['tracker']). try(:show_url_for, issue_element['id']).to_s,
issue_element['_content']
]
end
Expand Down Expand Up @@ -312,6 +309,7 @@ def to_xml(project, package)
issues << [
new_issue,
issuetracker[index],
IssueTracker.find_by_name(issuetracker[index]).try(:show_url_for, new_issue).to_s,
issuesum[index]
]
end
Expand All @@ -327,7 +325,7 @@ def to_xml(project, package)
issues.to_a.each do |issue|
# people tend to enter entire cve strings instead of just the name
issue[0].gsub!(/^(CVE|cve)-/, '') if issue[1] == 'cve'
node.issue(issue[2], tracker: issue[1], id: issue[0])
node.issue(issue[3], tracker: issue[1], id: issue[0])
end
node.category(category.try(:strip))
node.rating(rating.try(:strip))
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/webui2/webui/patchinfo/show.html.haml
Expand Up @@ -40,7 +40,7 @@
.media
%i.pt-1.mr-1.fas.fa-bug.text-danger
.media-body.mb-3
= patchinfo_issue_link(issue[0], issue[1], issue[2])
= patchinfo_issue_link(issue[1], issue[0], issue[2])
- if issue[3].present?
%small.d-block.text-muted= issue[3]
.col-md-6
Expand Down

0 comments on commit 5d6bbe4

Please sign in to comment.