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 API link to the copied project on success

Oliver Günther5ecb700610ab
diff --git a/app/workers/copy_project_job.rb b/app/workers/copy_project_job.rb
index 75aae3cc35a..18bb63b0567 100644
--- a/app/workers/copy_project_job.rb
+++ b/app/workers/copy_project_job.rb
@@ -91,6 +91,7 @@ class CopyProjectJob < ApplicationJob
def successful_status_update
payload = redirect_payload(url_helpers.project_url(target_project))
+ .merge(hal_links(target_project))
if errors.any?
payload[:errors] = errors
@@ -111,6 +112,17 @@ class CopyProjectJob < ApplicationJob
upsert_status status: :failure, message:
end
+ def hal_links(project)
+ {
+ _links: {
+ project: {
+ href: ::API::V3::Utilities::PathHelper::ApiV3Path.project(project.id),
+ title: project.name
+ }
+ }
+ }
+ end
+
def user
@user ||= User.find user_id
end
diff --git a/spec/workers/copy_project_job_spec.rb b/spec/workers/copy_project_job_spec.rb
index 992f9aa5854..d58e6d7cdeb 100644
--- a/spec/workers/copy_project_job_spec.rb
+++ b/spec/workers/copy_project_job_spec.rb
@@ -92,6 +92,7 @@ describe CopyProjectJob, type: :model do
"#{WorkPackage.model_name.human} '#{work_package.type.name} ##{work_package.id}: #{work_package.subject}': #{custom_field.name} #{I18n.t('errors.messages.blank')}."
end
+ # rubocop:disable RSpec/InstanceVariable
before do
source_project.work_package_custom_fields << custom_field
type.custom_fields << custom_field
@@ -110,8 +111,12 @@ describe CopyProjectJob, type: :model do
expect(copy_job.job_status).to be_present
expect(copy_job.job_status[:status]).to eq 'success'
expect(copy_job.job_status[:payload]['redirect']).to include '/projects/copy'
+
+ expected_link = { 'href' => "/api/v3/projects/#{@copied_project.id}", 'title' => @copied_project.name }
+ expect(copy_job.job_status[:payload]['_links']['project']).to eq(expected_link)
end
end
+ # rubocop:enable RSpec/InstanceVariable
describe 'project has an invalid repository' do
let(:admin) { create(:admin) }