From 3f87f3c47a2667b8e4f0b3107da8951d2a55412d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 5 Apr 2007 17:20:04 +0000 Subject: [PATCH] Feature 9867 Allow file upload in comment and add to issue history git-svn-id: http://redmine.rubyforge.org/svn/trunk@425 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 22 +++++++++++++++++++++- app/helpers/issues_helper.rb | 22 +++++++++++++++++----- app/views/issues/change_status.rhtml | 8 +++++++- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index a23837940..be1b8c003 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -86,6 +86,15 @@ class IssuesController < ApplicationController journal = @issue.init_journal(self.logged_in_user, params[:notes]) @issue.status = @new_status if @issue.update_attributes(params[:issue]) + # Save attachments + params[:attachments].each { |file| + next unless file.size > 0 + a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user) + journal.details << JournalDetail.new(:property => 'attachment', + :prop_key => a.id, + :value => a.filename) unless a.new_record? + } if params[:attachments] and params[:attachments].is_a? Array + flash[:notice] = l(:notice_successful_update) Mailer.deliver_issue_edit(journal) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? redirect_to :action => 'show', :id => @issue @@ -106,17 +115,28 @@ class IssuesController < ApplicationController def add_attachment # Save the attachments @attachments = [] + journal = @issue.init_journal(self.logged_in_user) params[:attachments].each { |file| next unless file.size > 0 a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user) @attachments << a unless a.new_record? + journal.details << JournalDetail.new(:property => 'attachment', + :prop_key => a.id, + :value => a.filename) unless a.new_record? } if params[:attachments] and params[:attachments].is_a? Array + journal.save if journal.details.any? Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? redirect_to :action => 'show', :id => @issue end def destroy_attachment - @issue.attachments.find(params[:attachment_id]).destroy + a = @issue.attachments.find(params[:attachment_id]) + a.destroy + journal = @issue.init_journal(self.logged_in_user) + journal.details << JournalDetail.new(:property => 'attachment', + :prop_key => a.id, + :old_value => a.filename) + journal.save redirect_to :action => 'show', :id => @issue end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 8fa9f75eb..9d3f877a1 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -48,6 +48,8 @@ module IssuesHelper value = format_value(detail.value, custom_field.field_format) if detail.value old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value end + when 'attachment' + label = l(:label_attachment) end label ||= detail.prop_key @@ -62,13 +64,23 @@ module IssuesHelper end if detail.value and !detail.value.to_s.empty? - if old_value - label + " " + l(:text_journal_changed, old_value, value) - else - label + " " + l(:text_journal_set_to, value) + case detail.property + when 'attr', 'cf' + if old_value + label + " " + l(:text_journal_changed, old_value, value) + else + label + " " + l(:text_journal_set_to, value) + end + when 'attachment' + "#{label} #{value} #{l(:label_added)}" end else - label + " " + l(:text_journal_deleted) + " (#{old_value})" + case detail.property + when 'attr', 'cf' + label + " " + l(:text_journal_deleted) + " (#{old_value})" + when 'attachment' + "#{label} #{old_value} #{l(:label_deleted)}" + end end end end diff --git a/app/views/issues/change_status.rhtml b/app/views/issues/change_status.rhtml index 61e2fad29..f253c9600 100644 --- a/app/views/issues/change_status.rhtml +++ b/app/views/issues/change_status.rhtml @@ -1,7 +1,7 @@

<%=l(:label_issue)%> #<%= @issue.id %>: <%=h @issue.subject %>

<%= error_messages_for 'issue' %> -<% form_tag({:action => 'change_status', :id => @issue}, :class => "tabular") do %> +<% form_tag({:action => 'change_status', :id => @issue}, :multipart => true, :class => "tabular") do %> <%= hidden_field_tag 'confirm', 1 %> <%= hidden_field_tag 'new_status_id', @new_status.id %> @@ -30,6 +30,12 @@

<%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>

+<% if authorize_for('issues', 'add_attachment') %> +

+<%= file_field_tag 'attachments[]', :size => 30 %> (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)

+<% end %> + <%= hidden_field 'issue', 'lock_version' %> -- 2.39.5