@@ -188,10 +188,13 class ProjectsController < ApplicationController | |||
|
188 | 188 | |
|
189 | 189 | def add_file |
|
190 | 190 | if request.post? |
|
191 |
|
|
|
192 |
attachments = attach_files( |
|
|
193 |
|
|
|
191 | container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id])) | |
|
192 | attachments = attach_files(container, params[:attachments]) | |
|
193 | if !attachments.empty? && Setting.notified_events.include?('file_added') | |
|
194 | Mailer.deliver_attachments_added(attachments) | |
|
195 | end | |
|
194 | 196 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
197 | return | |
|
195 | 198 | end |
|
196 | 199 | @versions = @project.versions.sort |
|
197 | 200 | end |
@@ -199,7 +202,8 class ProjectsController < ApplicationController | |||
|
199 | 202 | def list_files |
|
200 | 203 | sort_init "#{Attachment.table_name}.filename", "asc" |
|
201 | 204 | sort_update |
|
202 |
@ |
|
|
205 | @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)] | |
|
206 | @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse | |
|
203 | 207 | render :layout => !request.xhr? |
|
204 | 208 | end |
|
205 | 209 |
@@ -73,6 +73,9 class Mailer < ActionMailer::Base | |||
|
73 | 73 | added_to = '' |
|
74 | 74 | added_to_url = '' |
|
75 | 75 | case container.class.name |
|
76 | when 'Project' | |
|
77 | added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container) | |
|
78 | added_to = "#{l(:label_project)}: #{container}" | |
|
76 | 79 | when 'Version' |
|
77 | 80 | added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id) |
|
78 | 81 | added_to = "#{l(:label_version)}: #{container.name}" |
@@ -44,6 +44,8 class Project < ActiveRecord::Base | |||
|
44 | 44 | :association_foreign_key => 'custom_field_id' |
|
45 | 45 | |
|
46 | 46 | acts_as_tree :order => "name", :counter_cache => true |
|
47 | acts_as_attachable :view_permission => :view_files, | |
|
48 | :delete_permission => :manage_files | |
|
47 | 49 | |
|
48 | 50 | acts_as_customizable |
|
49 | 51 | acts_as_searchable :columns => ['name', 'description'], :project_key => 'id', :permission => nil |
@@ -4,10 +4,13 | |||
|
4 | 4 | <div class="box"> |
|
5 | 5 | <% form_tag({ :action => 'add_file', :id => @project }, :multipart => true, :class => "tabular") do %> |
|
6 | 6 | |
|
7 | <p><label for="version_id"><%=l(:field_version)%> <span class="required">*</span></label> | |
|
8 | <%= select_tag "version_id", options_from_collection_for_select(@versions, "id", "name") %></p> | |
|
7 | <% if @versions.any? %> | |
|
8 | <p><label for="version_id"><%=l(:field_version)%></label> | |
|
9 | <%= select_tag "version_id", content_tag('option', '') + | |
|
10 | options_from_collection_for_select(@versions, "id", "name") %></p> | |
|
11 | <% end %> | |
|
9 | 12 | |
|
10 | 13 | <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p> |
|
11 | 14 | </div> |
|
12 | 15 | <%= submit_tag l(:button_add) %> |
|
13 | <% end %> No newline at end of file | |
|
16 | <% end %> |
@@ -8,36 +8,33 | |||
|
8 | 8 | |
|
9 | 9 | <table class="list"> |
|
10 | 10 | <thead><tr> |
|
11 | <th><%=l(:field_version)%></th> | |
|
12 | 11 | <%= sort_header_tag("#{Attachment.table_name}.filename", :caption => l(:field_filename)) %> |
|
13 | 12 | <%= sort_header_tag("#{Attachment.table_name}.created_on", :caption => l(:label_date), :default_order => 'desc') %> |
|
14 | 13 | <%= sort_header_tag("#{Attachment.table_name}.filesize", :caption => l(:field_filesize), :default_order => 'desc') %> |
|
15 | 14 | <%= sort_header_tag("#{Attachment.table_name}.downloads", :caption => l(:label_downloads_abbr), :default_order => 'desc') %> |
|
16 | 15 | <th>MD5</th> |
|
17 | <% if delete_allowed %><th></th><% end %> | |
|
16 | <th></th> | |
|
18 | 17 | </tr></thead> |
|
19 | 18 | <tbody> |
|
20 | <% for version in @versions %> | |
|
21 |
<% |
|
|
22 | <tr><th colspan="7" align="left"><span class="icon icon-package"><b><%= version.name %></b></span></th></tr> | |
|
23 | <% for file in version.attachments %> | |
|
19 | <% @containers.each do |container| %> | |
|
20 | <% next if container.attachments.empty? -%> | |
|
21 | <% if container.is_a?(Version) -%> | |
|
22 | <tr><th colspan="6" align="left"><span class="icon icon-package"><b><%=h container %></b></span></th></tr> | |
|
23 | <% end -%> | |
|
24 | <% container.attachments.each do |file| %> | |
|
24 | 25 | <tr class="<%= cycle("odd", "even") %>"> |
|
25 | <td></td> | |
|
26 | 26 | <td><%= link_to_attachment file, :download => true, :title => file.description %></td> |
|
27 | 27 | <td align="center"><%= format_time(file.created_on) %></td> |
|
28 | 28 | <td align="center"><%= number_to_human_size(file.filesize) %></td> |
|
29 | 29 | <td align="center"><%= file.downloads %></td> |
|
30 | 30 | <td align="center"><small><%= file.digest %></small></td> |
|
31 | <% if delete_allowed %> | |
|
32 | 31 | <td align="center"> |
|
33 |
|
|
|
34 |
|
|
|
32 | <%= link_to(image_tag('delete.png'), {:controller => 'attachments', :action => 'destroy', :id => file}, | |
|
33 | :confirm => l(:text_are_you_sure), :method => :post) if delete_allowed %> | |
|
35 | 34 | </td> |
|
36 | <% end %> | |
|
37 | 35 | </tr> |
|
38 | 36 | <% end |
|
39 | 37 | reset_cycle %> |
|
40 | <% end %> | |
|
41 | 38 | <% end %> |
|
42 | 39 | </tbody> |
|
43 | 40 | </table> |
@@ -85,4 +85,28 attachments_007: | |||
|
85 | 85 | filename: archive.zip |
|
86 | 86 | author_id: 1 |
|
87 | 87 | content_type: application/octet-stream |
|
88 | attachments_008: | |
|
89 | created_on: 2006-07-19 21:07:27 +02:00 | |
|
90 | container_type: Project | |
|
91 | container_id: 1 | |
|
92 | downloads: 0 | |
|
93 | disk_filename: 060719210727_project_file.zip | |
|
94 | digest: b91e08d0cf966d5c6ff411bd8c4cc3a2 | |
|
95 | id: 8 | |
|
96 | filesize: 320 | |
|
97 | filename: project_file.zip | |
|
98 | author_id: 2 | |
|
99 | content_type: application/octet-stream | |
|
100 | attachments_009: | |
|
101 | created_on: 2006-07-19 21:07:27 +02:00 | |
|
102 | container_type: Version | |
|
103 | container_id: 1 | |
|
104 | downloads: 0 | |
|
105 | disk_filename: 060719210727_version_file.zip | |
|
106 | digest: b91e08d0cf966d5c6ff411bd8c4cc3a2 | |
|
107 | id: 9 | |
|
108 | filesize: 452 | |
|
109 | filename: version_file.zip | |
|
110 | author_id: 2 | |
|
111 | content_type: application/octet-stream | |
|
88 | 112 | No newline at end of file |
@@ -97,6 +97,23 class AttachmentsControllerTest < Test::Unit::TestCase | |||
|
97 | 97 | @request.session[:user_id] = 2 |
|
98 | 98 | assert_difference 'Attachment.count', -1 do |
|
99 | 99 | post :destroy, :id => 3 |
|
100 | assert_response 302 | |
|
101 | end | |
|
102 | end | |
|
103 | ||
|
104 | def test_destroy_project_attachment | |
|
105 | @request.session[:user_id] = 2 | |
|
106 | assert_difference 'Attachment.count', -1 do | |
|
107 | post :destroy, :id => 8 | |
|
108 | assert_response 302 | |
|
109 | end | |
|
110 | end | |
|
111 | ||
|
112 | def test_destroy_version_attachment | |
|
113 | @request.session[:user_id] = 2 | |
|
114 | assert_difference 'Attachment.count', -1 do | |
|
115 | post :destroy, :id => 9 | |
|
116 | assert_response 302 | |
|
100 | 117 | end |
|
101 | 118 | end |
|
102 | 119 |
@@ -23,7 +23,8 class ProjectsController; def rescue_action(e) raise e end; end | |||
|
23 | 23 | |
|
24 | 24 | class ProjectsControllerTest < Test::Unit::TestCase |
|
25 | 25 | fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details, |
|
26 | :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages | |
|
26 | :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages, | |
|
27 | :attachments | |
|
27 | 28 | |
|
28 | 29 | def setup |
|
29 | 30 | @controller = ProjectsController.new |
@@ -112,12 +113,56 class ProjectsControllerTest < Test::Unit::TestCase | |||
|
112 | 113 | assert_redirected_to 'admin/projects' |
|
113 | 114 | assert_nil Project.find_by_id(1) |
|
114 | 115 | end |
|
116 | ||
|
117 | def test_add_file | |
|
118 | set_tmp_attachments_directory | |
|
119 | @request.session[:user_id] = 2 | |
|
120 | Setting.notified_events << 'file_added' | |
|
121 | ActionMailer::Base.deliveries.clear | |
|
122 | ||
|
123 | assert_difference 'Attachment.count' do | |
|
124 | post :add_file, :id => 1, :version_id => '', | |
|
125 | :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}} | |
|
126 | end | |
|
127 | assert_redirected_to 'projects/list_files/ecookbook' | |
|
128 | a = Attachment.find(:first, :order => 'created_on DESC') | |
|
129 | assert_equal 'testfile.txt', a.filename | |
|
130 | assert_equal Project.find(1), a.container | |
|
131 | ||
|
132 | mail = ActionMailer::Base.deliveries.last | |
|
133 | assert_kind_of TMail::Mail, mail | |
|
134 | assert_equal "[eCookbook] New file", mail.subject | |
|
135 | assert mail.body.include?('testfile.txt') | |
|
136 | end | |
|
137 | ||
|
138 | def test_add_version_file | |
|
139 | set_tmp_attachments_directory | |
|
140 | @request.session[:user_id] = 2 | |
|
141 | Setting.notified_events << 'file_added' | |
|
142 | ||
|
143 | assert_difference 'Attachment.count' do | |
|
144 | post :add_file, :id => 1, :version_id => '2', | |
|
145 | :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}} | |
|
146 | end | |
|
147 | assert_redirected_to 'projects/list_files/ecookbook' | |
|
148 | a = Attachment.find(:first, :order => 'created_on DESC') | |
|
149 | assert_equal 'testfile.txt', a.filename | |
|
150 | assert_equal Version.find(2), a.container | |
|
151 | end | |
|
115 | 152 | |
|
116 | 153 | def test_list_files |
|
117 | 154 | get :list_files, :id => 1 |
|
118 | 155 | assert_response :success |
|
119 | 156 | assert_template 'list_files' |
|
120 |
assert_not_nil assigns(: |
|
|
157 | assert_not_nil assigns(:containers) | |
|
158 | ||
|
159 | # file attached to the project | |
|
160 | assert_tag :a, :content => 'project_file.zip', | |
|
161 | :attributes => { :href => '/attachments/download/8/project_file.zip' } | |
|
162 | ||
|
163 | # file attached to a project's version | |
|
164 | assert_tag :a, :content => 'version_file.zip', | |
|
165 | :attributes => { :href => '/attachments/download/9/version_file.zip' } | |
|
121 | 166 | end |
|
122 | 167 | |
|
123 | 168 | def test_changelog |
General Comments 0
You need to be logged in to leave comments.
Login now