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
This commit is contained in:
parent
a188abbe28
commit
daa8eaa9ae
|
@ -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
|
|
@ -18,7 +18,7 @@
|
||||||
class ProjectsController < ApplicationController
|
class ProjectsController < ApplicationController
|
||||||
menu_item :overview
|
menu_item :overview
|
||||||
menu_item :roadmap, :only => :roadmap
|
menu_item :roadmap, :only => :roadmap
|
||||||
menu_item :files, :only => [:list_files, :add_file]
|
menu_item :files, :only => [:add_file]
|
||||||
menu_item :settings, :only => :settings
|
menu_item :settings, :only => :settings
|
||||||
|
|
||||||
before_filter :find_project, :except => [ :index, :list, :add, :copy ]
|
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')
|
if !attachments.empty? && Setting.notified_events.include?('file_added')
|
||||||
Mailer.deliver_attachments_added(attachments[:files])
|
Mailer.deliver_attachments_added(attachments[:files])
|
||||||
end
|
end
|
||||||
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
|
redirect_to :controller => 'files', :action => 'index', :id => @project
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@versions = @project.versions.sort
|
@versions = @project.versions.sort
|
||||||
|
@ -275,18 +275,6 @@ class ProjectsController < ApplicationController
|
||||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
|
redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
|
||||||
end
|
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
|
private
|
||||||
def find_optional_project
|
def find_optional_project
|
||||||
return true unless params[:id]
|
return true unless params[:id]
|
||||||
|
|
|
@ -181,7 +181,7 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
project_views.connect 'projects/:id', :action => 'show'
|
project_views.connect 'projects/:id', :action => 'show'
|
||||||
project_views.connect 'projects/:id.:format', :action => 'show'
|
project_views.connect 'projects/:id.:format', :action => 'show'
|
||||||
project_views.connect 'projects/:id/:action', :action => /destroy|settings/
|
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/files/new', :action => 'add_file'
|
||||||
project_views.connect 'projects/:id/settings/:tab', :action => 'settings'
|
project_views.connect 'projects/:id/settings/:tab', :action => 'settings'
|
||||||
project_views.connect 'projects/:project_id/issues/:copy_from/copy', :controller => 'issues', :action => 'new'
|
project_views.connect 'projects/:project_id/issues/:copy_from/copy', :controller => 'issues', :action => 'new'
|
||||||
|
|
|
@ -103,7 +103,7 @@ Redmine::AccessControl.map do |map|
|
||||||
|
|
||||||
map.project_module :files do |map|
|
map.project_module :files do |map|
|
||||||
map.permission :manage_files, {:projects => :add_file}, :require => :loggedin
|
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
|
end
|
||||||
|
|
||||||
map.project_module :wiki do |map|
|
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? }
|
:if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
|
||||||
menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
|
menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
|
||||||
:if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
|
: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' },
|
menu.push :repository, { :controller => 'repositories', :action => 'show' },
|
||||||
:if => Proc.new { |p| p.repository && !p.repository.new_record? }
|
:if => Proc.new { |p| p.repository && !p.repository.new_record? }
|
||||||
menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true
|
menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true
|
||||||
|
|
|
@ -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
|
|
@ -353,21 +353,6 @@ class ProjectsControllerTest < ActionController::TestCase
|
||||||
assert_equal Version.find(2), a.container
|
assert_equal Version.find(2), a.container
|
||||||
end
|
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
|
def test_archive
|
||||||
@request.session[:user_id] = 1 # admin
|
@request.session[:user_id] = 1 # admin
|
||||||
post :archive, :id => 1
|
post :archive, :id => 1
|
||||||
|
|
|
@ -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", :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/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/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/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/roadmap", :controller => 'versions', :action => 'index', :project_id => '33'
|
||||||
should_route :get, "/projects/33/activity", :controller => 'activities', :action => 'index', :id => '33'
|
should_route :get, "/projects/33/activity", :controller => 'activities', :action => 'index', :id => '33'
|
||||||
|
|
Loading…
Reference in New Issue