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.

journals_controller.rb 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- 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 JournalsController < ApplicationController
  19. before_action :find_journal, :only => [:edit, :update, :diff]
  20. before_action :find_issue, :only => [:new]
  21. before_action :find_optional_project, :only => [:index]
  22. before_action :authorize, :only => [:new, :edit, :update, :diff]
  23. accept_atom_auth :index
  24. accept_api_auth :update
  25. menu_item :issues
  26. helper :issues
  27. helper :custom_fields
  28. helper :queries
  29. helper :attachments
  30. include QueriesHelper
  31. def index
  32. retrieve_query
  33. if @query.valid?
  34. @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
  35. :limit => 25)
  36. end
  37. @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
  38. render :layout => false, :content_type => 'application/atom+xml'
  39. rescue ActiveRecord::RecordNotFound
  40. render_404
  41. end
  42. def diff
  43. @issue = @journal.issue
  44. if params[:detail_id].present?
  45. @detail = @journal.details.find_by_id(params[:detail_id])
  46. else
  47. @detail = @journal.details.detect {|d| d.property == 'attr' && d.prop_key == 'description'}
  48. end
  49. unless @issue && @detail
  50. render_404
  51. return false
  52. end
  53. if @detail.property == 'cf'
  54. unless @detail.custom_field && @detail.custom_field.visible_by?(@issue.project, User.current)
  55. raise ::Unauthorized
  56. end
  57. end
  58. @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value)
  59. end
  60. def new
  61. @journal = Journal.visible.find(params[:journal_id]) if params[:journal_id]
  62. if @journal
  63. user = @journal.user
  64. text = @journal.notes
  65. @content = +"#{ll(Setting.default_language, :text_user_wrote_in, {:value => user, :link => "#note-#{params[:journal_indice]}"})}\n> "
  66. else
  67. user = @issue.author
  68. text = @issue.description
  69. @content = +"#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
  70. end
  71. # Replaces pre blocks with [...]
  72. text = text.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]')
  73. @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
  74. rescue ActiveRecord::RecordNotFound
  75. render_404
  76. end
  77. def edit
  78. (render_403; return false) unless @journal.editable_by?(User.current)
  79. respond_to do |format|
  80. # TODO: implement non-JS journal update
  81. format.js
  82. end
  83. end
  84. def update
  85. (render_403; return false) unless @journal.editable_by?(User.current)
  86. journal_attributes = params[:journal]
  87. journal_attributes[:updated_by] = User.current
  88. @journal.safe_attributes = journal_attributes
  89. @journal.save
  90. @journal.destroy if @journal.details.empty? && @journal.notes.blank?
  91. call_hook(:controller_journals_edit_post, {:journal => @journal, :params => params})
  92. respond_to do |format|
  93. format.html {redirect_to issue_path(@journal.journalized)}
  94. format.js
  95. format.api { render_api_ok }
  96. end
  97. end
  98. private
  99. def find_journal
  100. @journal = Journal.visible.find(params[:id])
  101. @project = @journal.journalized.project
  102. rescue ActiveRecord::RecordNotFound
  103. render_404
  104. end
  105. end