You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

issue_relations_controller.rb 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 Jean-Philippe Lang
  3. #
  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. #
  9. # 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. #
  14. # 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. class IssueRelationsController < ApplicationController
  18. before_filter :find_issue, :find_project_from_association, :authorize, :only => [:index, :create]
  19. before_filter :find_relation, :except => [:index, :create]
  20. accept_api_auth :index, :show, :create, :destroy
  21. def index
  22. @relations = @issue.relations
  23. respond_to do |format|
  24. format.html { render :nothing => true }
  25. format.api
  26. end
  27. end
  28. def show
  29. raise Unauthorized unless @relation.visible?
  30. respond_to do |format|
  31. format.html { render :nothing => true }
  32. format.api
  33. end
  34. end
  35. def create
  36. @relation = IssueRelation.new(params[:relation])
  37. @relation.issue_from = @issue
  38. if params[:relation] && m = params[:relation][:issue_to_id].to_s.strip.match(/^#?(\d+)$/)
  39. @relation.issue_to = Issue.visible.find_by_id(m[1].to_i)
  40. end
  41. saved = @relation.save
  42. respond_to do |format|
  43. format.html { redirect_to issue_path(@issue) }
  44. format.js {
  45. @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
  46. }
  47. format.api {
  48. if saved
  49. render :action => 'show', :status => :created, :location => relation_url(@relation)
  50. else
  51. render_validation_errors(@relation)
  52. end
  53. }
  54. end
  55. end
  56. def destroy
  57. raise Unauthorized unless @relation.deletable?
  58. @relation.destroy
  59. respond_to do |format|
  60. format.html { redirect_to issue_path(@relation.issue_from) }
  61. format.js
  62. format.api { render_api_ok }
  63. end
  64. end
  65. private
  66. def find_issue
  67. @issue = @object = Issue.find(params[:issue_id])
  68. rescue ActiveRecord::RecordNotFound
  69. render_404
  70. end
  71. def find_relation
  72. @relation = IssueRelation.find(params[:id])
  73. rescue ActiveRecord::RecordNotFound
  74. render_404
  75. end
  76. end