Chris@1115: # Redmine - project management software Chris@1295: # Copyright (C) 2006-2013 Jean-Philippe Lang Chris@1115: # Chris@1115: # This program is free software; you can redistribute it and/or Chris@1115: # modify it under the terms of the GNU General Public License Chris@1115: # as published by the Free Software Foundation; either version 2 Chris@1115: # of the License, or (at your option) any later version. Chris@1115: # Chris@1115: # This program is distributed in the hope that it will be useful, Chris@1115: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@1115: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@1115: # GNU General Public License for more details. Chris@1115: # Chris@1115: # You should have received a copy of the GNU General Public License Chris@1115: # along with this program; if not, write to the Free Software Chris@1115: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@1115: chris@22: class FilesController < ApplicationController chris@22: menu_item :files chris@22: chris@22: before_filter :find_project_by_project_id chris@22: before_filter :authorize chris@22: chris@22: helper :sort chris@22: include SortHelper chris@22: chris@22: def index Chris@326: sort_init 'active', 'desc' chris@22: sort_update 'filename' => "#{Attachment.table_name}.filename", chris@254: 'active' => "#{Attachment.table_name}.active", chris@22: 'created_on' => "#{Attachment.table_name}.created_on", chris@22: 'size' => "#{Attachment.table_name}.filesize", chris@22: 'downloads' => "#{Attachment.table_name}.downloads" Chris@441: Chris@1295: @containers = [ Project.includes(:attachments).reorder(sort_clause).find(@project.id)] Chris@1295: @containers += @project.versions.includes(:attachments).reorder(sort_clause).all.sort.reverse chris@22: render :layout => !request.xhr? chris@22: end chris@22: chris@22: def new chris@22: @versions = @project.versions.sort chris@22: end chris@22: chris@22: def create chris@22: container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id])) chris@22: attachments = Attachment.attach_files(container, params[:attachments]) chris@22: render_attachment_warning_if_needed(container) chris@22: chris@37: if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') Chris@1115: Mailer.attachments_added(attachments[:files]).deliver chris@22: end chris@22: redirect_to project_files_path(@project) chris@22: end chris@257: chris@22: end