From: Jean-Philippe Lang Date: Tue, 22 Nov 2011 22:04:07 +0000 (+0000) Subject: Resourcified issue statuses. X-Git-Tag: 1.3.0~122 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=68f3e91bd7030c7ac0a33bb0bfa36b30a3645d32;p=redmine.git Resourcified issue statuses. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7890 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/issue_statuses_controller.rb b/app/controllers/issue_statuses_controller.rb index 1f747a4f3..8364074d4 100644 --- a/app/controllers/issue_statuses_controller.rb +++ b/app/controllers/issue_statuses_controller.rb @@ -22,9 +22,6 @@ class IssueStatusesController < ApplicationController before_filter :require_admin_or_api_request, :only => :index accept_api_auth :index - verify :method => :post, :only => [ :destroy, :create, :update, :move, :update_issue_done_ratio ], - :redirect_to => { :action => :index } - def index respond_to do |format| format.html { @@ -43,7 +40,7 @@ class IssueStatusesController < ApplicationController def create @issue_status = IssueStatus.new(params[:issue_status]) - if @issue_status.save + if request.post? && @issue_status.save flash[:notice] = l(:notice_successful_create) redirect_to :action => 'index' else @@ -57,7 +54,7 @@ class IssueStatusesController < ApplicationController def update @issue_status = IssueStatus.find(params[:id]) - if @issue_status.update_attributes(params[:issue_status]) + if request.put? && @issue_status.update_attributes(params[:issue_status]) flash[:notice] = l(:notice_successful_update) redirect_to :action => 'index' else @@ -65,6 +62,7 @@ class IssueStatusesController < ApplicationController end end + verify :method => :delete, :only => :destroy, :redirect_to => { :action => :index } def destroy IssueStatus.find(params[:id]).destroy redirect_to :action => 'index' @@ -74,7 +72,7 @@ class IssueStatusesController < ApplicationController end def update_issue_done_ratio - if IssueStatus.update_issue_done_ratios + if request.post? && IssueStatus.update_issue_done_ratios flash[:notice] = l(:notice_issue_done_ratios_updated) else flash[:error] = l(:error_issue_done_ratios_not_updated) diff --git a/app/views/issue_statuses/_form.html.erb b/app/views/issue_statuses/_form.html.erb index 20c333e0d..37898737c 100644 --- a/app/views/issue_statuses/_form.html.erb +++ b/app/views/issue_statuses/_form.html.erb @@ -1,22 +1,12 @@ <%= error_messages_for 'issue_status' %> -
- -

-<%= text_field 'issue_status', 'name' %>

- +
+

<%= f.text_field :name, :required => true %>

<% if Issue.use_status_for_done_ratio? %> -

-<%= select 'issue_status', :default_done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }), :include_blank => true %>

+

<%= f.select :default_done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }), :include_blank => true, :label => :field_done_ratio %>

<% end %> - -

-<%= check_box 'issue_status', 'is_closed' %>

- -

-<%= check_box 'issue_status', 'is_default' %>

+

<%= f.check_box :is_closed %>

+

<%= f.check_box :is_default %>

<%= call_hook(:view_issue_statuses_form, :issue_status => @issue_status) %> - -
diff --git a/app/views/issue_statuses/edit.html.erb b/app/views/issue_statuses/edit.html.erb index 4120ad34b..82a1a2e55 100644 --- a/app/views/issue_statuses/edit.html.erb +++ b/app/views/issue_statuses/edit.html.erb @@ -1,6 +1,6 @@ -

<%= link_to l(:label_issue_status_plural), :controller => 'issue_statuses', :action => 'index' %> » <%=h @issue_status %>

+

<%= link_to l(:label_issue_status_plural), issue_statuses_path %> » <%=h @issue_status %>

