From: Eric Davis Date: Fri, 30 Apr 2010 17:24:11 +0000 (+0000) Subject: Refactor: Pull up #find_optional_project to ApplicationController. X-Git-Tag: 1.0.0~112 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=306ca5e7145a6d382da497d059b369c8b64f9599;p=redmine.git Refactor: Pull up #find_optional_project to ApplicationController. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3716 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c0d947c8a..54339b4e9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -168,6 +168,16 @@ class ApplicationController < ActionController::Base render_404 end + # Find a project based on params[:project_id] + # TODO: some subclasses override this, see about merging their logic + def find_optional_project + @project = Project.find(params[:project_id]) unless params[:project_id].blank? + allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true) + allowed ? true : deny_access + rescue ActiveRecord::RecordNotFound + render_404 + end + # Finds and sets @project based on @object.project def find_project_from_association render_404 unless @object.present? diff --git a/app/controllers/gantts_controller.rb b/app/controllers/gantts_controller.rb index 3933577c5..bc2d6350c 100644 --- a/app/controllers/gantts_controller.rb +++ b/app/controllers/gantts_controller.rb @@ -42,15 +42,4 @@ class GanttsController < ApplicationController end end - private - - # TODO: Refactor, duplicates IssuesController - def find_optional_project - @project = Project.find(params[:project_id]) unless params[:project_id].blank? - allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true) - allowed ? true : deny_access - rescue ActiveRecord::RecordNotFound - render_404 - end - end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 9ff4bf06d..32fd83a89 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -445,14 +445,6 @@ private render_404 end - def find_optional_project - @project = Project.find(params[:project_id]) unless params[:project_id].blank? - allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true) - allowed ? true : deny_access - rescue ActiveRecord::RecordNotFound - render_404 - end - # Used by #edit and #update to set some common instance variables # from the params # TODO: Refactor, not everything in here is needed by #edit