| 
									
										
										
										
											2019-03-15 01:32:57 +00:00
										 |  |  | # frozen_string_literal: false | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 13:34:41 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							| 
									
										
										
										
											2017-06-25 08:40:31 +00:00
										 |  |  | # Copyright (C) 2006-2017  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2008-02-02 10:50:31 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | # modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | # of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2011-08-31 10:10:33 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2008-02-02 10:50:31 +00:00
										 |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											2011-08-31 10:10:33 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2008-02-02 10:50:31 +00:00
										 |  |  | # You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | # along with this program; if not, write to the Free Software | 
					
						
							|  |  |  | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class JournalsController < ApplicationController | 
					
						
							| 
									
										
										
										
											2016-07-14 07:27:31 +00:00
										 |  |  |   before_action :find_journal, :only => [:edit, :update, :diff] | 
					
						
							|  |  |  |   before_action :find_issue, :only => [:new] | 
					
						
							|  |  |  |   before_action :find_optional_project, :only => [:index] | 
					
						
							|  |  |  |   before_action :authorize, :only => [:new, :edit, :update, :diff] | 
					
						
							| 
									
										
										
										
											2011-07-09 08:56:07 +00:00
										 |  |  |   accept_rss_auth :index | 
					
						
							| 
									
										
										
										
											2011-02-27 13:34:41 +00:00
										 |  |  |   menu_item :issues | 
					
						
							| 
									
										
										
										
											2011-08-31 10:10:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-23 15:04:36 +00:00
										 |  |  |   helper :issues | 
					
						
							| 
									
										
										
										
											2011-03-06 16:04:35 +00:00
										 |  |  |   helper :custom_fields | 
					
						
							| 
									
										
										
										
											2010-08-23 15:04:36 +00:00
										 |  |  |   helper :queries | 
					
						
							|  |  |  |   include QueriesHelper | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def index | 
					
						
							|  |  |  |     retrieve_query | 
					
						
							|  |  |  |     if @query.valid? | 
					
						
							| 
									
										
										
										
											2011-08-31 10:10:33 +00:00
										 |  |  |       @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", | 
					
						
							| 
									
										
										
										
											2010-08-23 15:04:36 +00:00
										 |  |  |                                   :limit => 25) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) | 
					
						
							|  |  |  |     render :layout => false, :content_type => 'application/atom+xml' | 
					
						
							|  |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 10:10:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 13:34:41 +00:00
										 |  |  |   def diff | 
					
						
							|  |  |  |     @issue = @journal.issue | 
					
						
							|  |  |  |     if params[:detail_id].present? | 
					
						
							|  |  |  |       @detail = @journal.details.find_by_id(params[:detail_id]) | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2015-01-31 10:42:41 +00:00
										 |  |  |       @detail = @journal.details.detect {|d| d.property == 'attr' && d.prop_key == 'description'} | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     unless @issue && @detail | 
					
						
							|  |  |  |       render_404 | 
					
						
							|  |  |  |       return false | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     if @detail.property == 'cf' | 
					
						
							|  |  |  |       unless @detail.custom_field && @detail.custom_field.visible_by?(@issue.project, User.current) | 
					
						
							|  |  |  |         raise ::Unauthorized | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2011-02-27 13:34:41 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |     @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 10:10:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-16 16:25:04 +00:00
										 |  |  |   def new | 
					
						
							| 
									
										
										
										
											2012-10-03 21:36:19 +00:00
										 |  |  |     @journal = Journal.visible.find(params[:journal_id]) if params[:journal_id] | 
					
						
							|  |  |  |     if @journal | 
					
						
							|  |  |  |       user = @journal.user | 
					
						
							|  |  |  |       text = @journal.notes | 
					
						
							| 
									
										
										
										
											2010-08-16 16:25:04 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       user = @issue.author | 
					
						
							|  |  |  |       text = @issue.description | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     # Replaces pre blocks with [...] | 
					
						
							| 
									
										
										
										
											2014-03-15 10:36:56 +00:00
										 |  |  |     text = text.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]') | 
					
						
							| 
									
										
										
										
											2012-07-19 19:10:18 +00:00
										 |  |  |     @content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> " | 
					
						
							|  |  |  |     @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" | 
					
						
							| 
									
										
										
										
											2012-10-03 21:36:19 +00:00
										 |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							| 
									
										
										
										
											2010-08-16 16:25:04 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 10:10:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-02 10:50:31 +00:00
										 |  |  |   def edit | 
					
						
							| 
									
										
										
										
											2011-02-27 13:34:41 +00:00
										 |  |  |     (render_403; return false) unless @journal.editable_by?(User.current) | 
					
						
							| 
									
										
										
										
											2016-01-21 04:39:56 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							|  |  |  |       # TODO: implement non-JS journal update | 
					
						
							|  |  |  |       format.js | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def update | 
					
						
							|  |  |  |     (render_403; return false) unless @journal.editable_by?(User.current) | 
					
						
							| 
									
										
										
										
											2016-07-10 10:58:00 +00:00
										 |  |  |     @journal.safe_attributes = params[:journal] | 
					
						
							|  |  |  |     @journal.save | 
					
						
							| 
									
										
										
										
											2016-01-21 04:39:56 +00:00
										 |  |  |     @journal.destroy if @journal.details.empty? && @journal.notes.blank? | 
					
						
							|  |  |  |     call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params}) | 
					
						
							|  |  |  |     respond_to do |format| | 
					
						
							|  |  |  |       format.html { redirect_to issue_path(@journal.journalized) } | 
					
						
							|  |  |  |       format.js | 
					
						
							| 
									
										
										
										
											2008-02-02 10:50:31 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 10:10:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 13:34:41 +00:00
										 |  |  |   private | 
					
						
							| 
									
										
										
										
											2011-08-31 10:10:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-02 10:50:31 +00:00
										 |  |  |   def find_journal | 
					
						
							| 
									
										
										
										
											2012-10-03 21:36:19 +00:00
										 |  |  |     @journal = Journal.visible.find(params[:id]) | 
					
						
							| 
									
										
										
										
											2008-02-12 18:31:15 +00:00
										 |  |  |     @project = @journal.journalized.project | 
					
						
							| 
									
										
										
										
											2008-02-02 10:50:31 +00:00
										 |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |