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

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