From 729bea1cf38ed80bc34c47a8ef3783d9e06ce5c5 Mon Sep 17 00:00:00 2001
From: Jean-Philippe Lang
Date: Sat, 6 Mar 2010 18:25:01 +0000
Subject: [PATCH] Moves ProjectsController#add_version to
VersionsController#new.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3548 e93f8b46-1217-0410-a6f0-8f06a7374b81
---
app/controllers/projects_controller.rb | 33 -----------------
app/controllers/versions_controller.rb | 36 +++++++++++++++++--
app/views/issues/_attributes.rhtml | 4 +--
app/views/projects/settings/_versions.rhtml | 2 +-
.../new.html.erb} | 2 +-
config/routes.rb | 3 +-
lib/redmine.rb | 2 +-
test/functional/projects_controller_test.rb | 35 ------------------
test/functional/versions_controller_test.rb | 34 ++++++++++++++++++
9 files changed, 74 insertions(+), 77 deletions(-)
rename app/views/{projects/add_version.rhtml => versions/new.html.erb} (86%)
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index a8ab59bd..f0099468 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -266,39 +266,6 @@ class ProjectsController < ApplicationController
end
end
end
-
- # Add a new version to @project
- def add_version
- @version = @project.versions.build
- if params[:version]
- attributes = params[:version].dup
- attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
- @version.attributes = attributes
- end
- if request.post?
- if @version.save
- respond_to do |format|
- format.html do
- flash[:notice] = l(:notice_successful_create)
- redirect_to :action => 'settings', :tab => 'versions', :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_fixed_version_id",
- content_tag('select', '' + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]')
- }
- end
- end
- else
- respond_to do |format|
- format.html
- format.js do
- render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) }
- end
- end
- end
- end
- end
def add_file
if request.post?
diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb
index 69b253c6..0ea440e1 100644
--- a/app/controllers/versions_controller.rb
+++ b/app/controllers/versions_controller.rb
@@ -17,8 +17,8 @@
class VersionsController < ApplicationController
menu_item :roadmap
- before_filter :find_version, :except => :close_completed
- before_filter :find_project, :only => :close_completed
+ before_filter :find_version, :except => [:new, :close_completed]
+ before_filter :find_project, :only => [:new, :close_completed]
before_filter :authorize
helper :custom_fields
@@ -27,6 +27,38 @@ class VersionsController < ApplicationController
def show
end
+ def new
+ @version = @project.versions.build
+ if params[:version]
+ attributes = params[:version].dup
+ attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
+ @version.attributes = attributes
+ end
+ if request.post?
+ if @version.save
+ respond_to do |format|
+ format.html do
+ flash[:notice] = l(:notice_successful_create)
+ redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :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_fixed_version_id",
+ content_tag('select', '' + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]')
+ }
+ end
+ end
+ else
+ respond_to do |format|
+ format.html
+ format.js do
+ render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) }
+ end
+ end
+ end
+ end
+ end
+
def edit
if request.post? && params[:version]
attributes = params[:version].dup
diff --git a/app/views/issues/_attributes.rhtml b/app/views/issues/_attributes.rhtml
index f8fc8d67..2f0d3edf 100644
--- a/app/views/issues/_attributes.rhtml
+++ b/app/views/issues/_attributes.rhtml
@@ -23,9 +23,9 @@
<%= prompt_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'),
l(:label_version_new),
'version[name]',
- {:controller => 'projects', :action => 'add_version', :id => @project},
+ {:controller => 'versions', :action => 'new', :project_id => @project},
:title => l(:label_version_new),
- :tabindex => 200) if authorize_for('projects', 'add_version') %>
+ :tabindex => 200) if authorize_for('versions', 'new') %>
<% end %>
diff --git a/app/views/projects/settings/_versions.rhtml b/app/views/projects/settings/_versions.rhtml
index 8fcf11d1..77dad270 100644
--- a/app/views/projects/settings/_versions.rhtml
+++ b/app/views/projects/settings/_versions.rhtml
@@ -38,4 +38,4 @@
<% end %>
-<%= link_to_if_authorized l(:label_version_new), :controller => 'projects', :action => 'add_version', :id => @project %>
+<%= link_to_if_authorized l(:label_version_new), :controller => 'versions', :action => 'new', :project_id => @project %>
diff --git a/app/views/projects/add_version.rhtml b/app/views/versions/new.html.erb
similarity index 86%
rename from app/views/projects/add_version.rhtml
rename to app/views/versions/new.html.erb
index c038b7de..a7ef03e7 100644
--- a/app/views/projects/add_version.rhtml
+++ b/app/views/versions/new.html.erb
@@ -1,6 +1,6 @@
<%=l(:label_version_new)%>
-<% labelled_tabular_form_for :version, @version, :url => { :action => 'add_version' } do |f| %>
+<% labelled_tabular_form_for :version, @version, :url => { :action => 'new' } do |f| %>
<%= render :partial => 'versions/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<% end %>
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index e3707b64..1149942c 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/versions/new', :action => 'add_version'
project_views.connect 'projects/:id/categories/new', :action => 'add_issue_category'
project_views.connect 'projects/:id/settings/:tab', :action => 'settings'
end
@@ -209,7 +208,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/versions/new', :action => 'add_version'
project_actions.connect 'projects/:id/categories/new', :action => 'add_issue_category'
project_actions.connect 'projects/:id/activities/save', :action => 'save_activities'
end
@@ -225,6 +223,7 @@ ActionController::Routing::Routes.draw do |map|
end
map.with_options :controller => 'versions' do |versions|
+ versions.connect 'projects/:project_id/versions/new', :action => 'new'
versions.with_options :conditions => {:method => :post} do |version_actions|
version_actions.connect 'projects/:project_id/versions/close_completed', :action => 'close_completed'
end
diff --git a/lib/redmine.rb b/lib/redmine.rb
index 8b915450..a8b23986 100644
--- a/lib/redmine.rb
+++ b/lib/redmine.rb
@@ -39,7 +39,7 @@ Redmine::AccessControl.map do |map|
map.permission :edit_project, {:projects => [:settings, :edit]}, :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, :add_version], :versions => [:edit, :close_completed, :destroy]}, :require => :member
+ map.permission :manage_versions, {:projects => :settings, :versions => [:new, :edit, :close_completed, :destroy]}, :require => :member
map.permission :add_subprojects, {:projects => :add}, :require => :member
map.project_module :issue_tracking do |map|
diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb
index 6de55d1b..f4fe8dae 100644
--- a/test/functional/projects_controller_test.rb
+++ b/test/functional/projects_controller_test.rb
@@ -329,41 +329,6 @@ class ProjectsControllerTest < ActionController::TestCase
assert_equal 'Test changed name', project.name
end
- def test_add_version_routing
- assert_routing(
- {:method => :get, :path => 'projects/64/versions/new'},
- :controller => 'projects', :action => 'add_version', :id => '64'
- )
- assert_routing(
- #TODO: use PUT
- {:method => :post, :path => 'projects/64/versions/new'},
- :controller => 'projects', :action => 'add_version', :id => '64'
- )
- end
-
- def test_add_version
- @request.session[:user_id] = 2 # manager
- assert_difference 'Version.count' do
- post :add_version, :id => '1', :version => {:name => 'test_add_version'}
- end
- assert_redirected_to '/projects/ecookbook/settings/versions'
- version = Version.find_by_name('test_add_version')
- assert_not_nil version
- assert_equal 1, version.project_id
- end
-
- def test_add_version_from_issue_form
- @request.session[:user_id] = 2 # manager
- assert_difference 'Version.count' do
- xhr :post, :add_version, :id => '1', :version => {:name => 'test_add_version_from_issue_form'}
- end
- assert_response :success
- assert_select_rjs :replace, 'issue_fixed_version_id'
- version = Version.find_by_name('test_add_version_from_issue_form')
- assert_not_nil version
- assert_equal 1, version.project_id
- end
-
def test_add_issue_category_routing
assert_routing(
{:method => :get, :path => 'projects/test/categories/new'},
diff --git a/test/functional/versions_controller_test.rb b/test/functional/versions_controller_test.rb
index ebac584c..46a5db91 100644
--- a/test/functional/versions_controller_test.rb
+++ b/test/functional/versions_controller_test.rb
@@ -40,6 +40,40 @@ class VersionsControllerTest < ActionController::TestCase
assert_tag :tag => 'h2', :content => /1.0/
end
+ def test_new_routing
+ assert_routing(
+ {:method => :get, :path => 'projects/foo/versions/new'},
+ :controller => 'versions', :action => 'new', :project_id => 'foo'
+ )
+ assert_routing(
+ {:method => :post, :path => 'projects/foo/versions/new'},
+ :controller => 'versions', :action => 'new', :project_id => 'foo'
+ )
+ end
+
+ def test_new
+ @request.session[:user_id] = 2 # manager
+ assert_difference 'Version.count' do
+ post :new, :project_id => '1', :version => {:name => 'test_add_version'}
+ end
+ assert_redirected_to '/projects/ecookbook/settings/versions'
+ version = Version.find_by_name('test_add_version')
+ assert_not_nil version
+ assert_equal 1, version.project_id
+ end
+
+ def test_new_from_issue_form
+ @request.session[:user_id] = 2 # manager
+ assert_difference 'Version.count' do
+ xhr :post, :new, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}
+ end
+ assert_response :success
+ assert_select_rjs :replace, 'issue_fixed_version_id'
+ version = Version.find_by_name('test_add_version_from_issue_form')
+ assert_not_nil version
+ assert_equal 1, version.project_id
+ end
+
def test_get_edit
@request.session[:user_id] = 2
get :edit, :id => 2