From: Eric Davis Date: Tue, 31 Aug 2010 15:12:58 +0000 (+0000) Subject: Refactor: move method, ProjectsController#list_files to FilesController#index. X-Git-Tag: 1.1.0~407 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=daa8eaa9aebcc284e2904d1258cbfdd78ea23876;p=redmine.git Refactor: move method, ProjectsController#list_files to FilesController#index. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4051 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb new file mode 100644 index 000000000..c84ce5f51 --- /dev/null +++ b/app/controllers/files_controller.rb @@ -0,0 +1,22 @@ +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 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 845ab3c15..05c8d969d 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -18,7 +18,7 @@ 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 ] @@ -248,7 +248,7 @@ class ProjectsController < ApplicationController 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 @@ -275,18 +275,6 @@ class ProjectsController < ApplicationController 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] diff --git a/app/views/files/index.html.erb b/app/views/files/index.html.erb new file mode 100644 index 000000000..2b2e5e870 --- /dev/null +++ b/app/views/files/index.html.erb @@ -0,0 +1,46 @@ +
+<%= link_to_if_authorized l(:label_attachment_new), {:controller => 'projects', :action => 'add_file', :id => @project}, :class => 'icon icon-add' %> +
+ +

<%=l(:label_attachment_plural)%>

+ +<% delete_allowed = User.current.allowed_to?(:manage_files, @project) %> + + + + <%= 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') %> + + + + +<% @containers.each do |container| %> + <% next if container.attachments.empty? -%> + <% if container.is_a?(Version) -%> + + + + <% end -%> + <% container.attachments.each do |file| %> + "> + + + + + + + + <% end + reset_cycle %> +<% end %> + +
MD5
+ <%= link_to(h(container), {:controller => 'versions', :action => 'show', :id => container}, :class => "icon icon-package") %> +
<%= link_to_attachment file, :download => true, :title => file.description %><%= format_time(file.created_on) %><%= number_to_human_size(file.filesize) %><%= file.downloads %><%= file.digest %> + <%= link_to(image_tag('delete.png'), {:controller => 'attachments', :action => 'destroy', :id => file}, + :confirm => l(:text_are_you_sure), :method => :post) if delete_allowed %> +
+ +<% html_title(l(:label_attachment_plural)) -%> diff --git a/app/views/projects/list_files.rhtml b/app/views/projects/list_files.rhtml deleted file mode 100644 index 2b2e5e870..000000000 --- a/app/views/projects/list_files.rhtml +++ /dev/null @@ -1,46 +0,0 @@ -
-<%= link_to_if_authorized l(:label_attachment_new), {:controller => 'projects', :action => 'add_file', :id => @project}, :class => 'icon icon-add' %> -
- -

<%=l(:label_attachment_plural)%>

- -<% delete_allowed = User.current.allowed_to?(:manage_files, @project) %> - - - - <%= 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') %> - - - - -<% @containers.each do |container| %> - <% next if container.attachments.empty? -%> - <% if container.is_a?(Version) -%> - - - - <% end -%> - <% container.attachments.each do |file| %> - "> - - - - - - - - <% end - reset_cycle %> -<% end %> - -
MD5
- <%= link_to(h(container), {:controller => 'versions', :action => 'show', :id => container}, :class => "icon icon-package") %> -
<%= link_to_attachment file, :download => true, :title => file.description %><%= format_time(file.created_on) %><%= number_to_human_size(file.filesize) %><%= file.downloads %><%= file.digest %> - <%= link_to(image_tag('delete.png'), {:controller => 'attachments', :action => 'destroy', :id => file}, - :confirm => l(:text_are_you_sure), :method => :post) if delete_allowed %> -
- -<% html_title(l(:label_attachment_plural)) -%> diff --git a/config/routes.rb b/config/routes.rb index 1414e1000..270bab4a0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -181,7 +181,7 @@ ActionController::Routing::Routes.draw do |map| 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' diff --git a/lib/redmine.rb b/lib/redmine.rb index ecfc46252..726a2ad92 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -103,7 +103,7 @@ Redmine::AccessControl.map do |map| 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| @@ -198,7 +198,7 @@ Redmine::MenuManager.map :project_menu do |menu| :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 diff --git a/test/functional/files_controller_test.rb b/test/functional/files_controller_test.rb new file mode 100644 index 000000000..908502183 --- /dev/null +++ b/test/functional/files_controller_test.rb @@ -0,0 +1,29 @@ +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 diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 36d60c859..b22efd6ab 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -353,21 +353,6 @@ class ProjectsControllerTest < ActionController::TestCase 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 diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb index 590bd9119..cc1f451cf 100644 --- a/test/integration/routing_test.rb +++ b/test/integration/routing_test.rb @@ -172,7 +172,7 @@ class RoutingTest < ActionController::IntegrationTest 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'