Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add diff for agenda item notes (#15179)

Oliver Günther6227f6f04db4
diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb
index 391c70863e1..cd408645845 100644
--- a/app/controllers/journals_controller.rb
+++ b/app/controllers/journals_controller.rb
@@ -92,6 +92,7 @@ class JournalsController < ApplicationController
permission = case @journal.journable_type
when "WorkPackage" then :view_work_packages
when "Project" then :view_project
+ when "Meeting" then :view_meetings
end
do_authorize(permission)
@@ -104,7 +105,11 @@ class JournalsController < ApplicationController
end
def valid_field_for_diffing?
- %w[description status_explanation].include?(field_param)
+ %w[description status_explanation].include?(field_param) || agenda_item_notes?
+ end
+
+ def agenda_item_notes?
+ field_param.match?(/\Aagenda_items_\d+_notes\z/)
end
def journals_index_title
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 95448a87090..e69b828c234 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -55,7 +55,11 @@ class Journal < ApplicationRecord
register_journal_formatter :meeting_start_time, OpenProject::JournalFormatter::MeetingStartTime
register_journal_formatter :agenda_item_position, OpenProject::JournalFormatter::AgendaItemPosition
register_journal_formatter :agenda_item_duration, OpenProject::JournalFormatter::AgendaItemDuration
+ register_journal_formatter :agenda_item_diff, OpenProject::JournalFormatter::AgendaItemDiff
+ register_journal_formatter :agenda_item_title, OpenProject::JournalFormatter::AgendaItemTitle
register_journal_formatter :meeting_work_package_id, OpenProject::JournalFormatter::MeetingWorkPackageId
+ register_journal_formatter :agenda_item_diff, OpenProject::JournalFormatter::AgendaItemDiff
+ register_journal_formatter :agenda_item_title, OpenProject::JournalFormatter::AgendaItemTitle
# Attributes related to the cause are stored in a JSONB column so we can easily add new relations and related
# attributes without a heavy database migration. Fields will be prefixed with `cause_` but are stored in the JSONB
diff --git a/lib/open_project/journal_formatter/diff.rb b/lib/open_project/journal_formatter/diff.rb
index d07995701c8..14d7e73e771 100644
--- a/lib/open_project/journal_formatter/diff.rb
+++ b/lib/open_project/journal_formatter/diff.rb
@@ -74,7 +74,8 @@ class OpenProject::JournalFormatter::Diff < JournalFormatter::Base
if options[:html]
link_to(I18n.t(:label_details),
url_attr,
- class: "description-details")
+ target: "_top",
+ class: "diff-details")
else
url_for url_attr
end
diff --git a/modules/meeting/app/models/activities/meeting_event_mapper.rb b/modules/meeting/app/models/activities/meeting_event_mapper.rb
index d24a90372d4..a94198a49af 100644
--- a/modules/meeting/app/models/activities/meeting_event_mapper.rb
+++ b/modules/meeting/app/models/activities/meeting_event_mapper.rb
@@ -34,15 +34,16 @@ class Activities::MeetingEventMapper < Activities::EventMapper
protected
def map_to_event(journal)
- count = agenda_changes(journal).count
+ agenda_changes = agenda_changes(journal)
+ count = agenda_changes.count
total = journal.details.count
if count > 0 && count < total
# If we have a mix of meeting and agenda item journal, split it up
- split_agenda_event(journal)
+ split_agenda_event(journal, agenda_changes)
elsif count == total
# All changes are related to agenda items, convert it to an agenda event
- create_agenda_events(journal)
+ create_agenda_events(journal, agenda_changes)
else
create_meeting_event(journal)
end
@@ -51,8 +52,8 @@ class Activities::MeetingEventMapper < Activities::EventMapper
##
# We want to split journals into multiple events
# if they contain meeting AND agenda item changes.
- def split_agenda_event(journal)
- agenda_event = create_agenda_events(journal)
+ def split_agenda_event(journal, agenda_changes)
+ agenda_event = create_agenda_events(journal, agenda_changes)
# Create an agenda event
unless only_agenda_item_changes?(journal)
@@ -70,10 +71,10 @@ class Activities::MeetingEventMapper < Activities::EventMapper
create_event(params)
end
- def create_agenda_events(journal)
+ def create_agenda_events(journal, agenda_changes)
params = mapped_params(journal)
- agenda_changes(journal).map do |agenda_item_id, changes|
+ agenda_changes.map do |agenda_item_id, changes|
params[:data] = {
id: agenda_item_id,
details: changes,
@@ -89,32 +90,43 @@ class Activities::MeetingEventMapper < Activities::EventMapper
end
def initial_change?(changes)
- title_change = changes[:title]
- work_package_change = changes[:work_package_id]
+ title_change = named_change(changes, "title")
+ work_package_change = named_change(changes, "work_package_id")
(title_change && title_change.first.nil?) || (work_package_change && work_package_change.first.nil?)
end
def deleted_change?(changes)
- title_change = changes[:title]
- work_package_change = changes[:work_package_id]
+ title_change = named_change(changes, "title")
+ work_package_change = named_change(changes, "work_package_id")
- (title_change && title_change.last.nil?) || (work_package_change && work_package_change.last.nil?)
+ if work_package_change
+ work_package_change.last.nil?
+ elsif title_change
+ title_change.last.nil?
+ else
+ false
+ end
end
def agenda_item_title(journal, id, details)
agenda_journal = journal.agenda_item_journals.detect { |j| j.agenda_item_id == id }
+ work_package_change = named_change(details, "work_package_id")
if agenda_journal&.item_type == "work_package"
work_package_title(agenda_journal.work_package_id)
- elsif details[:work_package_id]
- work_package_title(details[:work_package_id].first)
+ elsif work_package_change
+ work_package_title(work_package_change.first)
else
- title = agenda_journal&.title || details[:title]&.compact&.last
+ title = agenda_journal&.title || named_change(details, "title")&.compact&.last
title.nil? ? I18n.t(:text_deleted_agenda_item) : I18n.t("text_agenda_item_title", title:)
end
end
+ def named_change(changes, key)
+ changes.detect { |k, _| k.to_s.include?(key) }&.last
+ end
+
def work_package_title(work_package_id)
if work_package_id.nil?
I18n.t(:text_agenda_work_package_deleted)
@@ -131,8 +143,8 @@ class Activities::MeetingEventMapper < Activities::EventMapper
.select { |key, _| key.start_with?("agenda_items_") }
.reject { |key, _| key.end_with?("_position") }
.each_with_object(Hash.new { |h, k| h[k] = {} }) do |(key, values), changes|
- id, attribute = key.gsub("agenda_items_", "").split("_", 2)
- changes[id.to_i][attribute.to_sym] = values
+ id, _ = key.gsub("agenda_items_", "").split("_", 2)
+ changes[id.to_i][key.to_sym] = values
end
end
diff --git a/modules/meeting/app/models/meeting/journalized.rb b/modules/meeting/app/models/meeting/journalized.rb
index 171e4c39875..4086a4d6dd7 100644
--- a/modules/meeting/app/models/meeting/journalized.rb
+++ b/modules/meeting/app/models/meeting/journalized.rb
@@ -47,11 +47,12 @@ module Meeting::Journalized
register_journal_formatted_fields(:meeting_start_time, "start_time")
register_journal_formatted_fields(:plaintext, "location")
- register_journal_formatted_fields(:plaintext, "notes")
register_journal_formatted_fields(:agenda_item_duration, "duration")
- register_journal_formatted_fields(:agenda_item_duration, "duration_in_minutes")
+ register_journal_formatted_fields(:agenda_item_diff, /agenda_items_\d+_notes/)
+ register_journal_formatted_fields(:agenda_item_title, /agenda_items_\d+_title/)
+ register_journal_formatted_fields(:agenda_item_duration, /agenda_items_\d+_duration_in_minutes/)
register_journal_formatted_fields(:agenda_item_position, "position")
- register_journal_formatted_fields(:meeting_work_package_id, "work_package_id")
+ register_journal_formatted_fields(:meeting_work_package_id, /agenda_items_\d+_work_package_id/)
def touch_and_save_journals
update_column(:updated_at, Time.current)
diff --git a/modules/meeting/lib/open_project/journal_formatter/agenda_item_diff.rb b/modules/meeting/lib/open_project/journal_formatter/agenda_item_diff.rb
new file mode 100644
index 00000000000..9d1afa0b7f0
--- /dev/null
+++ b/modules/meeting/lib/open_project/journal_formatter/agenda_item_diff.rb
@@ -0,0 +1,40 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+class OpenProject::JournalFormatter::AgendaItemDiff < OpenProject::JournalFormatter::Diff
+ def label(key, html: true)
+ _id, attr = key.to_s.gsub("agenda_items_", "").split("_", 2)
+ label = super(attr)
+
+ if html
+ content_tag("strong", label)
+ else
+ label
+ end
+ end
+end
diff --git a/modules/meeting/lib/open_project/journal_formatter/agenda_item_title.rb b/modules/meeting/lib/open_project/journal_formatter/agenda_item_title.rb
new file mode 100644
index 00000000000..f85ff4b2a02
--- /dev/null
+++ b/modules/meeting/lib/open_project/journal_formatter/agenda_item_title.rb
@@ -0,0 +1,39 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+class OpenProject::JournalFormatter::AgendaItemTitle < JournalFormatter::Plaintext
+ def label(_, html: true)
+ label = MeetingAgendaItem.human_attribute_name(:title)
+
+ if html
+ content_tag("strong", label)
+ else
+ label
+ end
+ end
+end
diff --git a/modules/meeting/spec/features/structured_meetings/history_spec.rb b/modules/meeting/spec/features/structured_meetings/history_spec.rb
index be82d756aa0..6c36a2f8025 100644
--- a/modules/meeting/spec/features/structured_meetings/history_spec.rb
+++ b/modules/meeting/spec/features/structured_meetings/history_spec.rb
@@ -84,6 +84,7 @@ RSpec.describe "history",
let(:show_page) { Pages::StructuredMeeting::Show.new(meeting) }
let(:history_page) { Pages::StructuredMeeting::History.new(meeting) }
+ let(:editor) { Components::WysiwygEditor.new "#content", "opce-ckeditor-augmented-textarea" }
it "allows browsing the history", with_settings: { journal_aggregation_time_minutes: 0 } do
login_as(view_only_user)
@@ -160,7 +161,7 @@ RSpec.describe "history",
history_page.expect_event(
'Agenda item "Updated title"',
actor: user.name,
- timestamp: format_time(item.updated_at.utc),
+ timestamp: format_time(item.reload.updated_at.utc),
action: "updated by"
)
@@ -176,10 +177,10 @@ RSpec.describe "history",
show_page.add_agenda_item do
fill_in "Title", with: "Second"
end
+ show_page.expect_agenda_item(title: "Second")
second = MeetingAgendaItem.find_by(title: "Second")
show_page.select_action(second, I18n.t(:label_sort_higher))
- login_as(view_only_user)
show_page.visit!
history_page.open_history_modal
@@ -302,6 +303,36 @@ RSpec.describe "history",
expect(item).to have_css(".op-activity-list--item-subtitle", text: user.name)
end
+ it "shows the history of notes as a diff", with_settings: { journal_aggregation_time_minutes: 0 } do
+ login_as(user)
+ show_page.visit!
+
+ show_page.add_agenda_item do
+ fill_in "Title", with: "My agenda item"
+ click_on "Notes"
+ end
+
+ show_page.cancel_add_form
+ show_page.expect_agenda_item(title: "My agenda item")
+ item = MeetingAgendaItem.find_by(title: "My agenda item")
+
+ show_page.select_action(item, "Add notes")
+ editor.set_markdown "# Hello there"
+
+ show_page.in_edit_form(item) do
+ click_button "Save"
+ end
+
+ history_page.open_history_modal
+ within("li.op-activity-list--item", match: :first) do
+ expect(page).to have_css("li", text: "Notes set")
+ click_link "Details"
+ end
+
+ expect(page).to have_current_path /\/journals\/\d+\/diff\/agenda_items_\d+_notes/
+ expect(page).to have_css('ins.diffmod', text: "# Hello there")
+ end
+
it "for a user with no permissions, renders an error", with_settings: { journal_aggregation_time_minutes: 0 } do
login_as no_member_user
diff --git a/modules/meeting/spec/support/pages/structured_meeting/show.rb b/modules/meeting/spec/support/pages/structured_meeting/show.rb
index 714cac138a6..7f2421543ea 100644
--- a/modules/meeting/spec/support/pages/structured_meeting/show.rb
+++ b/modules/meeting/spec/support/pages/structured_meeting/show.rb
@@ -56,12 +56,16 @@ module Pages::StructuredMeeting
end
def cancel_edit_form(item)
- page.within("#meeting-agenda-items-item-component-#{item.id}") do
+ in_edit_form(item) do
click_on I18n.t(:button_cancel)
expect(page).to have_no_link I18n.t(:button_cancel)
end
end
+ def in_edit_form(item, &)
+ page.within("#meeting-agenda-items-item-component-#{item.id}", &)
+ end
+
def in_agenda_form(&)
page.within("#meeting-agenda-items-form-component", &)
end
diff --git a/spec/lib/journal_formatter/diff_spec.rb b/spec/lib/journal_formatter/diff_spec.rb
index 46e7051342c..2cff44e7f81 100644
--- a/spec/lib/journal_formatter/diff_spec.rb
+++ b/spec/lib/journal_formatter/diff_spec.rb
@@ -71,8 +71,8 @@ RSpec.describe OpenProject::JournalFormatter::Diff do
protocol: Setting.protocol,
host: Setting.host_name)
end
- let(:link) { link_to(I18n.t(:label_details), path, class: "description-details") }
- let(:full_url_link) { link_to(I18n.t(:label_details), url, class: "description-details") }
+ let(:link) { link_to(I18n.t(:label_details), path, class: "diff-details", target: "_top") }
+ let(:full_url_link) { link_to(I18n.t(:label_details), url, class: "diff-details", target: "_top") }
describe "#render" do
describe "WITH the first value being nil, and the second a string" do
@@ -82,7 +82,7 @@ RSpec.describe OpenProject::JournalFormatter::Diff do
link:)
end
- it { expect(instance.render(key, [nil, "new value"])).to eq(expected) }
+ it { expect(instance.render(key, [nil, "new value"])).to be_html_eql(expected) }
end
describe "WITH the first value being a string, and the second a string" do
@@ -92,7 +92,7 @@ RSpec.describe OpenProject::JournalFormatter::Diff do
link:)
end
- it { expect(instance.render(key, ["old value", "new value"])).to eq(expected) }
+ it { expect(instance.render(key, ["old value", "new value"])).to be_html_eql(expected) }
end
describe "WITH the first value being a string, and the second a string
@@ -111,7 +111,7 @@ RSpec.describe OpenProject::JournalFormatter::Diff do
I18n.locale = :en
end
- it { expect(instance.render(key, ["old value", "new value"])).to eq(expected) }
+ it { expect(instance.render(key, ["old value", "new value"])).to be_html_eql(expected) }
end
describe "WITH the first value being a string, and the second nil (with link)" do
@@ -121,7 +121,7 @@ RSpec.describe OpenProject::JournalFormatter::Diff do
link:)
end
- it { expect(instance.render(key, ["old_value", nil])).to eq(expected) }
+ it { expect(instance.render(key, ["old_value", nil])).to be_html_eql(expected) }
end
describe "WITH the first value being nil, and the second a string
@@ -132,7 +132,7 @@ RSpec.describe OpenProject::JournalFormatter::Diff do
link: path)
end
- it { expect(instance.render(key, [nil, "new value"], html: false)).to eq(expected) }
+ it { expect(instance.render(key, [nil, "new value"], html: false)).to be_html_eql(expected) }
end
describe "WITH the first value being a string, and the second a string
@@ -143,7 +143,7 @@ RSpec.describe OpenProject::JournalFormatter::Diff do
link: path)
end
- it { expect(instance.render(key, ["old value", "new value"], html: false)).to eq(expected) }
+ it { expect(instance.render(key, ["old value", "new value"], html: false)).to be_html_eql(expected) }
end
describe "WITH the first value being a string, and the second a string
@@ -154,7 +154,7 @@ RSpec.describe OpenProject::JournalFormatter::Diff do
link: full_url_link)
end
- it { expect(instance.render(key, ["old value", "new value"], only_path: false)).to eq(expected) }
+ it { expect(instance.render(key, ["old value", "new value"], only_path: false)).to be_html_eql(expected) }
end
describe "WITH the first value being a string, and the second nil (with url)" do
@@ -164,7 +164,7 @@ RSpec.describe OpenProject::JournalFormatter::Diff do
link: path)
end
- it { expect(instance.render(key, ["old_value", nil], html: false)).to eq(expected) }
+ it { expect(instance.render(key, ["old_value", nil], html: false)).to be_html_eql(expected) }
end
end
end
diff --git a/spec/lib/journal_formatter/wiki_diff_spec.rb b/spec/lib/journal_formatter/wiki_diff_spec.rb
index 7bd8cee8673..5344b7c61ad 100644
--- a/spec/lib/journal_formatter/wiki_diff_spec.rb
+++ b/spec/lib/journal_formatter/wiki_diff_spec.rb
@@ -67,8 +67,8 @@ RSpec.describe OpenProject::JournalFormatter::WikiDiff do
protocol: Setting.protocol,
host: Setting.host_name)
end
- let(:link) { link_to(I18n.t(:label_details), path, class: "description-details") }
- let(:full_url_link) { link_to(I18n.t(:label_details), url, class: "description-details") }
+ let(:link) { link_to(I18n.t(:label_details), path, class: "diff-details", target: "_top") }
+ let(:full_url_link) { link_to(I18n.t(:label_details), url, class: "diff-details") }
describe "#render" do
describe "a wiki diff for a wiki journal correctly" do
@@ -78,7 +78,7 @@ RSpec.describe OpenProject::JournalFormatter::WikiDiff do
link:)
end
- it { expect(wiki_instance.render(wiki_key, ["old value", "new value"])).to eq(expected) }
+ it { expect(wiki_instance.render(wiki_key, ["old value", "new value"])).to be_html_eql(expected) }
end
end
end