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

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