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