2010-08-31 17:12:58 +02:00
|
|
|
class FilesController < ApplicationController
|
|
|
|
menu_item :files
|
|
|
|
|
2010-09-14 18:24:07 +02:00
|
|
|
before_filter :find_project_by_project_id
|
2010-08-31 17:12:58 +02:00
|
|
|
before_filter :authorize
|
|
|
|
|
|
|
|
helper :sort
|
|
|
|
include SortHelper
|
|
|
|
|
|
|
|
def index
|
|
|
|
sort_init 'filename', 'asc'
|
|
|
|
sort_update 'filename' => "#{Attachment.table_name}.filename",
|
|
|
|
'created_on' => "#{Attachment.table_name}.created_on",
|
|
|
|
'size' => "#{Attachment.table_name}.filesize",
|
|
|
|
'downloads' => "#{Attachment.table_name}.downloads"
|
|
|
|
|
|
|
|
@containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
|
|
|
|
@containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
|
|
|
|
render :layout => !request.xhr?
|
|
|
|
end
|
|
|
|
|
2010-09-01 17:17:45 +02:00
|
|
|
def new
|
2010-09-13 22:35:03 +02:00
|
|
|
@versions = @project.versions.sort
|
|
|
|
end
|
2010-09-01 17:17:45 +02:00
|
|
|
|
2010-09-13 22:35:03 +02:00
|
|
|
def create
|
|
|
|
container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
|
|
|
|
attachments = Attachment.attach_files(container, params[:attachments])
|
|
|
|
render_attachment_warning_if_needed(container)
|
|
|
|
|
2010-09-26 10:07:41 +02:00
|
|
|
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
|
2010-09-13 22:35:03 +02:00
|
|
|
Mailer.deliver_attachments_added(attachments[:files])
|
2010-09-01 17:17:45 +02:00
|
|
|
end
|
2010-09-14 18:24:07 +02:00
|
|
|
redirect_to project_files_path(@project)
|
2010-09-01 17:17:45 +02:00
|
|
|
end
|
2010-08-31 17:12:58 +02:00
|
|
|
end
|