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
feature/64166 Add work package internal comments (write) API
Kabiru Mwenja6ed5ef1529f2
diff --git a/docs/api/apiv3/components/schemas/activity_comment_write_model.yml b/docs/api/apiv3/components/schemas/activity_comment_write_model.ymlindex bfd993e0c61..b413c224149 100644--- a/docs/api/apiv3/components/schemas/activity_comment_write_model.yml+++ b/docs/api/apiv3/components/schemas/activity_comment_write_model.yml@@ -3,4 +3,14 @@type: objectproperties:comment:- type: string+ type: object+ properties:+ raw:+ type: string+ description: The raw content of the comment+ internal:+ type: boolean+ description: Whether this comment is internal (only available to users with add_internal_comments permission)+example:+ comment:+ raw: I think this is awesome!diff --git a/docs/api/apiv3/paths/work_package_activities.yml b/docs/api/apiv3/paths/work_package_activities.ymlindex 0c7e5c4a122..cce73562385 100644--- a/docs/api/apiv3/paths/work_package_activities.yml+++ b/docs/api/apiv3/paths/work_package_activities.yml@@ -153,14 +153,5 @@ post:content:application/json:schema:- example:- comment:- raw: I think this is awesome!- properties:- comment:- properties:- raw:- type: string- type: object- type: object+ $ref: "../components/schemas/activity_comment_write_model.yml"summary: Comment work packagediff --git a/lib/api/v3/activities/activities_by_work_package_api.rb b/lib/api/v3/activities/activities_by_work_package_api.rbindex e7adcf4eeb4..ca01eb6abfe 100644--- a/lib/api/v3/activities/activities_by_work_package_api.rb+++ b/lib/api/v3/activities/activities_by_work_package_api.rb@@ -33,6 +33,12 @@ module APImodule Activitiesclass ActivitiesByWorkPackageAPI < ::API::OpenProjectAPIresource :activities do+ helpers do+ def to_boolean(value, default)+ ActiveRecord::Type::Boolean.new.cast(value.presence || default)+ end+ end+get doself_link = api_v3_paths.work_package_activities @work_package.id@@ -58,11 +64,13 @@ module APIraise ::API::Errors::NotFound.newend+ internal = to_boolean(params[:internal], false)call = AddWorkPackageNoteService.new(user: current_user,work_package: @work_package).call(params[:comment][:raw],- send_notifications: !(params.has_key?(:notify) && params[:notify] == "false"))+ send_notifications: to_boolean(params[:notify], true),+ internal:)if call.success?Activities::ActivityRepresenter.new(call.result, current_user:)diff --git a/spec/requests/api/v3/activities_by_work_package_resource_spec.rb b/spec/requests/api/v3/activities_by_work_package_resource_spec.rbindex 9876ba410a5..76df6cec8bc 100644--- a/spec/requests/api/v3/activities_by_work_package_resource_spec.rb+++ b/spec/requests/api/v3/activities_by_work_package_resource_spec.rb@@ -148,6 +148,56 @@ RSpec.describe API::V3::Activities::ActivitiesByWorkPackageAPI do # rubocop:disa.at_path("message")endend++ context "when creating an internal comment" do+ shared_context "to create internal comment" do |internal: false|+ before do+ header "Content-Type", "application/json"+ post api_v3_paths.work_package_activities(work_package.id),+ { comment: { raw: comment }, internal: }.to_json+ end+ end++ context "and the user has the permission to create internal comments" do+ it_behaves_like "valid activity request" do+ let(:permissions) { %i(view_work_packages view_internal_comments add_internal_comments) }+ let(:status_code) { 201 }++ include_context "to create internal comment", internal: true++ it "creates an internal comment" do+ expect(last_response.body).to be_json_eql(true.to_json).at_path("internal")+ end+ end++ it_behaves_like "valid activity request" do+ let(:permissions) { %i(view_work_packages view_internal_comments add_internal_comments) }+ let(:status_code) { 201 }++ include_context "to create internal comment", internal: false++ it "creates an internal comment" do+ expect(last_response.body).to be_json_eql(false.to_json).at_path("internal")+ end+ end+ end++ context "and the user does not have the permission to create internal comments" do+ let(:permissions) { %i(view_work_packages add_work_package_comments view_internal_comments) }++ include_context "to create internal comment", internal: true++ it "fails with HTTP Unprocessable Entity" do+ expect(last_response).to have_http_status :unprocessable_entity+ end++ it "notes the error" do+ expect(last_response.body)+ .to be_json_eql("Internal Journal may not be accessed.".to_json)+ .at_path("message")+ end+ end+ endendendend