From bf7476af5b6b2ec70e20254c8f2fe346ca22c089 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 8 Sep 2010 16:01:51 +0000 Subject: [PATCH] Refactor: split method ProjectsController#edit to ProjectsController#update. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4070 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/projects_controller.rb | 48 +++++++++++---------- app/views/projects/_edit.rhtml | 2 +- config/routes.rb | 5 ++- lib/redmine.rb | 2 +- test/functional/projects_controller_test.rb | 4 +- test/integration/routing_test.rb | 4 +- 6 files changed, 34 insertions(+), 31 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 376034097..f16349329 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -25,13 +25,16 @@ class ProjectsController < ApplicationController before_filter :authorize_global, :only => [:new, :create] before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ] accept_key_auth :index - - after_filter :only => [:create, :edit, :archive, :unarchive, :destroy] do |controller| + + after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller| if controller.request.post? controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt' end end - + + # TODO: convert to PUT only + verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed } + helper :sort include SortHelper helper :custom_fields @@ -179,28 +182,27 @@ class ProjectsController < ApplicationController @wiki ||= @project.wiki end - # Edit @project def edit - if request.get? + end + + def update + @project.attributes = params[:project] + if validate_parent_id && @project.save + @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_to :action => 'settings', :id => @project + } + format.xml { head :ok } + end else - @project.attributes = params[:project] - if validate_parent_id && @project.save - @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') - respond_to do |format| - format.html { - flash[:notice] = l(:notice_successful_update) - redirect_to :action => 'settings', :id => @project - } - format.xml { head :ok } - end - else - respond_to do |format| - format.html { - settings - render :action => 'settings' - } - format.xml { render :xml => @project.errors, :status => :unprocessable_entity } - end + respond_to do |format| + format.html { + settings + render :action => 'settings' + } + format.xml { render :xml => @project.errors, :status => :unprocessable_entity } end end end diff --git a/app/views/projects/_edit.rhtml b/app/views/projects/_edit.rhtml index b7c2987d2..dc667f267 100644 --- a/app/views/projects/_edit.rhtml +++ b/app/views/projects/_edit.rhtml @@ -1,4 +1,4 @@ -<% labelled_tabular_form_for :project, @project, :url => { :action => "edit", :id => @project } do |f| %> +<% labelled_tabular_form_for :project, @project, :url => { :action => "update", :id => @project } do |f| %> <%= render :partial => 'form', :locals => { :f => f } %> <%= submit_tag l(:button_save) %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 7f971da7c..01d6a5062 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -198,13 +198,14 @@ ActionController::Routing::Routes.draw do |map| project_actions.connect 'projects/new', :action => 'create' project_actions.connect 'projects', :action => 'create' project_actions.connect 'projects.:format', :action => 'create', :format => /xml/ - project_actions.connect 'projects/:id/:action', :action => /edit|destroy|archive|unarchive/ + project_actions.connect 'projects/:id/edit', :action => 'update' + project_actions.connect 'projects/:id/:action', :action => /destroy|archive|unarchive/ project_actions.connect 'projects/:id/files/new', :controller => 'files', :action => 'new' project_actions.connect 'projects/:id/activities/save', :controller => 'project_enumerations', :action => 'save' end projects.with_options :conditions => {:method => :put} do |project_actions| - project_actions.conditions 'projects/:id.:format', :action => 'edit', :format => /xml/ + project_actions.conditions 'projects/:id.:format', :action => 'update', :format => /xml/ end projects.with_options :conditions => {:method => :delete} do |project_actions| diff --git a/lib/redmine.rb b/lib/redmine.rb index dcddeb902..534f85875 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -47,7 +47,7 @@ Redmine::AccessControl.map do |map| map.permission :view_project, {:projects => [:show], :activities => [:index]}, :public => true map.permission :search_project, {:search => :index}, :public => true map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin - map.permission :edit_project, {:projects => [:settings, :edit]}, :require => :member + map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member map.permission :select_project_modules, {:projects => :modules}, :require => :member map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member]}, :require => :member map.permission :manage_versions, {:projects => :settings, :versions => [:new, :edit, :close_completed, :destroy]}, :require => :member diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index e661ca29e..636cb1751 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -318,9 +318,9 @@ class ProjectsControllerTest < ActionController::TestCase assert_template 'settings' end - def test_edit + def test_update @request.session[:user_id] = 2 # manager - post :edit, :id => 1, :project => {:name => 'Test changed name', + post :update, :id => 1, :project => {:name => 'Test changed name', :issue_custom_field_ids => ['']} assert_redirected_to 'projects/ecookbook/settings' project = Project.find(1) diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb index f43dc8a61..0db45ce02 100644 --- a/test/integration/routing_test.rb +++ b/test/integration/routing_test.rb @@ -180,14 +180,14 @@ class RoutingTest < ActionController::IntegrationTest should_route :post, "/projects/new", :controller => 'projects', :action => 'create' should_route :post, "/projects.xml", :controller => 'projects', :action => 'create', :format => 'xml' - should_route :post, "/projects/4223/edit", :controller => 'projects', :action => 'edit', :id => '4223' + should_route :post, "/projects/4223/edit", :controller => 'projects', :action => 'update', :id => '4223' should_route :post, "/projects/64/destroy", :controller => 'projects', :action => 'destroy', :id => '64' should_route :post, "/projects/33/files/new", :controller => 'files', :action => 'new', :id => '33' should_route :post, "/projects/64/archive", :controller => 'projects', :action => 'archive', :id => '64' should_route :post, "/projects/64/unarchive", :controller => 'projects', :action => 'unarchive', :id => '64' should_route :post, "/projects/64/activities/save", :controller => 'project_enumerations', :action => 'save', :id => '64' - should_route :put, "/projects/1.xml", :controller => 'projects', :action => 'edit', :id => '1', :format => 'xml' + should_route :put, "/projects/1.xml", :controller => 'projects', :action => 'update', :id => '1', :format => 'xml' should_route :delete, "/projects/1.xml", :controller => 'projects', :action => 'destroy', :id => '1', :format => 'xml' should_route :delete, "/projects/64/reset_activities", :controller => 'project_enumerations', :action => 'destroy', :id => '64' -- 2.39.5