You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

files_controller.rb 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2012 Jean-Philippe Lang
  3. #
  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.
  8. #
  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.
  13. #
  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.
  17. class FilesController < ApplicationController
  18. menu_item :files
  19. before_filter :find_project_by_project_id
  20. before_filter :authorize
  21. helper :sort
  22. include SortHelper
  23. def index
  24. sort_init 'filename', 'asc'
  25. sort_update 'filename' => "#{Attachment.table_name}.filename",
  26. 'created_on' => "#{Attachment.table_name}.created_on",
  27. 'size' => "#{Attachment.table_name}.filesize",
  28. 'downloads' => "#{Attachment.table_name}.downloads"
  29. @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
  30. @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
  31. render :layout => !request.xhr?
  32. end
  33. def new
  34. @versions = @project.versions.sort
  35. end
  36. def create
  37. container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
  38. attachments = Attachment.attach_files(container, params[:attachments])
  39. render_attachment_warning_if_needed(container)
  40. if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
  41. Mailer.deliver_attachments_added(attachments[:files])
  42. end
  43. redirect_to project_files_path(@project)
  44. end
  45. end