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
Restrict emoji reactions (toggle) API to activity comments (#19023)
Kabiru Mwenjac28650b20c6b
diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 33141688b86..56731489e07 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -4574,6 +4574,8 @@ en:code_500: "An internal error has occurred."code_500_outbound_request_failure: "An outbound request to another resource has failed with status code %{status_code}."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."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/emoji_reactions/emoji_reactions_by_activity_comment_api.rb b/lib/api/v3/emoji_reactions/emoji_reactions_by_activity_comment_api.rbindex 6eef7addaa6..d66f8c39a4d 100644--- a/lib/api/v3/emoji_reactions/emoji_reactions_by_activity_comment_api.rb+++ b/lib/api/v3/emoji_reactions/emoji_reactions_by_activity_comment_api.rb@@ -41,6 +41,10 @@ module APIdef get_emoji_reactions_self_pathapi_v3_paths.emoji_reactions_by_activity_comment(reactable.id)end++ def activity_comment?+ reactable.notes.present?+ endendget do@@ -56,6 +60,12 @@ module APIendpatch do+ unless activity_comment?+ raise ::API::Errors::BadRequest.new(+ I18n.t("api_v3.errors.bad_request.emoji_reactions_activity_type_not_supported")+ )+ end+toggle_service = ::EmojiReactions::ToggleEmojiReactionService.call(user: current_user,reactable: reactable,diff --git a/spec/requests/api/v3/emoji_reactions/emoji_reactions_by_activity_comment_api_spec.rb b/spec/requests/api/v3/emoji_reactions/emoji_reactions_by_activity_comment_api_spec.rbindex 39ae45828d8..e6535e92f60 100644--- a/spec/requests/api/v3/emoji_reactions/emoji_reactions_by_activity_comment_api_spec.rb+++ b/spec/requests/api/v3/emoji_reactions/emoji_reactions_by_activity_comment_api_spec.rb@@ -44,7 +44,7 @@ RSpec.describe API::V3::EmojiReactions::EmojiReactionsByActivityCommentAPI dolet(:permissions) do%i(view_work_packages add_work_package_comments view_internal_comments)end- let(:activity) { create(:work_package_journal, journable: work_package, user: admin, version: 2) }+ let(:activity) { create(:work_package_journal, journable: work_package, user: admin, version: 2, notes: "Comment") }let!(:emoji_reaction) { create(:emoji_reaction, reactable: activity, user: current_user) }before do@@ -258,6 +258,23 @@ RSpec.describe API::V3::EmojiReactions::EmojiReactionsByActivityCommentAPI doendend+ context "when the activity is not a comment" do+ let(:non_comment_activity) { work_package.journals.first }++ before do+ patch api_v3_paths.emoji_reactions_by_activity_comment(non_comment_activity.id), { reaction: }.to_json,+ headers+ end++ it "returns 422 Unprocessable Entity" do+ expect(last_response).to have_http_status :bad_request++ expect(last_response.body)+ .to be_json_eql("Bad request: This activity type does not support emoji reactions.".to_json)+ .at_path("message")+ end+ end+it_behaves_like "handling anonymous user"endend