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
use default end points on wp#available_projects_on_...
ulfertsede01caaa4f7
diff --git a/lib/api/v3/utilities/endpoints/index.rb b/lib/api/v3/utilities/endpoints/index.rbindex 0bef92e58c8..6ded458405a 100644--- a/lib/api/v3/utilities/endpoints/index.rb+++ b/lib/api/v3/utilities/endpoints/index.rb@@ -31,6 +31,16 @@ module APImodule Utilitiesmodule Endpointsclass Index < API::Utilities::Endpoints::Index+ def initialize(model:,+ api_name: model.name.demodulize,+ scope: nil,+ render_representer: nil,+ self_path: api_name.underscore.pluralize)+ super(model: model, api_name: api_name, scope: scope, render_representer: render_representer)++ self.self_path = self_path+ end+def mountindex = self@@ -51,21 +61,18 @@ module APIif query.valid?render_success(query,request.params,- request.api_v3_paths.send(self_path),+ calculated_self_path(request),scope ? request.instance_exec(&scope) : model)elserender_error(query)endend- def self_path- api_name.underscore.pluralize- end-attr_accessor :model,:api_name,:scope,- :render_representer+ :render_representer,+ :self_pathprivate@@ -128,6 +135,14 @@ module APIraise ::API::Errors::InvalidQuery.new(query.errors.full_messages)end+ def calculated_self_path(request)+ if self_path.respond_to?(:call)+ request.instance_exec(&self_path)+ else+ request.api_v3_paths.send(self_path)+ end+ end+def deduce_render_representer"::API::V3::#{deduce_api_namespace}::#{api_name}CollectionRepresenter".constantizeenddiff --git a/lib/api/v3/work_packages/available_projects_on_create_api.rb b/lib/api/v3/work_packages/available_projects_on_create_api.rbindex 3e57bad6632..57673a35c52 100644--- a/lib/api/v3/work_packages/available_projects_on_create_api.rb+++ b/lib/api/v3/work_packages/available_projects_on_create_api.rb@@ -26,8 +26,6 @@# See COPYRIGHT and LICENSE files for more details.#++-require 'api/v3/projects/project_collection_representer'-module APImodule V3module WorkPackages@@ -35,31 +33,32 @@ module APIresource :available_projects doafter_validation doauthorize(:add_work_packages, global: true)++ checked_permissions = Projects::ProjectCollectionRepresenter.checked_permissions+ current_user.preload_projects_allowed_to(checked_permissions)endparams dooptional :for_type, type: Integerend- get do- checked_permissions = Projects::ProjectCollectionRepresenter.checked_permissions- current_user.preload_projects_allowed_to(checked_permissions)-- available_projects = WorkPackage- .allowed_target_projects_on_create(current_user)- .includes(Projects::ProjectCollectionRepresenter.to_eager_load)+ get &::API::V3::Utilities::Endpoints::Index+ .new(model: Project,+ self_path: -> { api_v3_paths.available_projects_on_create(params[:for_type]) },+ scope: -> {+ available_projects = WorkPackage+ .allowed_target_projects_on_create(current_user)+ .includes(Projects::ProjectCollectionRepresenter.to_eager_load)- query = ::Queries::Projects::ProjectQuery.new(user: current_user)- if params[:for_type]- query.where('type_id', '=', params[:for_type])- available_projects = query.results.merge(available_projects)- end-- self_link = api_v3_paths.available_projects_on_create(params[:for_type])- Projects::ProjectCollectionRepresenter.new(available_projects,- self_link: self_link,- current_user: current_user)- end+ if params[:for_type]+ query = ::Queries::Projects::ProjectQuery.new(user: current_user)+ query.where('type_id', '=', params[:for_type])+ query.results.merge(available_projects)+ else+ available_projects+ end+ })+ .mountendendenddiff --git a/lib/api/v3/work_packages/available_projects_on_edit_api.rb b/lib/api/v3/work_packages/available_projects_on_edit_api.rbindex 2bd9a1bccc5..ca12dca8cf2 100644--- a/lib/api/v3/work_packages/available_projects_on_edit_api.rb+++ b/lib/api/v3/work_packages/available_projects_on_edit_api.rb@@ -26,8 +26,6 @@# See COPYRIGHT and LICENSE files for more details.#++-require 'api/v3/projects/project_collection_representer'-module APImodule V3module WorkPackages@@ -35,20 +33,20 @@ module APIresource :available_projects doafter_validation doauthorize(:edit_work_packages, context: @work_package.project)- end- get dochecked_permissions = Projects::ProjectCollectionRepresenter.checked_permissionscurrent_user.preload_projects_allowed_to(checked_permissions)-- available_projects = WorkPackage- .allowed_target_projects_on_move(current_user)- .includes(Projects::ProjectCollectionRepresenter.to_eager_load)- self_link = api_v3_paths.available_projects_on_edit(@work_package.id)- Projects::ProjectCollectionRepresenter.new(available_projects,- self_link: self_link,- current_user: current_user)end++ get &::API::V3::Utilities::Endpoints::Index+ .new(model: Project,+ self_path: -> { api_v3_paths.available_projects_on_edit(@work_package.id) },+ scope: -> {+ WorkPackage+ .allowed_target_projects_on_move(current_user)+ .includes(Projects::ProjectCollectionRepresenter.to_eager_load)+ })+ .mountendendend