kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.8 KiB
97 lines
3.8 KiB
#-- encoding: UTF-8
|
|
#-- copyright
|
|
# OpenProject is a project management system.
|
|
# Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
|
|
#
|
|
# 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 doc/COPYRIGHT.rdoc for more details.
|
|
#++
|
|
|
|
class CopyProjectsController < ApplicationController
|
|
helper :timelines
|
|
|
|
before_filter :disable_api
|
|
before_filter :find_project
|
|
before_filter :authorize, :only => [ :copy, :copy_project ]
|
|
|
|
def copy
|
|
@source_project = @project
|
|
UserMailer.with_deliveries(params[:notifications] == '1') do
|
|
@project = Project.new
|
|
@project.safe_attributes = params[:project]
|
|
@project.enabled_module_names = params[:enabled_modules]
|
|
if @project.save && validate_parent_id
|
|
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
|
if @project.copy_associations(@source_project, :only => params[:only])
|
|
flash[:notice] = l(:notice_successful_create)
|
|
end
|
|
# Project was created
|
|
# But some objects might not have been copied due to validation failures
|
|
errors = (@project.compiled_errors.flatten + [@project.errors]).map(&:full_messages).flatten
|
|
flash[:error] = errors if errors.present?
|
|
redirect_to :controller => '/projects', :action => 'settings', :id => @project
|
|
else
|
|
# Project was not created
|
|
flash[:error] = @project.errors.full_messages
|
|
redirect_to :back
|
|
end
|
|
end
|
|
rescue ActiveRecord::RecordNotFound
|
|
redirect_to :back
|
|
end
|
|
|
|
def copy_project
|
|
from = (["admin", "settings"].include?(params[:coming_from]) ? params[:coming_from] : "settings")
|
|
@issue_custom_fields = WorkPackageCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
|
@types = Type.all
|
|
@root_projects = Project.find(:all,
|
|
:conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
|
|
:order => 'name')
|
|
@copy_project = Project.copy_attributes(@project)
|
|
if @copy_project
|
|
@copy_project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
|
|
render :action => "copy_from_#{from}"
|
|
else
|
|
redirect_to :back
|
|
end
|
|
rescue ActiveRecord::RecordNotFound
|
|
redirect_to :back
|
|
end
|
|
|
|
protected
|
|
|
|
# Validates parent_id param according to user's permissions
|
|
# TODO: move it to Project model in a validation that depends on User.current
|
|
def validate_parent_id
|
|
return true if User.current.admin?
|
|
parent_id = params[:project] && params[:project][:parent_id]
|
|
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
|
|
end
|
|
|