To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / issue_relations_controller.rb @ 1298:4f746d8966dd

History | View | Annotate | Download (2.58 KB)

1 507:0c939c159af4 Chris
# Redmine - project management software
2 1295:622f24f53b42 Chris
# Copyright (C) 2006-2013  Jean-Philippe Lang
3 0:513646585e45 Chris
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8 909:cbb26bc654de Chris
#
9 0:513646585e45 Chris
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13 909:cbb26bc654de Chris
#
14 0:513646585e45 Chris
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18
class IssueRelationsController < ApplicationController
19 909:cbb26bc654de Chris
  before_filter :find_issue, :find_project_from_association, :authorize, :only => [:index, :create]
20
  before_filter :find_relation, :except => [:index, :create]
21
22
  accept_api_auth :index, :show, :create, :destroy
23
24
  def index
25
    @relations = @issue.relations
26
27
    respond_to do |format|
28
      format.html { render :nothing => true }
29
      format.api
30
    end
31
  end
32
33
  def show
34
    raise Unauthorized unless @relation.visible?
35
36
    respond_to do |format|
37
      format.html { render :nothing => true }
38
      format.api
39
    end
40
  end
41
42
  def create
43 0:513646585e45 Chris
    @relation = IssueRelation.new(params[:relation])
44
    @relation.issue_from = @issue
45 1115:433d4f72a19b Chris
    if params[:relation] && m = params[:relation][:issue_to_id].to_s.strip.match(/^#?(\d+)$/)
46 0:513646585e45 Chris
      @relation.issue_to = Issue.visible.find_by_id(m[1].to_i)
47
    end
48 909:cbb26bc654de Chris
    saved = @relation.save
49
50 0:513646585e45 Chris
    respond_to do |format|
51 1295:622f24f53b42 Chris
      format.html { redirect_to issue_path(@issue) }
52 1115:433d4f72a19b Chris
      format.js {
53 1295:622f24f53b42 Chris
        @relations = @issue.reload.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
54 1115:433d4f72a19b Chris
      }
55 909:cbb26bc654de Chris
      format.api {
56
        if saved
57
          render :action => 'show', :status => :created, :location => relation_url(@relation)
58
        else
59
          render_validation_errors(@relation)
60
        end
61 210:0579821a129a Chris
      }
62 0:513646585e45 Chris
    end
63
  end
64 909:cbb26bc654de Chris
65
  def destroy
66
    raise Unauthorized unless @relation.deletable?
67
    @relation.destroy
68
69
    respond_to do |format|
70 1295:622f24f53b42 Chris
      format.html { redirect_to issue_path(@relation.issue_from) }
71 1115:433d4f72a19b Chris
      format.js
72
      format.api  { render_api_ok }
73 909:cbb26bc654de Chris
    end
74
  end
75
76 0:513646585e45 Chris
private
77
  def find_issue
78
    @issue = @object = Issue.find(params[:issue_id])
79
  rescue ActiveRecord::RecordNotFound
80
    render_404
81
  end
82 909:cbb26bc654de Chris
83
  def find_relation
84
    @relation = IssueRelation.find(params[:id])
85
  rescue ActiveRecord::RecordNotFound
86
    render_404
87
  end
88 0:513646585e45 Chris
end