Skip to content

Commit

Permalink
Refactor: Pull up #find_optional_project to ApplicationController.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3716 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
edavis10 committed Apr 30, 2010
1 parent f65c47e commit 306ca5e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -168,6 +168,16 @@ def find_project
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?
Expand Down
11 changes: 0 additions & 11 deletions app/controllers/gantts_controller.rb
Expand Up @@ -42,15 +42,4 @@ def show
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
8 changes: 0 additions & 8 deletions app/controllers/issues_controller.rb
Expand Up @@ -445,14 +445,6 @@ def find_project
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
Expand Down

0 comments on commit 306ca5e

Please sign in to comment.