Merge pull request #3909 from opf/22126-fix-copy-project

[22126] Fix copy project
pull/3915/head
Oliver Günther 9 years ago
commit 6289c8b6f1
  1. 3
      app/controllers/copy_projects_controller.rb
  2. 4
      app/models/permitted_params.rb
  3. 25
      app/workers/copy_project_job.rb
  4. 2
      config/application.rb
  5. 3
      features/projects/copy_project.feature

@ -41,9 +41,10 @@ class CopyProjectsController < ApplicationController
@copy_project.attributes = permitted_params.project
if @copy_project.valid?
modules = permitted_params.project[:enabled_module_names] || params[:enabled_modules]
copy_project_job = CopyProjectJob.new(user_id: User.current.id,
source_project_id: @project.id,
target_project_params: permitted_params.project,
target_project_params: permitted_params.project.to_hash,
enabled_modules: modules,
associations_to_copy: params[:only],
send_mails: params[:notifications] == '1')

@ -295,6 +295,10 @@ class PermittedParams
whitelist.permit(enabled_module_names: [])
end
if instance && current_user.allowed_to?(:add_subprojects, instance)
whitelist.permit(:parent_id)
end
unless params[:project][:custom_field_values].nil?
whitelist[:custom_field_values] = params[:project][:custom_field_values]
end

@ -88,9 +88,9 @@ class CopyProjectJob
UserMailer.with_deliveries(send_mails) do
parent_id = target_project_params[:parent_id]
target_project = Project.new.tap do |p|
p.attributes = target_project_params
p.enabled_module_names = enabled_modules
target_project = Project.new.tap do |project|
project.attributes = target_project_params
project.enabled_module_names = enabled_modules
end
if validate_parent_id(target_project, parent_id) && target_project.save
@ -114,8 +114,17 @@ class CopyProjectJob
target_project = nil
end
end
rescue ActiveRecord::RecordNotFound
rescue ActiveRecord::RecordNotFound => e
logger.error("Entity missing: #{e.message} #{e.backtrace.join("\n")}")
rescue StandardError => e
logger.error('Encountered an error when trying to copy project '\
"'#{source_project_id}' : #{e.message} #{e.backtrace.join("\n")}")
ensure
unless errors.empty?
logger.info('Encountered an errors while trying to copy related objects for '\
"project '#{source_project_id}': #{errors.inspect}")
end
return target_project, errors
end
@ -123,13 +132,21 @@ class CopyProjectJob
# TODO: move it to Project model in a validation that depends on User.current
def validate_parent_id(project, parent_id)
return true if User.current.admin?
if parent_id || project.new_record?
parent = parent_id.blank? ? nil : Project.find_by(id: parent_id.to_i)
unless project.allowed_parents.include?(parent)
project.errors.add :parent_id, :invalid
return false
end
end
true
end
def logger
Delayed::Worker.logger
end
end

@ -168,5 +168,7 @@ module OpenProject
config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')]
OpenProject::Configuration.configure_cache(config)
config.active_job.queue_adapter = :delayed_job
end
end

@ -175,9 +175,8 @@ Feature: Project Settings
And I go to the page of the planning element "pe2" of the project called "Copied Project"
Then I should see "pe2" within "#content"
@javascript @wip
@javascript
Scenario: Copying a project with a complex issue
# FIXME 16364 assignee is not shown on work package views (full and split screen)
Given the project "project1" has 1 version with:
| name | version1 |
| description | yeah, boy |

Loading…
Cancel
Save