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