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

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