2012-05-05 16:56:53 +04:00
|
|
|
# Redmine - project management software
|
2014-01-30 02:45:39 +04:00
|
|
|
# Copyright (C) 2006-2014 Jean-Philippe Lang
|
2012-05-05 16:56:53 +04: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.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2010-08-31 19:12:58 +04:00
|
|
|
class FilesController < ApplicationController
|
|
|
|
menu_item :files
|
|
|
|
|
2010-09-14 20:24:07 +04:00
|
|
|
before_filter :find_project_by_project_id
|
2010-08-31 19:12:58 +04: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"
|
2011-05-18 11:12:48 +04:00
|
|
|
|
2012-12-03 01:28:19 +04:00
|
|
|
@containers = [ Project.includes(:attachments).reorder(sort_clause).find(@project.id)]
|
|
|
|
@containers += @project.versions.includes(:attachments).reorder(sort_clause).all.sort.reverse
|
2010-08-31 19:12:58 +04:00
|
|
|
render :layout => !request.xhr?
|
|
|
|
end
|
|
|
|
|
2010-09-01 19:17:45 +04:00
|
|
|
def new
|
2010-09-14 00:35:03 +04:00
|
|
|
@versions = @project.versions.sort
|
|
|
|
end
|
2010-09-01 19:17:45 +04:00
|
|
|
|
2010-09-14 00:35:03 +04: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 12:07:41 +04:00
|
|
|
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
|
2012-05-05 17:07:12 +04:00
|
|
|
Mailer.attachments_added(attachments[:files]).deliver
|
2010-09-01 19:17:45 +04:00
|
|
|
end
|
2010-09-14 20:24:07 +04:00
|
|
|
redirect_to project_files_path(@project)
|
2010-09-01 19:17:45 +04:00
|
|
|
end
|
2010-08-31 19:12:58 +04:00
|
|
|
end
|