##// END OF EJS Templates
Move VersionsController#download to AttachmentsController....
Jean-Philippe Lang -
r1668:8a7bfc72b20a
parent child
Show More
@@ -1,49 +1,53
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class AttachmentsController < ApplicationController
18 class AttachmentsController < ApplicationController
19 layout 'base'
19 layout 'base'
20 before_filter :find_project, :check_project_privacy
20 before_filter :find_project
21
21
22 def show
22 def show
23 if @attachment.is_diff?
23 if @attachment.is_diff?
24 @diff = File.new(@attachment.diskfile, "rb").read
24 @diff = File.new(@attachment.diskfile, "rb").read
25 render :action => 'diff'
25 render :action => 'diff'
26 elsif @attachment.is_text?
26 elsif @attachment.is_text?
27 @content = File.new(@attachment.diskfile, "rb").read
27 @content = File.new(@attachment.diskfile, "rb").read
28 render :action => 'file'
28 render :action => 'file'
29 elsif
29 elsif
30 download
30 download
31 end
31 end
32 end
32 end
33
33
34 def download
34 def download
35 @attachment.increment_download if @attachment.container.is_a?(Version)
36
35 # images are sent inline
37 # images are sent inline
36 send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
38 send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
37 :type => @attachment.content_type,
39 :type => @attachment.content_type,
38 :disposition => (@attachment.image? ? 'inline' : 'attachment')
40 :disposition => (@attachment.image? ? 'inline' : 'attachment')
39 end
41 end
40
42
41 private
43 private
42 def find_project
44 def find_project
43 @attachment = Attachment.find(params[:id])
45 @attachment = Attachment.find(params[:id])
44 #render_404 and return false unless File.readable?(@attachment.diskfile)
45 @project = @attachment.project
46 @project = @attachment.project
46 #rescue
47 permission = @attachment.container.is_a?(Version) ? :view_files : "view_#{@attachment.container.class.name.underscore.pluralize}".to_sym
47 # render_404
48 allowed = User.current.allowed_to?(permission, @project)
49 allowed ? true : (User.current.logged? ? render_403 : require_login)
50 rescue ActiveRecord::RecordNotFound
51 render_404
48 end
52 end
49 end
53 end
@@ -1,102 +1,93
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class DocumentsController < ApplicationController
18 class DocumentsController < ApplicationController
19 layout 'base'
19 layout 'base'
20 before_filter :find_project, :only => [:index, :new]
20 before_filter :find_project, :only => [:index, :new]
21 before_filter :find_document, :except => [:index, :new]
21 before_filter :find_document, :except => [:index, :new]
22 before_filter :authorize
22 before_filter :authorize
23
23
24 helper :attachments
24 helper :attachments
25
25
26 def index
26 def index
27 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
27 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
28 documents = @project.documents.find :all, :include => [:attachments, :category]
28 documents = @project.documents.find :all, :include => [:attachments, :category]
29 case @sort_by
29 case @sort_by
30 when 'date'
30 when 'date'
31 @grouped = documents.group_by {|d| d.created_on.to_date }
31 @grouped = documents.group_by {|d| d.created_on.to_date }
32 when 'title'
32 when 'title'
33 @grouped = documents.group_by {|d| d.title.first.upcase}
33 @grouped = documents.group_by {|d| d.title.first.upcase}
34 when 'author'
34 when 'author'
35 @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
35 @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
36 else
36 else
37 @grouped = documents.group_by(&:category)
37 @grouped = documents.group_by(&:category)
38 end
38 end
39 render :layout => false if request.xhr?
39 render :layout => false if request.xhr?
40 end
40 end
41
41
42 def show
42 def show
43 @attachments = @document.attachments.find(:all, :order => "created_on DESC")
43 @attachments = @document.attachments.find(:all, :order => "created_on DESC")
44 end
44 end
45
45
46 def new
46 def new
47 @document = @project.documents.build(params[:document])
47 @document = @project.documents.build(params[:document])
48 if request.post? and @document.save
48 if request.post? and @document.save
49 attach_files(@document, params[:attachments])
49 attach_files(@document, params[:attachments])
50 flash[:notice] = l(:notice_successful_create)
50 flash[:notice] = l(:notice_successful_create)
51 Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
51 Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
52 redirect_to :action => 'index', :project_id => @project
52 redirect_to :action => 'index', :project_id => @project
53 end
53 end
54 end
54 end
55
55
56 def edit
56 def edit
57 @categories = Enumeration::get_values('DCAT')
57 @categories = Enumeration::get_values('DCAT')
58 if request.post? and @document.update_attributes(params[:document])
58 if request.post? and @document.update_attributes(params[:document])
59 flash[:notice] = l(:notice_successful_update)
59 flash[:notice] = l(:notice_successful_update)
60 redirect_to :action => 'show', :id => @document
60 redirect_to :action => 'show', :id => @document
61 end
61 end
62 end
62 end
63
63
64 def destroy
64 def destroy
65 @document.destroy
65 @document.destroy
66 redirect_to :controller => 'documents', :action => 'index', :project_id => @project
66 redirect_to :controller => 'documents', :action => 'index', :project_id => @project
67 end
67 end
68
69 def download
70 @attachment = @document.attachments.find(params[:attachment_id])
71 @attachment.increment_download
72 send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
73 :type => @attachment.content_type
74 rescue
75 render_404
76 end
77
68
78 def add_attachment
69 def add_attachment
79 attachments = attach_files(@document, params[:attachments])
70 attachments = attach_files(@document, params[:attachments])
80 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('document_added')
71 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('document_added')
81 redirect_to :action => 'show', :id => @document
72 redirect_to :action => 'show', :id => @document
82 end
73 end
83
74
84 def destroy_attachment
75 def destroy_attachment
85 @document.attachments.find(params[:attachment_id]).destroy
76 @document.attachments.find(params[:attachment_id]).destroy
86 redirect_to :action => 'show', :id => @document
77 redirect_to :action => 'show', :id => @document
87 end
78 end
88
79
89 private
80 private
90 def find_project
81 def find_project
91 @project = Project.find(params[:project_id])
82 @project = Project.find(params[:project_id])
92 rescue ActiveRecord::RecordNotFound
83 rescue ActiveRecord::RecordNotFound
93 render_404
84 render_404
94 end
85 end
95
86
96 def find_document
87 def find_document
97 @document = Document.find(params[:id])
88 @document = Document.find(params[:id])
98 @project = @document.project
89 @project = @document.project
99 rescue ActiveRecord::RecordNotFound
90 rescue ActiveRecord::RecordNotFound
100 render_404
91 render_404
101 end
92 end
102 end
93 end
@@ -1,70 +1,61
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class VersionsController < ApplicationController
18 class VersionsController < ApplicationController
19 layout 'base'
19 layout 'base'
20 menu_item :roadmap
20 menu_item :roadmap
21 before_filter :find_project, :authorize
21 before_filter :find_project, :authorize
22
22
23 def show
23 def show
24 end
24 end
25
25
26 def edit
26 def edit
27 if request.post? and @version.update_attributes(params[:version])
27 if request.post? and @version.update_attributes(params[:version])
28 flash[:notice] = l(:notice_successful_update)
28 flash[:notice] = l(:notice_successful_update)
29 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
29 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
30 end
30 end
31 end
31 end
32
32
33 def destroy
33 def destroy
34 @version.destroy
34 @version.destroy
35 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
35 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
36 rescue
36 rescue
37 flash[:error] = "Unable to delete version"
37 flash[:error] = "Unable to delete version"
38 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
38 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
39 end
39 end
40
41 def download
42 @attachment = @version.attachments.find(params[:attachment_id])
43 @attachment.increment_download
44 send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
45 :type => @attachment.content_type
46 rescue
47 render_404
48 end
49
40
50 def destroy_file
41 def destroy_file
51 @version.attachments.find(params[:attachment_id]).destroy
42 @version.attachments.find(params[:attachment_id]).destroy
52 flash[:notice] = l(:notice_successful_delete)
43 flash[:notice] = l(:notice_successful_delete)
53 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
44 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
54 end
45 end
55
46
56 def status_by
47 def status_by
57 respond_to do |format|
48 respond_to do |format|
58 format.html { render :action => 'show' }
49 format.html { render :action => 'show' }
59 format.js { render(:update) {|page| page.replace_html 'status_by', render_issue_status_by(@version, params[:status_by])} }
50 format.js { render(:update) {|page| page.replace_html 'status_by', render_issue_status_by(@version, params[:status_by])} }
60 end
51 end
61 end
52 end
62
53
63 private
54 private
64 def find_project
55 def find_project
65 @version = Version.find(params[:id])
56 @version = Version.find(params[:id])
66 @project = @version.project
57 @project = @version.project
67 rescue ActiveRecord::RecordNotFound
58 rescue ActiveRecord::RecordNotFound
68 render_404
59 render_404
69 end
60 end
70 end
61 end
@@ -1,45 +1,45
1 <div class="contextual">
1 <div class="contextual">
2 <%= link_to_if_authorized l(:label_attachment_new), {:controller => 'projects', :action => 'add_file', :id => @project}, :class => 'icon icon-add' %>
2 <%= link_to_if_authorized l(:label_attachment_new), {:controller => 'projects', :action => 'add_file', :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>
6
6
7 <% delete_allowed = authorize_for('versions', 'destroy_file') %>
7 <% delete_allowed = authorize_for('versions', 'destroy_file') %>
8
8
9 <table class="list">
9 <table class="list">
10 <thead><tr>
10 <thead><tr>
11 <th><%=l(:field_version)%></th>
11 <th><%=l(:field_version)%></th>
12 <%= sort_header_tag("#{Attachment.table_name}.filename", :caption => l(:field_filename)) %>
12 <%= sort_header_tag("#{Attachment.table_name}.filename", :caption => l(:field_filename)) %>
13 <%= sort_header_tag("#{Attachment.table_name}.created_on", :caption => l(:label_date), :default_order => 'desc') %>
13 <%= sort_header_tag("#{Attachment.table_name}.created_on", :caption => l(:label_date), :default_order => 'desc') %>
14 <%= sort_header_tag("#{Attachment.table_name}.filesize", :caption => l(:field_filesize), :default_order => 'desc') %>
14 <%= sort_header_tag("#{Attachment.table_name}.filesize", :caption => l(:field_filesize), :default_order => 'desc') %>
15 <%= sort_header_tag("#{Attachment.table_name}.downloads", :caption => l(:label_downloads_abbr), :default_order => 'desc') %>
15 <%= sort_header_tag("#{Attachment.table_name}.downloads", :caption => l(:label_downloads_abbr), :default_order => 'desc') %>
16 <th>MD5</th>
16 <th>MD5</th>
17 <% if delete_allowed %><th></th><% end %>
17 <% if delete_allowed %><th></th><% end %>
18 </tr></thead>
18 </tr></thead>
19 <tbody>
19 <tbody>
20 <% for version in @versions %>
20 <% for version in @versions %>
21 <% unless version.attachments.empty? %>
21 <% unless version.attachments.empty? %>
22 <tr><th colspan="7" align="left"><span class="icon icon-package"><b><%= version.name %></b></span></th></tr>
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 %>
23 <% for file in version.attachments %>
24 <tr class="<%= cycle("odd", "even") %>">
24 <tr class="<%= cycle("odd", "even") %>">
25 <td></td>
25 <td></td>
26 <td><%= link_to(file.filename, {:controller => 'versions', :action => 'download', :id => version, :attachment_id => file},
26 <td><%= link_to(h(file.filename), {:controller => 'attachments', :action => 'download', :id => file},
27 :title => file.description) %></td>
27 :title => file.description) %></td>
28 <td align="center"><%= format_time(file.created_on) %></td>
28 <td align="center"><%= format_time(file.created_on) %></td>
29 <td align="center"><%= number_to_human_size(file.filesize) %></td>
29 <td align="center"><%= number_to_human_size(file.filesize) %></td>
30 <td align="center"><%= file.downloads %></td>
30 <td align="center"><%= file.downloads %></td>
31 <td align="center"><small><%= file.digest %></small></td>
31 <td align="center"><small><%= file.digest %></small></td>
32 <% if delete_allowed %>
32 <% if delete_allowed %>
33 <td align="center">
33 <td align="center">
34 <%= link_to_if_authorized image_tag('delete.png'), {:controller => 'versions', :action => 'destroy_file', :id => version, :attachment_id => file}, :confirm => l(:text_are_you_sure), :method => :post %>
34 <%= link_to_if_authorized image_tag('delete.png'), {:controller => 'versions', :action => 'destroy_file', :id => version, :attachment_id => file}, :confirm => l(:text_are_you_sure), :method => :post %>
35 </td>
35 </td>
36 <% end %>
36 <% end %>
37 </tr>
37 </tr>
38 <% end
38 <% end
39 reset_cycle %>
39 reset_cycle %>
40 <% end %>
40 <% end %>
41 <% end %>
41 <% end %>
42 </tbody>
42 </tbody>
43 </table>
43 </table>
44
44
45 <% html_title(l(:label_attachment_plural)) -%>
45 <% html_title(l(:label_attachment_plural)) -%>
@@ -1,75 +1,88
1 ---
1 ---
2 attachments_001:
2 attachments_001:
3 created_on: 2006-07-19 21:07:27 +02:00
3 created_on: 2006-07-19 21:07:27 +02:00
4 downloads: 0
4 downloads: 0
5 content_type: text/plain
5 content_type: text/plain
6 disk_filename: 060719210727_error281.txt
6 disk_filename: 060719210727_error281.txt
7 container_id: 3
7 container_id: 3
8 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
8 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
9 id: 1
9 id: 1
10 container_type: Issue
10 container_type: Issue
11 filesize: 28
11 filesize: 28
12 filename: error281.txt
12 filename: error281.txt
13 author_id: 2
13 author_id: 2
14 attachments_002:
14 attachments_002:
15 created_on: 2006-07-19 21:07:27 +02:00
15 created_on: 2006-07-19 21:07:27 +02:00
16 downloads: 0
16 downloads: 0
17 content_type: text/plain
17 content_type: text/plain
18 disk_filename: 060719210727_document.txt
18 disk_filename: 060719210727_document.txt
19 container_id: 1
19 container_id: 1
20 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
20 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
21 id: 2
21 id: 2
22 container_type: Document
22 container_type: Document
23 filesize: 28
23 filesize: 28
24 filename: document.txt
24 filename: document.txt
25 author_id: 2
25 author_id: 2
26 attachments_003:
26 attachments_003:
27 created_on: 2006-07-19 21:07:27 +02:00
27 created_on: 2006-07-19 21:07:27 +02:00
28 downloads: 0
28 downloads: 0
29 content_type: image/gif
29 content_type: image/gif
30 disk_filename: 060719210727_logo.gif
30 disk_filename: 060719210727_logo.gif
31 container_id: 4
31 container_id: 4
32 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
32 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
33 id: 3
33 id: 3
34 container_type: WikiPage
34 container_type: WikiPage
35 filesize: 280
35 filesize: 280
36 filename: logo.gif
36 filename: logo.gif
37 description: This is a logo
37 description: This is a logo
38 author_id: 2
38 author_id: 2
39 attachments_004:
39 attachments_004:
40 created_on: 2006-07-19 21:07:27 +02:00
40 created_on: 2006-07-19 21:07:27 +02:00
41 container_type: Issue
41 container_type: Issue
42 container_id: 3
42 container_id: 3
43 downloads: 0
43 downloads: 0
44 disk_filename: 060719210727_source.rb
44 disk_filename: 060719210727_source.rb
45 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
45 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
46 id: 4
46 id: 4
47 filesize: 153
47 filesize: 153
48 filename: source.rb
48 filename: source.rb
49 author_id: 2
49 author_id: 2
50 description: This is a Ruby source file
50 description: This is a Ruby source file
51 content_type: application/x-ruby
51 content_type: application/x-ruby
52 attachments_005:
52 attachments_005:
53 created_on: 2006-07-19 21:07:27 +02:00
53 created_on: 2006-07-19 21:07:27 +02:00
54 container_type: Issue
54 container_type: Issue
55 container_id: 3
55 container_id: 3
56 downloads: 0
56 downloads: 0
57 disk_filename: 060719210727_changeset.diff
57 disk_filename: 060719210727_changeset.diff
58 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
58 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
59 id: 5
59 id: 5
60 filesize: 687
60 filesize: 687
61 filename: changeset.diff
61 filename: changeset.diff
62 author_id: 2
62 author_id: 2
63 content_type: text/x-diff
63 content_type: text/x-diff
64 attachments_006:
64 attachments_006:
65 created_on: 2006-07-19 21:07:27 +02:00
65 created_on: 2006-07-19 21:07:27 +02:00
66 container_type: Issue
66 container_type: Issue
67 container_id: 3
67 container_id: 3
68 downloads: 0
68 downloads: 0
69 disk_filename: 060719210727_archive.zip
69 disk_filename: 060719210727_archive.zip
70 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
70 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
71 id: 6
71 id: 6
72 filesize: 157
72 filesize: 157
73 filename: archive.zip
73 filename: archive.zip
74 author_id: 2
74 author_id: 2
75 content_type: application/octet-stream
75 content_type: application/octet-stream
76 attachments_007:
77 created_on: 2006-07-19 21:07:27 +02:00
78 container_type: Issue
79 container_id: 4
80 downloads: 0
81 disk_filename: 060719210727_archive.zip
82 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
83 id: 7
84 filesize: 157
85 filename: archive.zip
86 author_id: 1
87 content_type: application/octet-stream
88 No newline at end of file
@@ -1,59 +1,64
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'attachments_controller'
19 require 'attachments_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class AttachmentsController; def rescue_action(e) raise e end; end
22 class AttachmentsController; def rescue_action(e) raise e end; end
23
23
24
24
25 class AttachmentsControllerTest < Test::Unit::TestCase
25 class AttachmentsControllerTest < Test::Unit::TestCase
26 fixtures :users, :projects, :issues, :attachments
26 fixtures :users, :projects, :issues, :attachments
27
27
28 def setup
28 def setup
29 @controller = AttachmentsController.new
29 @controller = AttachmentsController.new
30 @request = ActionController::TestRequest.new
30 @request = ActionController::TestRequest.new
31 @response = ActionController::TestResponse.new
31 @response = ActionController::TestResponse.new
32 Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
32 Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
33 User.current = nil
33 User.current = nil
34 end
34 end
35
35
36 def test_show_diff
36 def test_show_diff
37 get :show, :id => 5
37 get :show, :id => 5
38 assert_response :success
38 assert_response :success
39 assert_template 'diff'
39 assert_template 'diff'
40 end
40 end
41
41
42 def test_show_text_file
42 def test_show_text_file
43 get :show, :id => 4
43 get :show, :id => 4
44 assert_response :success
44 assert_response :success
45 assert_template 'file'
45 assert_template 'file'
46 end
46 end
47
47
48 def test_show_other
48 def test_show_other
49 get :show, :id => 6
49 get :show, :id => 6
50 assert_response :success
50 assert_response :success
51 assert_equal 'application/octet-stream', @response.content_type
51 assert_equal 'application/octet-stream', @response.content_type
52 end
52 end
53
53
54 def test_download_text_file
54 def test_download_text_file
55 get :download, :id => 4
55 get :download, :id => 4
56 assert_response :success
56 assert_response :success
57 assert_equal 'application/x-ruby', @response.content_type
57 assert_equal 'application/x-ruby', @response.content_type
58 end
58 end
59
60 def test_anonymous_on_private_private
61 get :download, :id => 7
62 assert_redirected_to 'account/login'
63 end
59 end
64 end
General Comments 0
You need to be logged in to leave comments. Login now