]> source.dussan.org Git - redmine.git/commitdiff
Backported r3683 from trunk.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 30 Apr 2010 17:32:42 +0000 (17:32 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 30 Apr 2010 17:32:42 +0000 (17:32 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/0.9-stable@3717 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
app/models/issue.rb
test/unit/issue_test.rb

index d627f712de4545afda6b88d3c9f0a05fc9372d7d..2a60c3616489bc5da2312e6606d642a879523050 100644 (file)
@@ -283,14 +283,7 @@ class IssuesController < ApplicationController
 
   def move
     @copy = params[:copy_options] && params[:copy_options][:copy]
-    @allowed_projects = []
-    # find projects to which the user is allowed to move the issue
-    if User.current.admin?
-      # admin is allowed to move issues to any active (visible) project
-      @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current))
-    else
-      User.current.memberships.each {|m| @allowed_projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}}
-    end
+    @allowed_projects = Issue.allowed_target_projects_on_move
     @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
     @target_project ||= @project    
     @trackers = @target_project.trackers
index 25a07107c14022f7eb8c604763d62d8940bfe618..36051f20965f659cfdde5be80e99729166ed4f9e 100644 (file)
@@ -389,6 +389,22 @@ class Issue < ActiveRecord::Base
     Issue.update_versions(["#{Version.table_name}.project_id IN (?) OR #{Issue.table_name}.project_id IN (?)", moved_project_ids, moved_project_ids])
   end
 
+  # Returns an array of projects that current user can move issues to
+  def self.allowed_target_projects_on_move
+    projects = []
+    if User.current.admin?
+      # admin is allowed to move issues to any active (visible) project
+      projects = Project.visible.all
+    elsif User.current.logged?
+      if Role.non_member.allowed_to?(:move_issues)
+        projects = Project.visible.all
+      else
+        User.current.memberships.each {|m| projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}}
+      end
+    end
+    projects
+  end
+   
   private
   
   # Update issues so their versions are not pointing to a
index f2a67d160ff7f8101b80062cebb9a64e694e2659..a129b2636d52a832695228b30064f6b6584bb034 100644 (file)
@@ -599,4 +599,20 @@ class IssueTest < ActiveSupport::TestCase
       end
     end
   end
+  
+  context ".allowed_target_projects_on_move" do
+    should "return all active projects for admin users" do
+      User.current = User.find(1)
+      assert_equal Project.active.count, Issue.allowed_target_projects_on_move.size
+    end
+    
+    should "return allowed projects for non admin users" do
+      User.current = User.find(2)
+      Role.non_member.remove_permission! :move_issues
+      assert_equal 3, Issue.allowed_target_projects_on_move.size
+      
+      Role.non_member.add_permission! :move_issues
+      assert_equal Project.active.count, Issue.allowed_target_projects_on_move.size
+    end
+  end
 end