@@ -19,4 +19,19 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 | |||
|
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) | |||
|
28 | ||||
|
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 | |||
|
34 | end | |||
|
35 | @versions = @project.versions.sort | |||
|
36 | end | |||
22 | end |
|
37 | end |
@@ -18,7 +18,6 | |||||
18 | class ProjectsController < ApplicationController |
|
18 | class ProjectsController < ApplicationController | |
19 | menu_item :overview |
|
19 | menu_item :overview | |
20 | menu_item :roadmap, :only => :roadmap |
|
20 | menu_item :roadmap, :only => :roadmap | |
21 | menu_item :files, :only => [:add_file] |
|
|||
22 | menu_item :settings, :only => :settings |
|
21 | menu_item :settings, :only => :settings | |
23 |
|
22 | |||
24 | before_filter :find_project, :except => [ :index, :list, :add, :copy ] |
|
23 | before_filter :find_project, :except => [ :index, :list, :add, :copy ] | |
@@ -239,21 +238,6 class ProjectsController < ApplicationController | |||||
239 | @project = nil |
|
238 | @project = nil | |
240 | end |
|
239 | end | |
241 |
|
240 | |||
242 | def add_file |
|
|||
243 | if request.post? |
|
|||
244 | container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id])) |
|
|||
245 | attachments = Attachment.attach_files(container, params[:attachments]) |
|
|||
246 | render_attachment_warning_if_needed(container) |
|
|||
247 |
|
||||
248 | if !attachments.empty? && Setting.notified_events.include?('file_added') |
|
|||
249 | Mailer.deliver_attachments_added(attachments[:files]) |
|
|||
250 | end |
|
|||
251 | redirect_to :controller => 'files', :action => 'index', :id => @project |
|
|||
252 | return |
|
|||
253 | end |
|
|||
254 | @versions = @project.versions.sort |
|
|||
255 | end |
|
|||
256 |
|
||||
257 | def save_activities |
|
241 | def save_activities | |
258 | if request.post? && params[:enumerations] |
|
242 | if request.post? && params[:enumerations] | |
259 | Project.transaction do |
|
243 | Project.transaction do |
@@ -1,5 +1,5 | |||||
1 | <div class="contextual"> |
|
1 | <div class="contextual"> | |
2 |
<%= link_to_if_authorized l(:label_attachment_new), {:controller => ' |
|
2 | <%= link_to_if_authorized l(:label_attachment_new), {:controller => 'files', :action => 'new', :id => @project}, :class => 'icon icon-add' %> | |
3 | </div> |
|
3 | </div> | |
4 |
|
4 | |||
5 | <h2><%=l(:label_attachment_plural)%></h2> |
|
5 | <h2><%=l(:label_attachment_plural)%></h2> |
@@ -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 => 'new', :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> |
@@ -201,7 +201,7 ActionController::Routing::Routes.draw do |map| | |||||
201 | project_views.connect 'projects/:id.:format', :action => 'show' |
|
201 | project_views.connect 'projects/:id.:format', :action => 'show' | |
202 | project_views.connect 'projects/:id/:action', :action => /destroy|settings/ |
|
202 | project_views.connect 'projects/:id/:action', :action => /destroy|settings/ | |
203 | project_views.connect 'projects/:id/files', :controller => 'files', :action => 'index' |
|
203 | project_views.connect 'projects/:id/files', :controller => 'files', :action => 'index' | |
204 |
project_views.connect 'projects/:id/files/new', :action => ' |
|
204 | project_views.connect 'projects/:id/files/new', :controller => 'files', :action => 'new' | |
205 | project_views.connect 'projects/:id/settings/:tab', :action => 'settings' |
|
205 | project_views.connect 'projects/:id/settings/:tab', :action => 'settings' | |
206 | end |
|
206 | end | |
207 |
|
207 | |||
@@ -217,7 +217,7 ActionController::Routing::Routes.draw do |map| | |||||
217 | project_actions.connect 'projects', :action => 'add' |
|
217 | project_actions.connect 'projects', :action => 'add' | |
218 | project_actions.connect 'projects.:format', :action => 'add', :format => /xml/ |
|
218 | project_actions.connect 'projects.:format', :action => 'add', :format => /xml/ | |
219 | project_actions.connect 'projects/:id/:action', :action => /edit|destroy|archive|unarchive/ |
|
219 | project_actions.connect 'projects/:id/:action', :action => /edit|destroy|archive|unarchive/ | |
220 |
project_actions.connect 'projects/:id/files/new', :action => ' |
|
220 | project_actions.connect 'projects/:id/files/new', :controller => 'files', :action => 'new' | |
221 | project_actions.connect 'projects/:id/activities/save', :action => 'save_activities' |
|
221 | project_actions.connect 'projects/:id/activities/save', :action => 'save_activities' | |
222 | end |
|
222 | end | |
223 |
|
223 |
@@ -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, {: |
|
105 | map.permission :manage_files, {:files => :new}, :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,4 +26,42 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_add_file | |||
|
30 | set_tmp_attachments_directory | |||
|
31 | @request.session[:user_id] = 2 | |||
|
32 | Setting.notified_events = ['file_added'] | |||
|
33 | ActionMailer::Base.deliveries.clear | |||
|
34 | ||||
|
35 | assert_difference 'Attachment.count' do | |||
|
36 | post :new, :id => 1, :version_id => '', | |||
|
37 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |||
|
38 | assert_response :redirect | |||
|
39 | end | |||
|
40 | assert_redirected_to 'projects/ecookbook/files' | |||
|
41 | a = Attachment.find(:first, :order => 'created_on DESC') | |||
|
42 | assert_equal 'testfile.txt', a.filename | |||
|
43 | assert_equal Project.find(1), a.container | |||
|
44 | ||||
|
45 | mail = ActionMailer::Base.deliveries.last | |||
|
46 | assert_kind_of TMail::Mail, mail | |||
|
47 | assert_equal "[eCookbook] New file", mail.subject | |||
|
48 | assert mail.body.include?('testfile.txt') | |||
|
49 | end | |||
|
50 | ||||
|
51 | def test_add_version_file | |||
|
52 | set_tmp_attachments_directory | |||
|
53 | @request.session[:user_id] = 2 | |||
|
54 | Setting.notified_events = ['file_added'] | |||
|
55 | ||||
|
56 | assert_difference 'Attachment.count' do | |||
|
57 | post :new, :id => 1, :version_id => '2', | |||
|
58 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |||
|
59 | assert_response :redirect | |||
|
60 | end | |||
|
61 | assert_redirected_to 'projects/ecookbook/files' | |||
|
62 | a = Attachment.find(:first, :order => 'created_on DESC') | |||
|
63 | assert_equal 'testfile.txt', a.filename | |||
|
64 | assert_equal Version.find(2), a.container | |||
|
65 | end | |||
|
66 | ||||
29 | end |
|
67 | end |
@@ -317,42 +317,6 class ProjectsControllerTest < ActionController::TestCase | |||||
317 | assert_nil Project.find_by_id(1) |
|
317 | assert_nil Project.find_by_id(1) | |
318 | end |
|
318 | end | |
319 |
|
319 | |||
320 | def test_add_file |
|
|||
321 | set_tmp_attachments_directory |
|
|||
322 | @request.session[:user_id] = 2 |
|
|||
323 | Setting.notified_events = ['file_added'] |
|
|||
324 | ActionMailer::Base.deliveries.clear |
|
|||
325 |
|
||||
326 | assert_difference 'Attachment.count' do |
|
|||
327 | post :add_file, :id => 1, :version_id => '', |
|
|||
328 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
|||
329 | end |
|
|||
330 | assert_redirected_to 'projects/ecookbook/files' |
|
|||
331 | a = Attachment.find(:first, :order => 'created_on DESC') |
|
|||
332 | assert_equal 'testfile.txt', a.filename |
|
|||
333 | assert_equal Project.find(1), a.container |
|
|||
334 |
|
||||
335 | mail = ActionMailer::Base.deliveries.last |
|
|||
336 | assert_kind_of TMail::Mail, mail |
|
|||
337 | assert_equal "[eCookbook] New file", mail.subject |
|
|||
338 | assert mail.body.include?('testfile.txt') |
|
|||
339 | end |
|
|||
340 |
|
||||
341 | def test_add_version_file |
|
|||
342 | set_tmp_attachments_directory |
|
|||
343 | @request.session[:user_id] = 2 |
|
|||
344 | Setting.notified_events = ['file_added'] |
|
|||
345 |
|
||||
346 | assert_difference 'Attachment.count' do |
|
|||
347 | post :add_file, :id => 1, :version_id => '2', |
|
|||
348 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
|||
349 | end |
|
|||
350 | assert_redirected_to 'projects/ecookbook/files' |
|
|||
351 | a = Attachment.find(:first, :order => 'created_on DESC') |
|
|||
352 | assert_equal 'testfile.txt', a.filename |
|
|||
353 | assert_equal Version.find(2), a.container |
|
|||
354 | end |
|
|||
355 |
|
||||
356 | def test_archive |
|
320 | def test_archive | |
357 | @request.session[:user_id] = 1 # admin |
|
321 | @request.session[:user_id] = 1 # admin | |
358 | post :archive, :id => 1 |
|
322 | post :archive, :id => 1 |
@@ -173,7 +173,7 class RoutingTest < ActionController::IntegrationTest | |||||
173 | should_route :get, "/projects/4223/settings/members", :controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members' |
|
173 | should_route :get, "/projects/4223/settings/members", :controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members' | |
174 | should_route :get, "/projects/567/destroy", :controller => 'projects', :action => 'destroy', :id => '567' |
|
174 | should_route :get, "/projects/567/destroy", :controller => 'projects', :action => 'destroy', :id => '567' | |
175 | should_route :get, "/projects/33/files", :controller => 'files', :action => 'index', :id => '33' |
|
175 | should_route :get, "/projects/33/files", :controller => 'files', :action => 'index', :id => '33' | |
176 |
should_route :get, "/projects/33/files/new", :controller => ' |
|
176 | should_route :get, "/projects/33/files/new", :controller => 'files', :action => 'new', :id => '33' | |
177 | should_route :get, "/projects/33/roadmap", :controller => 'versions', :action => 'index', :project_id => '33' |
|
177 | should_route :get, "/projects/33/roadmap", :controller => 'versions', :action => 'index', :project_id => '33' | |
178 | should_route :get, "/projects/33/activity", :controller => 'activities', :action => 'index', :id => '33' |
|
178 | should_route :get, "/projects/33/activity", :controller => 'activities', :action => 'index', :id => '33' | |
179 | should_route :get, "/projects/33/activity.atom", :controller => 'activities', :action => 'index', :id => '33', :format => 'atom' |
|
179 | should_route :get, "/projects/33/activity.atom", :controller => 'activities', :action => 'index', :id => '33', :format => 'atom' | |
@@ -182,7 +182,7 class RoutingTest < ActionController::IntegrationTest | |||||
182 | should_route :post, "/projects.xml", :controller => 'projects', :action => 'add', :format => 'xml' |
|
182 | should_route :post, "/projects.xml", :controller => 'projects', :action => 'add', :format => 'xml' | |
183 | should_route :post, "/projects/4223/edit", :controller => 'projects', :action => 'edit', :id => '4223' |
|
183 | should_route :post, "/projects/4223/edit", :controller => 'projects', :action => 'edit', :id => '4223' | |
184 | should_route :post, "/projects/64/destroy", :controller => 'projects', :action => 'destroy', :id => '64' |
|
184 | should_route :post, "/projects/64/destroy", :controller => 'projects', :action => 'destroy', :id => '64' | |
185 |
should_route :post, "/projects/33/files/new", :controller => ' |
|
185 | should_route :post, "/projects/33/files/new", :controller => 'files', :action => 'new', :id => '33' | |
186 | should_route :post, "/projects/64/archive", :controller => 'projects', :action => 'archive', :id => '64' |
|
186 | should_route :post, "/projects/64/archive", :controller => 'projects', :action => 'archive', :id => '64' | |
187 | should_route :post, "/projects/64/unarchive", :controller => 'projects', :action => 'unarchive', :id => '64' |
|
187 | should_route :post, "/projects/64/unarchive", :controller => 'projects', :action => 'unarchive', :id => '64' | |
188 | should_route :post, "/projects/64/activities/save", :controller => 'projects', :action => 'save_activities', :id => '64' |
|
188 | should_route :post, "/projects/64/activities/save", :controller => 'projects', :action => 'save_activities', :id => '64' |
General Comments 0
You need to be logged in to leave comments.
Login now