Project

General

Profile

« Previous | Next » 

Revision 4:7d3a38ab714a

Added by Haru Iida about 8 years ago

  • ID 7d3a38ab714a

fixes #884 Can't add a relation to issue of the parent project.

View differences:

app/controllers/commit_relation_editor_controller.rb
17 17

  
18 18
class CommitRelationEditorController < ApplicationController
19 19
  unloadable
20
  before_filter :find_project, :authorize, :find_changeset, :find_issue
20
  before_filter :find_project, :authorize, :find_changeset
21 21

  
22
  def new    
23
    unless @issue
24
      flash[:error] = l(:error_issue_not_found_in_project) + ":##{@issue_id}"
22
  def new
23
    issue_id = params[:issue_id]
24
    issue = find_referenced_issue_by_id issue_id
25
    unless issue
26
      flash[:error] = l(:error_issue_not_found_in_project) + ":##{issue_id}"
25 27
    else
26
      if @changeset.issues.include? @issue
27
        flash[:notice] = l(:error_issue_is_already_related, :issue_id => @issue_id)
28
      if @changeset.issues.include? issue
29
        flash[:notice] = l(:error_issue_is_already_related, :issue_id => issue_id)
28 30
      else
29
        @changeset.issues << @issue
31
        @changeset.issues << issue
30 32
        if (@changeset.save) 
31 33
          flash[:notice] = l(:notice_successful_update)
32 34
        else
......
39 41
  end
40 42

  
41 43
  def destroy
42
    unless @issue
43
      flash[:error] = l(:error_issue_not_found_in_project) + ":##{@issue_id}"
44
    issue_id = params[:issue_id]
45
    issue = Issue.find(:first, :conditions => ['id = ?', issue_id])
46
    unless issue
47
      flash[:error] = l(:error_issue_not_found_in_project) + ":##{issue_id}"
44 48
    else
45
      unless @changeset.issues.include? @issue
46
        flash[:notice] = "Issue ##{@issue_id} is not related."
49
      unless @changeset.issues.include? issue
50
        flash[:notice] = "Issue ##{issue_id} is not related."
47 51
      else
48
        @changeset.issues.delete(@issue)
52
        @changeset.issues.delete(issue)
49 53
        if (@changeset.save) 
50 54
          flash[:notice] = l(:notice_successful_update)
51 55
        else
......
65 69

  
66 70
  end
67 71
  
68
  def find_issue
69
    @issue_id = params[:issue_id]
70
    @issue = Issue.find(:first, :conditions => ['id = ? and project_id = ?', @issue_id, @project])
72
  def find_referenced_issue_by_id(id)
73
    return nil if id.blank?
74
    issue = Issue.find_by_id(id.to_i, :include => :project)
75
    if issue
76
      unless issue.project &&
77
                (@project == issue.project || @project.is_ancestor_of?(issue.project) ||
78
                 @project.is_descendant_of?(issue.project))
79
        issue = nil
80
      end
81
    end
82
    issue
71 83
  end
72 84

  
73 85
end
test/functional/commit_relation_editor_controller_test.rb
59 59
      changeset.reload
60 60
      assert_equal(0, changeset.issues.length)
61 61
    end
62
    
63
    should "not add relation if issue belongs wrong project." do
64
      @request.session[:user_id] = 1
65
      changeset = Changeset.generate!
66
      project = Project.find(2)
67
      issue = Issue.generate_for_project!(project)
68
      issue_id = issue.id
69
      post :new, :id => 1, :changeset_id => changeset.id, :issue_id => issue_id
70
      assert_response :redirect
71
      changeset.reload
72
      assert_equal(0, changeset.issues.length)
73
    end
62 74
  end
63 75
  
64 76
  context "destroy" do

Also available in: Unified diff