@@ -1,199 +1,204 | |||||
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 ApplicationController < ActionController::Base |
|
18 | class ApplicationController < ActionController::Base | |
19 | before_filter :user_setup, :check_if_login_required, :set_localization |
|
19 | before_filter :user_setup, :check_if_login_required, :set_localization | |
20 | filter_parameter_logging :password |
|
20 | filter_parameter_logging :password | |
21 |
|
21 | |||
22 | REDMINE_SUPPORTED_SCM.each do |scm| |
|
22 | REDMINE_SUPPORTED_SCM.each do |scm| | |
23 | require_dependency "repository/#{scm.underscore}" |
|
23 | require_dependency "repository/#{scm.underscore}" | |
24 | end |
|
24 | end | |
25 |
|
25 | |||
26 | def current_role |
|
26 | def current_role | |
27 | @current_role ||= User.current.role_for_project(@project) |
|
27 | @current_role ||= User.current.role_for_project(@project) | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | def user_setup |
|
30 | def user_setup | |
31 | # Check the settings cache for each request |
|
31 | # Check the settings cache for each request | |
32 | Setting.check_cache |
|
32 | Setting.check_cache | |
33 | # Find the current user |
|
33 | # Find the current user | |
34 | User.current = find_current_user |
|
34 | User.current = find_current_user | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | # Returns the current user or nil if no user is logged in |
|
37 | # Returns the current user or nil if no user is logged in | |
38 | def find_current_user |
|
38 | def find_current_user | |
39 | if session[:user_id] |
|
39 | if session[:user_id] | |
40 | # existing session |
|
40 | # existing session | |
41 | (User.find_active(session[:user_id]) rescue nil) |
|
41 | (User.find_active(session[:user_id]) rescue nil) | |
42 | elsif cookies[:autologin] && Setting.autologin? |
|
42 | elsif cookies[:autologin] && Setting.autologin? | |
43 | # auto-login feature |
|
43 | # auto-login feature | |
44 | User.find_by_autologin_key(cookies[:autologin]) |
|
44 | User.find_by_autologin_key(cookies[:autologin]) | |
45 | elsif params[:key] && accept_key_auth_actions.include?(params[:action]) |
|
45 | elsif params[:key] && accept_key_auth_actions.include?(params[:action]) | |
46 | # RSS key authentication |
|
46 | # RSS key authentication | |
47 | User.find_by_rss_key(params[:key]) |
|
47 | User.find_by_rss_key(params[:key]) | |
48 | end |
|
48 | end | |
49 | end |
|
49 | end | |
50 |
|
50 | |||
51 | # check if login is globally required to access the application |
|
51 | # check if login is globally required to access the application | |
52 | def check_if_login_required |
|
52 | def check_if_login_required | |
53 | # no check needed if user is already logged in |
|
53 | # no check needed if user is already logged in | |
54 | return true if User.current.logged? |
|
54 | return true if User.current.logged? | |
55 | require_login if Setting.login_required? |
|
55 | require_login if Setting.login_required? | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
58 | def set_localization |
|
58 | def set_localization | |
59 | lang = begin |
|
59 | lang = begin | |
60 | if !User.current.language.blank? and GLoc.valid_languages.include? User.current.language.to_sym |
|
60 | if !User.current.language.blank? and GLoc.valid_languages.include? User.current.language.to_sym | |
61 | User.current.language |
|
61 | User.current.language | |
62 | elsif request.env['HTTP_ACCEPT_LANGUAGE'] |
|
62 | elsif request.env['HTTP_ACCEPT_LANGUAGE'] | |
63 | accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.split('-').first |
|
63 | accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.split('-').first | |
64 | if accept_lang and !accept_lang.empty? and GLoc.valid_languages.include? accept_lang.to_sym |
|
64 | if accept_lang and !accept_lang.empty? and GLoc.valid_languages.include? accept_lang.to_sym | |
65 | accept_lang |
|
65 | accept_lang | |
66 | end |
|
66 | end | |
67 | end |
|
67 | end | |
68 | rescue |
|
68 | rescue | |
69 | nil |
|
69 | nil | |
70 | end || Setting.default_language |
|
70 | end || Setting.default_language | |
71 | set_language_if_valid(lang) |
|
71 | set_language_if_valid(lang) | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def require_login |
|
74 | def require_login | |
75 | if !User.current.logged? |
|
75 | if !User.current.logged? | |
76 | store_location |
|
76 | store_location | |
77 | redirect_to :controller => "account", :action => "login" |
|
77 | redirect_to :controller => "account", :action => "login" | |
78 | return false |
|
78 | return false | |
79 | end |
|
79 | end | |
80 | true |
|
80 | true | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | def require_admin |
|
83 | def require_admin | |
84 | return unless require_login |
|
84 | return unless require_login | |
85 | if !User.current.admin? |
|
85 | if !User.current.admin? | |
86 | render_403 |
|
86 | render_403 | |
87 | return false |
|
87 | return false | |
88 | end |
|
88 | end | |
89 | true |
|
89 | true | |
90 | end |
|
90 | end | |
91 |
|
91 | |||
92 | # Authorize the user for the requested action |
|
92 | # Authorize the user for the requested action | |
93 | def authorize(ctrl = params[:controller], action = params[:action]) |
|
93 | def authorize(ctrl = params[:controller], action = params[:action]) | |
94 | allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project) |
|
94 | allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project) | |
95 | allowed ? true : (User.current.logged? ? render_403 : require_login) |
|
95 | allowed ? true : (User.current.logged? ? render_403 : require_login) | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | # make sure that the user is a member of the project (or admin) if project is private |
|
98 | # make sure that the user is a member of the project (or admin) if project is private | |
99 | # used as a before_filter for actions that do not require any particular permission on the project |
|
99 | # used as a before_filter for actions that do not require any particular permission on the project | |
100 | def check_project_privacy |
|
100 | def check_project_privacy | |
101 | unless @project.active? |
|
101 | unless @project.active? | |
102 | @project = nil |
|
102 | @project = nil | |
103 | render_404 |
|
103 | render_404 | |
104 | return false |
|
104 | return false | |
105 | end |
|
105 | end | |
106 | return true if @project.is_public? || User.current.member_of?(@project) || User.current.admin? |
|
106 | return true if @project.is_public? || User.current.member_of?(@project) || User.current.admin? | |
107 | User.current.logged? ? render_403 : require_login |
|
107 | User.current.logged? ? render_403 : require_login | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | # store current uri in session. |
|
110 | # store current uri in session. | |
111 | # return to this location by calling redirect_back_or_default |
|
111 | # return to this location by calling redirect_back_or_default | |
112 | def store_location |
|
112 | def store_location | |
113 | session[:return_to_params] = params |
|
113 | session[:return_to_params] = params | |
114 | end |
|
114 | end | |
115 |
|
115 | |||
116 | # move to the last store_location call or to the passed default one |
|
116 | # move to the last store_location call or to the passed default one | |
117 | def redirect_back_or_default(default) |
|
117 | def redirect_back_or_default(default) | |
118 | if session[:return_to_params].nil? |
|
118 | if session[:return_to_params].nil? | |
119 | redirect_to default |
|
119 | redirect_to default | |
120 | else |
|
120 | else | |
121 | redirect_to session[:return_to_params] |
|
121 | redirect_to session[:return_to_params] | |
122 | session[:return_to_params] = nil |
|
122 | session[:return_to_params] = nil | |
123 | end |
|
123 | end | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
126 | def render_403 |
|
126 | def render_403 | |
127 | @project = nil |
|
127 | @project = nil | |
128 | render :template => "common/403", :layout => !request.xhr?, :status => 403 |
|
128 | render :template => "common/403", :layout => !request.xhr?, :status => 403 | |
129 | return false |
|
129 | return false | |
130 | end |
|
130 | end | |
131 |
|
131 | |||
132 | def render_404 |
|
132 | def render_404 | |
133 | render :template => "common/404", :layout => !request.xhr?, :status => 404 |
|
133 | render :template => "common/404", :layout => !request.xhr?, :status => 404 | |
134 | return false |
|
134 | return false | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | def render_feed(items, options={}) |
|
137 | def render_feed(items, options={}) | |
138 | @items = items || [] |
|
138 | @items = items || [] | |
139 | @items.sort! {|x,y| y.event_datetime <=> x.event_datetime } |
|
139 | @items.sort! {|x,y| y.event_datetime <=> x.event_datetime } | |
140 | @title = options[:title] || Setting.app_title |
|
140 | @title = options[:title] || Setting.app_title | |
141 | render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml' |
|
141 | render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml' | |
142 | end |
|
142 | end | |
143 |
|
143 | |||
144 | def self.accept_key_auth(*actions) |
|
144 | def self.accept_key_auth(*actions) | |
145 | actions = actions.flatten.map(&:to_s) |
|
145 | actions = actions.flatten.map(&:to_s) | |
146 | write_inheritable_attribute('accept_key_auth_actions', actions) |
|
146 | write_inheritable_attribute('accept_key_auth_actions', actions) | |
147 | end |
|
147 | end | |
148 |
|
148 | |||
149 | def accept_key_auth_actions |
|
149 | def accept_key_auth_actions | |
150 | self.class.read_inheritable_attribute('accept_key_auth_actions') || [] |
|
150 | self.class.read_inheritable_attribute('accept_key_auth_actions') || [] | |
151 | end |
|
151 | end | |
152 |
|
152 | |||
153 | # TODO: move to model |
|
153 | # TODO: move to model | |
154 | def attach_files(obj, files) |
|
154 | def attach_files(obj, files) | |
155 | attachments = [] |
|
155 | attachments = [] | |
156 | if files && files.is_a?(Array) |
|
156 | if files && files.is_a?(Array) | |
157 | files.each do |file| |
|
157 | files.each do |file| | |
158 | next unless file.size > 0 |
|
158 | next unless file.size > 0 | |
159 | a = Attachment.create(:container => obj, :file => file, :author => User.current) |
|
159 | a = Attachment.create(:container => obj, :file => file, :author => User.current) | |
160 | attachments << a unless a.new_record? |
|
160 | attachments << a unless a.new_record? | |
161 | end |
|
161 | end | |
162 | end |
|
162 | end | |
163 | attachments |
|
163 | attachments | |
164 | end |
|
164 | end | |
165 |
|
165 | |||
166 | # Returns the number of objects that should be displayed |
|
166 | # Returns the number of objects that should be displayed | |
167 | # on the paginated list |
|
167 | # on the paginated list | |
168 | def per_page_option |
|
168 | def per_page_option | |
169 | per_page = nil |
|
169 | per_page = nil | |
170 | if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i) |
|
170 | if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i) | |
171 | per_page = params[:per_page].to_s.to_i |
|
171 | per_page = params[:per_page].to_s.to_i | |
172 | session[:per_page] = per_page |
|
172 | session[:per_page] = per_page | |
173 | elsif session[:per_page] |
|
173 | elsif session[:per_page] | |
174 | per_page = session[:per_page] |
|
174 | per_page = session[:per_page] | |
175 | else |
|
175 | else | |
176 | per_page = Setting.per_page_options_array.first || 25 |
|
176 | per_page = Setting.per_page_options_array.first || 25 | |
177 | end |
|
177 | end | |
178 | per_page |
|
178 | per_page | |
179 | end |
|
179 | end | |
180 |
|
180 | |||
181 | # qvalues http header parser |
|
181 | # qvalues http header parser | |
182 | # code taken from webrick |
|
182 | # code taken from webrick | |
183 | def parse_qvalues(value) |
|
183 | def parse_qvalues(value) | |
184 | tmp = [] |
|
184 | tmp = [] | |
185 | if value |
|
185 | if value | |
186 | parts = value.split(/,\s*/) |
|
186 | parts = value.split(/,\s*/) | |
187 | parts.each {|part| |
|
187 | parts.each {|part| | |
188 | if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part) |
|
188 | if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part) | |
189 | val = m[1] |
|
189 | val = m[1] | |
190 | q = (m[2] or 1).to_f |
|
190 | q = (m[2] or 1).to_f | |
191 | tmp.push([val, q]) |
|
191 | tmp.push([val, q]) | |
192 | end |
|
192 | end | |
193 | } |
|
193 | } | |
194 | tmp = tmp.sort_by{|val, q| -q} |
|
194 | tmp = tmp.sort_by{|val, q| -q} | |
195 | tmp.collect!{|val, q| val} |
|
195 | tmp.collect!{|val, q| val} | |
196 | end |
|
196 | end | |
197 | return tmp |
|
197 | return tmp | |
198 | end |
|
198 | end | |
|
199 | ||||
|
200 | # Returns a string that can be used as filename value in Content-Disposition header | |||
|
201 | def filename_for_content_disposition(name) | |||
|
202 | request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name | |||
|
203 | end | |||
199 | end |
|
204 | end |
@@ -1,39 +1,39 | |||||
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, :check_project_privacy | |
21 |
|
21 | |||
22 | def download |
|
22 | def download | |
23 | # images are sent inline |
|
23 | # images are sent inline | |
24 |
send_file @attachment.diskfile, :filename => @attachment.filename, |
|
24 | send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), | |
25 | :type => @attachment.content_type, |
|
25 | :type => @attachment.content_type, | |
26 | :disposition => (@attachment.image? ? 'inline' : 'attachment') |
|
26 | :disposition => (@attachment.image? ? 'inline' : 'attachment') | |
27 | rescue |
|
27 | rescue | |
28 | # in case the disk file was deleted |
|
28 | # in case the disk file was deleted | |
29 | render_404 |
|
29 | render_404 | |
30 | end |
|
30 | end | |
31 |
|
31 | |||
32 | private |
|
32 | private | |
33 | def find_project |
|
33 | def find_project | |
34 | @attachment = Attachment.find(params[:id]) |
|
34 | @attachment = Attachment.find(params[:id]) | |
35 | @project = @attachment.project |
|
35 | @project = @attachment.project | |
36 | rescue |
|
36 | rescue | |
37 | render_404 |
|
37 | render_404 | |
38 | end |
|
38 | end | |
39 | end |
|
39 | end |
@@ -1,99 +1,100 | |||||
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 | def index |
|
24 | def index | |
25 | @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' |
|
25 | @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' | |
26 | documents = @project.documents.find :all, :include => [:attachments, :category] |
|
26 | documents = @project.documents.find :all, :include => [:attachments, :category] | |
27 | case @sort_by |
|
27 | case @sort_by | |
28 | when 'date' |
|
28 | when 'date' | |
29 | @grouped = documents.group_by {|d| d.created_on.to_date } |
|
29 | @grouped = documents.group_by {|d| d.created_on.to_date } | |
30 | when 'title' |
|
30 | when 'title' | |
31 | @grouped = documents.group_by {|d| d.title.first.upcase} |
|
31 | @grouped = documents.group_by {|d| d.title.first.upcase} | |
32 | when 'author' |
|
32 | when 'author' | |
33 | @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author} |
|
33 | @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author} | |
34 | else |
|
34 | else | |
35 | @grouped = documents.group_by(&:category) |
|
35 | @grouped = documents.group_by(&:category) | |
36 | end |
|
36 | end | |
37 | render :layout => false if request.xhr? |
|
37 | render :layout => false if request.xhr? | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | def show |
|
40 | def show | |
41 | @attachments = @document.attachments.find(:all, :order => "created_on DESC") |
|
41 | @attachments = @document.attachments.find(:all, :order => "created_on DESC") | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def new |
|
44 | def new | |
45 | @document = @project.documents.build(params[:document]) |
|
45 | @document = @project.documents.build(params[:document]) | |
46 | if request.post? and @document.save |
|
46 | if request.post? and @document.save | |
47 | attach_files(@document, params[:attachments]) |
|
47 | attach_files(@document, params[:attachments]) | |
48 | flash[:notice] = l(:notice_successful_create) |
|
48 | flash[:notice] = l(:notice_successful_create) | |
49 | Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added') |
|
49 | Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added') | |
50 | redirect_to :action => 'index', :project_id => @project |
|
50 | redirect_to :action => 'index', :project_id => @project | |
51 | end |
|
51 | end | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | def edit |
|
54 | def edit | |
55 | @categories = Enumeration::get_values('DCAT') |
|
55 | @categories = Enumeration::get_values('DCAT') | |
56 | if request.post? and @document.update_attributes(params[:document]) |
|
56 | if request.post? and @document.update_attributes(params[:document]) | |
57 | flash[:notice] = l(:notice_successful_update) |
|
57 | flash[:notice] = l(:notice_successful_update) | |
58 | redirect_to :action => 'show', :id => @document |
|
58 | redirect_to :action => 'show', :id => @document | |
59 | end |
|
59 | end | |
60 | end |
|
60 | end | |
61 |
|
61 | |||
62 | def destroy |
|
62 | def destroy | |
63 | @document.destroy |
|
63 | @document.destroy | |
64 | redirect_to :controller => 'documents', :action => 'index', :project_id => @project |
|
64 | redirect_to :controller => 'documents', :action => 'index', :project_id => @project | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | def download |
|
67 | def download | |
68 | @attachment = @document.attachments.find(params[:attachment_id]) |
|
68 | @attachment = @document.attachments.find(params[:attachment_id]) | |
69 | @attachment.increment_download |
|
69 | @attachment.increment_download | |
70 |
send_file @attachment.diskfile, :filename => @attachment.filename, |
|
70 | send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), | |
|
71 | :type => @attachment.content_type | |||
71 | rescue |
|
72 | rescue | |
72 | render_404 |
|
73 | render_404 | |
73 | end |
|
74 | end | |
74 |
|
75 | |||
75 | def add_attachment |
|
76 | def add_attachment | |
76 | attachments = attach_files(@document, params[:attachments]) |
|
77 | attachments = attach_files(@document, params[:attachments]) | |
77 | Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('document_added') |
|
78 | Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('document_added') | |
78 | redirect_to :action => 'show', :id => @document |
|
79 | redirect_to :action => 'show', :id => @document | |
79 | end |
|
80 | end | |
80 |
|
81 | |||
81 | def destroy_attachment |
|
82 | def destroy_attachment | |
82 | @document.attachments.find(params[:attachment_id]).destroy |
|
83 | @document.attachments.find(params[:attachment_id]).destroy | |
83 | redirect_to :action => 'show', :id => @document |
|
84 | redirect_to :action => 'show', :id => @document | |
84 | end |
|
85 | end | |
85 |
|
86 | |||
86 | private |
|
87 | private | |
87 | def find_project |
|
88 | def find_project | |
88 | @project = Project.find(params[:project_id]) |
|
89 | @project = Project.find(params[:project_id]) | |
89 | rescue ActiveRecord::RecordNotFound |
|
90 | rescue ActiveRecord::RecordNotFound | |
90 | render_404 |
|
91 | render_404 | |
91 | end |
|
92 | end | |
92 |
|
93 | |||
93 | def find_document |
|
94 | def find_document | |
94 | @document = Document.find(params[:id]) |
|
95 | @document = Document.find(params[:id]) | |
95 | @project = @document.project |
|
96 | @project = @document.project | |
96 | rescue ActiveRecord::RecordNotFound |
|
97 | rescue ActiveRecord::RecordNotFound | |
97 | render_404 |
|
98 | render_404 | |
98 | end |
|
99 | end | |
99 | end |
|
100 | end |
@@ -1,70 +1,71 | |||||
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 show |
|
24 | def show | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | def edit |
|
27 | def edit | |
28 | if request.post? and @version.update_attributes(params[:version]) |
|
28 | if request.post? and @version.update_attributes(params[:version]) | |
29 | flash[:notice] = l(:notice_successful_update) |
|
29 | flash[:notice] = l(:notice_successful_update) | |
30 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project |
|
30 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
31 | end |
|
31 | end | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def destroy |
|
34 | def destroy | |
35 | @version.destroy |
|
35 | @version.destroy | |
36 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project |
|
36 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
37 | rescue |
|
37 | rescue | |
38 | flash[:error] = "Unable to delete version" |
|
38 | flash[:error] = "Unable to delete version" | |
39 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project |
|
39 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | def download |
|
42 | def download | |
43 | @attachment = @version.attachments.find(params[:attachment_id]) |
|
43 | @attachment = @version.attachments.find(params[:attachment_id]) | |
44 | @attachment.increment_download |
|
44 | @attachment.increment_download | |
45 |
send_file @attachment.diskfile, :filename => @attachment.filename, |
|
45 | send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), | |
|
46 | :type => @attachment.content_type | |||
46 | rescue |
|
47 | rescue | |
47 | render_404 |
|
48 | render_404 | |
48 | end |
|
49 | end | |
49 |
|
50 | |||
50 | def destroy_file |
|
51 | def destroy_file | |
51 | @version.attachments.find(params[:attachment_id]).destroy |
|
52 | @version.attachments.find(params[:attachment_id]).destroy | |
52 | flash[:notice] = l(:notice_successful_delete) |
|
53 | flash[:notice] = l(:notice_successful_delete) | |
53 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
54 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project | |
54 | end |
|
55 | end | |
55 |
|
56 | |||
56 | def status_by |
|
57 | def status_by | |
57 | respond_to do |format| |
|
58 | respond_to do |format| | |
58 | format.html { render :action => 'show' } |
|
59 | format.html { render :action => 'show' } | |
59 | format.js { render(:update) {|page| page.replace_html 'status_by', render_issue_status_by(@version, params[:status_by])} } |
|
60 | format.js { render(:update) {|page| page.replace_html 'status_by', render_issue_status_by(@version, params[:status_by])} } | |
60 | end |
|
61 | end | |
61 | end |
|
62 | end | |
62 |
|
63 | |||
63 | private |
|
64 | private | |
64 | def find_project |
|
65 | def find_project | |
65 | @version = Version.find(params[:id]) |
|
66 | @version = Version.find(params[:id]) | |
66 | @project = @version.project |
|
67 | @project = @version.project | |
67 | rescue ActiveRecord::RecordNotFound |
|
68 | rescue ActiveRecord::RecordNotFound | |
68 | render_404 |
|
69 | render_404 | |
69 | end |
|
70 | end | |
70 | end |
|
71 | end |
General Comments 0
You need to be logged in to leave comments.
Login now