From 81cf6b23439705231e1b3655709b3d3cae43a9cd Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 7 Jan 2012 12:34:52 +0000 Subject: Allows project to be changed from the regular issue update action (#4769, #9803). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8531 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 14 +++++++++-- app/models/issue.rb | 46 +++++++++++++++++++++++++++-------- app/views/issues/_attributes.html.erb | 14 +++++------ app/views/issues/_edit.html.erb | 2 ++ app/views/issues/_form.html.erb | 11 +++++++-- 5 files changed, 66 insertions(+), 21 deletions(-) (limited to 'app') diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 6433acc5f..076a3a663 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -135,7 +135,17 @@ class IssuesController < ApplicationController def new respond_to do |format| format.html { render :action => 'new', :layout => !request.xhr? } - format.js { render :partial => 'attributes' } + format.js { + render(:update) { |page| + if params[:project_change] + page.replace_html 'all_attributes', :partial => 'form' + else + page.replace_html 'attributes', :partial => 'attributes' + end + m = User.current.allowed_to?(:log_time, @issue.project) ? 'show' : 'hide' + page << "if ($('log_time')) {Element.#{m}('log_time');}" + } + } end end @@ -274,7 +284,7 @@ private end def find_project - project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] + project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id]) @project = Project.find(project_id) rescue ActiveRecord::RecordNotFound render_404 diff --git a/app/models/issue.rb b/app/models/issue.rb index 0427608ba..16707f8ad 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -147,7 +147,9 @@ class Issue < ActiveRecord::Base issue.init_journal(User.current, options[:notes]) - issue.project = new_project + # Preserve previous behaviour + # #move_to_project doesn't change tracker automatically + issue.send :project=, new_project, true if new_tracker issue.tracker = new_tracker end @@ -169,6 +171,16 @@ class Issue < ActiveRecord::Base write_attribute(:priority_id, pid) end + def category_id=(cid) + self.category = nil + write_attribute(:category_id, cid) + end + + def fixed_version_id=(vid) + self.fixed_version = nil + write_attribute(:fixed_version_id, vid) + end + def tracker_id=(tid) self.tracker = nil result = write_attribute(:tracker_id, tid) @@ -182,11 +194,14 @@ class Issue < ActiveRecord::Base end end - def project=(project) + def project=(project, keep_tracker=false) project_was = self.project write_attribute(:project_id, project ? project.id : nil) association_instance_set('project', project) if project_was && project && project_was != project + unless keep_tracker || project.trackers.include?(tracker) + self.tracker = project.trackers.first + end # Reassign to the category with same name if any if category self.category = project.issue_categories.find_by_name(category.name) @@ -229,6 +244,12 @@ class Issue < ActiveRecord::Base write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h) end + safe_attributes 'project_id', + :if => lambda {|issue, user| + projects = Issue.allowed_target_projects_on_move(user) + projects.include?(issue.project) && projects.size > 1 + } + safe_attributes 'tracker_id', 'status_id', 'category_id', @@ -278,7 +299,11 @@ class Issue < ActiveRecord::Base attrs = delete_unsafe_attributes(attrs, user) return if attrs.empty? - # Tracker must be set before since new_statuses_allowed_to depends on it. + # Project and Tracker must be set before since new_statuses_allowed_to depends on it. + if p = attrs.delete('project_id') + self.project_id = p + end + if t = attrs.delete('tracker_id') self.tracker_id = t end @@ -725,16 +750,16 @@ class Issue < ActiveRecord::Base # End ReportsController extraction # Returns an array of projects that current user can move issues to - def self.allowed_target_projects_on_move + def self.allowed_target_projects_on_move(user=User.current) projects = [] - if User.current.admin? + if user.admin? # admin is allowed to move issues to any active (visible) project - projects = Project.visible.all - elsif User.current.logged? + projects = Project.visible(user).all + elsif user.logged? if Role.non_member.allowed_to?(:move_issues) - projects = Project.visible.all + projects = Project.visible(user).all else - User.current.memberships.each {|m| projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}} + user.memberships.each {|m| projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}} end end projects @@ -754,7 +779,8 @@ class Issue < ActiveRecord::Base # Move subtasks children.each do |child| - child.project = project + # Change project and keep project + child.send :project=, project, true unless child.save raise ActiveRecord::Rollback end diff --git a/app/views/issues/_attributes.html.erb b/app/views/issues/_attributes.html.erb index 802c7194a..fed949e24 100644 --- a/app/views/issues/_attributes.html.erb +++ b/app/views/issues/_attributes.html.erb @@ -15,14 +15,14 @@

<%= f.select :assigned_to_id, principals_options_for_select(@issue.assignable_users, @issue.assigned_to), :include_blank => true %>

<% end %> -<% if @issue.safe_attribute?('category_id') && @project.issue_categories.any? %> -

<%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %> +<% if @issue.safe_attribute?('category_id') && @issue.project.issue_categories.any? %> +

<%= f.select :category_id, (@issue.project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %> <%= prompt_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'), l(:label_issue_category_new), 'issue_category[name]', - {:controller => 'issue_categories', :action => 'create', :project_id => @project}, + {:controller => 'issue_categories', :action => 'create', :project_id => @issue.project}, :title => l(:label_issue_category_new), - :tabindex => 199) if authorize_for('issue_categories', 'new') %>

+ :tabindex => 199) if User.current.allowed_to?(:manage_categories, @issue.project) %>

<% end %> <% if @issue.safe_attribute?('fixed_version_id') && @issue.assignable_versions.any? %> @@ -30,9 +30,9 @@ <%= prompt_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'), l(:label_version_new), 'version[name]', - {:controller => 'versions', :action => 'create', :project_id => @project}, + {:controller => 'versions', :action => 'create', :project_id => @issue.project}, :title => l(:label_version_new), - :tabindex => 200) if authorize_for('versions', 'new') %> + :tabindex => 200) if User.current.allowed_to?(:manage_versions, @issue.project) %>

<% end %> @@ -41,7 +41,7 @@ <% if @issue.safe_attribute? 'parent_issue_id' %>

<%= f.text_field :parent_issue_id, :size => 10 %>

-<%= javascript_tag "observeParentIssueField('#{auto_complete_issues_path(:id => @issue, :project_id => @project) }')" %> +<%= javascript_tag "observeParentIssueField('#{auto_complete_issues_path(:id => @issue, :project_id => @issue.project) }')" %> <% end %> <% if @issue.safe_attribute? 'start_date' %> diff --git a/app/views/issues/_edit.html.erb b/app/views/issues/_edit.html.erb index 7e1d04826..4db1a3e0f 100644 --- a/app/views/issues/_edit.html.erb +++ b/app/views/issues/_edit.html.erb @@ -3,7 +3,9 @@
<% if @edit_allowed || !@allowed_statuses.empty? %>
<%= l(:label_change_properties) %> +
<%= render :partial => 'form', :locals => {:f => f} %> +
<% end %> <% if User.current.allowed_to?(:log_time, @project) %> diff --git a/app/views/issues/_form.html.erb b/app/views/issues/_form.html.erb index e63adfbb3..fdfcfdda4 100644 --- a/app/views/issues/_form.html.erb +++ b/app/views/issues/_form.html.erb @@ -1,3 +1,4 @@ +<% labelled_fields_for :issue, @issue do |f| %> <%= call_hook(:view_issues_form_details_top, { :issue => @issue, :form => f }) %> <% if @issue.safe_attribute? 'is_private' %> @@ -6,10 +7,15 @@

<% end %> +<% if !@issue.new_record? && @issue.safe_attribute?('project_id') %> +

<%= f.select :project_id, Issue.allowed_target_projects_on_move.collect {|t| [t.name, t.id]}, :required => true %>

+<%= observe_field :issue_project_id, :url => project_issue_form_path(@project, :id => @issue, :project_change => '1'), + :with => "Form.serialize('issue-form')" %> +<% end %> + <% if @issue.safe_attribute? 'tracker_id' %> -

<%= f.select :tracker_id, @project.trackers.collect {|t| [t.name, t.id]}, :required => true %>

+

<%= f.select :tracker_id, @issue.project.trackers.collect {|t| [t.name, t.id]}, :required => true %>

<%= observe_field :issue_tracker_id, :url => project_issue_form_path(@project, :id => @issue), - :update => :attributes, :with => "Form.serialize('issue-form')" %> <% end %> @@ -39,3 +45,4 @@
<%= call_hook(:view_issues_form_details_bottom, { :issue => @issue, :form => f }) %> +<% end %> -- cgit v1.2.3