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 `POST /api/v3/work_packages/:work_package_id/reminders`
Kabiru Mwenjad060182bf2cd
diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 1c5ca416213..b696c8cfbd3 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -4579,6 +4579,8 @@ en:code_500_missing_enterprise_token: "The request can not be handled due to invalid or missing Enterprise token."bad_request:emoji_reactions_activity_type_not_supported: "This activity type does not support emoji reactions."+ multiple_reminders_not_allowed: |-+ You can only set one reminder at a time for a work package. Please delete or update the existing reminder.not_found:work_package: "The work package you are looking for cannot be found or has been deleted."expected:diff --git a/lib/api/v3/reminders/reminder_payload_representer.rb b/lib/api/v3/reminders/reminder_payload_representer.rbnew file mode 100644index 00000000000..7fa888e79f5--- /dev/null+++ b/lib/api/v3/reminders/reminder_payload_representer.rb@@ -0,0 +1,35 @@+# frozen_string_literal: true++#-- 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::Reminders+ class ReminderPayloadRepresenter < ReminderRepresenter+ include ::API::Utilities::PayloadRepresenter+ end+enddiff --git a/lib/api/v3/reminders/reminder_representer.rb b/lib/api/v3/reminders/reminder_representer.rbindex 88e78173cd5..3e991c509bd 100644--- a/lib/api/v3/reminders/reminder_representer.rb+++ b/lib/api/v3/reminders/reminder_representer.rb@@ -42,6 +42,10 @@ module APIassociated_resource :creator,v3_path: :user,representer: ::API::V3::Users::UserRepresenter++ def _type+ "Reminder"+ endendendenddiff --git a/lib/api/v3/reminders/reminders_api.rb b/lib/api/v3/reminders/reminders_api.rbindex e187d5967d1..25d3f00799d 100644--- a/lib/api/v3/reminders/reminders_api.rb+++ b/lib/api/v3/reminders/reminders_api.rb@@ -39,6 +39,14 @@ module APIdef reminders@work_package.reminders.upcoming_and_visible_to(User.current)end++ def restrict_multiple_reminders+ if reminders.any?+ raise ::API::Errors::BadRequest.new(+ I18n.t("api_v3.errors.bad_request.multiple_reminders_not_allowed")+ )+ end+ endendget do@@ -46,6 +54,13 @@ module APIself_link: api_v3_paths.work_package_reminders(@work_package.id),current_user: User.current)end++ post(&API::V3::Utilities::Endpoints::Create.new(model: Reminder,+ before_hook: ->(request:) { request.restrict_multiple_reminders },+ params_modifier: ->(params) do+ params.merge(remindable: @work_package,+ creator: User.current)+ end).mount)endendenddiff --git a/spec/requests/api/v3/reminders/reminders_api_spec.rb b/spec/requests/api/v3/reminders/reminders_api_spec.rbindex 5be86a3cc29..58775a10555 100644--- a/spec/requests/api/v3/reminders/reminders_api_spec.rb+++ b/spec/requests/api/v3/reminders/reminders_api_spec.rb@@ -126,4 +126,61 @@ RSpec.describe API::V3::Reminders::RemindersAPI doendendend++ describe "POST /api/v3/work_packages/:work_package_id/reminders", :freeze_time do+ let(:path) { api_v3_paths.work_package_reminders(work_package.id) }+ let(:headers) { { "CONTENT_TYPE" => "application/json" } }+ let(:remind_at) { 1.day.from_now }+ let(:note) { "Remind me to do something" }+ let(:params) { { remindAt: remind_at, note: } }++ def make_request+ post path, params.to_json, headers+ end++ context "with permissions" do+ current_user { user_with_permissions }++ before do+ Reminder.destroy_all+ make_request+ end++ it_behaves_like "successful response", 201, "Reminder" do+ it "returns reminder attributes" do+ expect(last_response.body)+ .to be_json_eql(API::V3::Utilities::DateTimeFormatter.format_datetime(remind_at).to_json)+ .at_path("remindAt")++ expect(last_response.body)+ .to be_json_eql(note.to_json)+ .at_path("note")++ expect(last_response.body)+ .to be_json_eql({ "href" => "/api/v3/users/#{current_user.id}", "title" => current_user.name }.to_json)+ .at_path("_links/creator")+ end+ end+ end++ context "with an existing reminder" do+ current_user { user_with_permissions }++ before { make_request }++ it_behaves_like "error response",+ 400, "BadRequest",+ "You can only set one reminder at a time for a work package. Please delete or update the existing reminder."+ end++ context "with no permissions" do+ current_user { other_user_without_permissions }++ before { make_request }++ it_behaves_like "error response",+ 404, "NotFound",+ "The work package you are looking for cannot be found or has been deleted."+ end+ endend