diff --git a/app/controllers/issue_categories_controller.rb b/app/controllers/issue_categories_controller.rb index 8315d6eb..8c077cf7 100644 --- a/app/controllers/issue_categories_controller.rb +++ b/app/controllers/issue_categories_controller.rb @@ -17,10 +17,39 @@ class IssueCategoriesController < ApplicationController menu_item :settings - before_filter :find_project, :authorize + before_filter :find_category, :except => :new + before_filter :find_project, :only => :new + 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', '' + 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 + format.js do + render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) } + end + end + end + end + end + def edit if request.post? and @category.update_attributes(params[:category]) flash[:notice] = l(:notice_successful_update) @@ -43,10 +72,16 @@ class IssueCategoriesController < ApplicationController end private - def find_project + def find_category @category = IssueCategory.find(params[:id]) @project = @category.project rescue ActiveRecord::RecordNotFound render_404 end + + def find_project + @project = Project.find(params[:project_id]) + rescue ActiveRecord::RecordNotFound + render_404 + end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f0099468..ea04927c 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -238,34 +238,6 @@ class ProjectsController < ApplicationController # hide project in layout @project = nil end - - # Add a new issue category to @project - def add_issue_category - @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 :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', '' + 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 - format.js do - render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) } - end - end - end - end - end def add_file if request.post? diff --git a/app/views/projects/add_issue_category.rhtml b/app/views/issue_categories/new.html.erb similarity index 84% rename from app/views/projects/add_issue_category.rhtml rename to app/views/issue_categories/new.html.erb index 08bc6d0e..ac7936a4 100644 --- a/app/views/projects/add_issue_category.rhtml +++ b/app/views/issue_categories/new.html.erb @@ -1,6 +1,6 @@

<%=l(:label_issue_category_new)%>

-<% labelled_tabular_form_for :category, @category, :url => { :action => 'add_issue_category' } do |f| %> +<% labelled_tabular_form_for :category, @category, :url => { :action => 'new' } do |f| %> <%= render :partial => 'issue_categories/form', :locals => { :f => f } %> <%= submit_tag l(:button_create) %> <% end %> diff --git a/app/views/issues/_attributes.rhtml b/app/views/issues/_attributes.rhtml index 2f0d3edf..acbd9101 100644 --- a/app/views/issues/_attributes.rhtml +++ b/app/views/issues/_attributes.rhtml @@ -14,9 +14,9 @@ <%= prompt_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'), l(:label_issue_category_new), 'category[name]', - {:controller => 'projects', :action => 'add_issue_category', :id => @project}, + {:controller => 'issue_categories', :action => 'new', :project_id => @project}, :title => l(:label_issue_category_new), - :tabindex => 199) if authorize_for('projects', 'add_issue_category') %>

+ :tabindex => 199) if authorize_for('issue_categories', 'new') %>

<% end %> <% unless @issue.assignable_versions.empty? %>

<%= f.select :fixed_version_id, version_options_for_select(@issue.assignable_versions, @issue.fixed_version), :include_blank => true %> diff --git a/app/views/projects/settings/_issue_categories.rhtml b/app/views/projects/settings/_issue_categories.rhtml index bea576c1..52e34f4a 100644 --- a/app/views/projects/settings/_issue_categories.rhtml +++ b/app/views/projects/settings/_issue_categories.rhtml @@ -24,4 +24,4 @@

<%= l(:label_no_data) %>

<% end %> -

<%= link_to_if_authorized l(:label_issue_category_new), :controller => 'projects', :action => 'add_issue_category', :id => @project %>

+

<%= link_to_if_authorized l(:label_issue_category_new), :controller => 'issue_categories', :action => 'new', :project_id => @project %>

diff --git a/config/routes.rb b/config/routes.rb index 1149942c..8c707f2e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -191,7 +191,6 @@ ActionController::Routing::Routes.draw do |map| project_views.connect 'projects/:id/:action', :action => /roadmap|destroy|settings/ project_views.connect 'projects/:id/files', :action => 'list_files' project_views.connect 'projects/:id/files/new', :action => 'add_file' - project_views.connect 'projects/:id/categories/new', :action => 'add_issue_category' project_views.connect 'projects/:id/settings/:tab', :action => 'settings' end @@ -208,7 +207,6 @@ ActionController::Routing::Routes.draw do |map| project_actions.connect 'projects.:format', :action => 'add', :format => /xml/ project_actions.connect 'projects/:id/:action', :action => /edit|destroy|archive|unarchive/ project_actions.connect 'projects/:id/files/new', :action => 'add_file' - project_actions.connect 'projects/:id/categories/new', :action => 'add_issue_category' project_actions.connect 'projects/:id/activities/save', :action => 'save_activities' end @@ -229,6 +227,10 @@ ActionController::Routing::Routes.draw do |map| end 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 a8b23986..1205f6fa 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -44,7 +44,7 @@ Redmine::AccessControl.map do |map| map.project_module :issue_tracking do |map| # Issue categories - map.permission :manage_categories, {:projects => [:settings, :add_issue_category], :issue_categories => [:edit, :destroy]}, :require => :member + map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :edit, :destroy]}, :require => :member # Issues map.permission :view_issues, {:projects => :roadmap, :issues => [:index, :changes, :show, :context_menu], diff --git a/test/functional/issue_categories_controller_test.rb b/test/functional/issue_categories_controller_test.rb index 3d1dd069..ae5919a2 100644 --- a/test/functional/issue_categories_controller_test.rb +++ b/test/functional/issue_categories_controller_test.rb @@ -32,6 +32,35 @@ class IssueCategoriesControllerTest < ActionController::TestCase @request.session[:user_id] = 2 end + def test_new_routing + assert_routing( + {:method => :get, :path => 'projects/test/issue_categories/new'}, + :controller => 'issue_categories', :action => 'new', :project_id => 'test' + ) + assert_routing( + {:method => :post, :path => 'projects/test/issue_categories/new'}, + :controller => 'issue_categories', :action => 'new', :project_id => 'test' + ) + end + + def test_get_new + @request.session[:user_id] = 2 # manager + get :new, :project_id => '1' + assert_response :success + assert_template 'new' + end + + def test_post_new + @request.session[:user_id] = 2 # manager + assert_difference 'IssueCategory.count' do + post :new, :project_id => '1', :category => {:name => 'New category'} + end + assert_redirected_to '/projects/ecookbook/settings/categories' + category = IssueCategory.find_by_name('New category') + assert_not_nil category + assert_equal 1, category.project_id + end + def test_post_edit assert_no_difference 'IssueCategory.count' do post :edit, :id => 2, :category => { :name => 'Testing' } diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index f4fe8dae..e64602ae 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -329,18 +329,6 @@ class ProjectsControllerTest < ActionController::TestCase assert_equal 'Test changed name', project.name end - def test_add_issue_category_routing - assert_routing( - {:method => :get, :path => 'projects/test/categories/new'}, - :controller => 'projects', :action => 'add_issue_category', :id => 'test' - ) - assert_routing( - #TODO: use PUT and update form - {:method => :post, :path => 'projects/64/categories/new'}, - :controller => 'projects', :action => 'add_issue_category', :id => '64' - ) - end - def test_destroy_routing assert_routing( {:method => :get, :path => '/projects/567/destroy'},