From 8f40750ad7f7ad512fd816757f072c42fae20e66 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 9 Nov 2009 18:53:12 +0000 Subject: [PATCH] Adds a link to automatically close completed versions in project settings (#1245). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3023 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/versions_controller.rb | 21 ++++++++++++++++++--- app/models/project.rb | 11 +++++++++++ app/views/projects/settings/_versions.rhtml | 6 ++++++ config/routes.rb | 6 ++++++ lib/redmine.rb | 2 +- test/functional/versions_controller_test.rb | 8 ++++++++ test/unit/project_test.rb | 11 +++++++++++ 7 files changed, 61 insertions(+), 4 deletions(-) diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index c269432f3..6513d080c 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -17,7 +17,9 @@ class VersionsController < ApplicationController menu_item :roadmap - before_filter :find_project, :authorize + before_filter :find_version, :except => :close_completed + before_filter :find_project, :only => :close_completed + before_filter :authorize def show end @@ -28,6 +30,13 @@ class VersionsController < ApplicationController redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project end end + + def close_completed + if request.post? + @project.close_completed_versions + end + redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project + end def destroy @version.destroy @@ -45,10 +54,16 @@ class VersionsController < ApplicationController end private - def find_project + def find_version @version = Version.find(params[:id]) @project = @version.project rescue ActiveRecord::RecordNotFound render_404 - end + end + + def find_project + @project = Project.find(params[:project_id]) + rescue ActiveRecord::RecordNotFound + render_404 + end end diff --git a/app/models/project.rb b/app/models/project.rb index 00aa5df6c..b97d365e5 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -304,6 +304,17 @@ class Project < ActiveRecord::Base :order => "#{Tracker.table_name}.position") end + # Closes open and locked project versions that are completed + def close_completed_versions + Version.transaction do + versions.find(:all, :conditions => {:status => %w(open locked)}).each do |version| + if version.completed? + version.update_attribute(:status, 'closed') + end + end + end + end + # Returns a hash of project users grouped by role def users_by_role members.find(:all, :include => [:user, :roles]).inject({}) do |h, m| diff --git a/app/views/projects/settings/_versions.rhtml b/app/views/projects/settings/_versions.rhtml index 95b72f178..9bca58cf7 100644 --- a/app/views/projects/settings/_versions.rhtml +++ b/app/views/projects/settings/_versions.rhtml @@ -28,4 +28,10 @@

<%= l(:label_no_data) %>

<% end %> +
+<% if @project.versions.any? %> + <%= link_to 'Close completed versions', {:controller => 'versions', :action => 'close_completed', :project_id => @project}, :method => :post %> +<% end %> +
+

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

diff --git a/config/routes.rb b/config/routes.rb index 1e340011b..21e33f501 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -208,6 +208,12 @@ ActionController::Routing::Routes.draw do |map| end end + map.with_options :controller => 'versions' do |versions| + versions.with_options :conditions => {:method => :post} do |version_actions| + version_actions.connect 'projects/:project_id/versions/close_completed', :action => 'close_completed' + end + 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 16e52619c..ebec9060b 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -31,7 +31,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, :destroy]}, :require => :member + map.permission :manage_versions, {:projects => [:settings, :add_version], :versions => [:edit, :close_completed, :destroy]}, :require => :member map.project_module :issue_tracking do |map| # Issue categories diff --git a/test/functional/versions_controller_test.rb b/test/functional/versions_controller_test.rb index 4343b887a..ebac584c4 100644 --- a/test/functional/versions_controller_test.rb +++ b/test/functional/versions_controller_test.rb @@ -47,6 +47,14 @@ class VersionsControllerTest < ActionController::TestCase assert_template 'edit' end + def test_close_completed + Version.update_all("status = 'open'") + @request.session[:user_id] = 2 + post :close_completed, :project_id => 'ecookbook' + assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' + assert_not_nil Version.find_by_status('closed') + end + def test_post_edit @request.session[:user_id] = 2 post :edit, :id => 2, diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 082a850b8..2c1d2601a 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -374,6 +374,17 @@ class ProjectTest < ActiveSupport::TestCase assert project.activities(true).include?(overridden_activity), "Inactive Project specific Activity not found" end + + def test_close_completed_versions + Version.update_all("status = 'open'") + project = Project.find(1) + assert_not_nil project.versions.detect {|v| v.completed? && v.status == 'open'} + assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} + project.close_completed_versions + project.reload + assert_nil project.versions.detect {|v| v.completed? && v.status != 'closed'} + assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} + end context "Project#copy" do setup do