Merged r4615 and r4616 from trunk.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.1-stable@4617 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
1 parent
119732c3ee
commit
ded234794e
4 files changed
+25
-4
No files matched your search
@@ -124,13 +124,13 @@ class ProjectsController < ApplicationController
|
|||||||
if validate_parent_id && @project.copy(@source_project, :only => params[:only])
|
if validate_parent_id && @project.copy(@source_project, :only => params[:only])
|
||||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :controller => 'projects', :action => 'settings'
|
redirect_to :controller => 'projects', :action => 'settings', :id => @project
|
||||||
elsif !@project.new_record?
|
elsif !@project.new_record?
|
||||||
# Project was created
|
# Project was created
|
||||||
# But some objects were not copied due to validation failures
|
# But some objects were not copied due to validation failures
|
||||||
# (eg. issues from disabled trackers)
|
# (eg. issues from disabled trackers)
|
||||||
# TODO: inform about that
|
# TODO: inform about that
|
||||||
redirect_to :controller => 'projects', :action => 'settings'
|
redirect_to :controller => 'projects', :action => 'settings', :id => @project
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -740,7 +740,12 @@ class Project < ActiveRecord::Base
|
|||||||
|
|
||||||
# Copies members from +project+
|
# Copies members from +project+
|
||||||
def copy_members(project)
|
def copy_members(project)
|
||||||
project.memberships.each do |member|
|
# Copy users first, then groups to handle members with inherited and given roles
|
||||||
|
members_to_copy = []
|
||||||
|
members_to_copy += project.memberships.select {|m| m.principal.is_a?(User)}
|
||||||
|
members_to_copy += project.memberships.select {|m| !m.principal.is_a?(User)}
|
||||||
|
|
||||||
|
members_to_copy.each do |member|
|
||||||
new_member = Member.new
|
new_member = Member.new
|
||||||
new_member.attributes = member.attributes.dup.except("id", "project_id", "created_on")
|
new_member.attributes = member.attributes.dup.except("id", "project_id", "created_on")
|
||||||
# only copy non inherited roles
|
# only copy non inherited roles
|
||||||
|
|||||||
@@ -429,7 +429,7 @@ class ProjectsControllerTest < ActionController::TestCase
|
|||||||
@request.session[:user_id] = 1 # admin
|
@request.session[:user_id] = 1 # admin
|
||||||
post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'}
|
post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'}
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
assert_redirected_to :controller => 'projects', :action => 'settings'
|
assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -770,6 +770,22 @@ class ProjectTest < ActiveSupport::TestCase
|
|||||||
assert_equal @project, membership.project
|
assert_equal @project, membership.project
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "copy memberships with groups and additional roles" do
|
||||||
|
group = Group.create!(:lastname => "Copy group")
|
||||||
|
user = User.find(7)
|
||||||
|
group.users << user
|
||||||
|
# group role
|
||||||
|
Member.create!(:project_id => @source_project.id, :principal => group, :role_ids => [2])
|
||||||
|
member = Member.find_by_user_id_and_project_id(user.id, @source_project.id)
|
||||||
|
# additional role
|
||||||
|
member.role_ids = [1]
|
||||||
|
|
||||||
|
assert @project.copy(@source_project)
|
||||||
|
member = Member.find_by_user_id_and_project_id(user.id, @project.id)
|
||||||
|
assert_not_nil member
|
||||||
|
assert_equal [1, 2], member.role_ids.sort
|
||||||
|
end
|
||||||
|
|
||||||
should "copy project specific queries" do
|
should "copy project specific queries" do
|
||||||
assert @project.valid?
|
assert @project.valid?
|
||||||
|
|||||||
Reference in new issue
Block a user