Commit 6662e592 authored by jplang's avatar jplang
Browse files

Adds a link to automatically close completed versions in project settings (#1245).

git-svn-id: https://svn.redmine.org/redmine/trunk@3023 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 969907ec
......@@ -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
......@@ -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|
......
......@@ -28,4 +28,10 @@
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
<div class="contextual">
<% if @project.versions.any? %>
<%= link_to 'Close completed versions', {:controller => 'versions', :action => 'close_completed', :project_id => @project}, :method => :post %>
<% end %>
</div>
<p><%= link_to_if_authorized l(:label_version_new), :controller => 'projects', :action => 'add_version', :id => @project %></p>
......@@ -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'
......
......@@ -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
......
......@@ -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,
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment