Skip to content

Commit

Permalink
Real support for cross-project issues relations
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed Apr 13, 2011
1 parent d809efa commit ccfcdb2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
10 changes: 7 additions & 3 deletions app/controllers/issues_controller.rb
Expand Up @@ -130,7 +130,7 @@ def show
def new
respond_to do |format|
format.html { render :action => 'new', :layout => !request.xhr? }
format.js { render :partial => 'attributes' }
format.js { render :template => 'issues/new.rhtml', :layout => FALSE }
end
end

Expand Down Expand Up @@ -299,10 +299,14 @@ def build_new_issue_from_params
else
@issue = @project.issues.visible.find(params[:id])
end

@issue.project = @project
# Tracker must be set before custom field values
@issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
begin
@issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
rescue ActiveRecord::RecordNotFound
@issue.tracker ||= @project.trackers.find(:all).first;
end
if @issue.tracker.nil?
render_error l(:error_no_tracker_in_project)
return false
Expand Down
35 changes: 20 additions & 15 deletions app/models/issue.rb
Expand Up @@ -162,8 +162,11 @@ def move_to_project_without_transaction(new_project, new_tracker = nil, options
issue.fixed_version = nil
end
issue.project = new_project
if issue.parent && issue.parent.project_id != issue.project_id
issue.parent_issue_id = nil
# keep the parent issue dude!
unless Setting.cross_project_issue_relations?
if issue.parent && issue.parent.project_id != issue.project_id
issue.parent_issue_id = nil
end
end
end
if new_tracker
Expand Down Expand Up @@ -331,31 +334,33 @@ def validate
errors.add_to_base I18n.t(:error_can_not_reopen_issue_on_closed_version)
end
end

# Checks that the issue can not be added/moved to a disabled tracker
if project && (tracker_id_changed? || project_id_changed?)
unless project.trackers.include?(tracker)
errors.add :tracker_id, :inclusion
end
end

# Checks parent issue assignment
if @parent_issue
if @parent_issue.project_id != project_id
errors.add :parent_issue_id, :not_same_project
elsif !new_record?
# moving an existing issue
if @parent_issue.root_id != root_id
# we can always move to another tree
elsif move_possible?(@parent_issue)
# move accepted inside tree
else
errors.add :parent_issue_id, :not_a_valid_parent
unless Setting.cross_project_issue_relations?
if @parent_issue.project_id != project_id
errors.add :parent_issue_id, :not_same_project
elsif !new_record?
# moving an existing issue
if @parent_issue.root_id != root_id
# we can always move to another tree
elsif move_possible?(@parent_issue)
# move accepted inside tree
else
errors.add :parent_issue_id, :not_a_valid_parent
end
end
end
end
end

# Set the done_ratio using the status if that setting is set. This will keep the done_ratios
# even if the user turns off the setting later
def update_done_ratio_from_issue_status
Expand Down
2 changes: 1 addition & 1 deletion app/views/issues/_form.rhtml
Expand Up @@ -3,7 +3,7 @@
<div id="issue_descr_fields" <%= 'style="display:none"' unless @issue.new_record? || @issue.errors.any? %>>
<p><%= f.select :tracker_id, @project.trackers.collect {|t| [t.name, t.id]}, :required => true %></p>
<%= observe_field :issue_tracker_id, :url => { :action => :new, :project_id => @project, :id => @issue },
:update => :attributes,
:update => :project,
:with => "Form.serialize('issue-form')" %>

<p><%= f.text_field :subject, :size => 80, :required => true %></p>
Expand Down
9 changes: 7 additions & 2 deletions app/views/issues/new.rhtml
Expand Up @@ -4,18 +4,23 @@
:html => {:multipart => true, :id => 'issue-form', :class => 'tabular new-issue-form'} do |f| %>
<%= error_messages_for 'issue' %>
<div class="box">
<p><%= f.select "project_id", project_tree_options_for_select(Issue.allowed_target_projects_on_move, :selected => @issue.project), :required => true %></p>
<%= observe_field :issue_project_id, :url => { :action => :new, :project_id => @project, :id => @issue },
:update => 'content',
:with => "Form.serialize('issue-form')" %>
<%= render :partial => 'issues/form', :locals => {:f => f} %>
</div>
<%= submit_tag l(:button_create) %>
<%= submit_tag l(:button_create_and_continue), :name => 'continue' %>
<%= link_to_remote l(:label_preview),
<%= link_to_remote l(:label_preview),
{ :url => preview_issue_path(:project_id => @project),
:method => 'post',
:update => 'preview',
:with => "Form.serialize('issue-form')",
:complete => "Element.scrollTo('preview')"
}, :accesskey => accesskey(:preview) %>
<%= javascript_tag "Form.Element.focus('issue_subject');" %>
<% end %>

Expand Down

0 comments on commit ccfcdb2

Please sign in to comment.