@@ -1,71 +1,71 | |||||
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, :authorize |
|
20 | before_filter :find_project, :authorize | |
21 |
|
21 | |||
22 | def show |
|
22 | def show | |
23 | @attachments = @document.attachments.find(:all, :order => "created_on DESC") |
|
23 | @attachments = @document.attachments.find(:all, :order => "created_on DESC") | |
24 | end |
|
24 | end | |
25 |
|
25 | |||
26 | def edit |
|
26 | def edit | |
27 | @categories = Enumeration::get_values('DCAT') |
|
27 | @categories = Enumeration::get_values('DCAT') | |
28 | if request.post? and @document.update_attributes(params[:document]) |
|
28 | if request.post? and @document.update_attributes(params[:document]) | |
29 | flash[:notice] = l(:notice_successful_update) |
|
29 | flash[:notice] = l(:notice_successful_update) | |
30 | redirect_to :action => 'show', :id => @document |
|
30 | redirect_to :action => 'show', :id => @document | |
31 | end |
|
31 | end | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def destroy |
|
34 | def destroy | |
35 | @document.destroy |
|
35 | @document.destroy | |
36 | redirect_to :controller => 'projects', :action => 'list_documents', :id => @project |
|
36 | redirect_to :controller => 'projects', :action => 'list_documents', :id => @project | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | def download |
|
39 | def download | |
40 | @attachment = @document.attachments.find(params[:attachment_id]) |
|
40 | @attachment = @document.attachments.find(params[:attachment_id]) | |
41 | @attachment.increment_download |
|
41 | @attachment.increment_download | |
42 | send_file @attachment.diskfile, :filename => @attachment.filename |
|
42 | send_file @attachment.diskfile, :filename => @attachment.filename, :type => @attachment.content_type | |
43 | rescue |
|
43 | rescue | |
44 | render_404 |
|
44 | render_404 | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def add_attachment |
|
47 | def add_attachment | |
48 | # Save the attachments |
|
48 | # Save the attachments | |
49 | @attachments = [] |
|
49 | @attachments = [] | |
50 | params[:attachments].each { |file| |
|
50 | params[:attachments].each { |file| | |
51 | next unless file.size > 0 |
|
51 | next unless file.size > 0 | |
52 | a = Attachment.create(:container => @document, :file => file, :author => logged_in_user) |
|
52 | a = Attachment.create(:container => @document, :file => file, :author => logged_in_user) | |
53 | @attachments << a unless a.new_record? |
|
53 | @attachments << a unless a.new_record? | |
54 | } if params[:attachments] and params[:attachments].is_a? Array |
|
54 | } if params[:attachments] and params[:attachments].is_a? Array | |
55 | Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('document_added') |
|
55 | Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('document_added') | |
56 | redirect_to :action => 'show', :id => @document |
|
56 | redirect_to :action => 'show', :id => @document | |
57 | end |
|
57 | end | |
58 |
|
58 | |||
59 | def destroy_attachment |
|
59 | def destroy_attachment | |
60 | @document.attachments.find(params[:attachment_id]).destroy |
|
60 | @document.attachments.find(params[:attachment_id]).destroy | |
61 | redirect_to :action => 'show', :id => @document |
|
61 | redirect_to :action => 'show', :id => @document | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | private |
|
64 | private | |
65 | def find_project |
|
65 | def find_project | |
66 | @document = Document.find(params[:id]) |
|
66 | @document = Document.find(params[:id]) | |
67 | @project = @document.project |
|
67 | @project = @document.project | |
68 | rescue ActiveRecord::RecordNotFound |
|
68 | rescue ActiveRecord::RecordNotFound | |
69 | render_404 |
|
69 | render_404 | |
70 | end |
|
70 | end | |
71 | end |
|
71 | end |
@@ -1,60 +1,60 | |||||
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 | before_filter :find_project, :authorize |
|
20 | before_filter :find_project, :authorize | |
21 |
|
21 | |||
22 | cache_sweeper :version_sweeper, :only => [ :edit, :destroy ] |
|
22 | cache_sweeper :version_sweeper, :only => [ :edit, :destroy ] | |
23 |
|
23 | |||
24 | def edit |
|
24 | def edit | |
25 | if request.post? and @version.update_attributes(params[:version]) |
|
25 | if request.post? and @version.update_attributes(params[:version]) | |
26 | flash[:notice] = l(:notice_successful_update) |
|
26 | flash[:notice] = l(:notice_successful_update) | |
27 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project |
|
27 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
28 | end |
|
28 | end | |
29 | end |
|
29 | end | |
30 |
|
30 | |||
31 | def destroy |
|
31 | def destroy | |
32 | @version.destroy |
|
32 | @version.destroy | |
33 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project |
|
33 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
34 | rescue |
|
34 | rescue | |
35 | flash[:error] = "Unable to delete version" |
|
35 | flash[:error] = "Unable to delete version" | |
36 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project |
|
36 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | def download |
|
39 | def download | |
40 | @attachment = @version.attachments.find(params[:attachment_id]) |
|
40 | @attachment = @version.attachments.find(params[:attachment_id]) | |
41 | @attachment.increment_download |
|
41 | @attachment.increment_download | |
42 | send_file @attachment.diskfile, :filename => @attachment.filename |
|
42 | send_file @attachment.diskfile, :filename => @attachment.filename, :type => @attachment.content_type | |
43 | rescue |
|
43 | rescue | |
44 | render_404 |
|
44 | render_404 | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def destroy_file |
|
47 | def destroy_file | |
48 | @version.attachments.find(params[:attachment_id]).destroy |
|
48 | @version.attachments.find(params[:attachment_id]).destroy | |
49 | flash[:notice] = l(:notice_successful_delete) |
|
49 | flash[:notice] = l(:notice_successful_delete) | |
50 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
50 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | private |
|
53 | private | |
54 | def find_project |
|
54 | def find_project | |
55 | @version = Version.find(params[:id]) |
|
55 | @version = Version.find(params[:id]) | |
56 | @project = @version.project |
|
56 | @project = @version.project | |
57 | rescue ActiveRecord::RecordNotFound |
|
57 | rescue ActiveRecord::RecordNotFound | |
58 | render_404 |
|
58 | render_404 | |
59 | end |
|
59 | end | |
60 | end |
|
60 | end |
General Comments 0
You need to be logged in to leave comments.
Login now