Moves ProjectsController#add_issue_category to IssueCategoriesController#new.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3549 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
729bea1cf3
commit
6511e94233
|
@ -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', '<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
|
||||
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
|
||||
|
|
|
@ -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', '<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
|
||||
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?
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<h2><%=l(:label_issue_category_new)%></h2>
|
||||
|
||||
<% 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 %>
|
|
@ -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') %></p>
|
||||
:tabindex => 199) if authorize_for('issue_categories', 'new') %></p>
|
||||
<% end %>
|
||||
<% unless @issue.assignable_versions.empty? %>
|
||||
<p><%= f.select :fixed_version_id, version_options_for_select(@issue.assignable_versions, @issue.fixed_version), :include_blank => true %>
|
||||
|
|
|
@ -24,4 +24,4 @@
|
|||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
||||
|
||||
<p><%= link_to_if_authorized l(:label_issue_category_new), :controller => 'projects', :action => 'add_issue_category', :id => @project %></p>
|
||||
<p><%= link_to_if_authorized l(:label_issue_category_new), :controller => 'issue_categories', :action => 'new', :project_id => @project %></p>
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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],
|
||||
|
|
|
@ -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' }
|
||||
|
|
|
@ -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'},
|
||||
|
|
Loading…
Reference in New Issue