Mercurial > hg > soundsoftware-site
comparison app/controllers/.svn/text-base/application_controller.rb.svn-base @ 14:1d32c0a0efbf
* Update to SVN trunk (revisions 3892-4040)
author | Chris Cannam |
---|---|
date | Wed, 25 Aug 2010 16:30:24 +0100 |
parents | 513646585e45 |
children | 40f7cfd4df19 |
comparison
equal
deleted
inserted
replaced
4:9cc62779c13a | 14:1d32c0a0efbf |
---|---|
199 end | 199 end |
200 | 200 |
201 def self.model_object(model) | 201 def self.model_object(model) |
202 write_inheritable_attribute('model_object', model) | 202 write_inheritable_attribute('model_object', model) |
203 end | 203 end |
204 | 204 |
205 # Filter for bulk issue operations | |
206 def find_issues | |
207 @issues = Issue.find_all_by_id(params[:id] || params[:ids]) | |
208 raise ActiveRecord::RecordNotFound if @issues.empty? | |
209 projects = @issues.collect(&:project).compact.uniq | |
210 if projects.size == 1 | |
211 @project = projects.first | |
212 else | |
213 # TODO: let users bulk edit/move/destroy issues from different projects | |
214 render_error 'Can not bulk edit/move/destroy issues from different projects' | |
215 return false | |
216 end | |
217 rescue ActiveRecord::RecordNotFound | |
218 render_404 | |
219 end | |
220 | |
205 # make sure that the user is a member of the project (or admin) if project is private | 221 # make sure that the user is a member of the project (or admin) if project is private |
206 # used as a before_filter for actions that do not require any particular permission on the project | 222 # used as a before_filter for actions that do not require any particular permission on the project |
207 def check_project_privacy | 223 def check_project_privacy |
208 if @project && @project.active? | 224 if @project && @project.active? |
209 if @project.is_public? || User.current.member_of?(@project) || User.current.admin? | 225 if @project.is_public? || User.current.member_of?(@project) || User.current.admin? |
214 else | 230 else |
215 @project = nil | 231 @project = nil |
216 render_404 | 232 render_404 |
217 false | 233 false |
218 end | 234 end |
235 end | |
236 | |
237 def back_url | |
238 params[:back_url] || request.env['HTTP_REFERER'] | |
219 end | 239 end |
220 | 240 |
221 def redirect_back_or_default(default) | 241 def redirect_back_or_default(default) |
222 back_url = CGI.unescape(params[:back_url].to_s) | 242 back_url = CGI.unescape(params[:back_url].to_s) |
223 if !back_url.blank? | 243 if !back_url.blank? |
236 end | 256 end |
237 | 257 |
238 def render_403 | 258 def render_403 |
239 @project = nil | 259 @project = nil |
240 respond_to do |format| | 260 respond_to do |format| |
241 format.html { render :template => "common/403", :layout => (request.xhr? ? false : 'base'), :status => 403 } | 261 format.html { render :template => "common/403", :layout => use_layout, :status => 403 } |
242 format.atom { head 403 } | 262 format.atom { head 403 } |
243 format.xml { head 403 } | 263 format.xml { head 403 } |
244 format.js { head 403 } | 264 format.js { head 403 } |
245 format.json { head 403 } | 265 format.json { head 403 } |
246 end | 266 end |
247 return false | 267 return false |
248 end | 268 end |
249 | 269 |
250 def render_404 | 270 def render_404 |
251 respond_to do |format| | 271 respond_to do |format| |
252 format.html { render :template => "common/404", :layout => !request.xhr?, :status => 404 } | 272 format.html { render :template => "common/404", :layout => use_layout, :status => 404 } |
253 format.atom { head 404 } | 273 format.atom { head 404 } |
254 format.xml { head 404 } | 274 format.xml { head 404 } |
255 format.js { head 404 } | 275 format.js { head 404 } |
256 format.json { head 404 } | 276 format.json { head 404 } |
257 end | 277 end |
260 | 280 |
261 def render_error(msg) | 281 def render_error(msg) |
262 respond_to do |format| | 282 respond_to do |format| |
263 format.html { | 283 format.html { |
264 flash.now[:error] = msg | 284 flash.now[:error] = msg |
265 render :text => '', :layout => !request.xhr?, :status => 500 | 285 render :text => '', :layout => use_layout, :status => 500 |
266 } | 286 } |
267 format.atom { head 500 } | 287 format.atom { head 500 } |
268 format.xml { head 500 } | 288 format.xml { head 500 } |
269 format.js { head 500 } | 289 format.js { head 500 } |
270 format.json { head 500 } | 290 format.json { head 500 } |
271 end | 291 end |
292 end | |
293 | |
294 # Picks which layout to use based on the request | |
295 # | |
296 # @return [boolean, string] name of the layout to use or false for no layout | |
297 def use_layout | |
298 request.xhr? ? false : 'base' | |
272 end | 299 end |
273 | 300 |
274 def invalid_authenticity_token | 301 def invalid_authenticity_token |
275 if api_request? | 302 if api_request? |
276 logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)." | 303 logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)." |
343 # Renders a warning flash if obj has unsaved attachments | 370 # Renders a warning flash if obj has unsaved attachments |
344 def render_attachment_warning_if_needed(obj) | 371 def render_attachment_warning_if_needed(obj) |
345 flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present? | 372 flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present? |
346 end | 373 end |
347 | 374 |
375 # Sets the `flash` notice or error based the number of issues that did not save | |
376 # | |
377 # @param [Array, Issue] issues all of the saved and unsaved Issues | |
378 # @param [Array, Integer] unsaved_issue_ids the issue ids that were not saved | |
379 def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids) | |
380 if unsaved_issue_ids.empty? | |
381 flash[:notice] = l(:notice_successful_update) unless issues.empty? | |
382 else | |
383 flash[:error] = l(:notice_failed_to_save_issues, | |
384 :count => unsaved_issue_ids.size, | |
385 :total => issues.size, | |
386 :ids => '#' + unsaved_issue_ids.join(', #')) | |
387 end | |
388 end | |
389 | |
348 # Rescues an invalid query statement. Just in case... | 390 # Rescues an invalid query statement. Just in case... |
349 def query_statement_invalid(exception) | 391 def query_statement_invalid(exception) |
350 logger.error "Query::StatementInvalid: #{exception.message}" if logger | 392 logger.error "Query::StatementInvalid: #{exception.message}" if logger |
351 session.delete(:query) | 393 session.delete(:query) |
352 sort_clear if respond_to?(:sort_clear) | 394 sort_clear if respond_to?(:sort_clear) |