@@ -1,429 +1,449 | |||||
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 | require 'uri' |
|
18 | require 'uri' | |
19 | require 'cgi' |
|
19 | require 'cgi' | |
20 |
|
20 | |||
21 | class ApplicationController < ActionController::Base |
|
21 | class ApplicationController < ActionController::Base | |
22 | include Redmine::I18n |
|
22 | include Redmine::I18n | |
23 |
|
23 | |||
24 | layout 'base' |
|
24 | layout 'base' | |
25 |
exempt_from_layout 'builder', ' |
|
25 | exempt_from_layout 'builder', 'rsb' | |
26 |
|
26 | |||
27 | # Remove broken cookie after upgrade from 0.8.x (#4292) |
|
27 | # Remove broken cookie after upgrade from 0.8.x (#4292) | |
28 | # See https://rails.lighthouseapp.com/projects/8994/tickets/3360 |
|
28 | # See https://rails.lighthouseapp.com/projects/8994/tickets/3360 | |
29 | # TODO: remove it when Rails is fixed |
|
29 | # TODO: remove it when Rails is fixed | |
30 | before_filter :delete_broken_cookies |
|
30 | before_filter :delete_broken_cookies | |
31 | def delete_broken_cookies |
|
31 | def delete_broken_cookies | |
32 | if cookies['_redmine_session'] && cookies['_redmine_session'] !~ /--/ |
|
32 | if cookies['_redmine_session'] && cookies['_redmine_session'] !~ /--/ | |
33 | cookies.delete '_redmine_session' |
|
33 | cookies.delete '_redmine_session' | |
34 | redirect_to home_path |
|
34 | redirect_to home_path | |
35 | return false |
|
35 | return false | |
36 | end |
|
36 | end | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | before_filter :user_setup, :check_if_login_required, :set_localization |
|
39 | before_filter :user_setup, :check_if_login_required, :set_localization | |
40 | filter_parameter_logging :password |
|
40 | filter_parameter_logging :password | |
41 | protect_from_forgery |
|
41 | protect_from_forgery | |
42 |
|
42 | |||
43 | rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token |
|
43 | rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token | |
44 |
|
44 | |||
45 | include Redmine::Search::Controller |
|
45 | include Redmine::Search::Controller | |
46 | include Redmine::MenuManager::MenuController |
|
46 | include Redmine::MenuManager::MenuController | |
47 | helper Redmine::MenuManager::MenuHelper |
|
47 | helper Redmine::MenuManager::MenuHelper | |
48 |
|
48 | |||
49 | Redmine::Scm::Base.all.each do |scm| |
|
49 | Redmine::Scm::Base.all.each do |scm| | |
50 | require_dependency "repository/#{scm.underscore}" |
|
50 | require_dependency "repository/#{scm.underscore}" | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def user_setup |
|
53 | def user_setup | |
54 | # Check the settings cache for each request |
|
54 | # Check the settings cache for each request | |
55 | Setting.check_cache |
|
55 | Setting.check_cache | |
56 | # Find the current user |
|
56 | # Find the current user | |
57 | User.current = find_current_user |
|
57 | User.current = find_current_user | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | # Returns the current user or nil if no user is logged in |
|
60 | # Returns the current user or nil if no user is logged in | |
61 | # and starts a session if needed |
|
61 | # and starts a session if needed | |
62 | def find_current_user |
|
62 | def find_current_user | |
63 | if session[:user_id] |
|
63 | if session[:user_id] | |
64 | # existing session |
|
64 | # existing session | |
65 | (User.active.find(session[:user_id]) rescue nil) |
|
65 | (User.active.find(session[:user_id]) rescue nil) | |
66 | elsif cookies[:autologin] && Setting.autologin? |
|
66 | elsif cookies[:autologin] && Setting.autologin? | |
67 | # auto-login feature starts a new session |
|
67 | # auto-login feature starts a new session | |
68 | user = User.try_to_autologin(cookies[:autologin]) |
|
68 | user = User.try_to_autologin(cookies[:autologin]) | |
69 | session[:user_id] = user.id if user |
|
69 | session[:user_id] = user.id if user | |
70 | user |
|
70 | user | |
71 | elsif params[:format] == 'atom' && params[:key] && accept_key_auth_actions.include?(params[:action]) |
|
71 | elsif params[:format] == 'atom' && params[:key] && accept_key_auth_actions.include?(params[:action]) | |
72 | # RSS key authentication does not start a session |
|
72 | # RSS key authentication does not start a session | |
73 | User.find_by_rss_key(params[:key]) |
|
73 | User.find_by_rss_key(params[:key]) | |
74 | elsif Setting.rest_api_enabled? && ['xml', 'json'].include?(params[:format]) |
|
74 | elsif Setting.rest_api_enabled? && ['xml', 'json'].include?(params[:format]) | |
75 | if params[:key].present? && accept_key_auth_actions.include?(params[:action]) |
|
75 | if params[:key].present? && accept_key_auth_actions.include?(params[:action]) | |
76 | # Use API key |
|
76 | # Use API key | |
77 | User.find_by_api_key(params[:key]) |
|
77 | User.find_by_api_key(params[:key]) | |
78 | else |
|
78 | else | |
79 | # HTTP Basic, either username/password or API key/random |
|
79 | # HTTP Basic, either username/password or API key/random | |
80 | authenticate_with_http_basic do |username, password| |
|
80 | authenticate_with_http_basic do |username, password| | |
81 | User.try_to_login(username, password) || User.find_by_api_key(username) |
|
81 | User.try_to_login(username, password) || User.find_by_api_key(username) | |
82 | end |
|
82 | end | |
83 | end |
|
83 | end | |
84 | end |
|
84 | end | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | # Sets the logged in user |
|
87 | # Sets the logged in user | |
88 | def logged_user=(user) |
|
88 | def logged_user=(user) | |
89 | reset_session |
|
89 | reset_session | |
90 | if user && user.is_a?(User) |
|
90 | if user && user.is_a?(User) | |
91 | User.current = user |
|
91 | User.current = user | |
92 | session[:user_id] = user.id |
|
92 | session[:user_id] = user.id | |
93 | else |
|
93 | else | |
94 | User.current = User.anonymous |
|
94 | User.current = User.anonymous | |
95 | end |
|
95 | end | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | # check if login is globally required to access the application |
|
98 | # check if login is globally required to access the application | |
99 | def check_if_login_required |
|
99 | def check_if_login_required | |
100 | # no check needed if user is already logged in |
|
100 | # no check needed if user is already logged in | |
101 | return true if User.current.logged? |
|
101 | return true if User.current.logged? | |
102 | require_login if Setting.login_required? |
|
102 | require_login if Setting.login_required? | |
103 | end |
|
103 | end | |
104 |
|
104 | |||
105 | def set_localization |
|
105 | def set_localization | |
106 | lang = nil |
|
106 | lang = nil | |
107 | if User.current.logged? |
|
107 | if User.current.logged? | |
108 | lang = find_language(User.current.language) |
|
108 | lang = find_language(User.current.language) | |
109 | end |
|
109 | end | |
110 | if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE'] |
|
110 | if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE'] | |
111 | accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first |
|
111 | accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first | |
112 | if !accept_lang.blank? |
|
112 | if !accept_lang.blank? | |
113 | accept_lang = accept_lang.downcase |
|
113 | accept_lang = accept_lang.downcase | |
114 | lang = find_language(accept_lang) || find_language(accept_lang.split('-').first) |
|
114 | lang = find_language(accept_lang) || find_language(accept_lang.split('-').first) | |
115 | end |
|
115 | end | |
116 | end |
|
116 | end | |
117 | lang ||= Setting.default_language |
|
117 | lang ||= Setting.default_language | |
118 | set_language_if_valid(lang) |
|
118 | set_language_if_valid(lang) | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | def require_login |
|
121 | def require_login | |
122 | if !User.current.logged? |
|
122 | if !User.current.logged? | |
123 | # Extract only the basic url parameters on non-GET requests |
|
123 | # Extract only the basic url parameters on non-GET requests | |
124 | if request.get? |
|
124 | if request.get? | |
125 | url = url_for(params) |
|
125 | url = url_for(params) | |
126 | else |
|
126 | else | |
127 | url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id]) |
|
127 | url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id]) | |
128 | end |
|
128 | end | |
129 | respond_to do |format| |
|
129 | respond_to do |format| | |
130 | format.html { redirect_to :controller => "account", :action => "login", :back_url => url } |
|
130 | format.html { redirect_to :controller => "account", :action => "login", :back_url => url } | |
131 | format.atom { redirect_to :controller => "account", :action => "login", :back_url => url } |
|
131 | format.atom { redirect_to :controller => "account", :action => "login", :back_url => url } | |
132 | format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' } |
|
132 | format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' } | |
133 | format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' } |
|
133 | format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' } | |
134 | format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' } |
|
134 | format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' } | |
135 | end |
|
135 | end | |
136 | return false |
|
136 | return false | |
137 | end |
|
137 | end | |
138 | true |
|
138 | true | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | def require_admin |
|
141 | def require_admin | |
142 | return unless require_login |
|
142 | return unless require_login | |
143 | if !User.current.admin? |
|
143 | if !User.current.admin? | |
144 | render_403 |
|
144 | render_403 | |
145 | return false |
|
145 | return false | |
146 | end |
|
146 | end | |
147 | true |
|
147 | true | |
148 | end |
|
148 | end | |
149 |
|
149 | |||
150 | def deny_access |
|
150 | def deny_access | |
151 | User.current.logged? ? render_403 : require_login |
|
151 | User.current.logged? ? render_403 : require_login | |
152 | end |
|
152 | end | |
153 |
|
153 | |||
154 | # Authorize the user for the requested action |
|
154 | # Authorize the user for the requested action | |
155 | def authorize(ctrl = params[:controller], action = params[:action], global = false) |
|
155 | def authorize(ctrl = params[:controller], action = params[:action], global = false) | |
156 | allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global) |
|
156 | allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global) | |
157 | if allowed |
|
157 | if allowed | |
158 | true |
|
158 | true | |
159 | else |
|
159 | else | |
160 | if @project && @project.archived? |
|
160 | if @project && @project.archived? | |
161 | render_403 :message => :notice_not_authorized_archived_project |
|
161 | render_403 :message => :notice_not_authorized_archived_project | |
162 | else |
|
162 | else | |
163 | deny_access |
|
163 | deny_access | |
164 | end |
|
164 | end | |
165 | end |
|
165 | end | |
166 | end |
|
166 | end | |
167 |
|
167 | |||
168 | # Authorize the user for the requested action outside a project |
|
168 | # Authorize the user for the requested action outside a project | |
169 | def authorize_global(ctrl = params[:controller], action = params[:action], global = true) |
|
169 | def authorize_global(ctrl = params[:controller], action = params[:action], global = true) | |
170 | authorize(ctrl, action, global) |
|
170 | authorize(ctrl, action, global) | |
171 | end |
|
171 | end | |
172 |
|
172 | |||
173 | # Find project of id params[:id] |
|
173 | # Find project of id params[:id] | |
174 | def find_project |
|
174 | def find_project | |
175 | @project = Project.find(params[:id]) |
|
175 | @project = Project.find(params[:id]) | |
176 | rescue ActiveRecord::RecordNotFound |
|
176 | rescue ActiveRecord::RecordNotFound | |
177 | render_404 |
|
177 | render_404 | |
178 | end |
|
178 | end | |
179 |
|
179 | |||
180 | # Find project of id params[:project_id] |
|
180 | # Find project of id params[:project_id] | |
181 | def find_project_by_project_id |
|
181 | def find_project_by_project_id | |
182 | @project = Project.find(params[:project_id]) |
|
182 | @project = Project.find(params[:project_id]) | |
183 | rescue ActiveRecord::RecordNotFound |
|
183 | rescue ActiveRecord::RecordNotFound | |
184 | render_404 |
|
184 | render_404 | |
185 | end |
|
185 | end | |
186 |
|
186 | |||
187 | # Find a project based on params[:project_id] |
|
187 | # Find a project based on params[:project_id] | |
188 | # TODO: some subclasses override this, see about merging their logic |
|
188 | # TODO: some subclasses override this, see about merging their logic | |
189 | def find_optional_project |
|
189 | def find_optional_project | |
190 | @project = Project.find(params[:project_id]) unless params[:project_id].blank? |
|
190 | @project = Project.find(params[:project_id]) unless params[:project_id].blank? | |
191 | allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true) |
|
191 | allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true) | |
192 | allowed ? true : deny_access |
|
192 | allowed ? true : deny_access | |
193 | rescue ActiveRecord::RecordNotFound |
|
193 | rescue ActiveRecord::RecordNotFound | |
194 | render_404 |
|
194 | render_404 | |
195 | end |
|
195 | end | |
196 |
|
196 | |||
197 | # Finds and sets @project based on @object.project |
|
197 | # Finds and sets @project based on @object.project | |
198 | def find_project_from_association |
|
198 | def find_project_from_association | |
199 | render_404 unless @object.present? |
|
199 | render_404 unless @object.present? | |
200 |
|
200 | |||
201 | @project = @object.project |
|
201 | @project = @object.project | |
202 | rescue ActiveRecord::RecordNotFound |
|
202 | rescue ActiveRecord::RecordNotFound | |
203 | render_404 |
|
203 | render_404 | |
204 | end |
|
204 | end | |
205 |
|
205 | |||
206 | def find_model_object |
|
206 | def find_model_object | |
207 | model = self.class.read_inheritable_attribute('model_object') |
|
207 | model = self.class.read_inheritable_attribute('model_object') | |
208 | if model |
|
208 | if model | |
209 | @object = model.find(params[:id]) |
|
209 | @object = model.find(params[:id]) | |
210 | self.instance_variable_set('@' + controller_name.singularize, @object) if @object |
|
210 | self.instance_variable_set('@' + controller_name.singularize, @object) if @object | |
211 | end |
|
211 | end | |
212 | rescue ActiveRecord::RecordNotFound |
|
212 | rescue ActiveRecord::RecordNotFound | |
213 | render_404 |
|
213 | render_404 | |
214 | end |
|
214 | end | |
215 |
|
215 | |||
216 | def self.model_object(model) |
|
216 | def self.model_object(model) | |
217 | write_inheritable_attribute('model_object', model) |
|
217 | write_inheritable_attribute('model_object', model) | |
218 | end |
|
218 | end | |
219 |
|
219 | |||
220 | # Filter for bulk issue operations |
|
220 | # Filter for bulk issue operations | |
221 | def find_issues |
|
221 | def find_issues | |
222 | @issues = Issue.find_all_by_id(params[:id] || params[:ids]) |
|
222 | @issues = Issue.find_all_by_id(params[:id] || params[:ids]) | |
223 | raise ActiveRecord::RecordNotFound if @issues.empty? |
|
223 | raise ActiveRecord::RecordNotFound if @issues.empty? | |
224 | @projects = @issues.collect(&:project).compact.uniq |
|
224 | @projects = @issues.collect(&:project).compact.uniq | |
225 | @project = @projects.first if @projects.size == 1 |
|
225 | @project = @projects.first if @projects.size == 1 | |
226 | rescue ActiveRecord::RecordNotFound |
|
226 | rescue ActiveRecord::RecordNotFound | |
227 | render_404 |
|
227 | render_404 | |
228 | end |
|
228 | end | |
229 |
|
229 | |||
230 | # Check if project is unique before bulk operations |
|
230 | # Check if project is unique before bulk operations | |
231 | def check_project_uniqueness |
|
231 | def check_project_uniqueness | |
232 | unless @project |
|
232 | unless @project | |
233 | # TODO: let users bulk edit/move/destroy issues from different projects |
|
233 | # TODO: let users bulk edit/move/destroy issues from different projects | |
234 | render_error 'Can not bulk edit/move/destroy issues from different projects' |
|
234 | render_error 'Can not bulk edit/move/destroy issues from different projects' | |
235 | return false |
|
235 | return false | |
236 | end |
|
236 | end | |
237 | end |
|
237 | end | |
238 |
|
238 | |||
239 | # make sure that the user is a member of the project (or admin) if project is private |
|
239 | # make sure that the user is a member of the project (or admin) if project is private | |
240 | # used as a before_filter for actions that do not require any particular permission on the project |
|
240 | # used as a before_filter for actions that do not require any particular permission on the project | |
241 | def check_project_privacy |
|
241 | def check_project_privacy | |
242 | if @project && @project.active? |
|
242 | if @project && @project.active? | |
243 | if @project.is_public? || User.current.member_of?(@project) || User.current.admin? |
|
243 | if @project.is_public? || User.current.member_of?(@project) || User.current.admin? | |
244 | true |
|
244 | true | |
245 | else |
|
245 | else | |
246 | User.current.logged? ? render_403 : require_login |
|
246 | User.current.logged? ? render_403 : require_login | |
247 | end |
|
247 | end | |
248 | else |
|
248 | else | |
249 | @project = nil |
|
249 | @project = nil | |
250 | render_404 |
|
250 | render_404 | |
251 | false |
|
251 | false | |
252 | end |
|
252 | end | |
253 | end |
|
253 | end | |
254 |
|
254 | |||
255 | def back_url |
|
255 | def back_url | |
256 | params[:back_url] || request.env['HTTP_REFERER'] |
|
256 | params[:back_url] || request.env['HTTP_REFERER'] | |
257 | end |
|
257 | end | |
258 |
|
258 | |||
259 | def redirect_back_or_default(default) |
|
259 | def redirect_back_or_default(default) | |
260 | back_url = CGI.unescape(params[:back_url].to_s) |
|
260 | back_url = CGI.unescape(params[:back_url].to_s) | |
261 | if !back_url.blank? |
|
261 | if !back_url.blank? | |
262 | begin |
|
262 | begin | |
263 | uri = URI.parse(back_url) |
|
263 | uri = URI.parse(back_url) | |
264 | # do not redirect user to another host or to the login or register page |
|
264 | # do not redirect user to another host or to the login or register page | |
265 | if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)}) |
|
265 | if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)}) | |
266 | redirect_to(back_url) |
|
266 | redirect_to(back_url) | |
267 | return |
|
267 | return | |
268 | end |
|
268 | end | |
269 | rescue URI::InvalidURIError |
|
269 | rescue URI::InvalidURIError | |
270 | # redirect to default |
|
270 | # redirect to default | |
271 | end |
|
271 | end | |
272 | end |
|
272 | end | |
273 | redirect_to default |
|
273 | redirect_to default | |
274 | end |
|
274 | end | |
275 |
|
275 | |||
276 | def render_403(options={}) |
|
276 | def render_403(options={}) | |
277 | @project = nil |
|
277 | @project = nil | |
278 | render_error({:message => :notice_not_authorized, :status => 403}.merge(options)) |
|
278 | render_error({:message => :notice_not_authorized, :status => 403}.merge(options)) | |
279 | return false |
|
279 | return false | |
280 | end |
|
280 | end | |
281 |
|
281 | |||
282 | def render_404(options={}) |
|
282 | def render_404(options={}) | |
283 | render_error({:message => :notice_file_not_found, :status => 404}.merge(options)) |
|
283 | render_error({:message => :notice_file_not_found, :status => 404}.merge(options)) | |
284 | return false |
|
284 | return false | |
285 | end |
|
285 | end | |
286 |
|
286 | |||
287 | # Renders an error response |
|
287 | # Renders an error response | |
288 | def render_error(arg) |
|
288 | def render_error(arg) | |
289 | arg = {:message => arg} unless arg.is_a?(Hash) |
|
289 | arg = {:message => arg} unless arg.is_a?(Hash) | |
290 |
|
290 | |||
291 | @message = arg[:message] |
|
291 | @message = arg[:message] | |
292 | @message = l(@message) if @message.is_a?(Symbol) |
|
292 | @message = l(@message) if @message.is_a?(Symbol) | |
293 | @status = arg[:status] || 500 |
|
293 | @status = arg[:status] || 500 | |
294 |
|
294 | |||
295 | respond_to do |format| |
|
295 | respond_to do |format| | |
296 | format.html { |
|
296 | format.html { | |
297 | render :template => 'common/error', :layout => use_layout, :status => @status |
|
297 | render :template => 'common/error', :layout => use_layout, :status => @status | |
298 | } |
|
298 | } | |
299 | format.atom { head @status } |
|
299 | format.atom { head @status } | |
300 | format.xml { head @status } |
|
300 | format.xml { head @status } | |
301 | format.js { head @status } |
|
301 | format.js { head @status } | |
302 | format.json { head @status } |
|
302 | format.json { head @status } | |
303 | end |
|
303 | end | |
304 | end |
|
304 | end | |
305 |
|
305 | |||
306 | # Picks which layout to use based on the request |
|
306 | # Picks which layout to use based on the request | |
307 | # |
|
307 | # | |
308 | # @return [boolean, string] name of the layout to use or false for no layout |
|
308 | # @return [boolean, string] name of the layout to use or false for no layout | |
309 | def use_layout |
|
309 | def use_layout | |
310 | request.xhr? ? false : 'base' |
|
310 | request.xhr? ? false : 'base' | |
311 | end |
|
311 | end | |
312 |
|
312 | |||
313 | def invalid_authenticity_token |
|
313 | def invalid_authenticity_token | |
314 | if api_request? |
|
314 | if api_request? | |
315 | logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)." |
|
315 | logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)." | |
316 | end |
|
316 | end | |
317 | render_error "Invalid form authenticity token." |
|
317 | render_error "Invalid form authenticity token." | |
318 | end |
|
318 | end | |
319 |
|
319 | |||
320 | def render_feed(items, options={}) |
|
320 | def render_feed(items, options={}) | |
321 | @items = items || [] |
|
321 | @items = items || [] | |
322 | @items.sort! {|x,y| y.event_datetime <=> x.event_datetime } |
|
322 | @items.sort! {|x,y| y.event_datetime <=> x.event_datetime } | |
323 | @items = @items.slice(0, Setting.feeds_limit.to_i) |
|
323 | @items = @items.slice(0, Setting.feeds_limit.to_i) | |
324 | @title = options[:title] || Setting.app_title |
|
324 | @title = options[:title] || Setting.app_title | |
325 | render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml' |
|
325 | render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml' | |
326 | end |
|
326 | end | |
327 |
|
327 | |||
328 | def self.accept_key_auth(*actions) |
|
328 | def self.accept_key_auth(*actions) | |
329 | actions = actions.flatten.map(&:to_s) |
|
329 | actions = actions.flatten.map(&:to_s) | |
330 | write_inheritable_attribute('accept_key_auth_actions', actions) |
|
330 | write_inheritable_attribute('accept_key_auth_actions', actions) | |
331 | end |
|
331 | end | |
332 |
|
332 | |||
333 | def accept_key_auth_actions |
|
333 | def accept_key_auth_actions | |
334 | self.class.read_inheritable_attribute('accept_key_auth_actions') || [] |
|
334 | self.class.read_inheritable_attribute('accept_key_auth_actions') || [] | |
335 | end |
|
335 | end | |
336 |
|
336 | |||
337 | # Returns the number of objects that should be displayed |
|
337 | # Returns the number of objects that should be displayed | |
338 | # on the paginated list |
|
338 | # on the paginated list | |
339 | def per_page_option |
|
339 | def per_page_option | |
340 | per_page = nil |
|
340 | per_page = nil | |
341 | if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i) |
|
341 | if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i) | |
342 | per_page = params[:per_page].to_s.to_i |
|
342 | per_page = params[:per_page].to_s.to_i | |
343 | session[:per_page] = per_page |
|
343 | session[:per_page] = per_page | |
344 | elsif session[:per_page] |
|
344 | elsif session[:per_page] | |
345 | per_page = session[:per_page] |
|
345 | per_page = session[:per_page] | |
346 | else |
|
346 | else | |
347 | per_page = Setting.per_page_options_array.first || 25 |
|
347 | per_page = Setting.per_page_options_array.first || 25 | |
348 | end |
|
348 | end | |
349 | per_page |
|
349 | per_page | |
350 | end |
|
350 | end | |
351 |
|
351 | |||
352 | # qvalues http header parser |
|
352 | # qvalues http header parser | |
353 | # code taken from webrick |
|
353 | # code taken from webrick | |
354 | def parse_qvalues(value) |
|
354 | def parse_qvalues(value) | |
355 | tmp = [] |
|
355 | tmp = [] | |
356 | if value |
|
356 | if value | |
357 | parts = value.split(/,\s*/) |
|
357 | parts = value.split(/,\s*/) | |
358 | parts.each {|part| |
|
358 | parts.each {|part| | |
359 | if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part) |
|
359 | if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part) | |
360 | val = m[1] |
|
360 | val = m[1] | |
361 | q = (m[2] or 1).to_f |
|
361 | q = (m[2] or 1).to_f | |
362 | tmp.push([val, q]) |
|
362 | tmp.push([val, q]) | |
363 | end |
|
363 | end | |
364 | } |
|
364 | } | |
365 | tmp = tmp.sort_by{|val, q| -q} |
|
365 | tmp = tmp.sort_by{|val, q| -q} | |
366 | tmp.collect!{|val, q| val} |
|
366 | tmp.collect!{|val, q| val} | |
367 | end |
|
367 | end | |
368 | return tmp |
|
368 | return tmp | |
369 | rescue |
|
369 | rescue | |
370 | nil |
|
370 | nil | |
371 | end |
|
371 | end | |
372 |
|
372 | |||
373 | # Returns a string that can be used as filename value in Content-Disposition header |
|
373 | # Returns a string that can be used as filename value in Content-Disposition header | |
374 | def filename_for_content_disposition(name) |
|
374 | def filename_for_content_disposition(name) | |
375 | request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name |
|
375 | request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name | |
376 | end |
|
376 | end | |
377 |
|
377 | |||
378 | def api_request? |
|
378 | def api_request? | |
379 | %w(xml json).include? params[:format] |
|
379 | %w(xml json).include? params[:format] | |
380 | end |
|
380 | end | |
381 |
|
381 | |||
382 | # Renders a warning flash if obj has unsaved attachments |
|
382 | # Renders a warning flash if obj has unsaved attachments | |
383 | def render_attachment_warning_if_needed(obj) |
|
383 | def render_attachment_warning_if_needed(obj) | |
384 | flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present? |
|
384 | flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present? | |
385 | end |
|
385 | end | |
386 |
|
386 | |||
387 | # Sets the `flash` notice or error based the number of issues that did not save |
|
387 | # Sets the `flash` notice or error based the number of issues that did not save | |
388 | # |
|
388 | # | |
389 | # @param [Array, Issue] issues all of the saved and unsaved Issues |
|
389 | # @param [Array, Issue] issues all of the saved and unsaved Issues | |
390 | # @param [Array, Integer] unsaved_issue_ids the issue ids that were not saved |
|
390 | # @param [Array, Integer] unsaved_issue_ids the issue ids that were not saved | |
391 | def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids) |
|
391 | def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids) | |
392 | if unsaved_issue_ids.empty? |
|
392 | if unsaved_issue_ids.empty? | |
393 | flash[:notice] = l(:notice_successful_update) unless issues.empty? |
|
393 | flash[:notice] = l(:notice_successful_update) unless issues.empty? | |
394 | else |
|
394 | else | |
395 | flash[:error] = l(:notice_failed_to_save_issues, |
|
395 | flash[:error] = l(:notice_failed_to_save_issues, | |
396 | :count => unsaved_issue_ids.size, |
|
396 | :count => unsaved_issue_ids.size, | |
397 | :total => issues.size, |
|
397 | :total => issues.size, | |
398 | :ids => '#' + unsaved_issue_ids.join(', #')) |
|
398 | :ids => '#' + unsaved_issue_ids.join(', #')) | |
399 | end |
|
399 | end | |
400 | end |
|
400 | end | |
401 |
|
401 | |||
402 | # Rescues an invalid query statement. Just in case... |
|
402 | # Rescues an invalid query statement. Just in case... | |
403 | def query_statement_invalid(exception) |
|
403 | def query_statement_invalid(exception) | |
404 | logger.error "Query::StatementInvalid: #{exception.message}" if logger |
|
404 | logger.error "Query::StatementInvalid: #{exception.message}" if logger | |
405 | session.delete(:query) |
|
405 | session.delete(:query) | |
406 | sort_clear if respond_to?(:sort_clear) |
|
406 | sort_clear if respond_to?(:sort_clear) | |
407 | render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator." |
|
407 | render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator." | |
408 | end |
|
408 | end | |
409 |
|
409 | |||
410 | # Converts the errors on an ActiveRecord object into a common JSON format |
|
410 | # Converts the errors on an ActiveRecord object into a common JSON format | |
411 | def object_errors_to_json(object) |
|
411 | def object_errors_to_json(object) | |
412 | object.errors.collect do |attribute, error| |
|
412 | object.errors.collect do |attribute, error| | |
413 | { attribute => error } |
|
413 | { attribute => error } | |
414 | end.to_json |
|
414 | end.to_json | |
415 | end |
|
415 | end | |
416 |
|
416 | |||
417 | # Renders API response on validation failure |
|
417 | # Renders API response on validation failure | |
418 | def render_validation_errors(object) |
|
418 | def render_validation_errors(object) | |
419 | options = { :status => :unprocessable_entity, :layout => false } |
|
419 | options = { :status => :unprocessable_entity, :layout => false } | |
420 | options.merge!(case params[:format] |
|
420 | options.merge!(case params[:format] | |
421 | when 'xml'; { :xml => object.errors } |
|
421 | when 'xml'; { :xml => object.errors } | |
422 | when 'json'; { :json => {'errors' => object.errors} } # ActiveResource client compliance |
|
422 | when 'json'; { :json => {'errors' => object.errors} } # ActiveResource client compliance | |
423 | else |
|
423 | else | |
424 | raise "Unknown format #{params[:format]} in #render_validation_errors" |
|
424 | raise "Unknown format #{params[:format]} in #render_validation_errors" | |
425 | end |
|
425 | end | |
426 | ) |
|
426 | ) | |
427 | render options |
|
427 | render options | |
428 | end |
|
428 | end | |
|
429 | ||||
|
430 | # Overrides #default_template so that the api template | |||
|
431 | # is used automatically if it exists | |||
|
432 | def default_template(action_name = self.action_name) | |||
|
433 | if api_request? | |||
|
434 | begin | |||
|
435 | return self.view_paths.find_template(default_template_name(action_name), 'api') | |||
|
436 | rescue ::ActionView::MissingTemplate | |||
|
437 | # the api template was not found | |||
|
438 | # fallback to the default behaviour | |||
|
439 | end | |||
|
440 | end | |||
|
441 | super | |||
|
442 | end | |||
|
443 | ||||
|
444 | # Overrides #pick_layout so that #render with no arguments | |||
|
445 | # doesn't use the layout for api requests | |||
|
446 | def pick_layout(*args) | |||
|
447 | api_request? ? nil : super | |||
|
448 | end | |||
429 | end |
|
449 | end |
@@ -1,313 +1,313 | |||||
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 | class IssuesController < ApplicationController |
|
18 | class IssuesController < ApplicationController | |
19 | menu_item :new_issue, :only => [:new, :create] |
|
19 | menu_item :new_issue, :only => [:new, :create] | |
20 | default_search_scope :issues |
|
20 | default_search_scope :issues | |
21 |
|
21 | |||
22 | before_filter :find_issue, :only => [:show, :edit, :update] |
|
22 | before_filter :find_issue, :only => [:show, :edit, :update] | |
23 | before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :move, :perform_move, :destroy] |
|
23 | before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :move, :perform_move, :destroy] | |
24 | before_filter :check_project_uniqueness, :only => [:move, :perform_move] |
|
24 | before_filter :check_project_uniqueness, :only => [:move, :perform_move] | |
25 | before_filter :find_project, :only => [:new, :create] |
|
25 | before_filter :find_project, :only => [:new, :create] | |
26 | before_filter :authorize, :except => [:index] |
|
26 | before_filter :authorize, :except => [:index] | |
27 | before_filter :find_optional_project, :only => [:index] |
|
27 | before_filter :find_optional_project, :only => [:index] | |
28 | before_filter :check_for_default_issue_status, :only => [:new, :create] |
|
28 | before_filter :check_for_default_issue_status, :only => [:new, :create] | |
29 | before_filter :build_new_issue_from_params, :only => [:new, :create] |
|
29 | before_filter :build_new_issue_from_params, :only => [:new, :create] | |
30 | accept_key_auth :index, :show, :create, :update, :destroy |
|
30 | accept_key_auth :index, :show, :create, :update, :destroy | |
31 |
|
31 | |||
32 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid |
|
32 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid | |
33 |
|
33 | |||
34 | helper :journals |
|
34 | helper :journals | |
35 | helper :projects |
|
35 | helper :projects | |
36 | include ProjectsHelper |
|
36 | include ProjectsHelper | |
37 | helper :custom_fields |
|
37 | helper :custom_fields | |
38 | include CustomFieldsHelper |
|
38 | include CustomFieldsHelper | |
39 | helper :issue_relations |
|
39 | helper :issue_relations | |
40 | include IssueRelationsHelper |
|
40 | include IssueRelationsHelper | |
41 | helper :watchers |
|
41 | helper :watchers | |
42 | include WatchersHelper |
|
42 | include WatchersHelper | |
43 | helper :attachments |
|
43 | helper :attachments | |
44 | include AttachmentsHelper |
|
44 | include AttachmentsHelper | |
45 | helper :queries |
|
45 | helper :queries | |
46 | include QueriesHelper |
|
46 | include QueriesHelper | |
47 | helper :sort |
|
47 | helper :sort | |
48 | include SortHelper |
|
48 | include SortHelper | |
49 | include IssuesHelper |
|
49 | include IssuesHelper | |
50 | helper :timelog |
|
50 | helper :timelog | |
51 | helper :gantt |
|
51 | helper :gantt | |
52 | include Redmine::Export::PDF |
|
52 | include Redmine::Export::PDF | |
53 |
|
53 | |||
54 | verify :method => [:post, :delete], |
|
54 | verify :method => [:post, :delete], | |
55 | :only => :destroy, |
|
55 | :only => :destroy, | |
56 | :render => { :nothing => true, :status => :method_not_allowed } |
|
56 | :render => { :nothing => true, :status => :method_not_allowed } | |
57 |
|
57 | |||
58 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } |
|
58 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } | |
59 | verify :method => :post, :only => :bulk_update, :render => {:nothing => true, :status => :method_not_allowed } |
|
59 | verify :method => :post, :only => :bulk_update, :render => {:nothing => true, :status => :method_not_allowed } | |
60 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } |
|
60 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | |
61 |
|
61 | |||
62 | def index |
|
62 | def index | |
63 | retrieve_query |
|
63 | retrieve_query | |
64 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) |
|
64 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) | |
65 | sort_update(@query.sortable_columns) |
|
65 | sort_update(@query.sortable_columns) | |
66 |
|
66 | |||
67 | if @query.valid? |
|
67 | if @query.valid? | |
68 | limit = case params[:format] |
|
68 | limit = case params[:format] | |
69 | when 'csv', 'pdf' |
|
69 | when 'csv', 'pdf' | |
70 | Setting.issues_export_limit.to_i |
|
70 | Setting.issues_export_limit.to_i | |
71 | when 'atom' |
|
71 | when 'atom' | |
72 | Setting.feeds_limit.to_i |
|
72 | Setting.feeds_limit.to_i | |
73 | else |
|
73 | else | |
74 | per_page_option |
|
74 | per_page_option | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | @issue_count = @query.issue_count |
|
77 | @issue_count = @query.issue_count | |
78 | @issue_pages = Paginator.new self, @issue_count, limit, params['page'] |
|
78 | @issue_pages = Paginator.new self, @issue_count, limit, params['page'] | |
79 | @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], |
|
79 | @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], | |
80 | :order => sort_clause, |
|
80 | :order => sort_clause, | |
81 | :offset => @issue_pages.current.offset, |
|
81 | :offset => @issue_pages.current.offset, | |
82 | :limit => limit) |
|
82 | :limit => limit) | |
83 | @issue_count_by_group = @query.issue_count_by_group |
|
83 | @issue_count_by_group = @query.issue_count_by_group | |
84 |
|
84 | |||
85 | respond_to do |format| |
|
85 | respond_to do |format| | |
86 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } |
|
86 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } | |
87 | format.api { render :template => 'issues/index.apit' } |
|
87 | format.api | |
88 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } |
|
88 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } | |
89 | format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') } |
|
89 | format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') } | |
90 | format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } |
|
90 | format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } | |
91 | end |
|
91 | end | |
92 | else |
|
92 | else | |
93 | # Send html if the query is not valid |
|
93 | # Send html if the query is not valid | |
94 | render(:template => 'issues/index.rhtml', :layout => !request.xhr?) |
|
94 | render(:template => 'issues/index.rhtml', :layout => !request.xhr?) | |
95 | end |
|
95 | end | |
96 | rescue ActiveRecord::RecordNotFound |
|
96 | rescue ActiveRecord::RecordNotFound | |
97 | render_404 |
|
97 | render_404 | |
98 | end |
|
98 | end | |
99 |
|
99 | |||
100 | def show |
|
100 | def show | |
101 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") |
|
101 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") | |
102 | @journals.each_with_index {|j,i| j.indice = i+1} |
|
102 | @journals.each_with_index {|j,i| j.indice = i+1} | |
103 | @journals.reverse! if User.current.wants_comments_in_reverse_order? |
|
103 | @journals.reverse! if User.current.wants_comments_in_reverse_order? | |
104 | @changesets = @issue.changesets.visible.all |
|
104 | @changesets = @issue.changesets.visible.all | |
105 | @changesets.reverse! if User.current.wants_comments_in_reverse_order? |
|
105 | @changesets.reverse! if User.current.wants_comments_in_reverse_order? | |
106 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
106 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
107 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
107 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |
108 | @priorities = IssuePriority.all |
|
108 | @priorities = IssuePriority.all | |
109 | @time_entry = TimeEntry.new |
|
109 | @time_entry = TimeEntry.new | |
110 | respond_to do |format| |
|
110 | respond_to do |format| | |
111 | format.html { render :template => 'issues/show.rhtml' } |
|
111 | format.html { render :template => 'issues/show.rhtml' } | |
112 | format.api { render :template => 'issues/show.apit' } |
|
112 | format.api | |
113 | format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' } |
|
113 | format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' } | |
114 | format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } |
|
114 | format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } | |
115 | end |
|
115 | end | |
116 | end |
|
116 | end | |
117 |
|
117 | |||
118 | # Add a new issue |
|
118 | # Add a new issue | |
119 | # The new issue will be created from an existing one if copy_from parameter is given |
|
119 | # The new issue will be created from an existing one if copy_from parameter is given | |
120 | def new |
|
120 | def new | |
121 | respond_to do |format| |
|
121 | respond_to do |format| | |
122 | format.html { render :action => 'new', :layout => !request.xhr? } |
|
122 | format.html { render :action => 'new', :layout => !request.xhr? } | |
123 | format.js { render :partial => 'attributes' } |
|
123 | format.js { render :partial => 'attributes' } | |
124 | end |
|
124 | end | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | def create |
|
127 | def create | |
128 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) |
|
128 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) | |
129 | if @issue.save |
|
129 | if @issue.save | |
130 | attachments = Attachment.attach_files(@issue, params[:attachments]) |
|
130 | attachments = Attachment.attach_files(@issue, params[:attachments]) | |
131 | render_attachment_warning_if_needed(@issue) |
|
131 | render_attachment_warning_if_needed(@issue) | |
132 | flash[:notice] = l(:notice_successful_create) |
|
132 | flash[:notice] = l(:notice_successful_create) | |
133 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) |
|
133 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) | |
134 | respond_to do |format| |
|
134 | respond_to do |format| | |
135 | format.html { |
|
135 | format.html { | |
136 | redirect_to(params[:continue] ? { :action => 'new', :project_id => @project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } : |
|
136 | redirect_to(params[:continue] ? { :action => 'new', :project_id => @project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } : | |
137 | { :action => 'show', :id => @issue }) |
|
137 | { :action => 'show', :id => @issue }) | |
138 | } |
|
138 | } | |
139 |
format.api { render : |
|
139 | format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) } | |
140 | end |
|
140 | end | |
141 | return |
|
141 | return | |
142 | else |
|
142 | else | |
143 | respond_to do |format| |
|
143 | respond_to do |format| | |
144 | format.html { render :action => 'new' } |
|
144 | format.html { render :action => 'new' } | |
145 | format.api { render_validation_errors(@issue) } |
|
145 | format.api { render_validation_errors(@issue) } | |
146 | end |
|
146 | end | |
147 | end |
|
147 | end | |
148 | end |
|
148 | end | |
149 |
|
149 | |||
150 | def edit |
|
150 | def edit | |
151 | update_issue_from_params |
|
151 | update_issue_from_params | |
152 |
|
152 | |||
153 | @journal = @issue.current_journal |
|
153 | @journal = @issue.current_journal | |
154 |
|
154 | |||
155 | respond_to do |format| |
|
155 | respond_to do |format| | |
156 | format.html { } |
|
156 | format.html { } | |
157 | format.xml { } |
|
157 | format.xml { } | |
158 | end |
|
158 | end | |
159 | end |
|
159 | end | |
160 |
|
160 | |||
161 | def update |
|
161 | def update | |
162 | update_issue_from_params |
|
162 | update_issue_from_params | |
163 |
|
163 | |||
164 | if @issue.save_issue_with_child_records(params, @time_entry) |
|
164 | if @issue.save_issue_with_child_records(params, @time_entry) | |
165 | render_attachment_warning_if_needed(@issue) |
|
165 | render_attachment_warning_if_needed(@issue) | |
166 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? |
|
166 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? | |
167 |
|
167 | |||
168 | respond_to do |format| |
|
168 | respond_to do |format| | |
169 | format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } |
|
169 | format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } | |
170 | format.api { head :ok } |
|
170 | format.api { head :ok } | |
171 | end |
|
171 | end | |
172 | else |
|
172 | else | |
173 | render_attachment_warning_if_needed(@issue) |
|
173 | render_attachment_warning_if_needed(@issue) | |
174 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? |
|
174 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? | |
175 | @journal = @issue.current_journal |
|
175 | @journal = @issue.current_journal | |
176 |
|
176 | |||
177 | respond_to do |format| |
|
177 | respond_to do |format| | |
178 | format.html { render :action => 'edit' } |
|
178 | format.html { render :action => 'edit' } | |
179 | format.api { render_validation_errors(@issue) } |
|
179 | format.api { render_validation_errors(@issue) } | |
180 | end |
|
180 | end | |
181 | end |
|
181 | end | |
182 | end |
|
182 | end | |
183 |
|
183 | |||
184 | # Bulk edit a set of issues |
|
184 | # Bulk edit a set of issues | |
185 | def bulk_edit |
|
185 | def bulk_edit | |
186 | @issues.sort! |
|
186 | @issues.sort! | |
187 | @available_statuses = @projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w} |
|
187 | @available_statuses = @projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w} | |
188 | @custom_fields = @projects.map{|p|p.all_issue_custom_fields}.inject{|memo,c|memo & c} |
|
188 | @custom_fields = @projects.map{|p|p.all_issue_custom_fields}.inject{|memo,c|memo & c} | |
189 | @assignables = @projects.map(&:assignable_users).inject{|memo,a| memo & a} |
|
189 | @assignables = @projects.map(&:assignable_users).inject{|memo,a| memo & a} | |
190 | @trackers = @projects.map(&:trackers).inject{|memo,t| memo & t} |
|
190 | @trackers = @projects.map(&:trackers).inject{|memo,t| memo & t} | |
191 | end |
|
191 | end | |
192 |
|
192 | |||
193 | def bulk_update |
|
193 | def bulk_update | |
194 | @issues.sort! |
|
194 | @issues.sort! | |
195 | attributes = parse_params_for_bulk_issue_attributes(params) |
|
195 | attributes = parse_params_for_bulk_issue_attributes(params) | |
196 |
|
196 | |||
197 | unsaved_issue_ids = [] |
|
197 | unsaved_issue_ids = [] | |
198 | @issues.each do |issue| |
|
198 | @issues.each do |issue| | |
199 | issue.reload |
|
199 | issue.reload | |
200 | journal = issue.init_journal(User.current, params[:notes]) |
|
200 | journal = issue.init_journal(User.current, params[:notes]) | |
201 | issue.safe_attributes = attributes |
|
201 | issue.safe_attributes = attributes | |
202 | call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) |
|
202 | call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) | |
203 | unless issue.save |
|
203 | unless issue.save | |
204 | # Keep unsaved issue ids to display them in flash error |
|
204 | # Keep unsaved issue ids to display them in flash error | |
205 | unsaved_issue_ids << issue.id |
|
205 | unsaved_issue_ids << issue.id | |
206 | end |
|
206 | end | |
207 | end |
|
207 | end | |
208 | set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) |
|
208 | set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) | |
209 | redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project}) |
|
209 | redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project}) | |
210 | end |
|
210 | end | |
211 |
|
211 | |||
212 | def destroy |
|
212 | def destroy | |
213 | @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f |
|
213 | @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f | |
214 | if @hours > 0 |
|
214 | if @hours > 0 | |
215 | case params[:todo] |
|
215 | case params[:todo] | |
216 | when 'destroy' |
|
216 | when 'destroy' | |
217 | # nothing to do |
|
217 | # nothing to do | |
218 | when 'nullify' |
|
218 | when 'nullify' | |
219 | TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) |
|
219 | TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) | |
220 | when 'reassign' |
|
220 | when 'reassign' | |
221 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) |
|
221 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) | |
222 | if reassign_to.nil? |
|
222 | if reassign_to.nil? | |
223 | flash.now[:error] = l(:error_issue_not_found_in_project) |
|
223 | flash.now[:error] = l(:error_issue_not_found_in_project) | |
224 | return |
|
224 | return | |
225 | else |
|
225 | else | |
226 | TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) |
|
226 | TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) | |
227 | end |
|
227 | end | |
228 | else |
|
228 | else | |
229 | # display the destroy form if it's a user request |
|
229 | # display the destroy form if it's a user request | |
230 | return unless api_request? |
|
230 | return unless api_request? | |
231 | end |
|
231 | end | |
232 | end |
|
232 | end | |
233 | @issues.each(&:destroy) |
|
233 | @issues.each(&:destroy) | |
234 | respond_to do |format| |
|
234 | respond_to do |format| | |
235 | format.html { redirect_back_or_default(:action => 'index', :project_id => @project) } |
|
235 | format.html { redirect_back_or_default(:action => 'index', :project_id => @project) } | |
236 | format.api { head :ok } |
|
236 | format.api { head :ok } | |
237 | end |
|
237 | end | |
238 | end |
|
238 | end | |
239 |
|
239 | |||
240 | private |
|
240 | private | |
241 | def find_issue |
|
241 | def find_issue | |
242 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) |
|
242 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) | |
243 | @project = @issue.project |
|
243 | @project = @issue.project | |
244 | rescue ActiveRecord::RecordNotFound |
|
244 | rescue ActiveRecord::RecordNotFound | |
245 | render_404 |
|
245 | render_404 | |
246 | end |
|
246 | end | |
247 |
|
247 | |||
248 | def find_project |
|
248 | def find_project | |
249 | project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] |
|
249 | project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] | |
250 | @project = Project.find(project_id) |
|
250 | @project = Project.find(project_id) | |
251 | rescue ActiveRecord::RecordNotFound |
|
251 | rescue ActiveRecord::RecordNotFound | |
252 | render_404 |
|
252 | render_404 | |
253 | end |
|
253 | end | |
254 |
|
254 | |||
255 | # Used by #edit and #update to set some common instance variables |
|
255 | # Used by #edit and #update to set some common instance variables | |
256 | # from the params |
|
256 | # from the params | |
257 | # TODO: Refactor, not everything in here is needed by #edit |
|
257 | # TODO: Refactor, not everything in here is needed by #edit | |
258 | def update_issue_from_params |
|
258 | def update_issue_from_params | |
259 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
259 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
260 | @priorities = IssuePriority.all |
|
260 | @priorities = IssuePriority.all | |
261 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
261 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |
262 | @time_entry = TimeEntry.new |
|
262 | @time_entry = TimeEntry.new | |
263 | @time_entry.attributes = params[:time_entry] |
|
263 | @time_entry.attributes = params[:time_entry] | |
264 |
|
264 | |||
265 | @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil) |
|
265 | @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil) | |
266 | @issue.init_journal(User.current, @notes) |
|
266 | @issue.init_journal(User.current, @notes) | |
267 | @issue.safe_attributes = params[:issue] |
|
267 | @issue.safe_attributes = params[:issue] | |
268 | end |
|
268 | end | |
269 |
|
269 | |||
270 | # TODO: Refactor, lots of extra code in here |
|
270 | # TODO: Refactor, lots of extra code in here | |
271 | # TODO: Changing tracker on an existing issue should not trigger this |
|
271 | # TODO: Changing tracker on an existing issue should not trigger this | |
272 | def build_new_issue_from_params |
|
272 | def build_new_issue_from_params | |
273 | if params[:id].blank? |
|
273 | if params[:id].blank? | |
274 | @issue = Issue.new |
|
274 | @issue = Issue.new | |
275 | @issue.copy_from(params[:copy_from]) if params[:copy_from] |
|
275 | @issue.copy_from(params[:copy_from]) if params[:copy_from] | |
276 | @issue.project = @project |
|
276 | @issue.project = @project | |
277 | else |
|
277 | else | |
278 | @issue = @project.issues.visible.find(params[:id]) |
|
278 | @issue = @project.issues.visible.find(params[:id]) | |
279 | end |
|
279 | end | |
280 |
|
280 | |||
281 | @issue.project = @project |
|
281 | @issue.project = @project | |
282 | # Tracker must be set before custom field values |
|
282 | # Tracker must be set before custom field values | |
283 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) |
|
283 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) | |
284 | if @issue.tracker.nil? |
|
284 | if @issue.tracker.nil? | |
285 | render_error l(:error_no_tracker_in_project) |
|
285 | render_error l(:error_no_tracker_in_project) | |
286 | return false |
|
286 | return false | |
287 | end |
|
287 | end | |
288 | @issue.start_date ||= Date.today |
|
288 | @issue.start_date ||= Date.today | |
289 | if params[:issue].is_a?(Hash) |
|
289 | if params[:issue].is_a?(Hash) | |
290 | @issue.safe_attributes = params[:issue] |
|
290 | @issue.safe_attributes = params[:issue] | |
291 | if User.current.allowed_to?(:add_issue_watchers, @project) && @issue.new_record? |
|
291 | if User.current.allowed_to?(:add_issue_watchers, @project) && @issue.new_record? | |
292 | @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] |
|
292 | @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] | |
293 | end |
|
293 | end | |
294 | end |
|
294 | end | |
295 | @issue.author = User.current |
|
295 | @issue.author = User.current | |
296 | @priorities = IssuePriority.all |
|
296 | @priorities = IssuePriority.all | |
297 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) |
|
297 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) | |
298 | end |
|
298 | end | |
299 |
|
299 | |||
300 | def check_for_default_issue_status |
|
300 | def check_for_default_issue_status | |
301 | if IssueStatus.default.nil? |
|
301 | if IssueStatus.default.nil? | |
302 | render_error l(:error_no_default_issue_status) |
|
302 | render_error l(:error_no_default_issue_status) | |
303 | return false |
|
303 | return false | |
304 | end |
|
304 | end | |
305 | end |
|
305 | end | |
306 |
|
306 | |||
307 | def parse_params_for_bulk_issue_attributes(params) |
|
307 | def parse_params_for_bulk_issue_attributes(params) | |
308 | attributes = (params[:issue] || {}).reject {|k,v| v.blank?} |
|
308 | attributes = (params[:issue] || {}).reject {|k,v| v.blank?} | |
309 | attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} |
|
309 | attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} | |
310 | attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values] |
|
310 | attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values] | |
311 | attributes |
|
311 | attributes | |
312 | end |
|
312 | end | |
313 | end |
|
313 | end |
@@ -1,267 +1,266 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2009 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 ProjectsController < ApplicationController |
|
18 | class ProjectsController < ApplicationController | |
19 | menu_item :overview |
|
19 | menu_item :overview | |
20 | menu_item :roadmap, :only => :roadmap |
|
20 | menu_item :roadmap, :only => :roadmap | |
21 | menu_item :settings, :only => :settings |
|
21 | menu_item :settings, :only => :settings | |
22 |
|
22 | |||
23 | before_filter :find_project, :except => [ :index, :list, :new, :create, :copy ] |
|
23 | before_filter :find_project, :except => [ :index, :list, :new, :create, :copy ] | |
24 | before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy] |
|
24 | before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy] | |
25 | before_filter :authorize_global, :only => [:new, :create] |
|
25 | before_filter :authorize_global, :only => [:new, :create] | |
26 | before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ] |
|
26 | before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ] | |
27 | accept_key_auth :index, :show, :create, :update, :destroy |
|
27 | accept_key_auth :index, :show, :create, :update, :destroy | |
28 |
|
28 | |||
29 | after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller| |
|
29 | after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller| | |
30 | if controller.request.post? |
|
30 | if controller.request.post? | |
31 | controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt' |
|
31 | controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt' | |
32 | end |
|
32 | end | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | # TODO: convert to PUT only |
|
35 | # TODO: convert to PUT only | |
36 | verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed } |
|
36 | verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | |
37 |
|
37 | |||
38 | helper :sort |
|
38 | helper :sort | |
39 | include SortHelper |
|
39 | include SortHelper | |
40 | helper :custom_fields |
|
40 | helper :custom_fields | |
41 | include CustomFieldsHelper |
|
41 | include CustomFieldsHelper | |
42 | helper :issues |
|
42 | helper :issues | |
43 | helper :queries |
|
43 | helper :queries | |
44 | include QueriesHelper |
|
44 | include QueriesHelper | |
45 | helper :repositories |
|
45 | helper :repositories | |
46 | include RepositoriesHelper |
|
46 | include RepositoriesHelper | |
47 | include ProjectsHelper |
|
47 | include ProjectsHelper | |
48 |
|
48 | |||
49 | # Lists visible projects |
|
49 | # Lists visible projects | |
50 | def index |
|
50 | def index | |
51 | respond_to do |format| |
|
51 | respond_to do |format| | |
52 | format.html { |
|
52 | format.html { | |
53 | @projects = Project.visible.find(:all, :order => 'lft') |
|
53 | @projects = Project.visible.find(:all, :order => 'lft') | |
54 | } |
|
54 | } | |
55 | format.api { |
|
55 | format.api { | |
56 | @projects = Project.visible.find(:all, :order => 'lft') |
|
56 | @projects = Project.visible.find(:all, :order => 'lft') | |
57 | render :template => 'projects/index.apit' |
|
|||
58 | } |
|
57 | } | |
59 | format.atom { |
|
58 | format.atom { | |
60 | projects = Project.visible.find(:all, :order => 'created_on DESC', |
|
59 | projects = Project.visible.find(:all, :order => 'created_on DESC', | |
61 | :limit => Setting.feeds_limit.to_i) |
|
60 | :limit => Setting.feeds_limit.to_i) | |
62 | render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") |
|
61 | render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") | |
63 | } |
|
62 | } | |
64 | end |
|
63 | end | |
65 | end |
|
64 | end | |
66 |
|
65 | |||
67 | def new |
|
66 | def new | |
68 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
67 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | |
69 | @trackers = Tracker.all |
|
68 | @trackers = Tracker.all | |
70 | @project = Project.new(params[:project]) |
|
69 | @project = Project.new(params[:project]) | |
71 | end |
|
70 | end | |
72 |
|
71 | |||
73 | def create |
|
72 | def create | |
74 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
73 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | |
75 | @trackers = Tracker.all |
|
74 | @trackers = Tracker.all | |
76 | @project = Project.new(params[:project]) |
|
75 | @project = Project.new(params[:project]) | |
77 |
|
76 | |||
78 | @project.enabled_module_names = params[:enabled_modules] if params[:enabled_modules] |
|
77 | @project.enabled_module_names = params[:enabled_modules] if params[:enabled_modules] | |
79 | if validate_parent_id && @project.save |
|
78 | if validate_parent_id && @project.save | |
80 | @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
|
79 | @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | |
81 | # Add current user as a project member if he is not admin |
|
80 | # Add current user as a project member if he is not admin | |
82 | unless User.current.admin? |
|
81 | unless User.current.admin? | |
83 | r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first |
|
82 | r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first | |
84 | m = Member.new(:user => User.current, :roles => [r]) |
|
83 | m = Member.new(:user => User.current, :roles => [r]) | |
85 | @project.members << m |
|
84 | @project.members << m | |
86 | end |
|
85 | end | |
87 | respond_to do |format| |
|
86 | respond_to do |format| | |
88 | format.html { |
|
87 | format.html { | |
89 | flash[:notice] = l(:notice_successful_create) |
|
88 | flash[:notice] = l(:notice_successful_create) | |
90 | redirect_to :controller => 'projects', :action => 'settings', :id => @project |
|
89 | redirect_to :controller => 'projects', :action => 'settings', :id => @project | |
91 | } |
|
90 | } | |
92 |
format.api { render : |
|
91 | format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } | |
93 | end |
|
92 | end | |
94 | else |
|
93 | else | |
95 | respond_to do |format| |
|
94 | respond_to do |format| | |
96 | format.html { render :action => 'new' } |
|
95 | format.html { render :action => 'new' } | |
97 | format.api { render_validation_errors(@project) } |
|
96 | format.api { render_validation_errors(@project) } | |
98 | end |
|
97 | end | |
99 | end |
|
98 | end | |
100 |
|
99 | |||
101 | end |
|
100 | end | |
102 |
|
101 | |||
103 | def copy |
|
102 | def copy | |
104 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
103 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | |
105 | @trackers = Tracker.all |
|
104 | @trackers = Tracker.all | |
106 | @root_projects = Project.find(:all, |
|
105 | @root_projects = Project.find(:all, | |
107 | :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", |
|
106 | :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", | |
108 | :order => 'name') |
|
107 | :order => 'name') | |
109 | @source_project = Project.find(params[:id]) |
|
108 | @source_project = Project.find(params[:id]) | |
110 | if request.get? |
|
109 | if request.get? | |
111 | @project = Project.copy_from(@source_project) |
|
110 | @project = Project.copy_from(@source_project) | |
112 | if @project |
|
111 | if @project | |
113 | @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? |
|
112 | @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? | |
114 | else |
|
113 | else | |
115 | redirect_to :controller => 'admin', :action => 'projects' |
|
114 | redirect_to :controller => 'admin', :action => 'projects' | |
116 | end |
|
115 | end | |
117 | else |
|
116 | else | |
118 | Mailer.with_deliveries(params[:notifications] == '1') do |
|
117 | Mailer.with_deliveries(params[:notifications] == '1') do | |
119 | @project = Project.new(params[:project]) |
|
118 | @project = Project.new(params[:project]) | |
120 | @project.enabled_module_names = params[:enabled_modules] |
|
119 | @project.enabled_module_names = params[:enabled_modules] | |
121 | if validate_parent_id && @project.copy(@source_project, :only => params[:only]) |
|
120 | if validate_parent_id && @project.copy(@source_project, :only => params[:only]) | |
122 | @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
|
121 | @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | |
123 | flash[:notice] = l(:notice_successful_create) |
|
122 | flash[:notice] = l(:notice_successful_create) | |
124 | redirect_to :controller => 'projects', :action => 'settings' |
|
123 | redirect_to :controller => 'projects', :action => 'settings' | |
125 | elsif !@project.new_record? |
|
124 | elsif !@project.new_record? | |
126 | # Project was created |
|
125 | # Project was created | |
127 | # But some objects were not copied due to validation failures |
|
126 | # But some objects were not copied due to validation failures | |
128 | # (eg. issues from disabled trackers) |
|
127 | # (eg. issues from disabled trackers) | |
129 | # TODO: inform about that |
|
128 | # TODO: inform about that | |
130 | redirect_to :controller => 'projects', :action => 'settings' |
|
129 | redirect_to :controller => 'projects', :action => 'settings' | |
131 | end |
|
130 | end | |
132 | end |
|
131 | end | |
133 | end |
|
132 | end | |
134 | rescue ActiveRecord::RecordNotFound |
|
133 | rescue ActiveRecord::RecordNotFound | |
135 | redirect_to :controller => 'admin', :action => 'projects' |
|
134 | redirect_to :controller => 'admin', :action => 'projects' | |
136 | end |
|
135 | end | |
137 |
|
136 | |||
138 | # Show @project |
|
137 | # Show @project | |
139 | def show |
|
138 | def show | |
140 | if params[:jump] |
|
139 | if params[:jump] | |
141 | # try to redirect to the requested menu item |
|
140 | # try to redirect to the requested menu item | |
142 | redirect_to_project_menu_item(@project, params[:jump]) && return |
|
141 | redirect_to_project_menu_item(@project, params[:jump]) && return | |
143 | end |
|
142 | end | |
144 |
|
143 | |||
145 | @users_by_role = @project.users_by_role |
|
144 | @users_by_role = @project.users_by_role | |
146 | @subprojects = @project.children.visible |
|
145 | @subprojects = @project.children.visible | |
147 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
|
146 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") | |
148 | @trackers = @project.rolled_up_trackers |
|
147 | @trackers = @project.rolled_up_trackers | |
149 |
|
148 | |||
150 | cond = @project.project_condition(Setting.display_subprojects_issues?) |
|
149 | cond = @project.project_condition(Setting.display_subprojects_issues?) | |
151 |
|
150 | |||
152 | @open_issues_by_tracker = Issue.visible.count(:group => :tracker, |
|
151 | @open_issues_by_tracker = Issue.visible.count(:group => :tracker, | |
153 | :include => [:project, :status, :tracker], |
|
152 | :include => [:project, :status, :tracker], | |
154 | :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false]) |
|
153 | :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false]) | |
155 | @total_issues_by_tracker = Issue.visible.count(:group => :tracker, |
|
154 | @total_issues_by_tracker = Issue.visible.count(:group => :tracker, | |
156 | :include => [:project, :status, :tracker], |
|
155 | :include => [:project, :status, :tracker], | |
157 | :conditions => cond) |
|
156 | :conditions => cond) | |
158 |
|
157 | |||
159 | TimeEntry.visible_by(User.current) do |
|
158 | TimeEntry.visible_by(User.current) do | |
160 | @total_hours = TimeEntry.sum(:hours, |
|
159 | @total_hours = TimeEntry.sum(:hours, | |
161 | :include => :project, |
|
160 | :include => :project, | |
162 | :conditions => cond).to_f |
|
161 | :conditions => cond).to_f | |
163 | end |
|
162 | end | |
164 | @key = User.current.rss_key |
|
163 | @key = User.current.rss_key | |
165 |
|
164 | |||
166 | respond_to do |format| |
|
165 | respond_to do |format| | |
167 | format.html |
|
166 | format.html | |
168 | format.api { render :template => 'projects/show.apit'} |
|
167 | format.api | |
169 | end |
|
168 | end | |
170 | end |
|
169 | end | |
171 |
|
170 | |||
172 | def settings |
|
171 | def settings | |
173 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
172 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | |
174 | @issue_category ||= IssueCategory.new |
|
173 | @issue_category ||= IssueCategory.new | |
175 | @member ||= @project.members.new |
|
174 | @member ||= @project.members.new | |
176 | @trackers = Tracker.all |
|
175 | @trackers = Tracker.all | |
177 | @repository ||= @project.repository |
|
176 | @repository ||= @project.repository | |
178 | @wiki ||= @project.wiki |
|
177 | @wiki ||= @project.wiki | |
179 | end |
|
178 | end | |
180 |
|
179 | |||
181 | def edit |
|
180 | def edit | |
182 | end |
|
181 | end | |
183 |
|
182 | |||
184 | def update |
|
183 | def update | |
185 | @project.attributes = params[:project] |
|
184 | @project.attributes = params[:project] | |
186 | if validate_parent_id && @project.save |
|
185 | if validate_parent_id && @project.save | |
187 | @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
|
186 | @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | |
188 | respond_to do |format| |
|
187 | respond_to do |format| | |
189 | format.html { |
|
188 | format.html { | |
190 | flash[:notice] = l(:notice_successful_update) |
|
189 | flash[:notice] = l(:notice_successful_update) | |
191 | redirect_to :action => 'settings', :id => @project |
|
190 | redirect_to :action => 'settings', :id => @project | |
192 | } |
|
191 | } | |
193 | format.api { head :ok } |
|
192 | format.api { head :ok } | |
194 | end |
|
193 | end | |
195 | else |
|
194 | else | |
196 | respond_to do |format| |
|
195 | respond_to do |format| | |
197 | format.html { |
|
196 | format.html { | |
198 | settings |
|
197 | settings | |
199 | render :action => 'settings' |
|
198 | render :action => 'settings' | |
200 | } |
|
199 | } | |
201 | format.api { render_validation_errors(@project) } |
|
200 | format.api { render_validation_errors(@project) } | |
202 | end |
|
201 | end | |
203 | end |
|
202 | end | |
204 | end |
|
203 | end | |
205 |
|
204 | |||
206 | def modules |
|
205 | def modules | |
207 | @project.enabled_module_names = params[:enabled_modules] |
|
206 | @project.enabled_module_names = params[:enabled_modules] | |
208 | flash[:notice] = l(:notice_successful_update) |
|
207 | flash[:notice] = l(:notice_successful_update) | |
209 | redirect_to :action => 'settings', :id => @project, :tab => 'modules' |
|
208 | redirect_to :action => 'settings', :id => @project, :tab => 'modules' | |
210 | end |
|
209 | end | |
211 |
|
210 | |||
212 | def archive |
|
211 | def archive | |
213 | if request.post? |
|
212 | if request.post? | |
214 | unless @project.archive |
|
213 | unless @project.archive | |
215 | flash[:error] = l(:error_can_not_archive_project) |
|
214 | flash[:error] = l(:error_can_not_archive_project) | |
216 | end |
|
215 | end | |
217 | end |
|
216 | end | |
218 | redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) |
|
217 | redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) | |
219 | end |
|
218 | end | |
220 |
|
219 | |||
221 | def unarchive |
|
220 | def unarchive | |
222 | @project.unarchive if request.post? && !@project.active? |
|
221 | @project.unarchive if request.post? && !@project.active? | |
223 | redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) |
|
222 | redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) | |
224 | end |
|
223 | end | |
225 |
|
224 | |||
226 | # Delete @project |
|
225 | # Delete @project | |
227 | def destroy |
|
226 | def destroy | |
228 | @project_to_destroy = @project |
|
227 | @project_to_destroy = @project | |
229 | if request.get? |
|
228 | if request.get? | |
230 | # display confirmation view |
|
229 | # display confirmation view | |
231 | else |
|
230 | else | |
232 | if api_request? || params[:confirm] |
|
231 | if api_request? || params[:confirm] | |
233 | @project_to_destroy.destroy |
|
232 | @project_to_destroy.destroy | |
234 | respond_to do |format| |
|
233 | respond_to do |format| | |
235 | format.html { redirect_to :controller => 'admin', :action => 'projects' } |
|
234 | format.html { redirect_to :controller => 'admin', :action => 'projects' } | |
236 | format.api { head :ok } |
|
235 | format.api { head :ok } | |
237 | end |
|
236 | end | |
238 | end |
|
237 | end | |
239 | end |
|
238 | end | |
240 | # hide project in layout |
|
239 | # hide project in layout | |
241 | @project = nil |
|
240 | @project = nil | |
242 | end |
|
241 | end | |
243 |
|
242 | |||
244 | private |
|
243 | private | |
245 | def find_optional_project |
|
244 | def find_optional_project | |
246 | return true unless params[:id] |
|
245 | return true unless params[:id] | |
247 | @project = Project.find(params[:id]) |
|
246 | @project = Project.find(params[:id]) | |
248 | authorize |
|
247 | authorize | |
249 | rescue ActiveRecord::RecordNotFound |
|
248 | rescue ActiveRecord::RecordNotFound | |
250 | render_404 |
|
249 | render_404 | |
251 | end |
|
250 | end | |
252 |
|
251 | |||
253 | # Validates parent_id param according to user's permissions |
|
252 | # Validates parent_id param according to user's permissions | |
254 | # TODO: move it to Project model in a validation that depends on User.current |
|
253 | # TODO: move it to Project model in a validation that depends on User.current | |
255 | def validate_parent_id |
|
254 | def validate_parent_id | |
256 | return true if User.current.admin? |
|
255 | return true if User.current.admin? | |
257 | parent_id = params[:project] && params[:project][:parent_id] |
|
256 | parent_id = params[:project] && params[:project][:parent_id] | |
258 | if parent_id || @project.new_record? |
|
257 | if parent_id || @project.new_record? | |
259 | parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i) |
|
258 | parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i) | |
260 | unless @project.allowed_parents.include?(parent) |
|
259 | unless @project.allowed_parents.include?(parent) | |
261 | @project.errors.add :parent_id, :invalid |
|
260 | @project.errors.add :parent_id, :invalid | |
262 | return false |
|
261 | return false | |
263 | end |
|
262 | end | |
264 | end |
|
263 | end | |
265 | true |
|
264 | true | |
266 | end |
|
265 | end | |
267 | end |
|
266 | end |
@@ -1,274 +1,272 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2010 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2010 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 TimelogController < ApplicationController |
|
18 | class TimelogController < ApplicationController | |
19 | menu_item :issues |
|
19 | menu_item :issues | |
20 | before_filter :find_project, :only => [:new, :create] |
|
20 | before_filter :find_project, :only => [:new, :create] | |
21 | before_filter :find_time_entry, :only => [:show, :edit, :update, :destroy] |
|
21 | before_filter :find_time_entry, :only => [:show, :edit, :update, :destroy] | |
22 | before_filter :authorize, :except => [:index] |
|
22 | before_filter :authorize, :except => [:index] | |
23 | before_filter :find_optional_project, :only => [:index] |
|
23 | before_filter :find_optional_project, :only => [:index] | |
24 | accept_key_auth :index, :show, :create, :update, :destroy |
|
24 | accept_key_auth :index, :show, :create, :update, :destroy | |
25 |
|
25 | |||
26 | helper :sort |
|
26 | helper :sort | |
27 | include SortHelper |
|
27 | include SortHelper | |
28 | helper :issues |
|
28 | helper :issues | |
29 | include TimelogHelper |
|
29 | include TimelogHelper | |
30 | helper :custom_fields |
|
30 | helper :custom_fields | |
31 | include CustomFieldsHelper |
|
31 | include CustomFieldsHelper | |
32 |
|
32 | |||
33 | def index |
|
33 | def index | |
34 | sort_init 'spent_on', 'desc' |
|
34 | sort_init 'spent_on', 'desc' | |
35 | sort_update 'spent_on' => 'spent_on', |
|
35 | sort_update 'spent_on' => 'spent_on', | |
36 | 'user' => 'user_id', |
|
36 | 'user' => 'user_id', | |
37 | 'activity' => 'activity_id', |
|
37 | 'activity' => 'activity_id', | |
38 | 'project' => "#{Project.table_name}.name", |
|
38 | 'project' => "#{Project.table_name}.name", | |
39 | 'issue' => 'issue_id', |
|
39 | 'issue' => 'issue_id', | |
40 | 'hours' => 'hours' |
|
40 | 'hours' => 'hours' | |
41 |
|
41 | |||
42 | cond = ARCondition.new |
|
42 | cond = ARCondition.new | |
43 | if @project.nil? |
|
43 | if @project.nil? | |
44 | cond << Project.allowed_to_condition(User.current, :view_time_entries) |
|
44 | cond << Project.allowed_to_condition(User.current, :view_time_entries) | |
45 | elsif @issue.nil? |
|
45 | elsif @issue.nil? | |
46 | cond << @project.project_condition(Setting.display_subprojects_issues?) |
|
46 | cond << @project.project_condition(Setting.display_subprojects_issues?) | |
47 | else |
|
47 | else | |
48 | cond << "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}" |
|
48 | cond << "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}" | |
49 | end |
|
49 | end | |
50 |
|
50 | |||
51 | retrieve_date_range |
|
51 | retrieve_date_range | |
52 | cond << ['spent_on BETWEEN ? AND ?', @from, @to] |
|
52 | cond << ['spent_on BETWEEN ? AND ?', @from, @to] | |
53 |
|
53 | |||
54 | TimeEntry.visible_by(User.current) do |
|
54 | TimeEntry.visible_by(User.current) do | |
55 | respond_to do |format| |
|
55 | respond_to do |format| | |
56 | format.html { |
|
56 | format.html { | |
57 | # Paginate results |
|
57 | # Paginate results | |
58 | @entry_count = TimeEntry.count(:include => [:project, :issue], :conditions => cond.conditions) |
|
58 | @entry_count = TimeEntry.count(:include => [:project, :issue], :conditions => cond.conditions) | |
59 | @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page'] |
|
59 | @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page'] | |
60 | @entries = TimeEntry.find(:all, |
|
60 | @entries = TimeEntry.find(:all, | |
61 | :include => [:project, :activity, :user, {:issue => :tracker}], |
|
61 | :include => [:project, :activity, :user, {:issue => :tracker}], | |
62 | :conditions => cond.conditions, |
|
62 | :conditions => cond.conditions, | |
63 | :order => sort_clause, |
|
63 | :order => sort_clause, | |
64 | :limit => @entry_pages.items_per_page, |
|
64 | :limit => @entry_pages.items_per_page, | |
65 | :offset => @entry_pages.current.offset) |
|
65 | :offset => @entry_pages.current.offset) | |
66 | @total_hours = TimeEntry.sum(:hours, :include => [:project, :issue], :conditions => cond.conditions).to_f |
|
66 | @total_hours = TimeEntry.sum(:hours, :include => [:project, :issue], :conditions => cond.conditions).to_f | |
67 |
|
67 | |||
68 | render :layout => !request.xhr? |
|
68 | render :layout => !request.xhr? | |
69 | } |
|
69 | } | |
70 | format.api { |
|
70 | format.api { | |
71 | @entry_count = TimeEntry.count(:include => [:project, :issue], :conditions => cond.conditions) |
|
71 | @entry_count = TimeEntry.count(:include => [:project, :issue], :conditions => cond.conditions) | |
72 | @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page'] |
|
72 | @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page'] | |
73 | @entries = TimeEntry.find(:all, |
|
73 | @entries = TimeEntry.find(:all, | |
74 | :include => [:project, :activity, :user, {:issue => :tracker}], |
|
74 | :include => [:project, :activity, :user, {:issue => :tracker}], | |
75 | :conditions => cond.conditions, |
|
75 | :conditions => cond.conditions, | |
76 | :order => sort_clause, |
|
76 | :order => sort_clause, | |
77 | :limit => @entry_pages.items_per_page, |
|
77 | :limit => @entry_pages.items_per_page, | |
78 | :offset => @entry_pages.current.offset) |
|
78 | :offset => @entry_pages.current.offset) | |
79 |
|
||||
80 | render :template => 'timelog/index.apit' |
|
|||
81 | } |
|
79 | } | |
82 | format.atom { |
|
80 | format.atom { | |
83 | entries = TimeEntry.find(:all, |
|
81 | entries = TimeEntry.find(:all, | |
84 | :include => [:project, :activity, :user, {:issue => :tracker}], |
|
82 | :include => [:project, :activity, :user, {:issue => :tracker}], | |
85 | :conditions => cond.conditions, |
|
83 | :conditions => cond.conditions, | |
86 | :order => "#{TimeEntry.table_name}.created_on DESC", |
|
84 | :order => "#{TimeEntry.table_name}.created_on DESC", | |
87 | :limit => Setting.feeds_limit.to_i) |
|
85 | :limit => Setting.feeds_limit.to_i) | |
88 | render_feed(entries, :title => l(:label_spent_time)) |
|
86 | render_feed(entries, :title => l(:label_spent_time)) | |
89 | } |
|
87 | } | |
90 | format.csv { |
|
88 | format.csv { | |
91 | # Export all entries |
|
89 | # Export all entries | |
92 | @entries = TimeEntry.find(:all, |
|
90 | @entries = TimeEntry.find(:all, | |
93 | :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], |
|
91 | :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], | |
94 | :conditions => cond.conditions, |
|
92 | :conditions => cond.conditions, | |
95 | :order => sort_clause) |
|
93 | :order => sort_clause) | |
96 | send_data(entries_to_csv(@entries), :type => 'text/csv; header=present', :filename => 'timelog.csv') |
|
94 | send_data(entries_to_csv(@entries), :type => 'text/csv; header=present', :filename => 'timelog.csv') | |
97 | } |
|
95 | } | |
98 | end |
|
96 | end | |
99 | end |
|
97 | end | |
100 | end |
|
98 | end | |
101 |
|
99 | |||
102 | def show |
|
100 | def show | |
103 | respond_to do |format| |
|
101 | respond_to do |format| | |
104 | # TODO: Implement html response |
|
102 | # TODO: Implement html response | |
105 | format.html { render :nothing => true, :status => 406 } |
|
103 | format.html { render :nothing => true, :status => 406 } | |
106 | format.api { render :template => 'timelog/show.apit' } |
|
104 | format.api | |
107 | end |
|
105 | end | |
108 | end |
|
106 | end | |
109 |
|
107 | |||
110 | def new |
|
108 | def new | |
111 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) |
|
109 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) | |
112 | @time_entry.attributes = params[:time_entry] |
|
110 | @time_entry.attributes = params[:time_entry] | |
113 |
|
111 | |||
114 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) |
|
112 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) | |
115 | render :action => 'edit' |
|
113 | render :action => 'edit' | |
116 | end |
|
114 | end | |
117 |
|
115 | |||
118 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } |
|
116 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } | |
119 | def create |
|
117 | def create | |
120 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) |
|
118 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) | |
121 | @time_entry.attributes = params[:time_entry] |
|
119 | @time_entry.attributes = params[:time_entry] | |
122 |
|
120 | |||
123 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) |
|
121 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) | |
124 |
|
122 | |||
125 | if @time_entry.save |
|
123 | if @time_entry.save | |
126 | respond_to do |format| |
|
124 | respond_to do |format| | |
127 | format.html { |
|
125 | format.html { | |
128 | flash[:notice] = l(:notice_successful_update) |
|
126 | flash[:notice] = l(:notice_successful_update) | |
129 | redirect_back_or_default :action => 'index', :project_id => @time_entry.project |
|
127 | redirect_back_or_default :action => 'index', :project_id => @time_entry.project | |
130 | } |
|
128 | } | |
131 |
format.api { render : |
|
129 | format.api { render :action => 'show', :status => :created, :location => time_entry_url(@time_entry) } | |
132 | end |
|
130 | end | |
133 | else |
|
131 | else | |
134 | respond_to do |format| |
|
132 | respond_to do |format| | |
135 | format.html { render :action => 'edit' } |
|
133 | format.html { render :action => 'edit' } | |
136 | format.api { render_validation_errors(@time_entry) } |
|
134 | format.api { render_validation_errors(@time_entry) } | |
137 | end |
|
135 | end | |
138 | end |
|
136 | end | |
139 | end |
|
137 | end | |
140 |
|
138 | |||
141 | def edit |
|
139 | def edit | |
142 | @time_entry.attributes = params[:time_entry] |
|
140 | @time_entry.attributes = params[:time_entry] | |
143 |
|
141 | |||
144 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) |
|
142 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) | |
145 | end |
|
143 | end | |
146 |
|
144 | |||
147 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } |
|
145 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | |
148 | def update |
|
146 | def update | |
149 | @time_entry.attributes = params[:time_entry] |
|
147 | @time_entry.attributes = params[:time_entry] | |
150 |
|
148 | |||
151 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) |
|
149 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) | |
152 |
|
150 | |||
153 | if @time_entry.save |
|
151 | if @time_entry.save | |
154 | respond_to do |format| |
|
152 | respond_to do |format| | |
155 | format.html { |
|
153 | format.html { | |
156 | flash[:notice] = l(:notice_successful_update) |
|
154 | flash[:notice] = l(:notice_successful_update) | |
157 | redirect_back_or_default :action => 'index', :project_id => @time_entry.project |
|
155 | redirect_back_or_default :action => 'index', :project_id => @time_entry.project | |
158 | } |
|
156 | } | |
159 | format.api { head :ok } |
|
157 | format.api { head :ok } | |
160 | end |
|
158 | end | |
161 | else |
|
159 | else | |
162 | respond_to do |format| |
|
160 | respond_to do |format| | |
163 | format.html { render :action => 'edit' } |
|
161 | format.html { render :action => 'edit' } | |
164 | format.api { render_validation_errors(@time_entry) } |
|
162 | format.api { render_validation_errors(@time_entry) } | |
165 | end |
|
163 | end | |
166 | end |
|
164 | end | |
167 | end |
|
165 | end | |
168 |
|
166 | |||
169 | verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed } |
|
167 | verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed } | |
170 | def destroy |
|
168 | def destroy | |
171 | if @time_entry.destroy && @time_entry.destroyed? |
|
169 | if @time_entry.destroy && @time_entry.destroyed? | |
172 | respond_to do |format| |
|
170 | respond_to do |format| | |
173 | format.html { |
|
171 | format.html { | |
174 | flash[:notice] = l(:notice_successful_delete) |
|
172 | flash[:notice] = l(:notice_successful_delete) | |
175 | redirect_to :back |
|
173 | redirect_to :back | |
176 | } |
|
174 | } | |
177 | format.api { head :ok } |
|
175 | format.api { head :ok } | |
178 | end |
|
176 | end | |
179 | else |
|
177 | else | |
180 | respond_to do |format| |
|
178 | respond_to do |format| | |
181 | format.html { |
|
179 | format.html { | |
182 | flash[:error] = l(:notice_unable_delete_time_entry) |
|
180 | flash[:error] = l(:notice_unable_delete_time_entry) | |
183 | redirect_to :back |
|
181 | redirect_to :back | |
184 | } |
|
182 | } | |
185 | format.api { render_validation_errors(@time_entry) } |
|
183 | format.api { render_validation_errors(@time_entry) } | |
186 | end |
|
184 | end | |
187 | end |
|
185 | end | |
188 | rescue ::ActionController::RedirectBackError |
|
186 | rescue ::ActionController::RedirectBackError | |
189 | redirect_to :action => 'index', :project_id => @time_entry.project |
|
187 | redirect_to :action => 'index', :project_id => @time_entry.project | |
190 | end |
|
188 | end | |
191 |
|
189 | |||
192 | private |
|
190 | private | |
193 | def find_time_entry |
|
191 | def find_time_entry | |
194 | @time_entry = TimeEntry.find(params[:id]) |
|
192 | @time_entry = TimeEntry.find(params[:id]) | |
195 | unless @time_entry.editable_by?(User.current) |
|
193 | unless @time_entry.editable_by?(User.current) | |
196 | render_403 |
|
194 | render_403 | |
197 | return false |
|
195 | return false | |
198 | end |
|
196 | end | |
199 | @project = @time_entry.project |
|
197 | @project = @time_entry.project | |
200 | rescue ActiveRecord::RecordNotFound |
|
198 | rescue ActiveRecord::RecordNotFound | |
201 | render_404 |
|
199 | render_404 | |
202 | end |
|
200 | end | |
203 |
|
201 | |||
204 | def find_project |
|
202 | def find_project | |
205 | if issue_id = (params[:issue_id] || params[:time_entry] && params[:time_entry][:issue_id]) |
|
203 | if issue_id = (params[:issue_id] || params[:time_entry] && params[:time_entry][:issue_id]) | |
206 | @issue = Issue.find(issue_id) |
|
204 | @issue = Issue.find(issue_id) | |
207 | @project = @issue.project |
|
205 | @project = @issue.project | |
208 | elsif project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id]) |
|
206 | elsif project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id]) | |
209 | @project = Project.find(project_id) |
|
207 | @project = Project.find(project_id) | |
210 | else |
|
208 | else | |
211 | render_404 |
|
209 | render_404 | |
212 | return false |
|
210 | return false | |
213 | end |
|
211 | end | |
214 | rescue ActiveRecord::RecordNotFound |
|
212 | rescue ActiveRecord::RecordNotFound | |
215 | render_404 |
|
213 | render_404 | |
216 | end |
|
214 | end | |
217 |
|
215 | |||
218 | def find_optional_project |
|
216 | def find_optional_project | |
219 | if !params[:issue_id].blank? |
|
217 | if !params[:issue_id].blank? | |
220 | @issue = Issue.find(params[:issue_id]) |
|
218 | @issue = Issue.find(params[:issue_id]) | |
221 | @project = @issue.project |
|
219 | @project = @issue.project | |
222 | elsif !params[:project_id].blank? |
|
220 | elsif !params[:project_id].blank? | |
223 | @project = Project.find(params[:project_id]) |
|
221 | @project = Project.find(params[:project_id]) | |
224 | end |
|
222 | end | |
225 | deny_access unless User.current.allowed_to?(:view_time_entries, @project, :global => true) |
|
223 | deny_access unless User.current.allowed_to?(:view_time_entries, @project, :global => true) | |
226 | end |
|
224 | end | |
227 |
|
225 | |||
228 | # Retrieves the date range based on predefined ranges or specific from/to param dates |
|
226 | # Retrieves the date range based on predefined ranges or specific from/to param dates | |
229 | def retrieve_date_range |
|
227 | def retrieve_date_range | |
230 | @free_period = false |
|
228 | @free_period = false | |
231 | @from, @to = nil, nil |
|
229 | @from, @to = nil, nil | |
232 |
|
230 | |||
233 | if params[:period_type] == '1' || (params[:period_type].nil? && !params[:period].nil?) |
|
231 | if params[:period_type] == '1' || (params[:period_type].nil? && !params[:period].nil?) | |
234 | case params[:period].to_s |
|
232 | case params[:period].to_s | |
235 | when 'today' |
|
233 | when 'today' | |
236 | @from = @to = Date.today |
|
234 | @from = @to = Date.today | |
237 | when 'yesterday' |
|
235 | when 'yesterday' | |
238 | @from = @to = Date.today - 1 |
|
236 | @from = @to = Date.today - 1 | |
239 | when 'current_week' |
|
237 | when 'current_week' | |
240 | @from = Date.today - (Date.today.cwday - 1)%7 |
|
238 | @from = Date.today - (Date.today.cwday - 1)%7 | |
241 | @to = @from + 6 |
|
239 | @to = @from + 6 | |
242 | when 'last_week' |
|
240 | when 'last_week' | |
243 | @from = Date.today - 7 - (Date.today.cwday - 1)%7 |
|
241 | @from = Date.today - 7 - (Date.today.cwday - 1)%7 | |
244 | @to = @from + 6 |
|
242 | @to = @from + 6 | |
245 | when '7_days' |
|
243 | when '7_days' | |
246 | @from = Date.today - 7 |
|
244 | @from = Date.today - 7 | |
247 | @to = Date.today |
|
245 | @to = Date.today | |
248 | when 'current_month' |
|
246 | when 'current_month' | |
249 | @from = Date.civil(Date.today.year, Date.today.month, 1) |
|
247 | @from = Date.civil(Date.today.year, Date.today.month, 1) | |
250 | @to = (@from >> 1) - 1 |
|
248 | @to = (@from >> 1) - 1 | |
251 | when 'last_month' |
|
249 | when 'last_month' | |
252 | @from = Date.civil(Date.today.year, Date.today.month, 1) << 1 |
|
250 | @from = Date.civil(Date.today.year, Date.today.month, 1) << 1 | |
253 | @to = (@from >> 1) - 1 |
|
251 | @to = (@from >> 1) - 1 | |
254 | when '30_days' |
|
252 | when '30_days' | |
255 | @from = Date.today - 30 |
|
253 | @from = Date.today - 30 | |
256 | @to = Date.today |
|
254 | @to = Date.today | |
257 | when 'current_year' |
|
255 | when 'current_year' | |
258 | @from = Date.civil(Date.today.year, 1, 1) |
|
256 | @from = Date.civil(Date.today.year, 1, 1) | |
259 | @to = Date.civil(Date.today.year, 12, 31) |
|
257 | @to = Date.civil(Date.today.year, 12, 31) | |
260 | end |
|
258 | end | |
261 | elsif params[:period_type] == '2' || (params[:period_type].nil? && (!params[:from].nil? || !params[:to].nil?)) |
|
259 | elsif params[:period_type] == '2' || (params[:period_type].nil? && (!params[:from].nil? || !params[:to].nil?)) | |
262 | begin; @from = params[:from].to_s.to_date unless params[:from].blank?; rescue; end |
|
260 | begin; @from = params[:from].to_s.to_date unless params[:from].blank?; rescue; end | |
263 | begin; @to = params[:to].to_s.to_date unless params[:to].blank?; rescue; end |
|
261 | begin; @to = params[:to].to_s.to_date unless params[:to].blank?; rescue; end | |
264 | @free_period = true |
|
262 | @free_period = true | |
265 | else |
|
263 | else | |
266 | # default |
|
264 | # default | |
267 | end |
|
265 | end | |
268 |
|
266 | |||
269 | @from, @to = @to, @from if @from && @to && @from > @to |
|
267 | @from, @to = @to, @from if @from && @to && @from > @to | |
270 | @from ||= (TimeEntry.earilest_date_for_project(@project) || Date.today) |
|
268 | @from ||= (TimeEntry.earilest_date_for_project(@project) || Date.today) | |
271 | @to ||= (TimeEntry.latest_date_for_project(@project) || Date.today) |
|
269 | @to ||= (TimeEntry.latest_date_for_project(@project) || Date.today) | |
272 | end |
|
270 | end | |
273 |
|
271 | |||
274 | end |
|
272 | end |
@@ -1,223 +1,223 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2010 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2010 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 UsersController < ApplicationController |
|
18 | class UsersController < ApplicationController | |
19 | layout 'admin' |
|
19 | layout 'admin' | |
20 |
|
20 | |||
21 | before_filter :require_admin, :except => :show |
|
21 | before_filter :require_admin, :except => :show | |
22 | accept_key_auth :index, :show, :create, :update |
|
22 | accept_key_auth :index, :show, :create, :update | |
23 |
|
23 | |||
24 | helper :sort |
|
24 | helper :sort | |
25 | include SortHelper |
|
25 | include SortHelper | |
26 | helper :custom_fields |
|
26 | helper :custom_fields | |
27 | include CustomFieldsHelper |
|
27 | include CustomFieldsHelper | |
28 |
|
28 | |||
29 | def index |
|
29 | def index | |
30 | sort_init 'login', 'asc' |
|
30 | sort_init 'login', 'asc' | |
31 | sort_update %w(login firstname lastname mail admin created_on last_login_on) |
|
31 | sort_update %w(login firstname lastname mail admin created_on last_login_on) | |
32 |
|
32 | |||
33 | @status = params[:status] ? params[:status].to_i : 1 |
|
33 | @status = params[:status] ? params[:status].to_i : 1 | |
34 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) |
|
34 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) | |
35 |
|
35 | |||
36 | unless params[:name].blank? |
|
36 | unless params[:name].blank? | |
37 | name = "%#{params[:name].strip.downcase}%" |
|
37 | name = "%#{params[:name].strip.downcase}%" | |
38 | c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name] |
|
38 | c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name] | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | @user_count = User.count(:conditions => c.conditions) |
|
41 | @user_count = User.count(:conditions => c.conditions) | |
42 | @user_pages = Paginator.new self, @user_count, |
|
42 | @user_pages = Paginator.new self, @user_count, | |
43 | per_page_option, |
|
43 | per_page_option, | |
44 | params['page'] |
|
44 | params['page'] | |
45 | @users = User.find :all,:order => sort_clause, |
|
45 | @users = User.find :all,:order => sort_clause, | |
46 | :conditions => c.conditions, |
|
46 | :conditions => c.conditions, | |
47 | :limit => @user_pages.items_per_page, |
|
47 | :limit => @user_pages.items_per_page, | |
48 | :offset => @user_pages.current.offset |
|
48 | :offset => @user_pages.current.offset | |
49 |
|
49 | |||
50 | respond_to do |format| |
|
50 | respond_to do |format| | |
51 | format.html { render :layout => !request.xhr? } |
|
51 | format.html { render :layout => !request.xhr? } | |
52 | format.api { render :template => 'users/index.apit' } |
|
52 | format.api | |
53 | end |
|
53 | end | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def show |
|
56 | def show | |
57 | @user = User.find(params[:id]) |
|
57 | @user = User.find(params[:id]) | |
58 |
|
58 | |||
59 | # show projects based on current user visibility |
|
59 | # show projects based on current user visibility | |
60 | @memberships = @user.memberships.all(:conditions => Project.visible_by(User.current)) |
|
60 | @memberships = @user.memberships.all(:conditions => Project.visible_by(User.current)) | |
61 |
|
61 | |||
62 | events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) |
|
62 | events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) | |
63 | @events_by_day = events.group_by(&:event_date) |
|
63 | @events_by_day = events.group_by(&:event_date) | |
64 |
|
64 | |||
65 | unless User.current.admin? |
|
65 | unless User.current.admin? | |
66 | if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?) |
|
66 | if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?) | |
67 | render_404 |
|
67 | render_404 | |
68 | return |
|
68 | return | |
69 | end |
|
69 | end | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | respond_to do |format| |
|
72 | respond_to do |format| | |
73 | format.html { render :layout => 'base' } |
|
73 | format.html { render :layout => 'base' } | |
74 | format.api { render :template => 'users/show.apit' } |
|
74 | format.api | |
75 | end |
|
75 | end | |
76 | rescue ActiveRecord::RecordNotFound |
|
76 | rescue ActiveRecord::RecordNotFound | |
77 | render_404 |
|
77 | render_404 | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | def new |
|
80 | def new | |
81 | @notification_options = User::MAIL_NOTIFICATION_OPTIONS |
|
81 | @notification_options = User::MAIL_NOTIFICATION_OPTIONS | |
82 | @notification_option = Setting.default_notification_option |
|
82 | @notification_option = Setting.default_notification_option | |
83 |
|
83 | |||
84 | @user = User.new(:language => Setting.default_language) |
|
84 | @user = User.new(:language => Setting.default_language) | |
85 | @auth_sources = AuthSource.find(:all) |
|
85 | @auth_sources = AuthSource.find(:all) | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } |
|
88 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } | |
89 | def create |
|
89 | def create | |
90 | @notification_options = User::MAIL_NOTIFICATION_OPTIONS |
|
90 | @notification_options = User::MAIL_NOTIFICATION_OPTIONS | |
91 | @notification_option = Setting.default_notification_option |
|
91 | @notification_option = Setting.default_notification_option | |
92 |
|
92 | |||
93 | @user = User.new(params[:user]) |
|
93 | @user = User.new(params[:user]) | |
94 | @user.admin = params[:user][:admin] || false |
|
94 | @user.admin = params[:user][:admin] || false | |
95 | @user.login = params[:user][:login] |
|
95 | @user.login = params[:user][:login] | |
96 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id |
|
96 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id | |
97 |
|
97 | |||
98 | # TODO: Similar to My#account |
|
98 | # TODO: Similar to My#account | |
99 | @user.mail_notification = params[:notification_option] || 'only_my_events' |
|
99 | @user.mail_notification = params[:notification_option] || 'only_my_events' | |
100 | @user.pref.attributes = params[:pref] |
|
100 | @user.pref.attributes = params[:pref] | |
101 | @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') |
|
101 | @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') | |
102 |
|
102 | |||
103 | if @user.save |
|
103 | if @user.save | |
104 | @user.pref.save |
|
104 | @user.pref.save | |
105 | @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) |
|
105 | @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) | |
106 |
|
106 | |||
107 | Mailer.deliver_account_information(@user, params[:password]) if params[:send_information] |
|
107 | Mailer.deliver_account_information(@user, params[:password]) if params[:send_information] | |
108 |
|
108 | |||
109 | respond_to do |format| |
|
109 | respond_to do |format| | |
110 | format.html { |
|
110 | format.html { | |
111 | flash[:notice] = l(:notice_successful_create) |
|
111 | flash[:notice] = l(:notice_successful_create) | |
112 | redirect_to(params[:continue] ? |
|
112 | redirect_to(params[:continue] ? | |
113 | {:controller => 'users', :action => 'new'} : |
|
113 | {:controller => 'users', :action => 'new'} : | |
114 | {:controller => 'users', :action => 'edit', :id => @user} |
|
114 | {:controller => 'users', :action => 'edit', :id => @user} | |
115 | ) |
|
115 | ) | |
116 | } |
|
116 | } | |
117 |
format.api { render : |
|
117 | format.api { render :action => 'show', :status => :created, :location => user_url(@user) } | |
118 | end |
|
118 | end | |
119 | else |
|
119 | else | |
120 | @auth_sources = AuthSource.find(:all) |
|
120 | @auth_sources = AuthSource.find(:all) | |
121 | @notification_option = @user.mail_notification |
|
121 | @notification_option = @user.mail_notification | |
122 |
|
122 | |||
123 | respond_to do |format| |
|
123 | respond_to do |format| | |
124 | format.html { render :action => 'new' } |
|
124 | format.html { render :action => 'new' } | |
125 | format.api { render_validation_errors(@user) } |
|
125 | format.api { render_validation_errors(@user) } | |
126 | end |
|
126 | end | |
127 | end |
|
127 | end | |
128 | end |
|
128 | end | |
129 |
|
129 | |||
130 | def edit |
|
130 | def edit | |
131 | @user = User.find(params[:id]) |
|
131 | @user = User.find(params[:id]) | |
132 | @notification_options = @user.valid_notification_options |
|
132 | @notification_options = @user.valid_notification_options | |
133 | @notification_option = @user.mail_notification |
|
133 | @notification_option = @user.mail_notification | |
134 |
|
134 | |||
135 | @auth_sources = AuthSource.find(:all) |
|
135 | @auth_sources = AuthSource.find(:all) | |
136 | @membership ||= Member.new |
|
136 | @membership ||= Member.new | |
137 | end |
|
137 | end | |
138 |
|
138 | |||
139 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } |
|
139 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | |
140 | def update |
|
140 | def update | |
141 | @user = User.find(params[:id]) |
|
141 | @user = User.find(params[:id]) | |
142 | @notification_options = @user.valid_notification_options |
|
142 | @notification_options = @user.valid_notification_options | |
143 | @notification_option = @user.mail_notification |
|
143 | @notification_option = @user.mail_notification | |
144 |
|
144 | |||
145 | @user.admin = params[:user][:admin] if params[:user][:admin] |
|
145 | @user.admin = params[:user][:admin] if params[:user][:admin] | |
146 | @user.login = params[:user][:login] if params[:user][:login] |
|
146 | @user.login = params[:user][:login] if params[:user][:login] | |
147 | if params[:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?) |
|
147 | if params[:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?) | |
148 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] |
|
148 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] | |
149 | end |
|
149 | end | |
150 | @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids] |
|
150 | @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids] | |
151 | @user.attributes = params[:user] |
|
151 | @user.attributes = params[:user] | |
152 | # Was the account actived ? (do it before User#save clears the change) |
|
152 | # Was the account actived ? (do it before User#save clears the change) | |
153 | was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) |
|
153 | was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) | |
154 | # TODO: Similar to My#account |
|
154 | # TODO: Similar to My#account | |
155 | @user.mail_notification = params[:notification_option] || 'only_my_events' |
|
155 | @user.mail_notification = params[:notification_option] || 'only_my_events' | |
156 | @user.pref.attributes = params[:pref] |
|
156 | @user.pref.attributes = params[:pref] | |
157 | @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') |
|
157 | @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') | |
158 |
|
158 | |||
159 | if @user.save |
|
159 | if @user.save | |
160 | @user.pref.save |
|
160 | @user.pref.save | |
161 | @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) |
|
161 | @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) | |
162 |
|
162 | |||
163 | if was_activated |
|
163 | if was_activated | |
164 | Mailer.deliver_account_activated(@user) |
|
164 | Mailer.deliver_account_activated(@user) | |
165 | elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil? |
|
165 | elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil? | |
166 | Mailer.deliver_account_information(@user, params[:password]) |
|
166 | Mailer.deliver_account_information(@user, params[:password]) | |
167 | end |
|
167 | end | |
168 |
|
168 | |||
169 | respond_to do |format| |
|
169 | respond_to do |format| | |
170 | format.html { |
|
170 | format.html { | |
171 | flash[:notice] = l(:notice_successful_update) |
|
171 | flash[:notice] = l(:notice_successful_update) | |
172 | redirect_to :back |
|
172 | redirect_to :back | |
173 | } |
|
173 | } | |
174 | format.api { head :ok } |
|
174 | format.api { head :ok } | |
175 | end |
|
175 | end | |
176 | else |
|
176 | else | |
177 | @auth_sources = AuthSource.find(:all) |
|
177 | @auth_sources = AuthSource.find(:all) | |
178 | @membership ||= Member.new |
|
178 | @membership ||= Member.new | |
179 |
|
179 | |||
180 | respond_to do |format| |
|
180 | respond_to do |format| | |
181 | format.html { render :action => :edit } |
|
181 | format.html { render :action => :edit } | |
182 | format.api { render_validation_errors(@user) } |
|
182 | format.api { render_validation_errors(@user) } | |
183 | end |
|
183 | end | |
184 | end |
|
184 | end | |
185 | rescue ::ActionController::RedirectBackError |
|
185 | rescue ::ActionController::RedirectBackError | |
186 | redirect_to :controller => 'users', :action => 'edit', :id => @user |
|
186 | redirect_to :controller => 'users', :action => 'edit', :id => @user | |
187 | end |
|
187 | end | |
188 |
|
188 | |||
189 | def edit_membership |
|
189 | def edit_membership | |
190 | @user = User.find(params[:id]) |
|
190 | @user = User.find(params[:id]) | |
191 | @membership = Member.edit_membership(params[:membership_id], params[:membership], @user) |
|
191 | @membership = Member.edit_membership(params[:membership_id], params[:membership], @user) | |
192 | @membership.save if request.post? |
|
192 | @membership.save if request.post? | |
193 | respond_to do |format| |
|
193 | respond_to do |format| | |
194 | if @membership.valid? |
|
194 | if @membership.valid? | |
195 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } |
|
195 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } | |
196 | format.js { |
|
196 | format.js { | |
197 | render(:update) {|page| |
|
197 | render(:update) {|page| | |
198 | page.replace_html "tab-content-memberships", :partial => 'users/memberships' |
|
198 | page.replace_html "tab-content-memberships", :partial => 'users/memberships' | |
199 | page.visual_effect(:highlight, "member-#{@membership.id}") |
|
199 | page.visual_effect(:highlight, "member-#{@membership.id}") | |
200 | } |
|
200 | } | |
201 | } |
|
201 | } | |
202 | else |
|
202 | else | |
203 | format.js { |
|
203 | format.js { | |
204 | render(:update) {|page| |
|
204 | render(:update) {|page| | |
205 | page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', '))) |
|
205 | page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', '))) | |
206 | } |
|
206 | } | |
207 | } |
|
207 | } | |
208 | end |
|
208 | end | |
209 | end |
|
209 | end | |
210 | end |
|
210 | end | |
211 |
|
211 | |||
212 | def destroy_membership |
|
212 | def destroy_membership | |
213 | @user = User.find(params[:id]) |
|
213 | @user = User.find(params[:id]) | |
214 | @membership = Member.find(params[:membership_id]) |
|
214 | @membership = Member.find(params[:membership_id]) | |
215 | if request.post? && @membership.deletable? |
|
215 | if request.post? && @membership.deletable? | |
216 | @membership.destroy |
|
216 | @membership.destroy | |
217 | end |
|
217 | end | |
218 | respond_to do |format| |
|
218 | respond_to do |format| | |
219 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } |
|
219 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } | |
220 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} } |
|
220 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} } | |
221 | end |
|
221 | end | |
222 | end |
|
222 | end | |
223 | end |
|
223 | end |
1 | NO CONTENT: file renamed from app/views/issues/index.apit to app/views/issues/index.api.rsb |
|
NO CONTENT: file renamed from app/views/issues/index.apit to app/views/issues/index.api.rsb |
1 | NO CONTENT: file renamed from app/views/issues/show.apit to app/views/issues/show.api.rsb |
|
NO CONTENT: file renamed from app/views/issues/show.apit to app/views/issues/show.api.rsb |
1 | NO CONTENT: file renamed from app/views/projects/index.apit to app/views/projects/index.api.rsb |
|
NO CONTENT: file renamed from app/views/projects/index.apit to app/views/projects/index.api.rsb |
1 | NO CONTENT: file renamed from app/views/projects/show.apit to app/views/projects/show.api.rsb |
|
NO CONTENT: file renamed from app/views/projects/show.apit to app/views/projects/show.api.rsb |
1 | NO CONTENT: file renamed from app/views/timelog/index.apit to app/views/timelog/index.api.rsb |
|
NO CONTENT: file renamed from app/views/timelog/index.apit to app/views/timelog/index.api.rsb |
1 | NO CONTENT: file renamed from app/views/timelog/show.apit to app/views/timelog/show.api.rsb |
|
NO CONTENT: file renamed from app/views/timelog/show.apit to app/views/timelog/show.api.rsb |
1 | NO CONTENT: file renamed from app/views/users/index.apit to app/views/users/index.api.rsb |
|
NO CONTENT: file renamed from app/views/users/index.apit to app/views/users/index.api.rsb |
1 | NO CONTENT: file renamed from app/views/users/show.apit to app/views/users/show.api.rsb |
|
NO CONTENT: file renamed from app/views/users/show.apit to app/views/users/show.api.rsb |
@@ -1,233 +1,233 | |||||
1 | require 'redmine/access_control' |
|
1 | require 'redmine/access_control' | |
2 | require 'redmine/menu_manager' |
|
2 | require 'redmine/menu_manager' | |
3 | require 'redmine/activity' |
|
3 | require 'redmine/activity' | |
4 | require 'redmine/search' |
|
4 | require 'redmine/search' | |
5 | require 'redmine/custom_field_format' |
|
5 | require 'redmine/custom_field_format' | |
6 | require 'redmine/mime_type' |
|
6 | require 'redmine/mime_type' | |
7 | require 'redmine/core_ext' |
|
7 | require 'redmine/core_ext' | |
8 | require 'redmine/themes' |
|
8 | require 'redmine/themes' | |
9 | require 'redmine/hook' |
|
9 | require 'redmine/hook' | |
10 | require 'redmine/plugin' |
|
10 | require 'redmine/plugin' | |
11 | require 'redmine/notifiable' |
|
11 | require 'redmine/notifiable' | |
12 | require 'redmine/wiki_formatting' |
|
12 | require 'redmine/wiki_formatting' | |
13 | require 'redmine/scm/base' |
|
13 | require 'redmine/scm/base' | |
14 |
|
14 | |||
15 | begin |
|
15 | begin | |
16 | require_library_or_gem 'RMagick' unless Object.const_defined?(:Magick) |
|
16 | require_library_or_gem 'RMagick' unless Object.const_defined?(:Magick) | |
17 | rescue LoadError |
|
17 | rescue LoadError | |
18 | # RMagick is not available |
|
18 | # RMagick is not available | |
19 | end |
|
19 | end | |
20 |
|
20 | |||
21 | if RUBY_VERSION < '1.9' |
|
21 | if RUBY_VERSION < '1.9' | |
22 | require 'faster_csv' |
|
22 | require 'faster_csv' | |
23 | else |
|
23 | else | |
24 | require 'csv' |
|
24 | require 'csv' | |
25 | FCSV = CSV |
|
25 | FCSV = CSV | |
26 | end |
|
26 | end | |
27 |
|
27 | |||
28 | Redmine::Scm::Base.add "Subversion" |
|
28 | Redmine::Scm::Base.add "Subversion" | |
29 | Redmine::Scm::Base.add "Darcs" |
|
29 | Redmine::Scm::Base.add "Darcs" | |
30 | Redmine::Scm::Base.add "Mercurial" |
|
30 | Redmine::Scm::Base.add "Mercurial" | |
31 | Redmine::Scm::Base.add "Cvs" |
|
31 | Redmine::Scm::Base.add "Cvs" | |
32 | Redmine::Scm::Base.add "Bazaar" |
|
32 | Redmine::Scm::Base.add "Bazaar" | |
33 | Redmine::Scm::Base.add "Git" |
|
33 | Redmine::Scm::Base.add "Git" | |
34 | Redmine::Scm::Base.add "Filesystem" |
|
34 | Redmine::Scm::Base.add "Filesystem" | |
35 |
|
35 | |||
36 | Redmine::CustomFieldFormat.map do |fields| |
|
36 | Redmine::CustomFieldFormat.map do |fields| | |
37 | fields.register Redmine::CustomFieldFormat.new('string', :label => :label_string, :order => 1) |
|
37 | fields.register Redmine::CustomFieldFormat.new('string', :label => :label_string, :order => 1) | |
38 | fields.register Redmine::CustomFieldFormat.new('text', :label => :label_text, :order => 2) |
|
38 | fields.register Redmine::CustomFieldFormat.new('text', :label => :label_text, :order => 2) | |
39 | fields.register Redmine::CustomFieldFormat.new('int', :label => :label_integer, :order => 3) |
|
39 | fields.register Redmine::CustomFieldFormat.new('int', :label => :label_integer, :order => 3) | |
40 | fields.register Redmine::CustomFieldFormat.new('float', :label => :label_float, :order => 4) |
|
40 | fields.register Redmine::CustomFieldFormat.new('float', :label => :label_float, :order => 4) | |
41 | fields.register Redmine::CustomFieldFormat.new('list', :label => :label_list, :order => 5) |
|
41 | fields.register Redmine::CustomFieldFormat.new('list', :label => :label_list, :order => 5) | |
42 | fields.register Redmine::CustomFieldFormat.new('date', :label => :label_date, :order => 6) |
|
42 | fields.register Redmine::CustomFieldFormat.new('date', :label => :label_date, :order => 6) | |
43 | fields.register Redmine::CustomFieldFormat.new('bool', :label => :label_boolean, :order => 7) |
|
43 | fields.register Redmine::CustomFieldFormat.new('bool', :label => :label_boolean, :order => 7) | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | # Permissions |
|
46 | # Permissions | |
47 | Redmine::AccessControl.map do |map| |
|
47 | Redmine::AccessControl.map do |map| | |
48 | map.permission :view_project, {:projects => [:show], :activities => [:index]}, :public => true |
|
48 | map.permission :view_project, {:projects => [:show], :activities => [:index]}, :public => true | |
49 | map.permission :search_project, {:search => :index}, :public => true |
|
49 | map.permission :search_project, {:search => :index}, :public => true | |
50 | map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin |
|
50 | map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin | |
51 | map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member |
|
51 | map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member | |
52 | map.permission :select_project_modules, {:projects => :modules}, :require => :member |
|
52 | map.permission :select_project_modules, {:projects => :modules}, :require => :member | |
53 | map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member]}, :require => :member |
|
53 | map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member]}, :require => :member | |
54 | map.permission :manage_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :require => :member |
|
54 | map.permission :manage_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :require => :member | |
55 | map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member |
|
55 | map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member | |
56 |
|
56 | |||
57 | map.project_module :issue_tracking do |map| |
|
57 | map.project_module :issue_tracking do |map| | |
58 | # Issue categories |
|
58 | # Issue categories | |
59 | map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :edit, :destroy]}, :require => :member |
|
59 | map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :edit, :destroy]}, :require => :member | |
60 | # Issues |
|
60 | # Issues | |
61 | map.permission :view_issues, {:issues => [:index, :show], |
|
61 | map.permission :view_issues, {:issues => [:index, :show], | |
62 | :auto_complete => [:issues], |
|
62 | :auto_complete => [:issues], | |
63 | :context_menus => [:issues], |
|
63 | :context_menus => [:issues], | |
64 | :versions => [:index, :show, :status_by], |
|
64 | :versions => [:index, :show, :status_by], | |
65 | :journals => :index, |
|
65 | :journals => :index, | |
66 | :queries => :index, |
|
66 | :queries => :index, | |
67 | :reports => [:issue_report, :issue_report_details]} |
|
67 | :reports => [:issue_report, :issue_report_details]} | |
68 | map.permission :add_issues, {:issues => [:new, :create, :update_form]} |
|
68 | map.permission :add_issues, {:issues => [:new, :create, :update_form]} | |
69 | map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update, :update_form], :journals => [:new]} |
|
69 | map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update, :update_form], :journals => [:new]} | |
70 | map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]} |
|
70 | map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]} | |
71 | map.permission :manage_subtasks, {} |
|
71 | map.permission :manage_subtasks, {} | |
72 | map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new]} |
|
72 | map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new]} | |
73 | map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin |
|
73 | map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin | |
74 | map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin |
|
74 | map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin | |
75 | map.permission :move_issues, {:issue_moves => [:new, :create]}, :require => :loggedin |
|
75 | map.permission :move_issues, {:issue_moves => [:new, :create]}, :require => :loggedin | |
76 | map.permission :delete_issues, {:issues => :destroy}, :require => :member |
|
76 | map.permission :delete_issues, {:issues => :destroy}, :require => :member | |
77 | # Queries |
|
77 | # Queries | |
78 | map.permission :manage_public_queries, {:queries => [:new, :edit, :destroy]}, :require => :member |
|
78 | map.permission :manage_public_queries, {:queries => [:new, :edit, :destroy]}, :require => :member | |
79 | map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin |
|
79 | map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin | |
80 | # Watchers |
|
80 | # Watchers | |
81 | map.permission :view_issue_watchers, {} |
|
81 | map.permission :view_issue_watchers, {} | |
82 | map.permission :add_issue_watchers, {:watchers => :new} |
|
82 | map.permission :add_issue_watchers, {:watchers => :new} | |
83 | map.permission :delete_issue_watchers, {:watchers => :destroy} |
|
83 | map.permission :delete_issue_watchers, {:watchers => :destroy} | |
84 | end |
|
84 | end | |
85 |
|
85 | |||
86 | map.project_module :time_tracking do |map| |
|
86 | map.project_module :time_tracking do |map| | |
87 | map.permission :log_time, {:timelog => [:new, :create, :edit, :update]}, :require => :loggedin |
|
87 | map.permission :log_time, {:timelog => [:new, :create, :edit, :update]}, :require => :loggedin | |
88 | map.permission :view_time_entries, :timelog => [:index, :show], :time_entry_reports => [:report] |
|
88 | map.permission :view_time_entries, :timelog => [:index, :show], :time_entry_reports => [:report] | |
89 | map.permission :edit_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :member |
|
89 | map.permission :edit_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :member | |
90 | map.permission :edit_own_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :loggedin |
|
90 | map.permission :edit_own_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :loggedin | |
91 | map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member |
|
91 | map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member | |
92 | end |
|
92 | end | |
93 |
|
93 | |||
94 | map.project_module :news do |map| |
|
94 | map.project_module :news do |map| | |
95 | map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member |
|
95 | map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member | |
96 | map.permission :view_news, {:news => [:index, :show]}, :public => true |
|
96 | map.permission :view_news, {:news => [:index, :show]}, :public => true | |
97 | map.permission :comment_news, {:comments => :create} |
|
97 | map.permission :comment_news, {:comments => :create} | |
98 | end |
|
98 | end | |
99 |
|
99 | |||
100 | map.project_module :documents do |map| |
|
100 | map.project_module :documents do |map| | |
101 | map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment]}, :require => :loggedin |
|
101 | map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment]}, :require => :loggedin | |
102 | map.permission :view_documents, :documents => [:index, :show, :download] |
|
102 | map.permission :view_documents, :documents => [:index, :show, :download] | |
103 | end |
|
103 | end | |
104 |
|
104 | |||
105 | map.project_module :files do |map| |
|
105 | map.project_module :files do |map| | |
106 | map.permission :manage_files, {:files => [:new, :create]}, :require => :loggedin |
|
106 | map.permission :manage_files, {:files => [:new, :create]}, :require => :loggedin | |
107 | map.permission :view_files, :files => :index, :versions => :download |
|
107 | map.permission :view_files, :files => :index, :versions => :download | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | map.project_module :wiki do |map| |
|
110 | map.project_module :wiki do |map| | |
111 | map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member |
|
111 | map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member | |
112 | map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member |
|
112 | map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member | |
113 | map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member |
|
113 | map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member | |
114 | map.permission :view_wiki_pages, :wiki => [:index, :show, :special, :date_index] |
|
114 | map.permission :view_wiki_pages, :wiki => [:index, :show, :special, :date_index] | |
115 | map.permission :export_wiki_pages, :wiki => [:export] |
|
115 | map.permission :export_wiki_pages, :wiki => [:export] | |
116 | map.permission :view_wiki_edits, :wiki => [:history, :diff, :annotate] |
|
116 | map.permission :view_wiki_edits, :wiki => [:history, :diff, :annotate] | |
117 | map.permission :edit_wiki_pages, :wiki => [:edit, :update, :preview, :add_attachment] |
|
117 | map.permission :edit_wiki_pages, :wiki => [:edit, :update, :preview, :add_attachment] | |
118 | map.permission :delete_wiki_pages_attachments, {} |
|
118 | map.permission :delete_wiki_pages_attachments, {} | |
119 | map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member |
|
119 | map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member | |
120 | end |
|
120 | end | |
121 |
|
121 | |||
122 | map.project_module :repository do |map| |
|
122 | map.project_module :repository do |map| | |
123 | map.permission :manage_repository, {:repositories => [:edit, :committers, :destroy]}, :require => :member |
|
123 | map.permission :manage_repository, {:repositories => [:edit, :committers, :destroy]}, :require => :member | |
124 | map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph] |
|
124 | map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph] | |
125 | map.permission :view_changesets, :repositories => [:show, :revisions, :revision] |
|
125 | map.permission :view_changesets, :repositories => [:show, :revisions, :revision] | |
126 | map.permission :commit_access, {} |
|
126 | map.permission :commit_access, {} | |
127 | end |
|
127 | end | |
128 |
|
128 | |||
129 | map.project_module :boards do |map| |
|
129 | map.project_module :boards do |map| | |
130 | map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member |
|
130 | map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member | |
131 | map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true |
|
131 | map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true | |
132 | map.permission :add_messages, {:messages => [:new, :reply, :quote]} |
|
132 | map.permission :add_messages, {:messages => [:new, :reply, :quote]} | |
133 | map.permission :edit_messages, {:messages => :edit}, :require => :member |
|
133 | map.permission :edit_messages, {:messages => :edit}, :require => :member | |
134 | map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin |
|
134 | map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin | |
135 | map.permission :delete_messages, {:messages => :destroy}, :require => :member |
|
135 | map.permission :delete_messages, {:messages => :destroy}, :require => :member | |
136 | map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin |
|
136 | map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin | |
137 | end |
|
137 | end | |
138 |
|
138 | |||
139 | map.project_module :calendar do |map| |
|
139 | map.project_module :calendar do |map| | |
140 | map.permission :view_calendar, :calendars => [:show, :update] |
|
140 | map.permission :view_calendar, :calendars => [:show, :update] | |
141 | end |
|
141 | end | |
142 |
|
142 | |||
143 | map.project_module :gantt do |map| |
|
143 | map.project_module :gantt do |map| | |
144 | map.permission :view_gantt, :gantts => [:show, :update] |
|
144 | map.permission :view_gantt, :gantts => [:show, :update] | |
145 | end |
|
145 | end | |
146 | end |
|
146 | end | |
147 |
|
147 | |||
148 | Redmine::MenuManager.map :top_menu do |menu| |
|
148 | Redmine::MenuManager.map :top_menu do |menu| | |
149 | menu.push :home, :home_path |
|
149 | menu.push :home, :home_path | |
150 | menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? } |
|
150 | menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? } | |
151 | menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural |
|
151 | menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural | |
152 | menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true |
|
152 | menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true | |
153 | menu.push :help, Redmine::Info.help_url, :last => true |
|
153 | menu.push :help, Redmine::Info.help_url, :last => true | |
154 | end |
|
154 | end | |
155 |
|
155 | |||
156 | Redmine::MenuManager.map :account_menu do |menu| |
|
156 | Redmine::MenuManager.map :account_menu do |menu| | |
157 | menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? } |
|
157 | menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? } | |
158 | menu.push :register, { :controller => 'account', :action => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? } |
|
158 | menu.push :register, { :controller => 'account', :action => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? } | |
159 | menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? } |
|
159 | menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? } | |
160 | menu.push :logout, :signout_path, :if => Proc.new { User.current.logged? } |
|
160 | menu.push :logout, :signout_path, :if => Proc.new { User.current.logged? } | |
161 | end |
|
161 | end | |
162 |
|
162 | |||
163 | Redmine::MenuManager.map :application_menu do |menu| |
|
163 | Redmine::MenuManager.map :application_menu do |menu| | |
164 | # Empty |
|
164 | # Empty | |
165 | end |
|
165 | end | |
166 |
|
166 | |||
167 | Redmine::MenuManager.map :admin_menu do |menu| |
|
167 | Redmine::MenuManager.map :admin_menu do |menu| | |
168 | menu.push :projects, {:controller => 'admin', :action => 'projects'}, :caption => :label_project_plural |
|
168 | menu.push :projects, {:controller => 'admin', :action => 'projects'}, :caption => :label_project_plural | |
169 | menu.push :users, {:controller => 'users'}, :caption => :label_user_plural |
|
169 | menu.push :users, {:controller => 'users'}, :caption => :label_user_plural | |
170 | menu.push :groups, {:controller => 'groups'}, :caption => :label_group_plural |
|
170 | menu.push :groups, {:controller => 'groups'}, :caption => :label_group_plural | |
171 | menu.push :roles, {:controller => 'roles'}, :caption => :label_role_and_permissions |
|
171 | menu.push :roles, {:controller => 'roles'}, :caption => :label_role_and_permissions | |
172 | menu.push :trackers, {:controller => 'trackers'}, :caption => :label_tracker_plural |
|
172 | menu.push :trackers, {:controller => 'trackers'}, :caption => :label_tracker_plural | |
173 | menu.push :issue_statuses, {:controller => 'issue_statuses'}, :caption => :label_issue_status_plural, |
|
173 | menu.push :issue_statuses, {:controller => 'issue_statuses'}, :caption => :label_issue_status_plural, | |
174 | :html => {:class => 'issue_statuses'} |
|
174 | :html => {:class => 'issue_statuses'} | |
175 | menu.push :workflows, {:controller => 'workflows', :action => 'edit'}, :caption => :label_workflow |
|
175 | menu.push :workflows, {:controller => 'workflows', :action => 'edit'}, :caption => :label_workflow | |
176 | menu.push :custom_fields, {:controller => 'custom_fields'}, :caption => :label_custom_field_plural, |
|
176 | menu.push :custom_fields, {:controller => 'custom_fields'}, :caption => :label_custom_field_plural, | |
177 | :html => {:class => 'custom_fields'} |
|
177 | :html => {:class => 'custom_fields'} | |
178 | menu.push :enumerations, {:controller => 'enumerations'} |
|
178 | menu.push :enumerations, {:controller => 'enumerations'} | |
179 | menu.push :settings, {:controller => 'settings'} |
|
179 | menu.push :settings, {:controller => 'settings'} | |
180 | menu.push :ldap_authentication, {:controller => 'ldap_auth_sources', :action => 'index'}, |
|
180 | menu.push :ldap_authentication, {:controller => 'ldap_auth_sources', :action => 'index'}, | |
181 | :html => {:class => 'server_authentication'} |
|
181 | :html => {:class => 'server_authentication'} | |
182 | menu.push :plugins, {:controller => 'admin', :action => 'plugins'}, :last => true |
|
182 | menu.push :plugins, {:controller => 'admin', :action => 'plugins'}, :last => true | |
183 | menu.push :info, {:controller => 'admin', :action => 'info'}, :caption => :label_information_plural, :last => true |
|
183 | menu.push :info, {:controller => 'admin', :action => 'info'}, :caption => :label_information_plural, :last => true | |
184 | end |
|
184 | end | |
185 |
|
185 | |||
186 | Redmine::MenuManager.map :project_menu do |menu| |
|
186 | Redmine::MenuManager.map :project_menu do |menu| | |
187 | menu.push :overview, { :controller => 'projects', :action => 'show' } |
|
187 | menu.push :overview, { :controller => 'projects', :action => 'show' } | |
188 | menu.push :activity, { :controller => 'activities', :action => 'index' } |
|
188 | menu.push :activity, { :controller => 'activities', :action => 'index' } | |
189 | menu.push :roadmap, { :controller => 'versions', :action => 'index' }, :param => :project_id, |
|
189 | menu.push :roadmap, { :controller => 'versions', :action => 'index' }, :param => :project_id, | |
190 | :if => Proc.new { |p| p.shared_versions.any? } |
|
190 | :if => Proc.new { |p| p.shared_versions.any? } | |
191 | menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural |
|
191 | menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural | |
192 | menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new, |
|
192 | menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new, | |
193 | :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) } |
|
193 | :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) } | |
194 | menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt |
|
194 | menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt | |
195 | menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar |
|
195 | menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar | |
196 | menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural |
|
196 | menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural | |
197 | menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural |
|
197 | menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural | |
198 | menu.push :wiki, { :controller => 'wiki', :action => 'show', :id => nil }, :param => :project_id, |
|
198 | menu.push :wiki, { :controller => 'wiki', :action => 'show', :id => nil }, :param => :project_id, | |
199 | :if => Proc.new { |p| p.wiki && !p.wiki.new_record? } |
|
199 | :if => Proc.new { |p| p.wiki && !p.wiki.new_record? } | |
200 | menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, |
|
200 | menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, | |
201 | :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural |
|
201 | :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural | |
202 | menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural, :param => :project_id |
|
202 | menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural, :param => :project_id | |
203 | menu.push :repository, { :controller => 'repositories', :action => 'show' }, |
|
203 | menu.push :repository, { :controller => 'repositories', :action => 'show' }, | |
204 | :if => Proc.new { |p| p.repository && !p.repository.new_record? } |
|
204 | :if => Proc.new { |p| p.repository && !p.repository.new_record? } | |
205 | menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true |
|
205 | menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true | |
206 | end |
|
206 | end | |
207 |
|
207 | |||
208 | Redmine::Activity.map do |activity| |
|
208 | Redmine::Activity.map do |activity| | |
209 | activity.register :issues, :class_name => %w(Issue Journal) |
|
209 | activity.register :issues, :class_name => %w(Issue Journal) | |
210 | activity.register :changesets |
|
210 | activity.register :changesets | |
211 | activity.register :news |
|
211 | activity.register :news | |
212 | activity.register :documents, :class_name => %w(Document Attachment) |
|
212 | activity.register :documents, :class_name => %w(Document Attachment) | |
213 | activity.register :files, :class_name => 'Attachment' |
|
213 | activity.register :files, :class_name => 'Attachment' | |
214 | activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false |
|
214 | activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false | |
215 | activity.register :messages, :default => false |
|
215 | activity.register :messages, :default => false | |
216 | activity.register :time_entries, :default => false |
|
216 | activity.register :time_entries, :default => false | |
217 | end |
|
217 | end | |
218 |
|
218 | |||
219 | Redmine::Search.map do |search| |
|
219 | Redmine::Search.map do |search| | |
220 | search.register :issues |
|
220 | search.register :issues | |
221 | search.register :news |
|
221 | search.register :news | |
222 | search.register :documents |
|
222 | search.register :documents | |
223 | search.register :changesets |
|
223 | search.register :changesets | |
224 | search.register :wiki_pages |
|
224 | search.register :wiki_pages | |
225 | search.register :messages |
|
225 | search.register :messages | |
226 | search.register :projects |
|
226 | search.register :projects | |
227 | end |
|
227 | end | |
228 |
|
228 | |||
229 | Redmine::WikiFormatting.map do |format| |
|
229 | Redmine::WikiFormatting.map do |format| | |
230 | format.register :textile, Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting::Textile::Helper |
|
230 | format.register :textile, Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting::Textile::Helper | |
231 | end |
|
231 | end | |
232 |
|
232 | |||
233 |
ActionView::Template.register_template_handler : |
|
233 | ActionView::Template.register_template_handler :rsb, Redmine::Views::ApiTemplateHandler |
General Comments 0
You need to be logged in to leave comments.
Login now