diff options
-rw-r--r-- | app/controllers/issue_categories_controller.rb | 58 | ||||
-rw-r--r-- | app/views/issue_categories/destroy.html.erb | 2 | ||||
-rw-r--r-- | app/views/issue_categories/edit.html.erb | 2 | ||||
-rw-r--r-- | app/views/issue_categories/new.html.erb | 2 | ||||
-rw-r--r-- | app/views/issues/_attributes.html.erb | 2 | ||||
-rw-r--r-- | app/views/projects/settings/_issue_categories.html.erb | 8 | ||||
-rw-r--r-- | config/routes.rb | 5 | ||||
-rw-r--r-- | lib/redmine.rb | 2 | ||||
-rw-r--r-- | test/functional/issue_categories_controller_test.rb | 42 |
9 files changed, 75 insertions, 48 deletions
diff --git a/app/controllers/issue_categories_controller.rb b/app/controllers/issue_categories_controller.rb index 59e69ad98..b0d11dd8f 100644 --- a/app/controllers/issue_categories_controller.rb +++ b/app/controllers/issue_categories_controller.rb @@ -18,47 +18,55 @@ class IssueCategoriesController < ApplicationController menu_item :settings model_object IssueCategory - before_filter :find_model_object, :except => :new - before_filter :find_project_from_association, :except => :new - before_filter :find_project, :only => :new + before_filter :find_model_object, :except => [:new, :create] + before_filter :find_project_from_association, :except => [:new, :create] + before_filter :find_project, :only => [:new, :create] before_filter :authorize - verify :method => :post, :only => :destroy - def new @category = @project.issue_categories.build(params[:category]) - if request.post? - if @category.save - respond_to do |format| - format.html do - flash[:notice] = l(:notice_successful_create) - redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project - end - format.js do - # IE doesn't support the replace_html rjs method for select box options - render(:update) {|page| page.replace "issue_category_id", - content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]') - } - end + end + + verify :method => :post, :only => :create + def create + @category = @project.issue_categories.build(params[:category]) + if @category.save + respond_to do |format| + format.html do + flash[:notice] = l(:notice_successful_create) + redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project end - else - respond_to do |format| - format.html - format.js do - render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) } - end + format.js do + # IE doesn't support the replace_html rjs method for select box options + render(:update) {|page| page.replace "issue_category_id", + content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]') + } + end + end + else + respond_to do |format| + format.html { render :action => 'new'} + format.js do + render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) } end end end end def edit - if request.post? and @category.update_attributes(params[:category]) + end + + verify :method => :put, :only => :update + def update + if @category.update_attributes(params[:category]) flash[:notice] = l(:notice_successful_update) redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project + else + render :action => 'edit' end end + verify :method => :delete, :only => :destroy def destroy @issue_count = @category.issues.size if @issue_count == 0 diff --git a/app/views/issue_categories/destroy.html.erb b/app/views/issue_categories/destroy.html.erb index fb169c868..882a75e4a 100644 --- a/app/views/issue_categories/destroy.html.erb +++ b/app/views/issue_categories/destroy.html.erb @@ -1,6 +1,6 @@ <h2><%=l(:label_issue_category)%>: <%=h @category.name %></h2> -<% form_tag({}) do %> +<% form_tag(issue_category_path(@category), :method => :delete) do %> <div class="box"> <p><strong><%= l(:text_issue_category_destroy_question, @issue_count) %></strong></p> <p><label><%= radio_button_tag 'todo', 'nullify', true %> <%= l(:text_issue_category_destroy_assignments) %></label><br /> diff --git a/app/views/issue_categories/edit.html.erb b/app/views/issue_categories/edit.html.erb index bc627797b..1e1a8fe7d 100644 --- a/app/views/issue_categories/edit.html.erb +++ b/app/views/issue_categories/edit.html.erb @@ -1,6 +1,6 @@ <h2><%=l(:label_issue_category)%></h2> -<% labelled_tabular_form_for :category, @category, :url => { :action => 'edit', :id => @category } do |f| %> +<% labelled_tabular_form_for :category, @category, :url => issue_category_path(@category), :html => {:method => :put} do |f| %> <%= render :partial => 'issue_categories/form', :locals => { :f => f } %> <%= submit_tag l(:button_save) %> <% end %> diff --git a/app/views/issue_categories/new.html.erb b/app/views/issue_categories/new.html.erb index ac7936a41..ccd88c5cd 100644 --- a/app/views/issue_categories/new.html.erb +++ b/app/views/issue_categories/new.html.erb @@ -1,6 +1,6 @@ <h2><%=l(:label_issue_category_new)%></h2> -<% labelled_tabular_form_for :category, @category, :url => { :action => 'new' } do |f| %> +<% labelled_tabular_form_for :category, @category, :url => project_issue_categories_path(@project) do |f| %> <%= render :partial => 'issue_categories/form', :locals => { :f => f } %> <%= submit_tag l(:button_create) %> <% end %> diff --git a/app/views/issues/_attributes.html.erb b/app/views/issues/_attributes.html.erb index 02aba7c79..d9d851c49 100644 --- a/app/views/issues/_attributes.html.erb +++ b/app/views/issues/_attributes.html.erb @@ -14,7 +14,7 @@ <%= prompt_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'), l(:label_issue_category_new), 'category[name]', - {:controller => 'issue_categories', :action => 'new', :project_id => @project}, + {:controller => 'issue_categories', :action => 'create', :project_id => @project}, :title => l(:label_issue_category_new), :tabindex => 199) if authorize_for('issue_categories', 'new') %></p> <% end %> diff --git a/app/views/projects/settings/_issue_categories.html.erb b/app/views/projects/settings/_issue_categories.html.erb index 4c9df908f..297d31a72 100644 --- a/app/views/projects/settings/_issue_categories.html.erb +++ b/app/views/projects/settings/_issue_categories.html.erb @@ -12,8 +12,10 @@ <td><%=h(category.name) %></td> <td><%=h(category.assigned_to.name) if category.assigned_to %></td> <td class="buttons"> - <%= link_to_if_authorized l(:button_edit), { :controller => 'issue_categories', :action => 'edit', :id => category }, :class => 'icon icon-edit' %> - <%= link_to_if_authorized l(:button_delete), {:controller => 'issue_categories', :action => 'destroy', :id => category}, :method => :post, :class => 'icon icon-del' %> + <% if User.current.allowed_to?(:manage_categories, @project) %> + <%= link_to l(:button_edit), edit_issue_category_path(category), :class => 'icon icon-edit' %> + <%= link_to l(:button_delete), issue_category_path(category), :confirm => l(:text_are_you_sure), :method => :delete, :class => 'icon icon-del' %> + <% end %> </td> </tr> <% end %> @@ -24,4 +26,4 @@ <p class="nodata"><%= l(:label_no_data) %></p> <% end %> -<p><%= link_to_if_authorized l(:label_issue_category_new), :controller => 'issue_categories', :action => 'new', :project_id => @project %></p> +<p><%= link_to l(:label_issue_category_new), new_project_issue_category_path(@project) if User.current.allowed_to?(:manage_categories, @project) %></p> diff --git a/config/routes.rb b/config/routes.rb index 7106be9d5..8d5735cff 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -157,6 +157,7 @@ ActionController::Routing::Routes.draw do |map| project.resources :news, :shallow => true project.resources :time_entries, :controller => 'timelog', :path_prefix => 'projects/:project_id' project.resources :queries, :only => [:new, :create] + project.resources :issue_categories, :shallow => true project.wiki_start_page 'wiki', :controller => 'wiki', :action => 'show', :conditions => {:method => :get} project.wiki_index 'wiki/index', :controller => 'wiki', :action => 'index', :conditions => {:method => :get} @@ -194,10 +195,6 @@ ActionController::Routing::Routes.draw do |map| activity.connect 'activity.:format', :id => nil end - map.with_options :controller => 'issue_categories' do |categories| - categories.connect 'projects/:project_id/issue_categories/new', :action => 'new' - end - map.with_options :controller => 'repositories' do |repositories| repositories.with_options :conditions => {:method => :get} do |repository_views| repository_views.connect 'projects/:id/repository', :action => 'show' diff --git a/lib/redmine.rb b/lib/redmine.rb index 98048edde..746b623ec 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -58,7 +58,7 @@ Redmine::AccessControl.map do |map| map.project_module :issue_tracking do |map| # Issue categories - map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :edit, :destroy]}, :require => :member + map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :create, :edit, :update, :destroy]}, :require => :member # Issues map.permission :view_issues, {:issues => [:index, :show], :auto_complete => [:issues], diff --git a/test/functional/issue_categories_controller_test.rb b/test/functional/issue_categories_controller_test.rb index 07f53980b..c9dbbe1f8 100644 --- a/test/functional/issue_categories_controller_test.rb +++ b/test/functional/issue_categories_controller_test.rb @@ -32,17 +32,17 @@ class IssueCategoriesControllerTest < ActionController::TestCase @request.session[:user_id] = 2 end - def test_get_new + def test_new @request.session[:user_id] = 2 # manager get :new, :project_id => '1' assert_response :success assert_template 'new' end - def test_post_new + def test_create @request.session[:user_id] = 2 # manager assert_difference 'IssueCategory.count' do - post :new, :project_id => '1', :category => {:name => 'New category'} + post :create, :project_id => '1', :category => {:name => 'New category'} end assert_redirected_to '/projects/ecookbook/settings/categories' category = IssueCategory.find_by_name('New category') @@ -50,27 +50,47 @@ class IssueCategoriesControllerTest < ActionController::TestCase assert_equal 1, category.project_id end - def test_post_edit + def test_create_failure + @request.session[:user_id] = 2 + post :create, :project_id => '1', :category => {:name => ''} + assert_response :success + assert_template 'new' + end + + def test_edit + @request.session[:user_id] = 2 + get :edit, :id => 2 + assert_response :success + assert_template 'edit' + end + + def test_update assert_no_difference 'IssueCategory.count' do - post :edit, :id => 2, :category => { :name => 'Testing' } + put :update, :id => 2, :category => { :name => 'Testing' } end assert_redirected_to '/projects/ecookbook/settings/categories' assert_equal 'Testing', IssueCategory.find(2).name end - def test_edit_not_found - post :edit, :id => 97, :category => { :name => 'Testing' } + def test_update_failure + put :update, :id => 2, :category => { :name => '' } + assert_response :success + assert_template 'edit' + end + + def test_update_not_found + put :update, :id => 97, :category => { :name => 'Testing' } assert_response 404 end def test_destroy_category_not_in_use - post :destroy, :id => 2 + delete :destroy, :id => 2 assert_redirected_to '/projects/ecookbook/settings/categories' assert_nil IssueCategory.find_by_id(2) end def test_destroy_category_in_use - post :destroy, :id => 1 + delete :destroy, :id => 1 assert_response :success assert_template 'destroy' assert_not_nil IssueCategory.find_by_id(1) @@ -78,7 +98,7 @@ class IssueCategoriesControllerTest < ActionController::TestCase def test_destroy_category_in_use_with_reassignment issue = Issue.find(:first, :conditions => {:category_id => 1}) - post :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2 + delete :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2 assert_redirected_to '/projects/ecookbook/settings/categories' assert_nil IssueCategory.find_by_id(1) # check that the issue was reassign @@ -87,7 +107,7 @@ class IssueCategoriesControllerTest < ActionController::TestCase def test_destroy_category_in_use_without_reassignment issue = Issue.find(:first, :conditions => {:category_id => 1}) - post :destroy, :id => 1, :todo => 'nullify' + delete :destroy, :id => 1, :todo => 'nullify' assert_redirected_to '/projects/ecookbook/settings/categories' assert_nil IssueCategory.find_by_id(1) # check that the issue category was nullified |