Save viewpoint references in BCF comments

pull/7487/head
Wieland Lindenthal 5 years ago
parent 24c9ac498a
commit ae9ee291b2
  1. 1
      modules/bcf/app/models/bcf/comment.rb
  2. 1
      modules/bcf/app/models/bcf/issue.rb
  3. 1
      modules/bcf/app/models/bcf/viewpoint.rb
  4. 5
      modules/bcf/db/migrate/20190719123448_add_viewpoint_to_bcf_comment.rb
  5. 18
      modules/bcf/lib/open_project/bcf/bcf_xml/issue_reader.rb
  6. 6
      modules/bcf/lib/open_project/bcf/bcf_xml/markup_extractor.rb
  7. 23
      modules/bcf/spec/bcf/bcf_xml/issue_reader_spec.rb
  8. 1
      modules/bcf/spec/bcf/bcf_xml/markup_extractor_spec.rb
  9. 4
      modules/bcf/spec/factories/bcf_issue_factory.rb
  10. BIN
      modules/bcf/spec/fixtures/files/MaximumInformation.bcf
  11. 1
      modules/pdf_export/spec/views/edit.html.erb_spec.rb

@ -4,6 +4,7 @@ module Bcf
belongs_to :journal
belongs_to :issue, foreign_key: :issue_id, class_name: "Bcf::Issue"
belongs_to :viewpoint, foreign_key: :viewpoint_id, class_name: "Bcf::Viewpoint"
validates_presence_of :uuid
validates_uniqueness_of :uuid, scope: [:issue_id]

@ -4,6 +4,7 @@ module Bcf
belongs_to :work_package
belongs_to :project
has_many :comments, class_name: 'Bcf::Comment', foreign_key: 'issue_id'
after_update :invalidate_markup_cache

@ -12,6 +12,7 @@ module Bcf
end
belongs_to :issue, foreign_key: :issue_id, class_name: "Bcf::Issue"
has_many :comments, foreign_key: :viewpoint_id, class_name: "Bcf::Comment"
delegate :project, :project_id, to: :issue, allow_nil: true
def snapshot

@ -0,0 +1,5 @@
class AddViewpointToBcfComment < ActiveRecord::Migration[5.1]
def change
add_reference :bcf_comments, :viewpoint, foreign_key: { to_table: :bcf_viewpoints }, index: true
end
end

@ -341,13 +341,19 @@ module OpenProject::Bcf::BcfXml
end
def new_comment(comment_data)
bcf_comment = issue.comments.build(comment_data.slice(:uuid))
bcf_comment = issue.comments.build(uuid: comment_data[:uuid], viewpoint: viewpoint_by_uuid(comment_data[:viewpoint_uuid]))
call = create_wp_comment_privileged(comment_data)
new_comment_handler(bcf_comment, call, comment_data[:date])
end
def viewpoint_by_uuid(uuid)
return nil if uuid.nil?
issue.viewpoints.find { |vp| vp.uuid == uuid }
end
def create_wp_comment_privileged(comment_data)
author = get_comment_author(comment_data)
if author.id == User.system.id
@ -371,12 +377,22 @@ module OpenProject::Bcf::BcfXml
def update_comment(comment_data)
if comment_data[:modified_date]
bcf_comment = issue.comments.find_by(comment_data.slice(:uuid))
update_comment_viewpoint_by_uuid(bcf_comment, comment_data[:viewpoint_uuid])
if bcf_comment.journal.created_at < comment_data[:modified_date]
update_journal_attributes(bcf_comment, comment_data)
end
end
end
def update_comment_viewpoint_by_uuid(bcf_comment, viewpoint_uuid)
bcf_comment.viewpoint = if viewpoint_uuid.nil?
nil
else
viewpoint_by_uuid(viewpoint_uuid)
end
end
def update_journal_attributes(bcf_comment, comment_data)
bcf_comment.journal.update_attributes(notes: comment_data[:comment],
created_at: comment_data[:modified_date])

@ -80,6 +80,7 @@ module OpenProject::Bcf::BcfXml
date: extract_date_time("Date", node),
author: extract_from_node('Author', node),
comment: extract_from_node('Comment', node),
viewpoint_uuid: comment_viewpoint_uuid(node),
modified_date: extract_date_time("ModifiedDate", node),
modified_author: extract_from_node("ModifiedAuthor", node)
}.with_indifferent_access
@ -101,6 +102,11 @@ module OpenProject::Bcf::BcfXml
private
def comment_viewpoint_uuid(node)
viewpoint_node = node.at('Viewpoint')
extract_from_node('@Guid', viewpoint_node, attribute: true) if viewpoint_node
end
def extract_date_time(path, node = nil)
node ||= doc
date_time = extract_from_node(path, node)

@ -116,16 +116,37 @@ describe ::OpenProject::Bcf::BcfXml::IssueReader do
context '#update_comment' do
let!(:bcf_issue) { FactoryBot.create :bcf_issue_with_comment }
it '#update_comment' do
before do
allow(subject).to receive(:issue).and_return(bcf_issue)
end
it '#update_comment' do
modified_time = Time.now + 1.minute
comment_data = { uuid: bcf_issue.comments.first.uuid, comment: 'Updated comment', modified_date: modified_time }
expect(subject).to receive(:update_comment_viewpoint_by_uuid)
subject.send(:update_comment, comment_data)
expect(bcf_issue.comments.first.journal.notes).to eql('Updated comment')
expect(bcf_issue.comments.first.journal.created_at.utc.to_s).to eql(modified_time.utc.to_s)
end
it '#update_comment_viewpoint_by_uuid' do
bcf_comment = bcf_issue.comments.first
viewpoint = bcf_comment.viewpoint
bcf_comment.viewpoint = nil
subject.send(:update_comment_viewpoint_by_uuid, bcf_comment, viewpoint.uuid)
expect(bcf_comment.viewpoint_id).to eql(viewpoint.id)
subject.send(:update_comment_viewpoint_by_uuid, bcf_comment, nil)
expect(bcf_comment.viewpoint).to be_nil
end
it '#viewpoint_by_uuid' do
expect(subject.send(:viewpoint_by_uuid, nil)).to be_nil
expect(subject.send(:viewpoint_by_uuid, bcf_issue.comments.first.viewpoint.uuid)).to eql(bcf_issue.comments.first.viewpoint)
end
end
end
end

@ -111,6 +111,7 @@ describe ::OpenProject::Bcf::BcfXml::MarkupExtractor do
expect(subject.comments.first[:comment]).to(
eql("This comment contained some spllng errs.\nHopefully, the modifier did catch them all.")
)
expect(subject.comments.first[:viewpoint_uuid]).to eql('8dc86298-9737-40b4-a448-98a9e953293a')
end
it '#people' do

@ -37,8 +37,8 @@ FactoryBot.define do
factory :bcf_issue, class: ::Bcf::Issue do
factory :bcf_issue_with_comment do
after(:create) do |issue|
create(:bcf_viewpoint, issue: issue)
create(:bcf_comment, issue: issue)
viewpoint = create(:bcf_viewpoint, issue: issue)
create(:bcf_comment, issue: issue, viewpoint: viewpoint)
end
end
end

@ -44,5 +44,4 @@ describe 'export_card_configurations/edit', :type => :view do
expect(rendered).to have_field("Orientation", with: config.orientation)
expect(rendered).to have_field("Rows", with: config.rows)
end
end

Loading…
Cancel
Save