From 47e88bfd765da31dcc38f707590262a9f075c88e Mon Sep 17 00:00:00 2001 From: Dombi Attila <83396+dombesz@users.noreply.github.com> Date: Tue, 8 Oct 2024 00:18:43 +0300 Subject: [PATCH] Add copy api endpoints and call them in the frontend --- .../api-v3-work-packages-paths.ts | 9 +++- lib/api/v3/utilities/path_helper.rb | 8 +++ lib/api/v3/work_packages/copy/copy_api.rb | 53 +++++++++++++++++++ .../v3/work_packages/copy/create_form_api.rb | 44 +++++++++++++++ .../copy/create_form_representer.rb | 47 ++++++++++++++++ .../work_package_copy_payload_representer.rb | 45 ++++++++++++++++ lib/api/v3/work_packages/work_packages_api.rb | 11 ++-- 7 files changed, 210 insertions(+), 7 deletions(-) create mode 100644 lib/api/v3/work_packages/copy/copy_api.rb create mode 100644 lib/api/v3/work_packages/copy/create_form_api.rb create mode 100644 lib/api/v3/work_packages/copy/create_form_representer.rb create mode 100644 lib/api/v3/work_packages/copy/work_package_copy_payload_representer.rb diff --git a/frontend/src/app/core/apiv3/endpoints/work_packages/api-v3-work-packages-paths.ts b/frontend/src/app/core/apiv3/endpoints/work_packages/api-v3-work-packages-paths.ts index 07c3c612d787..a4ce3d8f5847 100644 --- a/frontend/src/app/core/apiv3/endpoints/work_packages/api-v3-work-packages-paths.ts +++ b/frontend/src/app/core/apiv3/endpoints/work_packages/api-v3-work-packages-paths.ts @@ -47,8 +47,10 @@ export class ApiV3WorkPackagesPaths extends ApiV3Collection(attributes) { + attributes[:send_notifications] = notify_according_to_params + attributes + }) + .mount + + mount ::API::V3::WorkPackages::Copy::CreateFormAPI + end + end + end + end + end +end diff --git a/lib/api/v3/work_packages/copy/create_form_api.rb b/lib/api/v3/work_packages/copy/create_form_api.rb new file mode 100644 index 000000000000..5be766690864 --- /dev/null +++ b/lib/api/v3/work_packages/copy/create_form_api.rb @@ -0,0 +1,44 @@ +#-- 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 + module V3 + module WorkPackages + module Copy + class CreateFormAPI < ::API::OpenProjectAPI + resource :form do + post &::API::V3::Utilities::Endpoints::CreateForm.new(model: WorkPackage, + parse_service: WorkPackages::ParseParamsService, + process_contract: ::WorkPackages::CopyContract) + .mount + end + end + end + end + end +end diff --git a/lib/api/v3/work_packages/copy/create_form_representer.rb b/lib/api/v3/work_packages/copy/create_form_representer.rb new file mode 100644 index 000000000000..09dcf580108e --- /dev/null +++ b/lib/api/v3/work_packages/copy/create_form_representer.rb @@ -0,0 +1,47 @@ +#-- 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 + module V3 + module WorkPackages + module Copy + class CreateFormRepresenter < FormRepresenter + include API::Decorators::CreateForm + + def form_url + api_v3_paths.work_package_copy_form(meta.source.id) + end + + def resource_url + api_v3_paths.work_package_copy(meta.source.id) + end + end + end + end + end +end diff --git a/lib/api/v3/work_packages/copy/work_package_copy_payload_representer.rb b/lib/api/v3/work_packages/copy/work_package_copy_payload_representer.rb new file mode 100644 index 000000000000..ca366c3aca6f --- /dev/null +++ b/lib/api/v3/work_packages/copy/work_package_copy_payload_representer.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 + module V3 + module WorkPackages + module Copy + class WorkPackageCopyPayloadRepresenter < ::API::V3::WorkPackages::WorkPackageRepresenter + include ::API::Utilities::PayloadRepresenter + + cached_representer disabled: true + + def writable_attributes + super + %w[status] + end + end + end + end + end +end diff --git a/lib/api/v3/work_packages/work_packages_api.rb b/lib/api/v3/work_packages/work_packages_api.rb index 152033faa665..f922ff6de1ec 100644 --- a/lib/api/v3/work_packages/work_packages_api.rb +++ b/lib/api/v3/work_packages/work_packages_api.rb @@ -38,8 +38,11 @@ class WorkPackagesAPI < ::API::OpenProjectAPI # The endpoint needs to be mounted before the GET :work_packages/:id. # Otherwise, the matcher for the :id also seems to match available_projects. # This is also true when the :id param is declared to be of type: Integer. + # Note: Adding `requirements: /\d*/` to the :id definition matches numbers only. mount ::API::V3::WorkPackages::AvailableProjectsOnCreateAPI mount ::API::V3::WorkPackages::Schema::WorkPackageSchemasAPI + mount ::API::V3::WorkPackages::CreateFormAPI + mount ::API::V3::WorkPackages::Copy::CopyAPI get do authorize_in_any_work_package(:view_work_packages) @@ -61,7 +64,7 @@ class WorkPackagesAPI < ::API::OpenProjectAPI }) .mount - route_param :id, type: Integer, desc: "Work package ID" do + route_param :id, type: Integer, requirements: { id: /[0-9]*/ }, desc: "Work package ID" do helpers WorkPackagesSharedHelpers helpers do @@ -89,18 +92,16 @@ class WorkPackagesAPI < ::API::OpenProjectAPI delete &::API::V3::Utilities::Endpoints::Delete.new(model: WorkPackage) .mount - mount ::API::V3::WorkPackages::WatchersAPI mount ::API::V3::Activities::ActivitiesByWorkPackageAPI mount ::API::V3::Attachments::AttachmentsByWorkPackageAPI mount ::API::V3::Repositories::RevisionsByWorkPackageAPI - mount ::API::V3::WorkPackages::UpdateFormAPI mount ::API::V3::WorkPackages::AvailableAssigneesAPI mount ::API::V3::WorkPackages::AvailableProjectsOnEditAPI mount ::API::V3::WorkPackages::AvailableRelationCandidatesAPI + mount ::API::V3::WorkPackages::UpdateFormAPI + mount ::API::V3::WorkPackages::WatchersAPI mount ::API::V3::WorkPackages::WorkPackageRelationsAPI end - - mount ::API::V3::WorkPackages::CreateFormAPI end end end