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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add reminder note as an embedded notification detail
Kabiru Mwenjaa13494ce642f
diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 203fec0fad3..d7168566222 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1448,6 +1448,7 @@ en:login: "Username"mail: "Email"name: "Name"+ note: "Note"password: "Password"priority: "Priority"project: "Project"diff --git a/lib/api/v3/notifications/notification_representer.rb b/lib/api/v3/notifications/notification_representer.rbindex 5b67c4dd9a3..6984fe23518 100644--- a/lib/api/v3/notifications/notification_representer.rb+++ b/lib/api/v3/notifications/notification_representer.rb@@ -104,7 +104,7 @@ module API"Notification"end- self.to_eager_load = %i[actor journal]+ self.to_eager_load = %i[actor journal reminder]endendenddiff --git a/lib/api/v3/notifications/property_factory/reminder.rb b/lib/api/v3/notifications/property_factory/reminder.rbnew file mode 100644index 00000000000..e8bd4e210c2--- /dev/null+++ b/lib/api/v3/notifications/property_factory/reminder.rb@@ -0,0 +1,45 @@+# --copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+# ++++module API::V3::Notifications::PropertyFactory+ module Reminder+ extend ::API::V3::Utilities::PathHelper++ module_function++ def for(notification)+ return [] unless notification.reminder++ [+ ::API::V3::Values::PropertyGenericRepresenter+ .new(::API::V3::Values::PropertyModel.new(:note, notification.reminder.note),+ self_link: api_v3_paths.notification_detail(notification.id, 0))+ ]+ end+ end+enddiff --git a/lib/api/v3/values/property_generic_representer.rb b/lib/api/v3/values/property_generic_representer.rbnew file mode 100644index 00000000000..ed814ef2fa3--- /dev/null+++ b/lib/api/v3/values/property_generic_representer.rb@@ -0,0 +1,33 @@+# --copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+# ++++module API::V3::Values+ class PropertyGenericRepresenter < PropertyRepresenter+ property :value+ end+enddiff --git a/lib/api/v3/values/schemas/value_schema_factory.rb b/lib/api/v3/values/schemas/value_schema_factory.rbindex de98a68e279..441bb673472 100644--- a/lib/api/v3/values/schemas/value_schema_factory.rb+++ b/lib/api/v3/values/schemas/value_schema_factory.rb@@ -29,7 +29,7 @@module API::V3::Values::Schemasmodule ValueSchemaFactoryextend ::API::V3::Utilities::PathHelper- SUPPORTED = %w(start_date due_date date).freeze+ SUPPORTED = %w(start_date due_date date note).freezemodule_function@@ -64,10 +64,13 @@ module API::V3::Values::SchemasI18n.t("attributes.#{property}")end- def type_for(_property)- # This is but a stub. Currently, only 'start_date' and 'due_date'- # need to be supported so this simple approach works.- "Date"+ def type_for(property)+ case property+ when "start_date", "due_date", "date"+ "Date"+ when "note"+ "String"+ endendendenddiff --git a/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rb b/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rbindex c0fb12c42cb..bb3aef99788 100644--- a/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rb+++ b/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rb@@ -267,5 +267,60 @@ RSpec.describe API::V3::Notifications::NotificationRepresenter, "rendering" do.at_path("_embedded/details")endend++ shared_examples_for "embeds a Values::Property for reminder note" do+ it "embeds a Values::Property" do+ expect(generated)+ .to be_json_eql("Values::Property".to_json)+ .at_path("_embedded/details/0/_type")+ end++ it "has a note value for the `property` property" do+ expect(generated)+ .to be_json_eql("note".to_json)+ .at_path("_embedded/details/0/property")+ end++ it "has a reminder`s note for the value" do+ expect(generated)+ .to be_json_eql(notification.reminder.note.to_json)+ .at_path("_embedded/details/0/value")+ end+ end++ context "for a reminder when embedding" do+ let(:reminder) { build_stubbed(:reminder) }+ let(:reason) { :reminder }+ let(:embed_links) { true }++ before do+ allow(notification).to receive(:reminder).and_return(reminder)+ end++ it_behaves_like "embeds a Values::Property for reminder note"+ end++ context "for a reminder when not embedding" do+ let(:reminder) { build_stubbed(:reminder) }+ let(:reason) { :reminder }+ let(:embed_links) { false }++ before do+ allow(notification).to receive(:reminder).and_return(reminder)+ end++ it_behaves_like "embeds a Values::Property for reminder note"+ end++ context "for a reminder with no notification" do+ let(:reminder) { nil }+ let(:reason) { :reminder }++ it "has an empty details array" do+ expect(generated)+ .to have_json_size(0)+ .at_path("_embedded/details")+ end+ endendend