git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4085 e93f8b46-1217-0410-a6f0-8f06a7374b81tags/1.1.0
class FilesController < ApplicationController | class FilesController < ApplicationController | ||||
menu_item :files | menu_item :files | ||||
before_filter :find_project | |||||
before_filter :find_project_by_project_id | |||||
before_filter :authorize | before_filter :authorize | ||||
helper :sort | helper :sort | ||||
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 => 'files', :action => 'index', :id => @project | |||||
redirect_to project_files_path(@project) | |||||
end | end | ||||
end | end |
<div class="contextual"> | <div class="contextual"> | ||||
<%= link_to_if_authorized l(:label_attachment_new), {:controller => 'files', :action => 'new', :id => @project}, :class => 'icon icon-add' %> | |||||
<%= link_to_if_authorized l(:label_attachment_new), new_project_file_path(@project), :class => 'icon icon-add' %> | |||||
</div> | </div> | ||||
<h2><%=l(:label_attachment_plural)%></h2> | <h2><%=l(:label_attachment_plural)%></h2> |
<%= error_messages_for 'attachment' %> | <%= error_messages_for 'attachment' %> | ||||
<div class="box"> | <div class="box"> | ||||
<% form_tag({ :action => 'create', :id => @project }, :multipart => true, :class => "tabular") do %> | |||||
<% form_tag(project_files_path(@project), :multipart => true, :class => "tabular") do %> | |||||
<% if @versions.any? %> | <% if @versions.any? %> | ||||
<p><label for="version_id"><%=l(:field_version)%></label> | <p><label for="version_id"><%=l(:field_version)%></label> |
:unarchive => :post | :unarchive => :post | ||||
} do |project| | } do |project| | ||||
project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy] | project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy] | ||||
project.resources :files, :only => [:index, :new, :create] | |||||
end | end | ||||
# Destroy uses a get request to prompt the user before the actual DELETE request | # Destroy uses a get request to prompt the user before the actual DELETE request | ||||
# TODO: port to be part of the resources route(s) | # TODO: port to be part of the resources route(s) | ||||
map.with_options :controller => 'projects' do |project_mapper| | map.with_options :controller => 'projects' do |project_mapper| | ||||
project_mapper.with_options :conditions => {:method => :get} do |project_views| | project_mapper.with_options :conditions => {:method => :get} do |project_views| | ||||
project_views.connect 'projects/:id/files', :controller => 'files', :action => 'index' | |||||
project_views.connect 'projects/:id/files/new', :controller => 'files', :action => 'new' | |||||
project_views.connect 'projects/:id/settings/:tab', :controller => 'projects', :action => 'settings' | project_views.connect 'projects/:id/settings/:tab', :controller => 'projects', :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' | ||||
end | end | ||||
project_mapper.with_options :conditions => {:method => :post} do |project_actions| | |||||
project_actions.connect 'projects/:id/files/new', :controller => 'files', :action => 'create' | |||||
end | |||||
end | end | ||||
map.with_options :controller => 'activities', :action => 'index', :conditions => {:method => :get} do |activity| | map.with_options :controller => 'activities', :action => 'index', :conditions => {:method => :get} do |activity| |
: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 => 'files', :action => 'index' }, :caption => :label_file_plural | |||||
menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural, :param => :project_id | |||||
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 |
end | end | ||||
def test_index | def test_index | ||||
get :index, :id => 1 | |||||
get :index, :project_id => 1 | |||||
assert_response :success | assert_response :success | ||||
assert_template 'index' | assert_template 'index' | ||||
assert_not_nil assigns(:containers) | assert_not_nil assigns(:containers) | ||||
ActionMailer::Base.deliveries.clear | ActionMailer::Base.deliveries.clear | ||||
assert_difference 'Attachment.count' do | assert_difference 'Attachment.count' do | ||||
post :create, :id => 1, :version_id => '', | |||||
post :create, :project_id => 1, :version_id => '', | |||||
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | ||||
assert_response :redirect | assert_response :redirect | ||||
end | end | ||||
Setting.notified_events = ['file_added'] | Setting.notified_events = ['file_added'] | ||||
assert_difference 'Attachment.count' do | assert_difference 'Attachment.count' do | ||||
post :create, :id => 1, :version_id => '2', | |||||
post :create, :project_id => 1, :version_id => '2', | |||||
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | ||||
assert_response :redirect | assert_response :redirect | ||||
end | end |
should_route :get, "/projects/1.xml", :controller => 'projects', :action => 'show', :id => '1', :format => 'xml' | should_route :get, "/projects/1.xml", :controller => 'projects', :action => 'show', :id => '1', :format => 'xml' | ||||
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/33/files", :controller => 'files', :action => 'index', :id => '33' | |||||
should_route :get, "/projects/33/files/new", :controller => 'files', :action => 'new', :id => '33' | |||||
should_route :get, "/projects/33/files", :controller => 'files', :action => 'index', :project_id => '33' | |||||
should_route :get, "/projects/33/files/new", :controller => 'files', :action => 'new', :project_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' | ||||
should_route :get, "/projects/33/activity.atom", :controller => 'activities', :action => 'index', :id => '33', :format => 'atom' | should_route :get, "/projects/33/activity.atom", :controller => 'activities', :action => 'index', :id => '33', :format => 'atom' | ||||
should_route :post, "/projects", :controller => 'projects', :action => 'create' | should_route :post, "/projects", :controller => 'projects', :action => 'create' | ||||
should_route :post, "/projects.xml", :controller => 'projects', :action => 'create', :format => 'xml' | should_route :post, "/projects.xml", :controller => 'projects', :action => 'create', :format => 'xml' | ||||
should_route :post, "/projects/33/files/new", :controller => 'files', :action => 'create', :id => '33' | |||||
should_route :post, "/projects/33/files", :controller => 'files', :action => 'create', :project_id => '33' | |||||
should_route :post, "/projects/64/archive", :controller => 'projects', :action => 'archive', :id => '64' | should_route :post, "/projects/64/archive", :controller => 'projects', :action => 'archive', :id => '64' | ||||
should_route :post, "/projects/64/unarchive", :controller => 'projects', :action => 'unarchive', :id => '64' | should_route :post, "/projects/64/unarchive", :controller => 'projects', :action => 'unarchive', :id => '64' | ||||