Refactor: Split the find_object methods to prep for a larger refactoring.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3591 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2010-03-16 15:17:47 +00:00
parent 6b88de1234
commit e6c8760ad7
8 changed files with 24 additions and 16 deletions

View File

@ -166,7 +166,16 @@ class ApplicationController < ActionController::Base
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end
# Finds and sets @project based on @object.project
def find_project_from_association
render_404 unless @object.present?
@project = @object.project
rescue ActiveRecord::RecordNotFound
render_404
end
# make sure that the user is a member of the project (or admin) if project is private # make sure that the user is a member of the project (or admin) if project is private
# used as a before_filter for actions that do not require any particular permission on the project # used as a before_filter for actions that do not require any particular permission on the project
def check_project_privacy def check_project_privacy

View File

@ -19,6 +19,7 @@ class DocumentsController < ApplicationController
default_search_scope :documents default_search_scope :documents
before_filter :find_project, :only => [:index, :new] before_filter :find_project, :only => [:index, :new]
before_filter :find_document, :except => [:index, :new] before_filter :find_document, :except => [:index, :new]
before_filter :find_project_from_association, :except => [:index, :new]
before_filter :authorize before_filter :authorize
helper :attachments helper :attachments
@ -83,8 +84,7 @@ private
end end
def find_document def find_document
@document = Document.find(params[:id]) @document = @object = Document.find(params[:id])
@project = @document.project
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end

View File

@ -18,6 +18,7 @@
class IssueCategoriesController < ApplicationController class IssueCategoriesController < ApplicationController
menu_item :settings menu_item :settings
before_filter :find_category, :except => :new before_filter :find_category, :except => :new
before_filter :find_project_from_association, :except => :new
before_filter :find_project, :only => :new before_filter :find_project, :only => :new
before_filter :authorize before_filter :authorize
@ -73,8 +74,7 @@ class IssueCategoriesController < ApplicationController
private private
def find_category def find_category
@category = IssueCategory.find(params[:id]) @category = @object = IssueCategory.find(params[:id])
@project = @category.project
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end

View File

@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class IssueRelationsController < ApplicationController class IssueRelationsController < ApplicationController
before_filter :find_project, :authorize before_filter :find_issue, :find_project_from_association, :authorize
def new def new
@relation = IssueRelation.new(params[:relation]) @relation = IssueRelation.new(params[:relation])
@ -52,9 +52,8 @@ class IssueRelationsController < ApplicationController
end end
private private
def find_project def find_issue
@issue = Issue.find(params[:issue_id]) @issue = @object = Issue.find(params[:issue_id])
@project = @issue.project
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end

View File

@ -511,7 +511,7 @@ private
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end
# Retrieve query from session or build a new query # Retrieve query from session or build a new query
def retrieve_query def retrieve_query
if !params[:query_id].blank? if !params[:query_id].blank?

View File

@ -17,6 +17,7 @@
class MembersController < ApplicationController class MembersController < ApplicationController
before_filter :find_member, :except => [:new, :autocomplete_for_member] before_filter :find_member, :except => [:new, :autocomplete_for_member]
before_filter :find_project_from_association, :except => [:new, :autocomplete_for_member]
before_filter :find_project, :only => [:new, :autocomplete_for_member] before_filter :find_project, :only => [:new, :autocomplete_for_member]
before_filter :authorize before_filter :authorize
@ -75,8 +76,7 @@ class MembersController < ApplicationController
private private
def find_member def find_member
@member = Member.find(params[:id]) @member = @object = Member.find(params[:id])
@project = @member.project
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end

View File

@ -18,6 +18,7 @@
class NewsController < ApplicationController class NewsController < ApplicationController
default_search_scope :news default_search_scope :news
before_filter :find_news, :except => [:new, :index, :preview] before_filter :find_news, :except => [:new, :index, :preview]
before_filter :find_project_from_association, :except => [:new, :index, :preview]
before_filter :find_project, :only => [:new, :preview] before_filter :find_project, :only => [:new, :preview]
before_filter :authorize, :except => [:index, :preview] before_filter :authorize, :except => [:index, :preview]
before_filter :find_optional_project, :only => :index before_filter :find_optional_project, :only => :index
@ -89,8 +90,7 @@ class NewsController < ApplicationController
private private
def find_news def find_news
@news = News.find(params[:id]) @news = @object = News.find(params[:id])
@project = @news.project
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end

View File

@ -18,6 +18,7 @@
class VersionsController < ApplicationController class VersionsController < ApplicationController
menu_item :roadmap menu_item :roadmap
before_filter :find_version, :except => [:new, :close_completed] before_filter :find_version, :except => [:new, :close_completed]
before_filter :find_project_from_association, :except => [:new, :close_completed]
before_filter :find_project, :only => [:new, :close_completed] before_filter :find_project, :only => [:new, :close_completed]
before_filter :authorize before_filter :authorize
@ -94,8 +95,7 @@ class VersionsController < ApplicationController
private private
def find_version def find_version
@version = Version.find(params[:id]) @version = @object = Version.find(params[:id])
@project = @version.project
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end