Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

issue_relations_controller.rb 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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. begin
  42. saved = @relation.save
  43. rescue ActiveRecord::RecordNotUnique
  44. saved = false
  45. @relation.errors.add :base, :taken
  46. end
  47. respond_to do |format|
  48. format.html { redirect_to issue_path(@issue) }
  49. format.js {
  50. @relations = @issue.reload.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
  51. }
  52. format.api {
  53. if saved
  54. render :action => 'show', :status => :created, :location => relation_url(@relation)
  55. else
  56. render_validation_errors(@relation)
  57. end
  58. }
  59. end
  60. end
  61. def destroy
  62. raise Unauthorized unless @relation.deletable?
  63. @relation.init_journals(User.current)
  64. @relation.destroy
  65. respond_to do |format|
  66. format.html { redirect_to issue_path(@relation.issue_from) }
  67. format.js
  68. format.api { render_api_ok }
  69. end
  70. end
  71. private
  72. def find_issue
  73. @issue = Issue.find(params[:issue_id])
  74. @project = @issue.project
  75. rescue ActiveRecord::RecordNotFound
  76. render_404
  77. end
  78. def find_relation
  79. @relation = IssueRelation.find(params[:id])
  80. rescue ActiveRecord::RecordNotFound
  81. render_404
  82. end
  83. end