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

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