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

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