-<% form_tag({:action => 'update', :id => @issue_status}, :class => "tabular") do %> - <%= render :partial => 'form' %> +<% form_for @issue_status, :builder => TabularFormBuilder do |f| %> + <%= render :partial => 'form', :locals => {:f => f} %> <%= submit_tag l(:button_save) %> <% end %> diff --git a/app/views/issue_statuses/index.html.erb b/app/views/issue_statuses/index.html.erb index 0680016d8..430e873f2 100644 --- a/app/views/issue_statuses/index.html.erb +++ b/app/views/issue_statuses/index.html.erb @@ -1,6 +1,6 @@
-<%= link_to l(:label_issue_status_new), {:action => 'new'}, :class => 'icon icon-add' %> -<%= link_to(l(:label_update_issue_done_ratios), {:action => 'update_issue_done_ratio'}, :class => 'icon icon-multiple', :method => 'post', :confirm => l(:text_are_you_sure)) if Issue.use_status_for_done_ratio? %> +<%= link_to l(:label_issue_status_new), new_issue_status_path, :class => 'icon icon-add' %> +<%= link_to(l(:label_update_issue_done_ratios), update_issue_done_ratio_issue_statuses_path, :class => 'icon icon-multiple', :method => 'post', :confirm => l(:text_are_you_sure)) if Issue.use_status_for_done_ratio? %>

<%=l(:label_issue_status_plural)%>

@@ -19,16 +19,16 @@ <% for status in @issue_statuses %> "> - <%= link_to h(status.name), :action => 'edit', :id => status %> + <%= link_to h(status.name), edit_issue_status_path(status) %> <% if Issue.use_status_for_done_ratio? %> <%= h status.default_done_ratio %> <% end %> <%= checked_image status.is_default? %> <%= checked_image status.is_closed? %> - <%= reorder_links('issue_status', {:action => 'update', :id => status}) %> + <%= reorder_links('issue_status', {:action => 'update', :id => status}, :put) %> - <%= link_to(l(:button_delete), { :action => 'destroy', :id => status }, - :method => :post, + <%= link_to(l(:button_delete), issue_status_path(status), + :method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %> diff --git a/app/views/issue_statuses/new.html.erb b/app/views/issue_statuses/new.html.erb index bc74c8dc7..cefd493b4 100644 --- a/app/views/issue_statuses/new.html.erb +++ b/app/views/issue_statuses/new.html.erb @@ -1,6 +1,6 @@ -

<%= link_to l(:label_issue_status_plural), :controller => 'issue_statuses', :action => 'index' %> » <%=l(:label_issue_status_new)%>

+

<%= link_to l(:label_issue_status_plural), issue_statuses_path %> » <%=l(:label_issue_status_new)%>

-<% form_tag({:action => 'create'}, :class => "tabular") do %> - <%= render :partial => 'form' %> +<% form_for @issue_status, :builder => TabularFormBuilder do |f| %> + <%= render :partial => 'form', :locals => {:f => f} %> <%= submit_tag l(:button_create) %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 813399187..9d3a2175c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -223,9 +223,9 @@ ActionController::Routing::Routes.draw do |map| map.resources :groups map.resources :trackers, :except => :show + map.resources :issue_statuses, :except => :show, :collection => {:update_issue_done_ratio => :post} #left old routes at the bottom for backwards compat - map.connect 'issue_statuses.:format', :controller => 'issue_statuses', :action => 'index' map.connect 'projects/:project_id/issues/:action', :controller => 'issues' map.connect 'projects/:project_id/documents/:action', :controller => 'documents' map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards' diff --git a/test/functional/issue_statuses_controller_test.rb b/test/functional/issue_statuses_controller_test.rb index d49232605..478e14272 100644 --- a/test/functional/issue_statuses_controller_test.rb +++ b/test/functional/issue_statuses_controller_test.rb @@ -56,7 +56,7 @@ class IssueStatusesControllerTest < ActionController::TestCase end def test_update - post :update, :id => '3', :issue_status => {:name => 'Renamed status'} + put :update, :id => '3', :issue_status => {:name => 'Renamed status'} assert_redirected_to :action => 'index' status = IssueStatus.find(3) assert_equal 'Renamed status', status.name @@ -66,7 +66,7 @@ class IssueStatusesControllerTest < ActionController::TestCase Issue.delete_all("status_id = 1") assert_difference 'IssueStatus.count', -1 do - post :destroy, :id => '1' + delete :destroy, :id => '1' end assert_redirected_to :action => 'index' assert_nil IssueStatus.find_by_id(1) @@ -76,7 +76,7 @@ class IssueStatusesControllerTest < ActionController::TestCase assert_not_nil Issue.find_by_status_id(1) assert_no_difference 'IssueStatus.count' do - post :destroy, :id => '1' + delete :destroy, :id => '1' end assert_redirected_to :action => 'index' assert_not_nil IssueStatus.find_by_id(1)