@@ -19,19 +19,18 class FilesController < ApplicationController | |||||
19 | render :layout => !request.xhr? |
|
19 | render :layout => !request.xhr? | |
20 | end |
|
20 | end | |
21 |
|
21 | |||
22 | # TODO: split method into new (GET) and create (POST) |
|
|||
23 | def new |
|
22 | def new | |
24 | if request.post? |
|
23 | @versions = @project.versions.sort | |
25 | container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id])) |
|
24 | end | |
26 | attachments = Attachment.attach_files(container, params[:attachments]) |
|
|||
27 | render_attachment_warning_if_needed(container) |
|
|||
28 |
|
25 | |||
29 | if !attachments.empty? && Setting.notified_events.include?('file_added') |
|
26 | def create | |
30 | Mailer.deliver_attachments_added(attachments[:files]) |
|
27 | container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id])) | |
31 | end |
|
28 | attachments = Attachment.attach_files(container, params[:attachments]) | |
32 | redirect_to :controller => 'files', :action => 'index', :id => @project |
|
29 | render_attachment_warning_if_needed(container) | |
33 | return |
|
30 | ||
|
31 | if !attachments.empty? && Setting.notified_events.include?('file_added') | |||
|
32 | Mailer.deliver_attachments_added(attachments[:files]) | |||
34 | end |
|
33 | end | |
35 | @versions = @project.versions.sort |
|
34 | redirect_to :controller => 'files', :action => 'index', :id => @project | |
36 | end |
|
35 | end | |
37 | end |
|
36 | end |
@@ -2,7 +2,7 | |||||
2 |
|
2 | |||
3 | <%= error_messages_for 'attachment' %> |
|
3 | <%= error_messages_for 'attachment' %> | |
4 | <div class="box"> |
|
4 | <div class="box"> | |
5 |
<% form_tag({ :action => ' |
|
5 | <% form_tag({ :action => 'create', :id => @project }, :multipart => true, :class => "tabular") do %> | |
6 |
|
6 | |||
7 | <% if @versions.any? %> |
|
7 | <% if @versions.any? %> | |
8 | <p><label for="version_id"><%=l(:field_version)%></label> |
|
8 | <p><label for="version_id"><%=l(:field_version)%></label> |
@@ -196,7 +196,7 ActionController::Routing::Routes.draw do |map| | |||||
196 | end |
|
196 | end | |
197 |
|
197 | |||
198 | project_mapper.with_options :conditions => {:method => :post} do |project_actions| |
|
198 | project_mapper.with_options :conditions => {:method => :post} do |project_actions| | |
199 |
project_actions.connect 'projects/:id/files/new', :controller => 'files', :action => ' |
|
199 | project_actions.connect 'projects/:id/files/new', :controller => 'files', :action => 'create' | |
200 | end |
|
200 | end | |
201 | end |
|
201 | end | |
202 |
|
202 |
@@ -102,7 +102,7 Redmine::AccessControl.map do |map| | |||||
102 | end |
|
102 | end | |
103 |
|
103 | |||
104 | map.project_module :files do |map| |
|
104 | map.project_module :files do |map| | |
105 | map.permission :manage_files, {:files => :new}, :require => :loggedin |
|
105 | map.permission :manage_files, {:files => [:new, :create]}, :require => :loggedin | |
106 | map.permission :view_files, :files => :index, :versions => :download |
|
106 | map.permission :view_files, :files => :index, :versions => :download | |
107 | end |
|
107 | end | |
108 |
|
108 |
@@ -26,14 +26,14 class FilesControllerTest < ActionController::TestCase | |||||
26 | :attributes => { :href => '/attachments/download/9/version_file.zip' } |
|
26 | :attributes => { :href => '/attachments/download/9/version_file.zip' } | |
27 | end |
|
27 | end | |
28 |
|
28 | |||
29 |
def test_ |
|
29 | def test_create_file | |
30 | set_tmp_attachments_directory |
|
30 | set_tmp_attachments_directory | |
31 | @request.session[:user_id] = 2 |
|
31 | @request.session[:user_id] = 2 | |
32 | Setting.notified_events = ['file_added'] |
|
32 | Setting.notified_events = ['file_added'] | |
33 | ActionMailer::Base.deliveries.clear |
|
33 | ActionMailer::Base.deliveries.clear | |
34 |
|
34 | |||
35 | assert_difference 'Attachment.count' do |
|
35 | assert_difference 'Attachment.count' do | |
36 |
post : |
|
36 | post :create, :id => 1, :version_id => '', | |
37 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
37 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
38 | assert_response :redirect |
|
38 | assert_response :redirect | |
39 | end |
|
39 | end | |
@@ -48,13 +48,13 class FilesControllerTest < ActionController::TestCase | |||||
48 | assert mail.body.include?('testfile.txt') |
|
48 | assert mail.body.include?('testfile.txt') | |
49 | end |
|
49 | end | |
50 |
|
50 | |||
51 |
def test_ |
|
51 | def test_create_version_file | |
52 | set_tmp_attachments_directory |
|
52 | set_tmp_attachments_directory | |
53 | @request.session[:user_id] = 2 |
|
53 | @request.session[:user_id] = 2 | |
54 | Setting.notified_events = ['file_added'] |
|
54 | Setting.notified_events = ['file_added'] | |
55 |
|
55 | |||
56 | assert_difference 'Attachment.count' do |
|
56 | assert_difference 'Attachment.count' do | |
57 |
post : |
|
57 | post :create, :id => 1, :version_id => '2', | |
58 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
58 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
59 | assert_response :redirect |
|
59 | assert_response :redirect | |
60 | end |
|
60 | end |
@@ -179,7 +179,7 class RoutingTest < ActionController::IntegrationTest | |||||
179 |
|
179 | |||
180 | should_route :post, "/projects", :controller => 'projects', :action => 'create' |
|
180 | should_route :post, "/projects", :controller => 'projects', :action => 'create' | |
181 | should_route :post, "/projects.xml", :controller => 'projects', :action => 'create', :format => 'xml' |
|
181 | should_route :post, "/projects.xml", :controller => 'projects', :action => 'create', :format => 'xml' | |
182 |
should_route :post, "/projects/33/files/new", :controller => 'files', :action => ' |
|
182 | should_route :post, "/projects/33/files/new", :controller => 'files', :action => 'create', :id => '33' | |
183 | should_route :post, "/projects/64/archive", :controller => 'projects', :action => 'archive', :id => '64' |
|
183 | should_route :post, "/projects/64/archive", :controller => 'projects', :action => 'archive', :id => '64' | |
184 | should_route :post, "/projects/64/unarchive", :controller => 'projects', :action => 'unarchive', :id => '64' |
|
184 | should_route :post, "/projects/64/unarchive", :controller => 'projects', :action => 'unarchive', :id => '64' | |
185 |
|
185 |
General Comments 0
You need to be logged in to leave comments.
Login now