--- /dev/null
+class FilesController < ApplicationController
+ menu_item :files
+
+ before_filter :find_project
+ 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
+
+end
class ProjectsController < ApplicationController
menu_item :overview
menu_item :roadmap, :only => :roadmap
- menu_item :files, :only => [:list_files, :add_file]
+ menu_item :files, :only => [:add_file]
menu_item :settings, :only => :settings
before_filter :find_project, :except => [ :index, :list, :add, :copy ]
if !attachments.empty? && Setting.notified_events.include?('file_added')
Mailer.deliver_attachments_added(attachments[:files])
end
- redirect_to :controller => 'projects', :action => 'list_files', :id => @project
+ redirect_to :controller => 'files', :action => 'index', :id => @project
return
end
@versions = @project.versions.sort
redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
end
- def list_files
- 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
-
private
def find_optional_project
return true unless params[:id]
--- /dev/null
+<div class="contextual">
+<%= link_to_if_authorized l(:label_attachment_new), {:controller => 'projects', :action => 'add_file', :id => @project}, :class => 'icon icon-add' %>
+</div>
+
+<h2><%=l(:label_attachment_plural)%></h2>
+
+<% delete_allowed = User.current.allowed_to?(:manage_files, @project) %>
+
+<table class="list files">
+ <thead><tr>
+ <%= sort_header_tag('filename', :caption => l(:field_filename)) %>
+ <%= sort_header_tag('created_on', :caption => l(:label_date), :default_order => 'desc') %>
+ <%= sort_header_tag('size', :caption => l(:field_filesize), :default_order => 'desc') %>
+ <%= sort_header_tag('downloads', :caption => l(:label_downloads_abbr), :default_order => 'desc') %>
+ <th>MD5</th>
+ <th></th>
+ </tr></thead>
+ <tbody>
+<% @containers.each do |container| %>
+ <% next if container.attachments.empty? -%>
+ <% if container.is_a?(Version) -%>
+ <tr>
+ <th colspan="6" align="left">
+ <%= link_to(h(container), {:controller => 'versions', :action => 'show', :id => container}, :class => "icon icon-package") %>
+ </th>
+ </tr>
+ <% end -%>
+ <% container.attachments.each do |file| %>
+ <tr class="file <%= cycle("odd", "even") %>">
+ <td class="filename"><%= link_to_attachment file, :download => true, :title => file.description %></td>
+ <td class="created_on"><%= format_time(file.created_on) %></td>
+ <td class="filesize"><%= number_to_human_size(file.filesize) %></td>
+ <td class="downloads"><%= file.downloads %></td>
+ <td class="digest"><%= file.digest %></td>
+ <td align="center">
+ <%= link_to(image_tag('delete.png'), {:controller => 'attachments', :action => 'destroy', :id => file},
+ :confirm => l(:text_are_you_sure), :method => :post) if delete_allowed %>
+ </td>
+ </tr>
+ <% end
+ reset_cycle %>
+<% end %>
+ </tbody>
+</table>
+
+<% html_title(l(:label_attachment_plural)) -%>
+++ /dev/null
-<div class="contextual">
-<%= link_to_if_authorized l(:label_attachment_new), {:controller => 'projects', :action => 'add_file', :id => @project}, :class => 'icon icon-add' %>
-</div>
-
-<h2><%=l(:label_attachment_plural)%></h2>
-
-<% delete_allowed = User.current.allowed_to?(:manage_files, @project) %>
-
-<table class="list files">
- <thead><tr>
- <%= sort_header_tag('filename', :caption => l(:field_filename)) %>
- <%= sort_header_tag('created_on', :caption => l(:label_date), :default_order => 'desc') %>
- <%= sort_header_tag('size', :caption => l(:field_filesize), :default_order => 'desc') %>
- <%= sort_header_tag('downloads', :caption => l(:label_downloads_abbr), :default_order => 'desc') %>
- <th>MD5</th>
- <th></th>
- </tr></thead>
- <tbody>
-<% @containers.each do |container| %>
- <% next if container.attachments.empty? -%>
- <% if container.is_a?(Version) -%>
- <tr>
- <th colspan="6" align="left">
- <%= link_to(h(container), {:controller => 'versions', :action => 'show', :id => container}, :class => "icon icon-package") %>
- </th>
- </tr>
- <% end -%>
- <% container.attachments.each do |file| %>
- <tr class="file <%= cycle("odd", "even") %>">
- <td class="filename"><%= link_to_attachment file, :download => true, :title => file.description %></td>
- <td class="created_on"><%= format_time(file.created_on) %></td>
- <td class="filesize"><%= number_to_human_size(file.filesize) %></td>
- <td class="downloads"><%= file.downloads %></td>
- <td class="digest"><%= file.digest %></td>
- <td align="center">
- <%= link_to(image_tag('delete.png'), {:controller => 'attachments', :action => 'destroy', :id => file},
- :confirm => l(:text_are_you_sure), :method => :post) if delete_allowed %>
- </td>
- </tr>
- <% end
- reset_cycle %>
-<% end %>
- </tbody>
-</table>
-
-<% html_title(l(:label_attachment_plural)) -%>
project_views.connect 'projects/:id', :action => 'show'
project_views.connect 'projects/:id.:format', :action => 'show'
project_views.connect 'projects/:id/:action', :action => /destroy|settings/
- project_views.connect 'projects/:id/files', :action => 'list_files'
+ project_views.connect 'projects/:id/files', :controller => 'files', :action => 'index'
project_views.connect 'projects/:id/files/new', :action => 'add_file'
project_views.connect 'projects/:id/settings/:tab', :action => 'settings'
project_views.connect 'projects/:project_id/issues/:copy_from/copy', :controller => 'issues', :action => 'new'
map.project_module :files do |map|
map.permission :manage_files, {:projects => :add_file}, :require => :loggedin
- map.permission :view_files, :projects => :list_files, :versions => :download
+ map.permission :view_files, :files => :index, :versions => :download
end
map.project_module :wiki do |map|
:if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
:if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
- menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_file_plural
+ menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural
menu.push :repository, { :controller => 'repositories', :action => 'show' },
:if => Proc.new { |p| p.repository && !p.repository.new_record? }
menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true
--- /dev/null
+require File.dirname(__FILE__) + '/../test_helper'
+
+class FilesControllerTest < ActionController::TestCase
+ fixtures :all
+
+ def setup
+ @controller = FilesController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ @request.session[:user_id] = nil
+ Setting.default_language = 'en'
+ end
+
+ def test_index
+ get :index, :id => 1
+ assert_response :success
+ assert_template 'index'
+ assert_not_nil assigns(:containers)
+
+ # file attached to the project
+ assert_tag :a, :content => 'project_file.zip',
+ :attributes => { :href => '/attachments/download/8/project_file.zip' }
+
+ # file attached to a project's version
+ assert_tag :a, :content => 'version_file.zip',
+ :attributes => { :href => '/attachments/download/9/version_file.zip' }
+ end
+
+end
assert_equal Version.find(2), a.container
end
- def test_list_files
- get :list_files, :id => 1
- assert_response :success
- assert_template 'list_files'
- assert_not_nil assigns(:containers)
-
- # file attached to the project
- assert_tag :a, :content => 'project_file.zip',
- :attributes => { :href => '/attachments/download/8/project_file.zip' }
-
- # file attached to a project's version
- assert_tag :a, :content => 'version_file.zip',
- :attributes => { :href => '/attachments/download/9/version_file.zip' }
- end
-
def test_archive
@request.session[:user_id] = 1 # admin
post :archive, :id => 1
should_route :get, "/projects/4223/settings", :controller => 'projects', :action => 'settings', :id => '4223'
should_route :get, "/projects/4223/settings/members", :controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members'
should_route :get, "/projects/567/destroy", :controller => 'projects', :action => 'destroy', :id => '567'
- should_route :get, "/projects/33/files", :controller => 'projects', :action => 'list_files', :id => '33'
+ should_route :get, "/projects/33/files", :controller => 'files', :action => 'index', :id => '33'
should_route :get, "/projects/33/files/new", :controller => 'projects', :action => 'add_file', :id => '33'
should_route :get, "/projects/33/roadmap", :controller => 'versions', :action => 'index', :project_id => '33'
should_route :get, "/projects/33/activity", :controller => 'activities', :action => 'index', :id => '33'