1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
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.
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.
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.
18 class DocumentsController < ApplicationController
20 before_filter :find_project, :authorize
23 @attachments = @document.attachments.find(:all, :order => "created_on DESC")
27 @categories = Enumeration::get_values('DCAT')
28 if request.post? and @document.update_attributes(params[:document])
29 flash[:notice] = l(:notice_successful_update)
30 redirect_to :action => 'show', :id => @document
36 redirect_to :controller => 'projects', :action => 'list_documents', :id => @project
40 @attachment = @document.attachments.find(params[:attachment_id])
41 @attachment.increment_download
42 send_file @attachment.diskfile, :filename => @attachment.filename
48 # Save the attachments
50 params[:attachments].each { |file|
51 next unless file.size > 0
52 a = Attachment.create(:container => @document, :file => file, :author => logged_in_user)
53 @attachments << a unless a.new_record?
54 } if params[:attachments] and params[:attachments].is_a? Array
55 Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('document_added')
56 redirect_to :action => 'show', :id => @document
59 def destroy_attachment
60 @document.attachments.find(params[:attachment_id]).destroy
61 redirect_to :action => 'show', :id => @document
66 @document = Document.find(params[:id])
67 @project = @document.project
68 rescue ActiveRecord::RecordNotFound