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.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2016 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. helper :issues
  19. before_action :find_issue, :authorize, :only => [:index, :create]
  20. before_action :find_relation, :only => [:show, :destroy]
  21. accept_api_auth :index, :show, :create, :destroy
  22. def index
  23. @relations = @issue.relations
  24. respond_to do |format|
  25. format.html { head 200 }
  26. format.api
  27. end
  28. end
  29. def show
  30. raise Unauthorized unless @relation.visible?
  31. respond_to do |format|
  32. format.html { head 200 }
  33. format.api
  34. end
  35. end
  36. def create
  37. @relation = IssueRelation.new
  38. @relation.issue_from = @issue
  39. @relation.safe_attributes = params[:relation]
  40. @relation.init_journals(User.current)
  41. saved = @relation.save
  42. respond_to do |format|
  43. format.html { redirect_to issue_path(@issue) }
  44. format.js {
  45. @relations = @issue.reload.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.init_journals(User.current)
  59. @relation.destroy
  60. respond_to do |format|
  61. format.html { redirect_to issue_path(@relation.issue_from) }
  62. format.js
  63. format.api { render_api_ok }
  64. end
  65. end
  66. private
  67. def find_issue
  68. @issue = Issue.find(params[:issue_id])
  69. @project = @issue.project
  70. rescue ActiveRecord::RecordNotFound
  71. render_404
  72. end
  73. def find_relation
  74. @relation = IssueRelation.find(params[:id])
  75. rescue ActiveRecord::RecordNotFound
  76. render_404
  77. end
  78. end